blob: 38281b9d5fd84f2b206c16861e2c30ef306e1a17 [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);
134 } else {
135 LOG(DEBUG) << __func__ << ": stream already closed.";
136 ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
137 }
138 }
139 return ndk::ScopedAStatus::ok();
140}
141
142// Remove references to the specified input and output streams. When the device no longer
143// references input and output streams destroy the associated pipe.
144void StreamRemoteSubmix::shutdown() {
145 mCurrentRoute->closeStream(mIsInput);
146 // If all stream instances are closed, we can remove route information for this port.
147 if (!mCurrentRoute->hasAtleastOneStreamOpen()) {
148 mCurrentRoute->releasePipe();
149 LOG(DEBUG) << __func__ << ": pipe destroyed";
150
151 std::lock_guard guard(sSubmixRoutesLock);
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000152 sSubmixRoutes.erase(mDeviceAddress);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530153 }
Mikhail Naganov49712b52023-06-27 16:39:33 -0700154 mCurrentRoute.reset();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530155}
156
157::android::status_t StreamRemoteSubmix::transfer(void* buffer, size_t frameCount,
158 size_t* actualFrameCount, int32_t* latencyMs) {
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700159 *latencyMs = getDelayInUsForFrameCount(getStreamPipeSizeInFrames()) / 1000;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530160 LOG(VERBOSE) << __func__ << ": Latency " << *latencyMs << "ms";
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000161 mCurrentRoute->exitStandby(mIsInput);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530162 return (mIsInput ? inRead(buffer, frameCount, actualFrameCount)
163 : outWrite(buffer, frameCount, actualFrameCount));
164}
165
Mikhail Naganov459b7332023-08-03 10:26:21 -0700166::android::status_t StreamRemoteSubmix::refinePosition(StreamDescriptor::Position* position) {
Mikhail Naganov704aec42023-07-13 11:08:29 -0700167 sp<MonoPipeReader> source = mCurrentRoute->getSource();
168 if (source == nullptr) {
169 return ::android::NO_INIT;
170 }
171 const ssize_t framesInPipe = source->availableToRead();
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000172 if (framesInPipe <= 0) {
173 // No need to update the position frames
174 return ::android::OK;
Mikhail Naganov704aec42023-07-13 11:08:29 -0700175 }
176 if (mIsInput) {
177 position->frames += framesInPipe;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000178 } else if (position->frames >= framesInPipe) {
179 position->frames -= framesInPipe;
Mikhail Naganov704aec42023-07-13 11:08:29 -0700180 }
181 return ::android::OK;
182}
183
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700184long StreamRemoteSubmix::getDelayInUsForFrameCount(size_t frameCount) {
185 return frameCount * MICROS_PER_SECOND / mStreamConfig.sampleRate;
186}
187
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530188// Calculate the maximum size of the pipe buffer in frames for the specified stream.
189size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
190 auto pipeConfig = mCurrentRoute->mPipeConfig;
191 const size_t maxFrameSize = std::max(mStreamConfig.frameSize, pipeConfig.frameSize);
192 return (pipeConfig.frameCount * pipeConfig.frameSize) / maxFrameSize;
193}
194
195::android::status_t StreamRemoteSubmix::outWrite(void* buffer, size_t frameCount,
196 size_t* actualFrameCount) {
197 sp<MonoPipe> sink = mCurrentRoute->getSink();
198 if (sink != nullptr) {
199 if (sink->isShutdown()) {
200 sink.clear();
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700201 const auto delayUs = getDelayInUsForFrameCount(frameCount);
202 LOG(DEBUG) << __func__ << ": pipe shutdown, ignoring the write, sleeping for "
203 << delayUs << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530204 // the pipe has already been shutdown, this buffer will be lost but we must
205 // simulate timing so we don't drain the output faster than realtime
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530206 usleep(delayUs);
207 *actualFrameCount = frameCount;
208 return ::android::OK;
209 }
210 } else {
211 LOG(FATAL) << __func__ << ": without a pipe!";
212 return ::android::UNKNOWN_ERROR;
213 }
214
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700215 const bool shouldBlockWrite = mCurrentRoute->shouldBlockWrite();
216 size_t availableToWrite = sink->availableToWrite();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530217 // NOTE: sink has been checked above and sink and source life cycles are synchronized
218 sp<MonoPipeReader> source = mCurrentRoute->getSource();
219 // If the write to the sink should be blocked, flush enough frames from the pipe to make space
220 // to write the most recent data.
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700221 if (!shouldBlockWrite && availableToWrite < frameCount) {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530222 static uint8_t flushBuffer[64];
223 const size_t flushBufferSizeFrames = sizeof(flushBuffer) / mStreamConfig.frameSize;
224 size_t framesToFlushFromSource = frameCount - availableToWrite;
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700225 LOG(DEBUG) << __func__ << ": flushing " << framesToFlushFromSource
226 << " frames from the pipe to avoid blocking";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530227 while (framesToFlushFromSource) {
228 const size_t flushSize = std::min(framesToFlushFromSource, flushBufferSizeFrames);
229 framesToFlushFromSource -= flushSize;
230 // read does not block
231 source->read(flushBuffer, flushSize);
232 }
233 }
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700234 availableToWrite = sink->availableToWrite();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530235
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700236 if (!shouldBlockWrite && frameCount > availableToWrite) {
237 // Truncate the request to avoid blocking.
238 frameCount = availableToWrite;
239 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530240 ssize_t writtenFrames = sink->write(buffer, frameCount);
241 if (writtenFrames < 0) {
242 if (writtenFrames == (ssize_t)::android::NEGOTIATE) {
243 LOG(ERROR) << __func__ << ": write to pipe returned NEGOTIATE";
244 sink.clear();
245 *actualFrameCount = 0;
246 return ::android::UNKNOWN_ERROR;
247 } else {
248 // write() returned UNDERRUN or WOULD_BLOCK, retry
249 LOG(ERROR) << __func__ << ": write to pipe returned unexpected " << writtenFrames;
250 writtenFrames = sink->write(buffer, frameCount);
251 }
252 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530253
254 if (writtenFrames < 0) {
255 LOG(ERROR) << __func__ << ": failed writing to pipe with " << writtenFrames;
256 *actualFrameCount = 0;
257 return ::android::UNKNOWN_ERROR;
258 }
259 LOG(VERBOSE) << __func__ << ": wrote " << writtenFrames << "frames";
260 *actualFrameCount = writtenFrames;
261 return ::android::OK;
262}
263
264::android::status_t StreamRemoteSubmix::inRead(void* buffer, size_t frameCount,
265 size_t* actualFrameCount) {
266 // about to read from audio source
267 sp<MonoPipeReader> source = mCurrentRoute->getSource();
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000268 if (source == nullptr) {
269 int readErrorCount = mCurrentRoute->notifyReadError();
270 if (readErrorCount < kMaxReadErrorLogs) {
271 LOG(ERROR) << __func__
272 << ": no audio pipe yet we're trying to read! (not all errors will be "
273 "logged)";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530274 } else {
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000275 LOG(ERROR) << __func__ << ": Read errors " << readErrorCount;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530276 }
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700277 const auto delayUs = getDelayInUsForFrameCount(frameCount);
278 LOG(DEBUG) << __func__ << ": no source, ignoring the read, sleeping for " << delayUs
279 << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530280 usleep(delayUs);
281 memset(buffer, 0, mStreamConfig.frameSize * frameCount);
282 *actualFrameCount = frameCount;
283 return ::android::OK;
284 }
285
286 // read the data from the pipe
287 int attempts = 0;
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700288 const long delayUs = kReadAttemptSleepUs;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530289 char* buff = (char*)buffer;
290 size_t remainingFrames = frameCount;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000291 int availableToRead = source->availableToRead();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530292
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000293 while ((remainingFrames > 0) && (availableToRead > 0) && (attempts < kMaxReadFailureAttempts)) {
294 LOG(VERBOSE) << __func__ << ": frames available to read " << availableToRead;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530295
296 ssize_t framesRead = source->read(buff, remainingFrames);
297
298 LOG(VERBOSE) << __func__ << ": frames read " << framesRead;
299
300 if (framesRead > 0) {
301 remainingFrames -= framesRead;
302 buff += framesRead * mStreamConfig.frameSize;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000303 availableToRead -= framesRead;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530304 LOG(VERBOSE) << __func__ << ": (attempts = " << attempts << ") got " << framesRead
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700305 << " frames, remaining =" << remainingFrames;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530306 } else {
307 attempts++;
308 LOG(WARNING) << __func__ << ": read returned " << framesRead
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700309 << " , read failure attempts = " << attempts << ", sleeping for "
310 << delayUs << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530311 usleep(delayUs);
312 }
313 }
314 // done using the source
315 source.clear();
316
317 if (remainingFrames > 0) {
318 const size_t remainingBytes = remainingFrames * mStreamConfig.frameSize;
319 LOG(VERBOSE) << __func__ << ": clearing remaining_frames = " << remainingFrames;
320 memset(((char*)buffer) + (mStreamConfig.frameSize * frameCount) - remainingBytes, 0,
321 remainingBytes);
322 }
323
324 long readCounterFrames = mCurrentRoute->updateReadCounterFrames(frameCount);
325 *actualFrameCount = frameCount;
326
327 // compute how much we need to sleep after reading the data by comparing the wall clock with
328 // the projected time at which we should return.
329 // wall clock after reading from the pipe
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700330 auto recordDurationUs = std::chrono::duration_cast<std::chrono::microseconds>(
331 std::chrono::steady_clock::now() - mCurrentRoute->getRecordStartTime());
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530332
333 // readCounterFrames contains the number of frames that have been read since the beginning of
334 // recording (including this call): it's converted to usec and compared to how long we've been
335 // recording for, which gives us how long we must wait to sync the projected recording time, and
336 // the observed recording time.
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700337 const long projectedVsObservedOffsetUs =
338 getDelayInUsForFrameCount(readCounterFrames) - recordDurationUs.count();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530339
340 LOG(VERBOSE) << __func__ << ": record duration " << recordDurationUs.count()
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700341 << " us, will wait: " << projectedVsObservedOffsetUs << " us";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530342 if (projectedVsObservedOffsetUs > 0) {
343 usleep(projectedVsObservedOffsetUs);
344 }
345 return ::android::OK;
346}
347
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700348StreamInRemoteSubmix::StreamInRemoteSubmix(StreamContext&& context,
349 const SinkMetadata& sinkMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530350 const std::vector<MicrophoneInfo>& microphones)
Mikhail Naganov459b7332023-08-03 10:26:21 -0700351 : StreamIn(std::move(context), microphones), StreamSwitcher(&mContextInstance, sinkMetadata) {}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530352
353ndk::ScopedAStatus StreamInRemoteSubmix::getActiveMicrophones(
354 std::vector<MicrophoneDynamicInfo>* _aidl_return) {
355 LOG(DEBUG) << __func__ << ": not supported";
356 *_aidl_return = std::vector<MicrophoneDynamicInfo>();
357 return ndk::ScopedAStatus::ok();
358}
359
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000360StreamSwitcher::DeviceSwitchBehavior StreamInRemoteSubmix::switchCurrentStream(
361 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
362 // This implementation effectively postpones stream creation until
363 // receiving the first call to 'setConnectedDevices' with a non-empty list.
364 if (isStubStream()) {
365 if (devices.size() == 1) {
366 auto deviceDesc = devices.front().type;
367 if (deviceDesc.type ==
368 ::aidl::android::media::audio::common::AudioDeviceType::IN_SUBMIX) {
369 return DeviceSwitchBehavior::CREATE_NEW_STREAM;
370 }
371 LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
372 << " not supported";
373 } else {
374 LOG(ERROR) << __func__ << ": Only single device supported.";
375 }
376 return DeviceSwitchBehavior::UNSUPPORTED_DEVICES;
377 }
378 return DeviceSwitchBehavior::USE_CURRENT_STREAM;
379}
380
381std::unique_ptr<StreamCommonInterfaceEx> StreamInRemoteSubmix::createNewStream(
382 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
383 StreamContext* context, const Metadata& metadata) {
384 return std::unique_ptr<StreamCommonInterfaceEx>(
385 new InnerStreamWrapper<StreamRemoteSubmix>(context, metadata, devices.front().address));
386}
387
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700388StreamOutRemoteSubmix::StreamOutRemoteSubmix(StreamContext&& context,
389 const SourceMetadata& sourceMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530390 const std::optional<AudioOffloadInfo>& offloadInfo)
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700391 : StreamOut(std::move(context), offloadInfo),
Mikhail Naganov459b7332023-08-03 10:26:21 -0700392 StreamSwitcher(&mContextInstance, sourceMetadata) {}
Shraddha Basantwani2e460342023-07-26 16:12:21 +0000393
394StreamSwitcher::DeviceSwitchBehavior StreamOutRemoteSubmix::switchCurrentStream(
395 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) {
396 // This implementation effectively postpones stream creation until
397 // receiving the first call to 'setConnectedDevices' with a non-empty list.
398 if (isStubStream()) {
399 if (devices.size() == 1) {
400 auto deviceDesc = devices.front().type;
401 if (deviceDesc.type ==
402 ::aidl::android::media::audio::common::AudioDeviceType::OUT_SUBMIX) {
403 return DeviceSwitchBehavior::CREATE_NEW_STREAM;
404 }
405 LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
406 << " not supported";
407 } else {
408 LOG(ERROR) << __func__ << ": Only single device supported.";
409 }
410 return DeviceSwitchBehavior::UNSUPPORTED_DEVICES;
411 }
412 return DeviceSwitchBehavior::USE_CURRENT_STREAM;
413}
414
415std::unique_ptr<StreamCommonInterfaceEx> StreamOutRemoteSubmix::createNewStream(
416 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices,
417 StreamContext* context, const Metadata& metadata) {
418 return std::unique_ptr<StreamCommonInterfaceEx>(
419 new InnerStreamWrapper<StreamRemoteSubmix>(context, metadata, devices.front().address));
420}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530421
422} // namespace aidl::android::hardware::audio::core