blob: 6ba172533253aec9ac3c78cd0a500855bfcf8878 [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 Burk0bd745e2020-10-17 18:20:01 +000022#include <android-base/thread_annotations.h>
Phil Burke72481c2017-08-08 13:20:45 -070023#include <android-base/unique_fd.h>
Phil Burkc0c70e32017-02-09 13:18:38 -080024#include <media/audiohal/StreamHalInterface.h>
25#include <media/MmapStreamCallback.h>
26#include <media/MmapStreamInterface.h>
27#include <utils/RefBase.h>
28#include <utils/String16.h>
29#include <utils/Vector.h>
30
31#include "binding/AAudioServiceMessage.h"
32#include "AAudioServiceStreamBase.h"
33#include "binding/AudioEndpointParcelable.h"
34#include "SharedMemoryProxy.h"
35#include "TimestampScheduler.h"
36#include "utility/MonotonicCounter.h"
37
38namespace aaudio {
39
Phil Burk39f02dd2017-08-04 09:13:31 -070040/**
41 * These corresponds to an EXCLUSIVE mode MMAP client stream.
42 * It has exclusive use of one AAudioServiceEndpointMMAP to communicate with the underlying
43 * device or port.
44 */
45class AAudioServiceStreamMMAP : public AAudioServiceStreamBase {
Phil Burkc0c70e32017-02-09 13:18:38 -080046
47public:
Phil Burk39f02dd2017-08-04 09:13:31 -070048 AAudioServiceStreamMMAP(android::AAudioService &aAudioService,
49 bool inService);
Phil Burk98d6d922017-07-06 11:52:45 -070050 virtual ~AAudioServiceStreamMMAP() = default;
Phil Burkc0c70e32017-02-09 13:18:38 -080051
Phil Burk39f02dd2017-08-04 09:13:31 -070052 aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080053
Phil Burk39f02dd2017-08-04 09:13:31 -070054 aaudio_result_t startClient(const android::AudioClient& client,
jiabind1f1cb62020-03-24 11:57:57 -070055 const audio_attributes_t *attr,
Phil Burk39f02dd2017-08-04 09:13:31 -070056 audio_port_handle_t *clientHandle) override;
57
58 aaudio_result_t stopClient(audio_port_handle_t clientHandle) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080059
Phil Burk19e990e2018-03-22 13:59:34 -070060 const char *getTypeText() const override { return "MMAP"; }
Phil Burkc0c70e32017-02-09 13:18:38 -080061
62protected:
63
Phil Burk7ebbc112020-05-13 15:55:17 -070064 /**
65 * Stop the flow of data so that start() can resume without loss of data.
66 *
67 * This is not guaranteed to be synchronous but it currently is.
68 * An AAUDIO_SERVICE_EVENT_PAUSED will be sent to the client when complete.
69 */
Phil Burk0bd745e2020-10-17 18:20:01 +000070 aaudio_result_t pause_l() REQUIRES(mLock) override;
Phil Burk7ebbc112020-05-13 15:55:17 -070071
Phil Burk0bd745e2020-10-17 18:20:01 +000072 aaudio_result_t stop_l() REQUIRES(mLock) override;
Phil Burk7ebbc112020-05-13 15:55:17 -070073
Phil Burk523b3042017-09-13 13:03:08 -070074 aaudio_result_t getAudioDataDescription(AudioEndpointParcelable &parcelable) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080075
76 aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) override;
Phil Burk39f02dd2017-08-04 09:13:31 -070077
78 aaudio_result_t getHardwareTimestamp(int64_t *positionFrames, int64_t *timeNanos) override;
Phil Burkc0c70e32017-02-09 13:18:38 -080079
Phil Burkbcc36742017-08-31 17:24:51 -070080 /**
81 * Device specific startup.
82 * @return AAUDIO_OK or negative error.
83 */
84 aaudio_result_t startDevice() override;
85
Phil Burkc0c70e32017-02-09 13:18:38 -080086private:
Phil Burkc0c70e32017-02-09 13:18:38 -080087
Phil Burk39f02dd2017-08-04 09:13:31 -070088 bool mInService = false;
Phil Burkc0c70e32017-02-09 13:18:38 -080089};
90
91} // namespace aaudio
92
93#endif //AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H