| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 Burk | 0bd745e | 2020-10-17 18:20:01 +0000 | [diff] [blame] | 22 | #include <android-base/thread_annotations.h> | 
| Phil Burk | e72481c | 2017-08-08 13:20:45 -0700 | [diff] [blame] | 23 | #include <android-base/unique_fd.h> | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 24 | #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 |  | 
|  | 38 | namespace aaudio { | 
|  | 39 |  | 
| Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 40 | /** | 
|  | 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 | */ | 
|  | 45 | class AAudioServiceStreamMMAP : public AAudioServiceStreamBase { | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 46 |  | 
|  | 47 | public: | 
| Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 48 | AAudioServiceStreamMMAP(android::AAudioService &aAudioService, | 
|  | 49 | bool inService); | 
| jiabin | 613e6ae | 2022-12-21 20:20:11 +0000 | [diff] [blame] | 50 | ~AAudioServiceStreamMMAP() override = default; | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 51 |  | 
| jiabin | e100132 | 2023-12-04 23:58:39 +0000 | [diff] [blame] | 52 | aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override | 
|  | 53 | EXCLUDES(mUpMessageQueueLock); | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 54 |  | 
| Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 55 | aaudio_result_t startClient(const android::AudioClient& client, | 
| jiabin | d1f1cb6 | 2020-03-24 11:57:57 -0700 | [diff] [blame] | 56 | const audio_attributes_t *attr, | 
| Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 57 | audio_port_handle_t *clientHandle) override; | 
|  | 58 |  | 
|  | 59 | aaudio_result_t stopClient(audio_port_handle_t clientHandle) override; | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 60 |  | 
| Phil Burk | 19e990e | 2018-03-22 13:59:34 -0700 | [diff] [blame] | 61 | const char *getTypeText() const override { return "MMAP"; } | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 62 |  | 
|  | 63 | protected: | 
|  | 64 |  | 
| Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 65 | /** | 
|  | 66 | * Stop the flow of data so that start() can resume without loss of data. | 
|  | 67 | * | 
|  | 68 | * This is not guaranteed to be synchronous but it currently is. | 
|  | 69 | * An AAUDIO_SERVICE_EVENT_PAUSED will be sent to the client when complete. | 
|  | 70 | */ | 
| Phil Burk | 0bd745e | 2020-10-17 18:20:01 +0000 | [diff] [blame] | 71 | aaudio_result_t pause_l() REQUIRES(mLock) override; | 
| Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 72 |  | 
| Phil Burk | 0bd745e | 2020-10-17 18:20:01 +0000 | [diff] [blame] | 73 | aaudio_result_t stop_l() REQUIRES(mLock) override; | 
| Phil Burk | 7ebbc11 | 2020-05-13 15:55:17 -0700 | [diff] [blame] | 74 |  | 
| jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 75 | aaudio_result_t standby_l() REQUIRES(mLock) override; | 
| Phil Burk | 0abd79a | 2024-06-03 23:45:14 +0000 | [diff] [blame] | 76 | bool isStandbyImplemented() override { | 
|  | 77 | return true; | 
|  | 78 | } | 
| jiabin | f7f0615 | 2021-11-22 18:10:14 +0000 | [diff] [blame] | 79 |  | 
|  | 80 | aaudio_result_t exitStandby_l(AudioEndpointParcelable* parcelable) REQUIRES(mLock) override; | 
|  | 81 |  | 
| jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 82 | aaudio_result_t getAudioDataDescription_l( | 
|  | 83 | AudioEndpointParcelable* parcelable) REQUIRES(mLock) override; | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 84 |  | 
| jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 85 | aaudio_result_t getFreeRunningPosition_l(int64_t *positionFrames, | 
|  | 86 | int64_t *timeNanos) REQUIRES(mLock) override; | 
| Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 87 |  | 
| jiabin | 2a59462 | 2021-10-14 00:32:25 +0000 | [diff] [blame] | 88 | aaudio_result_t getHardwareTimestamp_l( | 
|  | 89 | int64_t *positionFrames, int64_t *timeNanos) REQUIRES(mLock) override; | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 90 |  | 
| jiabin | fc791ee | 2023-02-15 19:43:40 +0000 | [diff] [blame] | 91 | int64_t nextDataReportTime_l() REQUIRES(mLock) override; | 
|  | 92 |  | 
|  | 93 | void reportData_l() REQUIRES(mLock) override; | 
|  | 94 |  | 
| Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 95 | /** | 
|  | 96 | * Device specific startup. | 
|  | 97 | * @return AAUDIO_OK or negative error. | 
|  | 98 | */ | 
| jiabin | b86b403 | 2024-05-23 18:03:41 +0000 | [diff] [blame] | 99 | aaudio_result_t startDevice_l() REQUIRES(mLock) override; | 
|  | 100 |  | 
|  | 101 | aaudio_result_t startClient_l(const android::AudioClient& client, | 
|  | 102 | const audio_attributes_t *attr, | 
|  | 103 | audio_port_handle_t *clientHandle) REQUIRES(mLock) override; | 
|  | 104 |  | 
|  | 105 | aaudio_result_t stopClient_l(audio_port_handle_t clientHandle) REQUIRES(mLock) override; | 
| Phil Burk | bcc3674 | 2017-08-31 17:24:51 -0700 | [diff] [blame] | 106 |  | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 107 | private: | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 108 |  | 
| Phil Burk | 39f02dd | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 109 | bool                     mInService = false; | 
| Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 110 | }; | 
|  | 111 |  | 
|  | 112 | } // namespace aaudio | 
|  | 113 |  | 
|  | 114 | #endif //AAUDIO_AAUDIO_SERVICE_STREAM_MMAP_H |