Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [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_SERVICE_ENDPOINT_MMAP_H |
| 18 | #define AAUDIO_SERVICE_ENDPOINT_MMAP_H |
| 19 | |
| 20 | #include <atomic> |
| 21 | #include <functional> |
| 22 | #include <mutex> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "client/AudioStreamInternal.h" |
| 26 | #include "client/AudioStreamInternalPlay.h" |
| 27 | #include "binding/AAudioServiceMessage.h" |
| 28 | #include "AAudioServiceEndpointShared.h" |
| 29 | #include "AAudioServiceStreamShared.h" |
| 30 | #include "AAudioServiceStreamMMAP.h" |
| 31 | #include "AAudioMixer.h" |
| 32 | #include "AAudioService.h" |
| 33 | |
| 34 | namespace aaudio { |
| 35 | |
| 36 | /** |
| 37 | * This is used by AAudioServiceStreamMMAP to access the MMAP devices |
| 38 | * through AudioFlinger. |
| 39 | */ |
| 40 | class AAudioServiceEndpointMMAP |
| 41 | : public AAudioServiceEndpoint |
| 42 | , public android::MmapStreamCallback { |
| 43 | |
| 44 | public: |
Phil Burk | bbd5286 | 2018-04-13 11:37:42 -0700 | [diff] [blame] | 45 | explicit AAudioServiceEndpointMMAP(android::AAudioService &audioService); |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 46 | |
| 47 | virtual ~AAudioServiceEndpointMMAP(); |
| 48 | |
| 49 | std::string dump() const override; |
| 50 | |
| 51 | aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override; |
| 52 | |
Phil Burk | 4719048 | 2020-08-12 14:29:10 +0000 | [diff] [blame] | 53 | void close() override; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 54 | |
| 55 | aaudio_result_t startStream(android::sp<AAudioServiceStreamBase> stream, |
| 56 | audio_port_handle_t *clientHandle) override; |
| 57 | |
| 58 | aaudio_result_t stopStream(android::sp<AAudioServiceStreamBase> stream, |
| 59 | audio_port_handle_t clientHandle) override; |
| 60 | |
| 61 | aaudio_result_t startClient(const android::AudioClient& client, |
jiabin | d1f1cb6 | 2020-03-24 11:57:57 -0700 | [diff] [blame] | 62 | const audio_attributes_t *attr, |
| 63 | audio_port_handle_t *clientHandle) override; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 64 | |
| 65 | aaudio_result_t stopClient(audio_port_handle_t clientHandle) override; |
| 66 | |
| 67 | aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) override; |
| 68 | |
| 69 | aaudio_result_t getTimestamp(int64_t *positionFrames, int64_t *timeNanos) override; |
| 70 | |
Phil Burk | a77869d | 2020-05-07 10:39:47 -0700 | [diff] [blame] | 71 | void handleTearDownAsync(audio_port_handle_t portHandle); |
| 72 | |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 73 | // -------------- Callback functions for MmapStreamCallback --------------------- |
Phil Burk | a77869d | 2020-05-07 10:39:47 -0700 | [diff] [blame] | 74 | void onTearDown(audio_port_handle_t portHandle) override; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 75 | |
| 76 | void onVolumeChanged(audio_channel_mask_t channels, |
| 77 | android::Vector<float> values) override; |
| 78 | |
Phil Burk | a77869d | 2020-05-07 10:39:47 -0700 | [diff] [blame] | 79 | void onRoutingChanged(audio_port_handle_t portHandle) override; |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 80 | // ------------------------------------------------------------------------------ |
| 81 | |
| 82 | aaudio_result_t getDownDataDescription(AudioEndpointParcelable &parcelable); |
| 83 | |
| 84 | int64_t getHardwareTimeOffsetNanos() const { |
| 85 | return mHardwareTimeOffsetNanos; |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | MonotonicCounter mFramesTransferred; |
| 90 | |
| 91 | // Interface to the AudioFlinger MMAP support. |
| 92 | android::sp<android::MmapStreamInterface> mMmapStream; |
| 93 | struct audio_mmap_buffer_info mMmapBufferinfo; |
Phil Burk | bbd5286 | 2018-04-13 11:37:42 -0700 | [diff] [blame] | 94 | |
| 95 | // There is only one port associated with an MMAP endpoint. |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 96 | audio_port_handle_t mPortHandle = AUDIO_PORT_HANDLE_NONE; |
| 97 | |
Phil Burk | bbd5286 | 2018-04-13 11:37:42 -0700 | [diff] [blame] | 98 | android::AAudioService &mAAudioService; |
| 99 | |
Phil Burk | 15f7cab | 2017-08-04 09:13:31 -0700 | [diff] [blame] | 100 | android::base::unique_fd mAudioDataFileDescriptor; |
| 101 | |
| 102 | int64_t mHardwareTimeOffsetNanos = 0; // TODO get from HAL |
| 103 | |
| 104 | }; |
| 105 | |
| 106 | } /* namespace aaudio */ |
| 107 | |
| 108 | #endif //AAUDIO_SERVICE_ENDPOINT_MMAP_H |
| 109 | |