Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 ANDROID_HARDWARE_STREAM_HAL_LOCAL_H |
| 18 | #define ANDROID_HARDWARE_STREAM_HAL_LOCAL_H |
| 19 | |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 20 | #include <media/audiohal/StreamHalInterface.h> |
Andy Hung | 953608f | 2017-06-13 15:21:49 -0700 | [diff] [blame] | 21 | #include "StreamPowerLog.h" |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | class DeviceHalLocal; |
| 26 | |
| 27 | class StreamHalLocal : public virtual StreamHalInterface |
| 28 | { |
| 29 | public: |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 30 | // Return size of input/output buffer in bytes for this stream - eg. 4800. |
| 31 | virtual status_t getBufferSize(size_t *size); |
| 32 | |
Mikhail Naganov | 560637e | 2021-03-31 22:40:13 +0000 | [diff] [blame] | 33 | // Return the base configuration of the stream: |
| 34 | // - channel mask; |
| 35 | // - format - e.g. AUDIO_FORMAT_PCM_16_BIT; |
| 36 | // - sampling rate in Hz - eg. 44100. |
| 37 | virtual status_t getAudioProperties(audio_config_base_t *configBase); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 38 | |
| 39 | // Set audio stream parameters. |
| 40 | virtual status_t setParameters(const String8& kvPairs); |
| 41 | |
| 42 | // Get audio stream parameters. |
| 43 | virtual status_t getParameters(const String8& keys, String8 *values); |
| 44 | |
| 45 | // Add or remove the effect on the stream. |
| 46 | virtual status_t addEffect(sp<EffectHalInterface> effect); |
| 47 | virtual status_t removeEffect(sp<EffectHalInterface> effect); |
| 48 | |
| 49 | // Put the audio hardware input/output into standby mode. |
| 50 | virtual status_t standby(); |
| 51 | |
Andy Hung | 542ae9b | 2021-06-16 09:37:53 -0700 | [diff] [blame^] | 52 | virtual status_t dump(int fd, const Vector<String16>& args) override; |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 53 | |
Eric Laurent | af35aad | 2016-12-15 14:25:36 -0800 | [diff] [blame] | 54 | // Start a stream operating in mmap mode. |
| 55 | virtual status_t start() = 0; |
| 56 | |
| 57 | // Stop a stream operating in mmap mode. |
| 58 | virtual status_t stop() = 0; |
| 59 | |
| 60 | // Retrieve information on the data buffer in mmap mode. |
| 61 | virtual status_t createMmapBuffer(int32_t minSizeFrames, |
| 62 | struct audio_mmap_buffer_info *info) = 0; |
| 63 | |
| 64 | // Get current read/write position in the mmap buffer |
| 65 | virtual status_t getMmapPosition(struct audio_mmap_position *position) = 0; |
| 66 | |
Mikhail Naganov | e1c4b5d | 2016-12-22 09:22:45 -0800 | [diff] [blame] | 67 | // Set the priority of the thread that interacts with the HAL |
| 68 | // (must match the priority of the audioflinger's thread that calls 'read' / 'write') |
| 69 | virtual status_t setHalThreadPriority(int priority); |
| 70 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 71 | protected: |
| 72 | // Subclasses can not be constructed directly by clients. |
| 73 | StreamHalLocal(audio_stream_t *stream, sp<DeviceHalLocal> device); |
| 74 | |
| 75 | // The destructor automatically closes the stream. |
| 76 | virtual ~StreamHalLocal(); |
| 77 | |
| 78 | sp<DeviceHalLocal> mDevice; |
| 79 | |
Andy Hung | 953608f | 2017-06-13 15:21:49 -0700 | [diff] [blame] | 80 | // mStreamPowerLog is used for audio signal power logging. |
| 81 | StreamPowerLog mStreamPowerLog; |
| 82 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 83 | private: |
| 84 | audio_stream_t *mStream; |
| 85 | }; |
| 86 | |
| 87 | class StreamOutHalLocal : public StreamOutHalInterface, public StreamHalLocal { |
| 88 | public: |
| 89 | // Return the frame size (number of bytes per sample) of a stream. |
| 90 | virtual status_t getFrameSize(size_t *size); |
| 91 | |
| 92 | // Return the audio hardware driver estimated latency in milliseconds. |
| 93 | virtual status_t getLatency(uint32_t *latency); |
| 94 | |
| 95 | // Use this method in situations where audio mixing is done in the hardware. |
| 96 | virtual status_t setVolume(float left, float right); |
| 97 | |
Mikhail Naganov | ac917ac | 2018-11-28 14:03:52 -0800 | [diff] [blame] | 98 | // Selects the audio presentation (if available). |
| 99 | virtual status_t selectPresentation(int presentationId, int programId); |
| 100 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 101 | // Write audio buffer to driver. |
| 102 | virtual status_t write(const void *buffer, size_t bytes, size_t *written); |
| 103 | |
| 104 | // Return the number of audio frames written by the audio dsp to DAC since |
| 105 | // the output has exited standby. |
| 106 | virtual status_t getRenderPosition(uint32_t *dspFrames); |
| 107 | |
| 108 | // Get the local time at which the next write to the audio driver will be presented. |
| 109 | virtual status_t getNextWriteTimestamp(int64_t *timestamp); |
| 110 | |
| 111 | // Set the callback for notifying completion of non-blocking write and drain. |
Mikhail Naganov | 15897e4 | 2016-09-30 16:16:41 -0700 | [diff] [blame] | 112 | virtual status_t setCallback(wp<StreamOutHalInterfaceCallback> callback); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 113 | |
| 114 | // Returns whether pause and resume operations are supported. |
| 115 | virtual status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume); |
| 116 | |
| 117 | // Notifies to the audio driver to resume playback following a pause. |
| 118 | virtual status_t pause(); |
| 119 | |
| 120 | // Notifies to the audio driver to resume playback following a pause. |
| 121 | virtual status_t resume(); |
| 122 | |
| 123 | // Returns whether drain operation is supported. |
| 124 | virtual status_t supportsDrain(bool *supportsDrain); |
| 125 | |
| 126 | // Requests notification when data buffered by the driver/hardware has been played. |
Mikhail Naganov | cbc8f61 | 2016-10-11 18:05:13 -0700 | [diff] [blame] | 127 | virtual status_t drain(bool earlyNotify); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 128 | |
| 129 | // Notifies to the audio driver to flush the queued data. |
| 130 | virtual status_t flush(); |
| 131 | |
| 132 | // Return a recent count of the number of audio frames presented to an external observer. |
| 133 | virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp); |
| 134 | |
Eric Laurent | af35aad | 2016-12-15 14:25:36 -0800 | [diff] [blame] | 135 | // Start a stream operating in mmap mode. |
| 136 | virtual status_t start(); |
| 137 | |
| 138 | // Stop a stream operating in mmap mode. |
| 139 | virtual status_t stop(); |
| 140 | |
| 141 | // Retrieve information on the data buffer in mmap mode. |
| 142 | virtual status_t createMmapBuffer(int32_t minSizeFrames, |
| 143 | struct audio_mmap_buffer_info *info); |
| 144 | |
| 145 | // Get current read/write position in the mmap buffer |
| 146 | virtual status_t getMmapPosition(struct audio_mmap_position *position); |
| 147 | |
Kevin Rocard | a8975a7 | 2018-03-27 10:16:52 -0700 | [diff] [blame] | 148 | // Called when the metadata of the stream's source has been changed. |
| 149 | status_t updateSourceMetadata(const SourceMetadata& sourceMetadata) override; |
| 150 | |
Kuowei Li | 3bea3a4 | 2020-08-13 14:44:25 +0800 | [diff] [blame] | 151 | // Returns the Dual Mono mode presentation setting. |
| 152 | status_t getDualMonoMode(audio_dual_mono_mode_t* mode) override; |
| 153 | |
| 154 | // Sets the Dual Mono mode presentation on the output device. |
| 155 | status_t setDualMonoMode(audio_dual_mono_mode_t mode) override; |
| 156 | |
| 157 | // Returns the Audio Description Mix level in dB. |
| 158 | status_t getAudioDescriptionMixLevel(float* leveldB) override; |
| 159 | |
| 160 | // Sets the Audio Description Mix level in dB. |
| 161 | status_t setAudioDescriptionMixLevel(float leveldB) override; |
| 162 | |
| 163 | // Retrieves current playback rate parameters. |
| 164 | status_t getPlaybackRateParameters(audio_playback_rate_t* playbackRate) override; |
| 165 | |
| 166 | // Sets the playback rate parameters that control playback behavior. |
| 167 | status_t setPlaybackRateParameters(const audio_playback_rate_t& playbackRate) override; |
| 168 | |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 169 | status_t setEventCallback(const sp<StreamOutHalInterfaceEventCallback>& callback) override; |
| 170 | |
Eric Laurent | 09a0440 | 2022-01-27 21:10:55 +0100 | [diff] [blame] | 171 | status_t setLatencyMode(audio_latency_mode_t mode __unused) override { |
| 172 | return INVALID_OPERATION; |
| 173 | } |
| 174 | status_t getRecommendedLatencyModes( |
| 175 | std::vector<audio_latency_mode_t> *modes __unused) override { |
| 176 | return INVALID_OPERATION; |
| 177 | } |
| 178 | status_t setLatencyModeCallback( |
| 179 | const sp<StreamOutHalInterfaceLatencyModeCallback>& callback __unused) override { |
| 180 | return INVALID_OPERATION; |
| 181 | } |
| 182 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 183 | private: |
| 184 | audio_stream_out_t *mStream; |
| 185 | wp<StreamOutHalInterfaceCallback> mCallback; |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 186 | wp<StreamOutHalInterfaceEventCallback> mEventCallback; |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 187 | |
| 188 | friend class DeviceHalLocal; |
| 189 | |
| 190 | // Can not be constructed directly by clients. |
| 191 | StreamOutHalLocal(audio_stream_out_t *stream, sp<DeviceHalLocal> device); |
| 192 | |
| 193 | virtual ~StreamOutHalLocal(); |
| 194 | |
| 195 | static int asyncCallback(stream_callback_event_t event, void *param, void *cookie); |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 196 | |
| 197 | static int asyncEventCallback(stream_event_callback_type_t event, void *param, void *cookie); |
Eric Laurent | 6109cdb | 2020-11-20 18:41:04 +0100 | [diff] [blame] | 198 | |
| 199 | void doUpdateSourceMetadataV7(const SourceMetadata& sourceMetadata); |
| 200 | void doUpdateSourceMetadata(const SourceMetadata& sourceMetadata); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | class StreamInHalLocal : public StreamInHalInterface, public StreamHalLocal { |
| 204 | public: |
| 205 | // Return the frame size (number of bytes per sample) of a stream. |
| 206 | virtual status_t getFrameSize(size_t *size); |
| 207 | |
| 208 | // Set the input gain for the audio driver. |
| 209 | virtual status_t setGain(float gain); |
| 210 | |
| 211 | // Read audio buffer in from driver. |
| 212 | virtual status_t read(void *buffer, size_t bytes, size_t *read); |
| 213 | |
| 214 | // Return the amount of input frames lost in the audio driver. |
| 215 | virtual status_t getInputFramesLost(uint32_t *framesLost); |
| 216 | |
| 217 | // Return a recent count of the number of audio frames received and |
| 218 | // the clock time associated with that frame count. |
| 219 | virtual status_t getCapturePosition(int64_t *frames, int64_t *time); |
| 220 | |
Eric Laurent | af35aad | 2016-12-15 14:25:36 -0800 | [diff] [blame] | 221 | // Start a stream operating in mmap mode. |
| 222 | virtual status_t start(); |
| 223 | |
| 224 | // Stop a stream operating in mmap mode. |
| 225 | virtual status_t stop(); |
| 226 | |
| 227 | // Retrieve information on the data buffer in mmap mode. |
| 228 | virtual status_t createMmapBuffer(int32_t minSizeFrames, |
| 229 | struct audio_mmap_buffer_info *info); |
| 230 | |
| 231 | // Get current read/write position in the mmap buffer |
| 232 | virtual status_t getMmapPosition(struct audio_mmap_position *position); |
| 233 | |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 234 | // Get active microphones |
| 235 | virtual status_t getActiveMicrophones(std::vector<media::MicrophoneInfo> *microphones); |
| 236 | |
Paul McLean | 03a6e6a | 2018-12-04 10:54:13 -0700 | [diff] [blame] | 237 | // Sets microphone direction (for processing) |
Paul McLean | 1234008 | 2019-03-19 09:35:05 -0600 | [diff] [blame] | 238 | virtual status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction); |
Paul McLean | 03a6e6a | 2018-12-04 10:54:13 -0700 | [diff] [blame] | 239 | |
| 240 | // Sets microphone zoom (for processing) |
Paul McLean | 1234008 | 2019-03-19 09:35:05 -0600 | [diff] [blame] | 241 | virtual status_t setPreferredMicrophoneFieldDimension(float zoom); |
Paul McLean | 03a6e6a | 2018-12-04 10:54:13 -0700 | [diff] [blame] | 242 | |
Kevin Rocard | a8975a7 | 2018-03-27 10:16:52 -0700 | [diff] [blame] | 243 | // Called when the metadata of the stream's sink has been changed. |
| 244 | status_t updateSinkMetadata(const SinkMetadata& sinkMetadata) override; |
| 245 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 246 | private: |
| 247 | audio_stream_in_t *mStream; |
| 248 | |
| 249 | friend class DeviceHalLocal; |
| 250 | |
| 251 | // Can not be constructed directly by clients. |
| 252 | StreamInHalLocal(audio_stream_in_t *stream, sp<DeviceHalLocal> device); |
| 253 | |
| 254 | virtual ~StreamInHalLocal(); |
Eric Laurent | 6109cdb | 2020-11-20 18:41:04 +0100 | [diff] [blame] | 255 | |
| 256 | void doUpdateSinkMetadata(const SinkMetadata& sinkMetadata); |
| 257 | void doUpdateSinkMetadataV7(const SinkMetadata& sinkMetadata); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 260 | } // namespace android |
| 261 | |
| 262 | #endif // ANDROID_HARDWARE_STREAM_HAL_LOCAL_H |