blob: b20eb0097425feff396595607171ed1857ed5f2d [file] [log] [blame]
Mikhail Naganov31d46652023-01-10 18:29:25 +00001/*
2 * Copyright (C) 2023 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#pragma once
18
Mikhail Naganov89a9f742023-01-30 12:33:18 -080019#include <atomic>
Mikhail Naganov31d46652023-01-10 18:29:25 +000020#include <memory>
Mikhail Naganov89a9f742023-01-30 12:33:18 -080021#include <mutex>
Mikhail Naganov31d46652023-01-10 18:29:25 +000022#include <string_view>
23
David Lia0ad9f02023-03-02 21:46:19 +080024#include <aidl/android/hardware/audio/common/AudioOffloadMetadata.h>
Mikhail Naganov31d46652023-01-10 18:29:25 +000025#include <aidl/android/hardware/audio/core/BpStreamCommon.h>
26#include <aidl/android/hardware/audio/core/BpStreamIn.h>
27#include <aidl/android/hardware/audio/core/BpStreamOut.h>
David Li9cf5e622023-03-21 00:51:10 +080028#include <aidl/android/hardware/audio/core/MmapBufferDescriptor.h>
Mikhail Naganove7a26ad2023-05-25 17:36:48 -070029#include <aidl/android/media/audio/IHalAdapterVendorExtension.h>
Mikhail Naganov31d46652023-01-10 18:29:25 +000030#include <fmq/AidlMessageQueue.h>
31#include <media/audiohal/EffectHalInterface.h>
32#include <media/audiohal/StreamHalInterface.h>
Mikhail Naganove7a26ad2023-05-25 17:36:48 -070033#include <media/AidlConversionUtil.h>
David Lia0ad9f02023-03-02 21:46:19 +080034#include <media/AudioParameter.h>
Mikhail Naganov8065bfd2024-03-25 14:59:49 -070035#include <mediautils/Synchronization.h>
Mikhail Naganov31d46652023-01-10 18:29:25 +000036
37#include "ConversionHelperAidl.h"
38#include "StreamPowerLog.h"
39
David Lia0ad9f02023-03-02 21:46:19 +080040using ::aidl::android::hardware::audio::common::AudioOffloadMetadata;
David Li9cf5e622023-03-21 00:51:10 +080041using ::aidl::android::hardware::audio::core::MmapBufferDescriptor;
David Lia0ad9f02023-03-02 21:46:19 +080042
Mikhail Naganov31d46652023-01-10 18:29:25 +000043namespace android {
44
Mikhail Naganov89a9f742023-01-30 12:33:18 -080045class StreamContextAidl {
46 public:
47 typedef AidlMessageQueue<::aidl::android::hardware::audio::core::StreamDescriptor::Command,
48 ::aidl::android::hardware::common::fmq::SynchronizedReadWrite> CommandMQ;
49 typedef AidlMessageQueue<::aidl::android::hardware::audio::core::StreamDescriptor::Reply,
50 ::aidl::android::hardware::common::fmq::SynchronizedReadWrite> ReplyMQ;
51 typedef AidlMessageQueue<int8_t,
52 ::aidl::android::hardware::common::fmq::SynchronizedReadWrite> DataMQ;
53
Mikhail Naganove7a26ad2023-05-25 17:36:48 -070054 StreamContextAidl(
David Li9cf5e622023-03-21 00:51:10 +080055 ::aidl::android::hardware::audio::core::StreamDescriptor& descriptor,
Mikhail Naganov712d71b2023-02-23 17:57:16 -080056 bool isAsynchronous)
Mikhail Naganov89a9f742023-01-30 12:33:18 -080057 : mFrameSizeBytes(descriptor.frameSizeBytes),
58 mCommandMQ(new CommandMQ(descriptor.command)),
59 mReplyMQ(new ReplyMQ(descriptor.reply)),
60 mBufferSizeFrames(descriptor.bufferSizeFrames),
Mikhail Naganov712d71b2023-02-23 17:57:16 -080061 mDataMQ(maybeCreateDataMQ(descriptor)),
David Li9cf5e622023-03-21 00:51:10 +080062 mIsAsynchronous(isAsynchronous),
63 mIsMmapped(isMmapped(descriptor)),
64 mMmapBufferDescriptor(maybeGetMmapBuffer(descriptor)) {}
Mikhail Naganov89a9f742023-01-30 12:33:18 -080065 StreamContextAidl(StreamContextAidl&& other) :
66 mFrameSizeBytes(other.mFrameSizeBytes),
67 mCommandMQ(std::move(other.mCommandMQ)),
68 mReplyMQ(std::move(other.mReplyMQ)),
69 mBufferSizeFrames(other.mBufferSizeFrames),
Mikhail Naganov712d71b2023-02-23 17:57:16 -080070 mDataMQ(std::move(other.mDataMQ)),
David Li9cf5e622023-03-21 00:51:10 +080071 mIsAsynchronous(other.mIsAsynchronous),
72 mIsMmapped(other.mIsMmapped),
73 mMmapBufferDescriptor(std::move(other.mMmapBufferDescriptor)) {}
Mikhail Naganov89a9f742023-01-30 12:33:18 -080074 StreamContextAidl& operator=(StreamContextAidl&& other) {
75 mFrameSizeBytes = other.mFrameSizeBytes;
76 mCommandMQ = std::move(other.mCommandMQ);
77 mReplyMQ = std::move(other.mReplyMQ);
78 mBufferSizeFrames = other.mBufferSizeFrames;
79 mDataMQ = std::move(other.mDataMQ);
Mikhail Naganov712d71b2023-02-23 17:57:16 -080080 mIsAsynchronous = other.mIsAsynchronous;
David Li9cf5e622023-03-21 00:51:10 +080081 mIsMmapped = other.mIsMmapped;
82 mMmapBufferDescriptor = std::move(other.mMmapBufferDescriptor);
Mikhail Naganov89a9f742023-01-30 12:33:18 -080083 return *this;
84 }
85 bool isValid() const {
86 return mFrameSizeBytes != 0 &&
87 mCommandMQ != nullptr && mCommandMQ->isValid() &&
88 mReplyMQ != nullptr && mReplyMQ->isValid() &&
David Li9cf5e622023-03-21 00:51:10 +080089 (mDataMQ == nullptr || (
Mikhail Naganov89a9f742023-01-30 12:33:18 -080090 mDataMQ->isValid() &&
91 mDataMQ->getQuantumCount() * mDataMQ->getQuantumSize() >=
David Li9cf5e622023-03-21 00:51:10 +080092 mFrameSizeBytes * mBufferSizeFrames)) &&
93 (!mIsMmapped || mMmapBufferDescriptor.sharedMemory.fd.get() >= 0);
Mikhail Naganov89a9f742023-01-30 12:33:18 -080094 }
95 size_t getBufferSizeBytes() const { return mFrameSizeBytes * mBufferSizeFrames; }
96 size_t getBufferSizeFrames() const { return mBufferSizeFrames; }
Mikhail Naganov8065bfd2024-03-25 14:59:49 -070097 size_t getBufferDurationMs(int32_t sampleRate) const {
98 return sampleRate != 0 ? mBufferSizeFrames * MILLIS_PER_SECOND / sampleRate : 0;
99 }
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800100 CommandMQ* getCommandMQ() const { return mCommandMQ.get(); }
101 DataMQ* getDataMQ() const { return mDataMQ.get(); }
102 size_t getFrameSizeBytes() const { return mFrameSizeBytes; }
103 ReplyMQ* getReplyMQ() const { return mReplyMQ.get(); }
Mikhail Naganov712d71b2023-02-23 17:57:16 -0800104 bool isAsynchronous() const { return mIsAsynchronous; }
David Li9cf5e622023-03-21 00:51:10 +0800105 bool isMmapped() const { return mIsMmapped; }
106 const MmapBufferDescriptor& getMmapBufferDescriptor() const { return mMmapBufferDescriptor; }
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800107
108 private:
109 static std::unique_ptr<DataMQ> maybeCreateDataMQ(
110 const ::aidl::android::hardware::audio::core::StreamDescriptor& descriptor) {
111 using Tag = ::aidl::android::hardware::audio::core::StreamDescriptor::AudioBuffer::Tag;
112 if (descriptor.audio.getTag() == Tag::fmq) {
113 return std::make_unique<DataMQ>(descriptor.audio.get<Tag::fmq>());
114 }
115 return nullptr;
116 }
David Li9cf5e622023-03-21 00:51:10 +0800117 static bool isMmapped(
118 const ::aidl::android::hardware::audio::core::StreamDescriptor& descriptor) {
119 using Tag = ::aidl::android::hardware::audio::core::StreamDescriptor::AudioBuffer::Tag;
120 return descriptor.audio.getTag() == Tag::mmap;
121 }
122 static MmapBufferDescriptor maybeGetMmapBuffer(
123 ::aidl::android::hardware::audio::core::StreamDescriptor& descriptor) {
124 using Tag = ::aidl::android::hardware::audio::core::StreamDescriptor::AudioBuffer::Tag;
125 if (descriptor.audio.getTag() == Tag::mmap) {
126 return std::move(descriptor.audio.get<Tag::mmap>());
127 }
128 return {};
129 }
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800130
131 size_t mFrameSizeBytes;
132 std::unique_ptr<CommandMQ> mCommandMQ;
133 std::unique_ptr<ReplyMQ> mReplyMQ;
134 size_t mBufferSizeFrames;
135 std::unique_ptr<DataMQ> mDataMQ;
Mikhail Naganov712d71b2023-02-23 17:57:16 -0800136 bool mIsAsynchronous;
David Li9cf5e622023-03-21 00:51:10 +0800137 bool mIsMmapped;
138 MmapBufferDescriptor mMmapBufferDescriptor;
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800139};
Mikhail Naganov31d46652023-01-10 18:29:25 +0000140
141class StreamHalAidl : public virtual StreamHalInterface, public ConversionHelperAidl {
142 public:
143 // Return size of input/output buffer in bytes for this stream - eg. 4800.
144 status_t getBufferSize(size_t *size) override;
145
146 // Return the base configuration of the stream:
147 // - channel mask;
148 // - format - e.g. AUDIO_FORMAT_PCM_16_BIT;
149 // - sampling rate in Hz - eg. 44100.
150 status_t getAudioProperties(audio_config_base_t *configBase) override;
151
152 // Set audio stream parameters.
153 status_t setParameters(const String8& kvPairs) override;
154
155 // Get audio stream parameters.
156 status_t getParameters(const String8& keys, String8 *values) override;
157
158 // Return the frame size (number of bytes per sample) of a stream.
159 status_t getFrameSize(size_t *size) override;
160
161 // Add or remove the effect on the stream.
162 status_t addEffect(sp<EffectHalInterface> effect) override;
163 status_t removeEffect(sp<EffectHalInterface> effect) override;
164
165 // Put the audio hardware input/output into standby mode.
166 status_t standby() override;
167
168 status_t dump(int fd, const Vector<String16>& args) override;
169
170 // Start a stream operating in mmap mode.
171 status_t start() override;
172
173 // Stop a stream operating in mmap mode.
174 status_t stop() override;
175
176 // Retrieve information on the data buffer in mmap mode.
177 status_t createMmapBuffer(int32_t minSizeFrames,
178 struct audio_mmap_buffer_info *info) override;
179
180 // Get current read/write position in the mmap buffer
181 status_t getMmapPosition(struct audio_mmap_position *position) override;
182
183 // Set the priority of the thread that interacts with the HAL
184 // (must match the priority of the audioflinger's thread that calls 'read' / 'write')
185 status_t setHalThreadPriority(int priority) override;
186
187 status_t legacyCreateAudioPatch(const struct audio_port_config& port,
188 std::optional<audio_source_t> source,
189 audio_devices_t type) override;
190
191 status_t legacyReleaseAudioPatch() override;
192
193 protected:
Mikhail Naganove7a26ad2023-05-25 17:36:48 -0700194 // For tests.
195 friend class sp<StreamHalAidl>;
196
Mikhail Naganovfab697c2023-01-11 19:33:13 +0000197 template<class T>
198 static std::shared_ptr<::aidl::android::hardware::audio::core::IStreamCommon> getStreamCommon(
199 const std::shared_ptr<T>& stream);
200
Mikhail Naganov31d46652023-01-10 18:29:25 +0000201 // Subclasses can not be constructed directly by clients.
202 StreamHalAidl(std::string_view className,
203 bool isInput,
Mikhail Naganov5b1eed12023-01-25 11:29:11 -0800204 const audio_config& config,
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800205 int32_t nominalLatency,
206 StreamContextAidl&& context,
Mikhail Naganove7a26ad2023-05-25 17:36:48 -0700207 const std::shared_ptr<::aidl::android::hardware::audio::core::IStreamCommon>& stream,
208 const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension>& vext);
Mikhail Naganov31d46652023-01-10 18:29:25 +0000209
210 ~StreamHalAidl() override;
211
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800212 status_t getLatency(uint32_t *latency);
213
Mikhail Naganove2084702023-09-28 14:37:12 -0700214 // Always returns non-negative values.
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800215 status_t getObservablePosition(int64_t *frames, int64_t *timestamp);
216
Mikhail Naganove2084702023-09-28 14:37:12 -0700217 // Always returns non-negative values.
David Li9cf5e622023-03-21 00:51:10 +0800218 status_t getHardwarePosition(int64_t *frames, int64_t *timestamp);
219
Mikhail Naganove2084702023-09-28 14:37:12 -0700220 // Always returns non-negative values.
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800221 status_t getXruns(int32_t *frames);
222
223 status_t transfer(void *buffer, size_t bytes, size_t *transferred);
224
225 status_t pause(
226 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr);
227
228 status_t resume(
229 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr);
230
231 status_t drain(bool earlyNotify,
232 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr);
233
234 status_t flush(
235 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr);
236
237 status_t exit();
238
Mikhail Naganov8065bfd2024-03-25 14:59:49 -0700239 void onAsyncTransferReady();
240 void onAsyncDrainReady();
241 void onAsyncError();
242
Mikhail Naganov31d46652023-01-10 18:29:25 +0000243 const bool mIsInput;
Mikhail Naganov5b1eed12023-01-25 11:29:11 -0800244 const audio_config_base_t mConfig;
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800245 const StreamContextAidl mContext;
Mikhail Naganov914339d2024-04-12 17:28:09 -0700246 // This lock is used to make sending of a command and receiving a reply an atomic
247 // operation. Otherwise, when two threads are trying to send a command, they may both advance to
248 // reading of the reply once the HAL has consumed the command from the MQ, and that creates a
249 // race condition between them.
250 //
251 // Note that only access to command and reply MQs needs to be protected because the data MQ is
252 // only accessed by the I/O thread. Also, there is no need to protect lookup operations on the
253 // queues as they are thread-safe, only send/receive operation must be protected.
254 std::mutex mCommandReplyLock;
Mikhail Naganov31d46652023-01-10 18:29:25 +0000255
256 private:
Mikhail Naganov5b1eed12023-01-25 11:29:11 -0800257 static audio_config_base_t configToBase(const audio_config& config) {
258 audio_config_base_t result = AUDIO_CONFIG_BASE_INITIALIZER;
259 result.sample_rate = config.sample_rate;
260 result.channel_mask = config.channel_mask;
261 result.format = config.format;
262 return result;
263 }
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800264 ::aidl::android::hardware::audio::core::StreamDescriptor::State getState() {
265 std::lock_guard l(mLock);
266 return mLastReply.state;
Mikhail Naganov31d46652023-01-10 18:29:25 +0000267 }
Mikhail Naganov914339d2024-04-12 17:28:09 -0700268 // Note: Since `sendCommand` takes mLock while holding mCommandReplyLock, never call
269 // it with `mLock` being held.
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800270 status_t sendCommand(
271 const ::aidl::android::hardware::audio::core::StreamDescriptor::Command &command,
272 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr,
273 bool safeFromNonWorkerThread = false);
274 status_t updateCountersIfNeeded(
275 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply* reply = nullptr);
Mikhail Naganov31d46652023-01-10 18:29:25 +0000276
Mikhail Naganov31d46652023-01-10 18:29:25 +0000277 const std::shared_ptr<::aidl::android::hardware::audio::core::IStreamCommon> mStream;
Mikhail Naganove7a26ad2023-05-25 17:36:48 -0700278 const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt;
Mikhail Naganov8065bfd2024-03-25 14:59:49 -0700279 const int64_t mLastReplyLifeTimeNs;
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800280 std::mutex mLock;
281 ::aidl::android::hardware::audio::core::StreamDescriptor::Reply mLastReply GUARDED_BY(mLock);
Mikhail Naganov8065bfd2024-03-25 14:59:49 -0700282 int64_t mLastReplyExpirationNs GUARDED_BY(mLock) = 0;
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800283 // mStreamPowerLog is used for audio signal power logging.
284 StreamPowerLog mStreamPowerLog;
285 std::atomic<pid_t> mWorkerTid = -1;
Mikhail Naganov31d46652023-01-10 18:29:25 +0000286};
287
Mikhail Naganovdfd594e2023-02-08 16:59:41 -0800288class CallbackBroker;
289
Mikhail Naganov8065bfd2024-03-25 14:59:49 -0700290class StreamOutHalAidl : public virtual StreamOutHalInterface,
291 public virtual StreamOutHalInterfaceCallback,
292 public StreamHalAidl {
Mikhail Naganov31d46652023-01-10 18:29:25 +0000293 public:
David Lia0ad9f02023-03-02 21:46:19 +0800294 // Extract the output stream parameters and set by AIDL APIs.
295 status_t setParameters(const String8& kvPairs) override;
296
Mikhail Naganov31d46652023-01-10 18:29:25 +0000297 // Return the audio hardware driver estimated latency in milliseconds.
298 status_t getLatency(uint32_t *latency) override;
299
300 // Use this method in situations where audio mixing is done in the hardware.
301 status_t setVolume(float left, float right) override;
302
303 // Selects the audio presentation (if available).
304 status_t selectPresentation(int presentationId, int programId) override;
305
306 // Write audio buffer to driver.
307 status_t write(const void *buffer, size_t bytes, size_t *written) override;
308
309 // Return the number of audio frames written by the audio dsp to DAC since
310 // the output has exited standby.
311 status_t getRenderPosition(uint32_t *dspFrames) override;
312
313 // Get the local time at which the next write to the audio driver will be presented.
314 status_t getNextWriteTimestamp(int64_t *timestamp) override;
315
316 // Set the callback for notifying completion of non-blocking write and drain.
317 status_t setCallback(wp<StreamOutHalInterfaceCallback> callback) override;
318
319 // Returns whether pause and resume operations are supported.
320 status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume) override;
321
322 // Notifies to the audio driver to resume playback following a pause.
323 status_t pause() override;
324
325 // Notifies to the audio driver to resume playback following a pause.
326 status_t resume() override;
327
328 // Returns whether drain operation is supported.
329 status_t supportsDrain(bool *supportsDrain) override;
330
331 // Requests notification when data buffered by the driver/hardware has been played.
332 status_t drain(bool earlyNotify) override;
333
334 // Notifies to the audio driver to flush the queued data.
335 status_t flush() override;
336
337 // Return a recent count of the number of audio frames presented to an external observer.
338 status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp) override;
339
340 // Called when the metadata of the stream's source has been changed.
341 status_t updateSourceMetadata(const SourceMetadata& sourceMetadata) override;
342
343 // Returns the Dual Mono mode presentation setting.
344 status_t getDualMonoMode(audio_dual_mono_mode_t* mode) override;
345
346 // Sets the Dual Mono mode presentation on the output device.
347 status_t setDualMonoMode(audio_dual_mono_mode_t mode) override;
348
349 // Returns the Audio Description Mix level in dB.
350 status_t getAudioDescriptionMixLevel(float* leveldB) override;
351
352 // Sets the Audio Description Mix level in dB.
353 status_t setAudioDescriptionMixLevel(float leveldB) override;
354
355 // Retrieves current playback rate parameters.
356 status_t getPlaybackRateParameters(audio_playback_rate_t* playbackRate) override;
357
358 // Sets the playback rate parameters that control playback behavior.
359 status_t setPlaybackRateParameters(const audio_playback_rate_t& playbackRate) override;
360
361 status_t setEventCallback(const sp<StreamOutHalInterfaceEventCallback>& callback) override;
362
363 status_t setLatencyMode(audio_latency_mode_t mode) override;
364 status_t getRecommendedLatencyModes(std::vector<audio_latency_mode_t> *modes) override;
365 status_t setLatencyModeCallback(
366 const sp<StreamOutHalInterfaceLatencyModeCallback>& callback) override;
367
Mikhail Naganov31d46652023-01-10 18:29:25 +0000368 status_t exit() override;
369
Mikhail Naganov8065bfd2024-03-25 14:59:49 -0700370 // StreamOutHalInterfaceCallback
371 void onWriteReady() override;
372 void onDrainReady() override;
373 void onError() override;
374
Mikhail Naganov31d46652023-01-10 18:29:25 +0000375 private:
376 friend class sp<StreamOutHalAidl>;
377
Mikhail Naganov19418e32023-03-10 17:55:14 -0800378 static ConversionResult<::aidl::android::hardware::audio::common::SourceMetadata>
Mikhail Naganovb6e57752023-03-08 18:12:47 -0800379 legacy2aidl_SourceMetadata(const StreamOutHalInterface::SourceMetadata& legacy);
380
Mikhail Naganov31d46652023-01-10 18:29:25 +0000381 const std::shared_ptr<::aidl::android::hardware::audio::core::IStreamOut> mStream;
Mikhail Naganovdfd594e2023-02-08 16:59:41 -0800382 const wp<CallbackBroker> mCallbackBroker;
Mikhail Naganov8065bfd2024-03-25 14:59:49 -0700383 mediautils::atomic_wp<StreamOutHalInterfaceCallback> mClientCallback;
Mikhail Naganov31d46652023-01-10 18:29:25 +0000384
David Lia0ad9f02023-03-02 21:46:19 +0800385 AudioOffloadMetadata mOffloadMetadata;
386
Mikhail Naganov31d46652023-01-10 18:29:25 +0000387 // Can not be constructed directly by clients.
388 StreamOutHalAidl(
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800389 const audio_config& config, StreamContextAidl&& context, int32_t nominalLatency,
Mikhail Naganovdfd594e2023-02-08 16:59:41 -0800390 const std::shared_ptr<::aidl::android::hardware::audio::core::IStreamOut>& stream,
Mikhail Naganove7a26ad2023-05-25 17:36:48 -0700391 const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension>& vext,
Mikhail Naganovdfd594e2023-02-08 16:59:41 -0800392 const sp<CallbackBroker>& callbackBroker);
Mikhail Naganov31d46652023-01-10 18:29:25 +0000393
Mikhail Naganovdfd594e2023-02-08 16:59:41 -0800394 ~StreamOutHalAidl() override;
David Lia0ad9f02023-03-02 21:46:19 +0800395
396 // Filter and update the offload metadata. The parameters which are related to the offload
397 // metadata will be removed after filtering.
398 status_t filterAndUpdateOffloadMetadata(AudioParameter &parameters);
Mikhail Naganov31d46652023-01-10 18:29:25 +0000399};
400
Mikhail Naganovcad0afe2023-03-10 14:25:57 -0800401class MicrophoneInfoProvider;
402
Mikhail Naganov31d46652023-01-10 18:29:25 +0000403class StreamInHalAidl : public StreamInHalInterface, public StreamHalAidl {
404 public:
405 // Set the input gain for the audio driver.
406 status_t setGain(float gain) override;
407
408 // Read audio buffer in from driver.
409 status_t read(void *buffer, size_t bytes, size_t *read) override;
410
411 // Return the amount of input frames lost in the audio driver.
412 status_t getInputFramesLost(uint32_t *framesLost) override;
413
414 // Return a recent count of the number of audio frames received and
415 // the clock time associated with that frame count.
416 status_t getCapturePosition(int64_t *frames, int64_t *time) override;
417
418 // Get active microphones
Mikhail Naganov2a6a3012023-02-13 11:45:03 -0800419 status_t getActiveMicrophones(std::vector<media::MicrophoneInfoFw> *microphones) override;
Mikhail Naganov31d46652023-01-10 18:29:25 +0000420
421 // Set microphone direction (for processing)
422 status_t setPreferredMicrophoneDirection(
423 audio_microphone_direction_t direction) override;
424
425 // Set microphone zoom (for processing)
426 status_t setPreferredMicrophoneFieldDimension(float zoom) override;
427
428 // Called when the metadata of the stream's sink has been changed.
429 status_t updateSinkMetadata(const SinkMetadata& sinkMetadata) override;
430
431 private:
432 friend class sp<StreamInHalAidl>;
433
Mikhail Naganov19418e32023-03-10 17:55:14 -0800434 static ConversionResult<::aidl::android::hardware::audio::common::SinkMetadata>
Mikhail Naganovb6e57752023-03-08 18:12:47 -0800435 legacy2aidl_SinkMetadata(const StreamInHalInterface::SinkMetadata& legacy);
436
Mikhail Naganov31d46652023-01-10 18:29:25 +0000437 const std::shared_ptr<::aidl::android::hardware::audio::core::IStreamIn> mStream;
Mikhail Naganovcad0afe2023-03-10 14:25:57 -0800438 const wp<MicrophoneInfoProvider> mMicInfoProvider;
Mikhail Naganov31d46652023-01-10 18:29:25 +0000439
440 // Can not be constructed directly by clients.
441 StreamInHalAidl(
Mikhail Naganov89a9f742023-01-30 12:33:18 -0800442 const audio_config& config, StreamContextAidl&& context, int32_t nominalLatency,
Mikhail Naganovcad0afe2023-03-10 14:25:57 -0800443 const std::shared_ptr<::aidl::android::hardware::audio::core::IStreamIn>& stream,
Mikhail Naganove7a26ad2023-05-25 17:36:48 -0700444 const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension>& vext,
Mikhail Naganovcad0afe2023-03-10 14:25:57 -0800445 const sp<MicrophoneInfoProvider>& micInfoProvider);
Mikhail Naganov31d46652023-01-10 18:29:25 +0000446
447 ~StreamInHalAidl() override = default;
448};
449
450} // namespace android