blob: fc61dcb398dbae177ded37ebdb61446ee09046b9 [file] [log] [blame]
Shraddha Basantwani6bb69632023-04-25 15:26:38 +05301/*
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#define LOG_TAG "AHAL_StreamRemoteSubmix"
18#include <android-base/logging.h>
19
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053020#include "core-impl/StreamRemoteSubmix.h"
21
22using aidl::android::hardware::audio::common::SinkMetadata;
23using aidl::android::hardware::audio::common::SourceMetadata;
Shraddha Basantwani2e460342023-07-26 16:12:21 +000024using aidl::android::hardware::audio::core::r_submix::SubmixRoute;
25using aidl::android::media::audio::common::AudioDeviceAddress;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053026using aidl::android::media::audio::common::AudioOffloadInfo;
27using aidl::android::media::audio::common::MicrophoneDynamicInfo;
28using aidl::android::media::audio::common::MicrophoneInfo;
29
30namespace aidl::android::hardware::audio::core {
31
Shraddha Basantwani2e460342023-07-26 16:12:21 +000032StreamRemoteSubmix::StreamRemoteSubmix(StreamContext* context, const Metadata& metadata,
33 const AudioDeviceAddress& deviceAddress)
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -070034 : StreamCommonImpl(context, metadata),
Shraddha Basantwani2e460342023-07-26 16:12:21 +000035 mDeviceAddress(deviceAddress),
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053036 mIsInput(isInput(metadata)) {
Mikhail Naganov1eedc132023-07-21 17:45:28 -070037 mStreamConfig.frameSize = context->getFrameSize();
38 mStreamConfig.format = context->getFormat();
39 mStreamConfig.channelLayout = context->getChannelLayout();
40 mStreamConfig.sampleRate = context->getSampleRate();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053041}
42
43std::mutex StreamRemoteSubmix::sSubmixRoutesLock;
Shraddha Basantwani2e460342023-07-26 16:12:21 +000044std::map<AudioDeviceAddress, std::shared_ptr<SubmixRoute>> StreamRemoteSubmix::sSubmixRoutes;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053045
46::android::status_t StreamRemoteSubmix::init() {
47 {
48 std::lock_guard guard(sSubmixRoutesLock);
Shraddha Basantwani2e460342023-07-26 16:12:21 +000049 auto routeItr = sSubmixRoutes.find(mDeviceAddress);
50 if (routeItr != sSubmixRoutes.end()) {
51 mCurrentRoute = routeItr->second;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053052 }
53 }
54 // If route is not available for this port, add it.
55 if (mCurrentRoute == nullptr) {
56 // Initialize the pipe.
57 mCurrentRoute = std::make_shared<SubmixRoute>();
58 if (::android::OK != mCurrentRoute->createPipe(mStreamConfig)) {
59 LOG(ERROR) << __func__ << ": create pipe failed";
Mikhail Naganov49712b52023-06-27 16:39:33 -070060 return ::android::NO_INIT;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053061 }
62 {
63 std::lock_guard guard(sSubmixRoutesLock);
Shraddha Basantwani2e460342023-07-26 16:12:21 +000064 sSubmixRoutes.emplace(mDeviceAddress, mCurrentRoute);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053065 }
66 } else {
67 if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
68 LOG(ERROR) << __func__ << ": invalid stream config";
Mikhail Naganov49712b52023-06-27 16:39:33 -070069 return ::android::NO_INIT;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053070 }
71 sp<MonoPipe> sink = mCurrentRoute->getSink();
72 if (sink == nullptr) {
73 LOG(ERROR) << __func__ << ": nullptr sink when opening stream";
Mikhail Naganov49712b52023-06-27 16:39:33 -070074 return ::android::NO_INIT;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053075 }
76 // If the sink has been shutdown or pipe recreation is forced, delete the pipe and
77 // recreate it.
78 if (sink->isShutdown()) {
79 LOG(DEBUG) << __func__ << ": Non-nullptr shut down sink when opening stream";
80 if (::android::OK != mCurrentRoute->resetPipe()) {
81 LOG(ERROR) << __func__ << ": reset pipe failed";
Mikhail Naganov49712b52023-06-27 16:39:33 -070082 return ::android::NO_INIT;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053083 }
84 }
85 }
86
87 mCurrentRoute->openStream(mIsInput);
Mikhail Naganov49712b52023-06-27 16:39:33 -070088 return ::android::OK;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053089}
90
91::android::status_t StreamRemoteSubmix::drain(StreamDescriptor::DrainMode) {
92 usleep(1000);
93 return ::android::OK;
94}
95
96::android::status_t StreamRemoteSubmix::flush() {
97 usleep(1000);
98 return ::android::OK;
99}
100
101::android::status_t StreamRemoteSubmix::pause() {
102 usleep(1000);
103 return ::android::OK;
104}
105
Mikhail Naganov49712b52023-06-27 16:39:33 -0700106::android::status_t StreamRemoteSubmix::standby() {
107 mCurrentRoute->standby(mIsInput);
108 return ::android::OK;
109}
110
111::android::status_t StreamRemoteSubmix::start() {
112 mCurrentRoute->exitStandby(mIsInput);
113 return ::android::OK;
114}
115
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530116ndk::ScopedAStatus StreamRemoteSubmix::prepareToClose() {
117 if (!mIsInput) {
118 std::shared_ptr<SubmixRoute> route = nullptr;
119 {
120 std::lock_guard guard(sSubmixRoutesLock);
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000121 auto routeItr = sSubmixRoutes.find(mDeviceAddress);
122 if (routeItr != sSubmixRoutes.end()) {
123 route = routeItr->second;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530124 }
125 }
126 if (route != nullptr) {
127 sp<MonoPipe> sink = route->getSink();
128 if (sink == nullptr) {
129 ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
130 }
131 LOG(DEBUG) << __func__ << ": shutting down MonoPipe sink";
132
133 sink->shutdown(true);
Mikhail Naganov2ebe3902023-11-07 16:43:26 -0800134 // The client already considers this stream as closed, release the output end.
135 route->closeStream(mIsInput);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530136 } else {
137 LOG(DEBUG) << __func__ << ": stream already closed.";
138 ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
139 }
140 }
141 return ndk::ScopedAStatus::ok();
142}
143
144// Remove references to the specified input and output streams. When the device no longer
145// references input and output streams destroy the associated pipe.
146void StreamRemoteSubmix::shutdown() {
147 mCurrentRoute->closeStream(mIsInput);
148 // If all stream instances are closed, we can remove route information for this port.
149 if (!mCurrentRoute->hasAtleastOneStreamOpen()) {
150 mCurrentRoute->releasePipe();
151 LOG(DEBUG) << __func__ << ": pipe destroyed";
152
153 std::lock_guard guard(sSubmixRoutesLock);
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000154 sSubmixRoutes.erase(mDeviceAddress);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530155 }
Mikhail Naganov49712b52023-06-27 16:39:33 -0700156 mCurrentRoute.reset();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530157}
158
159::android::status_t StreamRemoteSubmix::transfer(void* buffer, size_t frameCount,
160 size_t* actualFrameCount, int32_t* latencyMs) {
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700161 *latencyMs = getDelayInUsForFrameCount(getStreamPipeSizeInFrames()) / 1000;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530162 LOG(VERBOSE) << __func__ << ": Latency " << *latencyMs << "ms";
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000163 mCurrentRoute->exitStandby(mIsInput);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530164 return (mIsInput ? inRead(buffer, frameCount, actualFrameCount)
165 : outWrite(buffer, frameCount, actualFrameCount));
166}
167
Mikhail Naganov459b7332023-08-03 10:26:21 -0700168::android::status_t StreamRemoteSubmix::refinePosition(StreamDescriptor::Position* position) {
Mikhail Naganov704aec42023-07-13 11:08:29 -0700169 sp<MonoPipeReader> source = mCurrentRoute->getSource();
170 if (source == nullptr) {
171 return ::android::NO_INIT;
172 }
173 const ssize_t framesInPipe = source->availableToRead();
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000174 if (framesInPipe <= 0) {
175 // No need to update the position frames
176 return ::android::OK;
Mikhail Naganov704aec42023-07-13 11:08:29 -0700177 }
178 if (mIsInput) {
179 position->frames += framesInPipe;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000180 } else if (position->frames >= framesInPipe) {
181 position->frames -= framesInPipe;
Mikhail Naganov704aec42023-07-13 11:08:29 -0700182 }
183 return ::android::OK;
184}
185
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700186long StreamRemoteSubmix::getDelayInUsForFrameCount(size_t frameCount) {
187 return frameCount * MICROS_PER_SECOND / mStreamConfig.sampleRate;
188}
189
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530190// Calculate the maximum size of the pipe buffer in frames for the specified stream.
191size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
192 auto pipeConfig = mCurrentRoute->mPipeConfig;
193 const size_t maxFrameSize = std::max(mStreamConfig.frameSize, pipeConfig.frameSize);
194 return (pipeConfig.frameCount * pipeConfig.frameSize) / maxFrameSize;
195}
196
197::android::status_t StreamRemoteSubmix::outWrite(void* buffer, size_t frameCount,
198 size_t* actualFrameCount) {
199 sp<MonoPipe> sink = mCurrentRoute->getSink();
200 if (sink != nullptr) {
201 if (sink->isShutdown()) {
202 sink.clear();
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700203 const auto delayUs = getDelayInUsForFrameCount(frameCount);
204 LOG(DEBUG) << __func__ << ": pipe shutdown, ignoring the write, sleeping for "
205 << delayUs << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530206 // the pipe has already been shutdown, this buffer will be lost but we must
207 // simulate timing so we don't drain the output faster than realtime
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530208 usleep(delayUs);
209 *actualFrameCount = frameCount;
210 return ::android::OK;
211 }
212 } else {
213 LOG(FATAL) << __func__ << ": without a pipe!";
214 return ::android::UNKNOWN_ERROR;
215 }
216
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700217 const bool shouldBlockWrite = mCurrentRoute->shouldBlockWrite();
218 size_t availableToWrite = sink->availableToWrite();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530219 // NOTE: sink has been checked above and sink and source life cycles are synchronized
220 sp<MonoPipeReader> source = mCurrentRoute->getSource();
221 // If the write to the sink should be blocked, flush enough frames from the pipe to make space
222 // to write the most recent data.
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700223 if (!shouldBlockWrite && availableToWrite < frameCount) {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530224 static uint8_t flushBuffer[64];
225 const size_t flushBufferSizeFrames = sizeof(flushBuffer) / mStreamConfig.frameSize;
226 size_t framesToFlushFromSource = frameCount - availableToWrite;
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700227 LOG(DEBUG) << __func__ << ": flushing " << framesToFlushFromSource
228 << " frames from the pipe to avoid blocking";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530229 while (framesToFlushFromSource) {
230 const size_t flushSize = std::min(framesToFlushFromSource, flushBufferSizeFrames);
231 framesToFlushFromSource -= flushSize;
232 // read does not block
233 source->read(flushBuffer, flushSize);
234 }
235 }
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700236 availableToWrite = sink->availableToWrite();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530237
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700238 if (!shouldBlockWrite && frameCount > availableToWrite) {
239 // Truncate the request to avoid blocking.
240 frameCount = availableToWrite;
241 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530242 ssize_t writtenFrames = sink->write(buffer, frameCount);
243 if (writtenFrames < 0) {
244 if (writtenFrames == (ssize_t)::android::NEGOTIATE) {
245 LOG(ERROR) << __func__ << ": write to pipe returned NEGOTIATE";
246 sink.clear();
247 *actualFrameCount = 0;
248 return ::android::UNKNOWN_ERROR;
249 } else {
250 // write() returned UNDERRUN or WOULD_BLOCK, retry
251 LOG(ERROR) << __func__ << ": write to pipe returned unexpected " << writtenFrames;
252 writtenFrames = sink->write(buffer, frameCount);
253 }
254 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530255
256 if (writtenFrames < 0) {
257 LOG(ERROR) << __func__ << ": failed writing to pipe with " << writtenFrames;
258 *actualFrameCount = 0;
259 return ::android::UNKNOWN_ERROR;
260 }
261 LOG(VERBOSE) << __func__ << ": wrote " << writtenFrames << "frames";
262 *actualFrameCount = writtenFrames;
263 return ::android::OK;
264}
265
266::android::status_t StreamRemoteSubmix::inRead(void* buffer, size_t frameCount,
267 size_t* actualFrameCount) {
268 // about to read from audio source
269 sp<MonoPipeReader> source = mCurrentRoute->getSource();
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000270 if (source == nullptr) {
271 int readErrorCount = mCurrentRoute->notifyReadError();
272 if (readErrorCount < kMaxReadErrorLogs) {
273 LOG(ERROR) << __func__
274 << ": no audio pipe yet we're trying to read! (not all errors will be "
275 "logged)";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530276 } else {
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000277 LOG(ERROR) << __func__ << ": Read errors " << readErrorCount;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530278 }
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700279 const auto delayUs = getDelayInUsForFrameCount(frameCount);
280 LOG(DEBUG) << __func__ << ": no source, ignoring the read, sleeping for " << delayUs
281 << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530282 usleep(delayUs);
283 memset(buffer, 0, mStreamConfig.frameSize * frameCount);
284 *actualFrameCount = frameCount;
285 return ::android::OK;
286 }
287
288 // read the data from the pipe
289 int attempts = 0;
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700290 const long delayUs = kReadAttemptSleepUs;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530291 char* buff = (char*)buffer;
292 size_t remainingFrames = frameCount;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000293 int availableToRead = source->availableToRead();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530294
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000295 while ((remainingFrames > 0) && (availableToRead > 0) && (attempts < kMaxReadFailureAttempts)) {
296 LOG(VERBOSE) << __func__ << ": frames available to read " << availableToRead;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530297
298 ssize_t framesRead = source->read(buff, remainingFrames);
299
300 LOG(VERBOSE) << __func__ << ": frames read " << framesRead;
301
302 if (framesRead > 0) {
303 remainingFrames -= framesRead;
304 buff += framesRead * mStreamConfig.frameSize;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000305 availableToRead -= framesRead;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530306 LOG(VERBOSE) << __func__ << ": (attempts = " << attempts << ") got " << framesRead
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700307 << " frames, remaining =" << remainingFrames;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530308 } else {
309 attempts++;
310 LOG(WARNING) << __func__ << ": read returned " << framesRead
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700311 << " , read failure attempts = " << attempts << ", sleeping for "
312 << delayUs << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530313 usleep(delayUs);
314 }
315 }
316 // done using the source
317 source.clear();
318
319 if (remainingFrames > 0) {
320 const size_t remainingBytes = remainingFrames * mStreamConfig.frameSize;
321 LOG(VERBOSE) << __func__ << ": clearing remaining_frames = " << remainingFrames;
322 memset(((char*)buffer) + (mStreamConfig.frameSize * frameCount) - remainingBytes, 0,
323 remainingBytes);
324 }
325
326 long readCounterFrames = mCurrentRoute->updateReadCounterFrames(frameCount);
327 *actualFrameCount = frameCount;
328
329 // compute how much we need to sleep after reading the data by comparing the wall clock with
330 // the projected time at which we should return.
331 // wall clock after reading from the pipe
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700332 auto recordDurationUs = std::chrono::duration_cast<std::chrono::microseconds>(
333 std::chrono::steady_clock::now() - mCurrentRoute->getRecordStartTime());
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530334
335 // readCounterFrames contains the number of frames that have been read since the beginning of
336 // recording (including this call): it's converted to usec and compared to how long we've been
337 // recording for, which gives us how long we must wait to sync the projected recording time, and
338 // the observed recording time.
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700339 const long projectedVsObservedOffsetUs =
340 getDelayInUsForFrameCount(readCounterFrames) - recordDurationUs.count();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530341
342 LOG(VERBOSE) << __func__ << ": record duration " << recordDurationUs.count()
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700343 << " us, will wait: " << projectedVsObservedOffsetUs << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530344 if (projectedVsObservedOffsetUs > 0) {
345 usleep(projectedVsObservedOffsetUs);
346 }
347 return ::android::OK;
348}
349
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700350StreamInRemoteSubmix::StreamInRemoteSubmix(StreamContext&& context,
351 const SinkMetadata& sinkMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530352 const std::vector<MicrophoneInfo>& microphones)
Mikhail Naganov459b7332023-08-03 10:26:21 -0700353 : StreamIn(std::move(context), microphones), StreamSwitcher(&mContextInstance, sinkMetadata) {}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530354
355ndk::ScopedAStatus StreamInRemoteSubmix::getActiveMicrophones(
356 std::vector<MicrophoneDynamicInfo>* _aidl_return) {
357 LOG(DEBUG) << __func__ << ": not supported";
358 *_aidl_return = std::vector<MicrophoneDynamicInfo>();
359 return ndk::ScopedAStatus::ok();
360}
361
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000362StreamSwitcher::DeviceSwitchBehavior StreamInRemoteSubmix::switchCurrentStream(
363 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
364 // This implementation effectively postpones stream creation until
365 // receiving the first call to 'setConnectedDevices' with a non-empty list.
366 if (isStubStream()) {
367 if (devices.size() == 1) {
368 auto deviceDesc = devices.front().type;
369 if (deviceDesc.type ==
370 ::aidl::android::media::audio::common::AudioDeviceType::IN_SUBMIX) {
371 return DeviceSwitchBehavior::CREATE_NEW_STREAM;
372 }
373 LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
374 << " not supported";
375 } else {
376 LOG(ERROR) << __func__ << ": Only single device supported.";
377 }
378 return DeviceSwitchBehavior::UNSUPPORTED_DEVICES;
379 }
380 return DeviceSwitchBehavior::USE_CURRENT_STREAM;
381}
382
383std::unique_ptr<StreamCommonInterfaceEx> StreamInRemoteSubmix::createNewStream(
384 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
385 StreamContext* context, const Metadata& metadata) {
386 return std::unique_ptr<StreamCommonInterfaceEx>(
387 new InnerStreamWrapper<StreamRemoteSubmix>(context, metadata, devices.front().address));
388}
389
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700390StreamOutRemoteSubmix::StreamOutRemoteSubmix(StreamContext&& context,
391 const SourceMetadata& sourceMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530392 const std::optional<AudioOffloadInfo>& offloadInfo)
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700393 : StreamOut(std::move(context), offloadInfo),
Mikhail Naganov459b7332023-08-03 10:26:21 -0700394 StreamSwitcher(&mContextInstance, sourceMetadata) {}
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000395
396StreamSwitcher::DeviceSwitchBehavior StreamOutRemoteSubmix::switchCurrentStream(
397 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
398 // This implementation effectively postpones stream creation until
399 // receiving the first call to 'setConnectedDevices' with a non-empty list.
400 if (isStubStream()) {
401 if (devices.size() == 1) {
402 auto deviceDesc = devices.front().type;
403 if (deviceDesc.type ==
404 ::aidl::android::media::audio::common::AudioDeviceType::OUT_SUBMIX) {
405 return DeviceSwitchBehavior::CREATE_NEW_STREAM;
406 }
407 LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
408 << " not supported";
409 } else {
410 LOG(ERROR) << __func__ << ": Only single device supported.";
411 }
412 return DeviceSwitchBehavior::UNSUPPORTED_DEVICES;
413 }
414 return DeviceSwitchBehavior::USE_CURRENT_STREAM;
415}
416
417std::unique_ptr<StreamCommonInterfaceEx> StreamOutRemoteSubmix::createNewStream(
418 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
419 StreamContext* context, const Metadata& metadata) {
420 return std::unique_ptr<StreamCommonInterfaceEx>(
421 new InnerStreamWrapper<StreamRemoteSubmix>(context, metadata, devices.front().address));
422}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530423
424} // namespace aidl::android::hardware::audio::core