blob: bf0aab3d802064fa9838e9d6c3dc1c8924a5622a [file] [log] [blame]
Phil Burkc0c70e32017-02-09 13:18:38 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H
18#define AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H
19
20#include <atomic>
21
Phil Burke72481c2017-08-08 13:20:45 -070022#include <android-base/unique_fd.h>
Phil Burkc0c70e32017-02-09 13:18:38 -080023#include <media/audiohal/StreamHalInterface.h>
24#include <media/MmapStreamCallback.h>
25#include <media/MmapStreamInterface.h>
26#include <utils/RefBase.h>
27#include <utils/String16.h>
28#include <utils/Vector.h>
29
30#include "binding/AAudioServiceMessage.h"
31#include "AAudioServiceStreamBase.h"
32#include "binding/AudioEndpointParcelable.h"
33#include "SharedMemoryProxy.h"
34#include "TimestampScheduler.h"
35#include "utility/MonotonicCounter.h"
36
Phil Burke72481c2017-08-08 13:20:45 -070037
Phil Burkc0c70e32017-02-09 13:18:38 -080038namespace aaudio {
39
Phil Burk39f02dd2017-08-04 09:13:31 -070040
41/**
42 * These corresponds to an EXCLUSIVE mode MMAP client stream.
43 * It has exclusive use of one AAudioServiceEndpointMMAP to communicate with the underlying
44 * device or port.
45 */
46class AAudioServiceStreamMMAP : public AAudioServiceStreamBase {
Phil Burkc0c70e32017-02-09 13:18:38 -080047
48public:
Phil Burk39f02dd2017-08-04 09:13:31 -070049 AAudioServiceStreamMMAP(android::AAudioService &aAudioService,
50 bool inService);
Phil Burk98d6d922017-07-06 11:52:45 -070051 virtual ~AAudioServiceStreamMMAP() = default;
Phil Burkc0c70e32017-02-09 13:18:38 -080052
Phil Burk39f02dd2017-08-04 09:13:31 -070053 aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080054
55 /**
56 * Start the flow of audio data.
57 *
58 * This is not guaranteed to be synchronous but it currently is.
59 * An AAUDIO_SERVICE_EVENT_STARTED will be sent to the client when complete.
60 */
61 aaudio_result_t start() override;
62
63 /**
64 * Stop the flow of data so that start() can resume without loss of data.
65 *
66 * This is not guaranteed to be synchronous but it currently is.
67 * An AAUDIO_SERVICE_EVENT_PAUSED will be sent to the client when complete.
68 */
69 aaudio_result_t pause() override;
70
Phil Burk71f35bb2017-04-13 16:05:07 -070071 aaudio_result_t stop() override;
72
Phil Burk39f02dd2017-08-04 09:13:31 -070073 aaudio_result_t startClient(const android::AudioClient& client,
74 audio_port_handle_t *clientHandle) override;
75
76 aaudio_result_t stopClient(audio_port_handle_t clientHandle) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080077
78 aaudio_result_t close() override;
79
80 /**
81 * Send a MMAP/NOIRQ buffer timestamp to the client.
82 */
Phil Burkc0c70e32017-02-09 13:18:38 -080083
84protected:
85
86 aaudio_result_t getDownDataDescription(AudioEndpointParcelable &parcelable) override;
87
88 aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) override;
Phil Burk39f02dd2017-08-04 09:13:31 -070089
90 aaudio_result_t getHardwareTimestamp(int64_t *positionFrames, int64_t *timeNanos) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080091
92private:
Phil Burkc0c70e32017-02-09 13:18:38 -080093
Phil Burk39f02dd2017-08-04 09:13:31 -070094 bool mInService = false;
Phil Burkc0c70e32017-02-09 13:18:38 -080095};
96
97} // namespace aaudio
98
99#endif //AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H