blob: 93fe02871bf43cd8e7e69f7597a4c62878297a67 [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>
Mikhail Naganov06085452023-11-27 17:28:51 -080019#include <audio_utils/clock.h>
20#include <error/Result.h>
21#include <error/expected_utils.h>
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053022
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053023#include "core-impl/StreamRemoteSubmix.h"
24
25using aidl::android::hardware::audio::common::SinkMetadata;
26using aidl::android::hardware::audio::common::SourceMetadata;
Shraddha Basantwani2e460342023-07-26 16:12:21 +000027using aidl::android::hardware::audio::core::r_submix::SubmixRoute;
28using aidl::android::media::audio::common::AudioDeviceAddress;
Mikhail Naganove9766252024-10-03 16:56:06 -070029using aidl::android::media::audio::common::AudioDeviceType;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053030using aidl::android::media::audio::common::AudioOffloadInfo;
31using aidl::android::media::audio::common::MicrophoneDynamicInfo;
32using aidl::android::media::audio::common::MicrophoneInfo;
33
34namespace aidl::android::hardware::audio::core {
35
Mikhail Naganove9766252024-10-03 16:56:06 -070036StreamRemoteSubmix::StreamRemoteSubmix(StreamContext* context, const Metadata& metadata)
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -070037 : StreamCommonImpl(context, metadata),
Mikhail Naganove9766252024-10-03 16:56:06 -070038 mIsInput(isInput(metadata)),
39 mStreamConfig{.sampleRate = context->getSampleRate(),
40 .format = context->getFormat(),
41 .channelLayout = context->getChannelLayout(),
42 .frameSize = context->getFrameSize()} {}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053043
Mikhail Naganov0413d072024-08-15 14:12:39 -070044StreamRemoteSubmix::~StreamRemoteSubmix() {
45 cleanupWorker();
46}
47
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053048::android::status_t StreamRemoteSubmix::init() {
Mikhail Naganov49712b52023-06-27 16:39:33 -070049 return ::android::OK;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053050}
51
52::android::status_t StreamRemoteSubmix::drain(StreamDescriptor::DrainMode) {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053053 return ::android::OK;
54}
55
56::android::status_t StreamRemoteSubmix::flush() {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053057 return ::android::OK;
58}
59
60::android::status_t StreamRemoteSubmix::pause() {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053061 return ::android::OK;
62}
63
Mikhail Naganov49712b52023-06-27 16:39:33 -070064::android::status_t StreamRemoteSubmix::standby() {
Mikhail Naganove9766252024-10-03 16:56:06 -070065 if (mCurrentRoute) mCurrentRoute->standby(mIsInput);
Mikhail Naganov49712b52023-06-27 16:39:33 -070066 return ::android::OK;
67}
68
69::android::status_t StreamRemoteSubmix::start() {
Mikhail Naganove9766252024-10-03 16:56:06 -070070 if (mDeviceAddressUpdated.load(std::memory_order_acquire)) {
71 LOG(DEBUG) << __func__ << ": device address updated, reset current route";
72 shutdown();
73 mDeviceAddressUpdated.store(false, std::memory_order_release);
74 }
75 if (!mCurrentRoute) {
76 RETURN_STATUS_IF_ERROR(setCurrentRoute());
77 LOG(DEBUG) << __func__ << ": have current route? " << (mCurrentRoute != nullptr);
78 }
79 if (mCurrentRoute) mCurrentRoute->exitStandby(mIsInput);
Mikhail Naganov06085452023-11-27 17:28:51 -080080 mStartTimeNs = ::android::uptimeNanos();
81 mFramesSinceStart = 0;
Mikhail Naganov49712b52023-06-27 16:39:33 -070082 return ::android::OK;
83}
84
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053085// Remove references to the specified input and output streams. When the device no longer
86// references input and output streams destroy the associated pipe.
87void StreamRemoteSubmix::shutdown() {
Mikhail Naganove9766252024-10-03 16:56:06 -070088 if (!mCurrentRoute) return;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053089 mCurrentRoute->closeStream(mIsInput);
90 // If all stream instances are closed, we can remove route information for this port.
91 if (!mCurrentRoute->hasAtleastOneStreamOpen()) {
92 mCurrentRoute->releasePipe();
93 LOG(DEBUG) << __func__ << ": pipe destroyed";
Mikhail Naganove9766252024-10-03 16:56:06 -070094 SubmixRoute::removeRoute(getDeviceAddress());
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053095 }
Mikhail Naganov49712b52023-06-27 16:39:33 -070096 mCurrentRoute.reset();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053097}
98
99::android::status_t StreamRemoteSubmix::transfer(void* buffer, size_t frameCount,
100 size_t* actualFrameCount, int32_t* latencyMs) {
Mikhail Naganove9766252024-10-03 16:56:06 -0700101 if (mDeviceAddressUpdated.load(std::memory_order_acquire)) {
102 // 'setConnectedDevices' was called. I/O will be restarted.
103 return ::android::OK;
104 }
105
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700106 *latencyMs = getDelayInUsForFrameCount(getStreamPipeSizeInFrames()) / 1000;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530107 LOG(VERBOSE) << __func__ << ": Latency " << *latencyMs << "ms";
Mikhail Naganove9766252024-10-03 16:56:06 -0700108 ::android::status_t status = ::android::OK;
109 if (mCurrentRoute) {
110 mCurrentRoute->exitStandby(mIsInput);
111 status = mIsInput ? inRead(buffer, frameCount, actualFrameCount)
112 : outWrite(buffer, frameCount, actualFrameCount);
113 if ((status != ::android::OK && mIsInput) ||
114 ((status != ::android::OK && status != ::android::DEAD_OBJECT) && !mIsInput)) {
115 return status;
116 }
117 } else {
118 LOG(WARNING) << __func__ << ": no current route";
119 if (mIsInput) {
120 memset(buffer, 0, mStreamConfig.frameSize * frameCount);
121 }
122 *actualFrameCount = frameCount;
Mikhail Naganova41ff512024-03-25 16:04:27 +0000123 }
Mikhail Naganov55e0afa2024-03-05 17:42:20 -0800124 mFramesSinceStart += *actualFrameCount;
Mikhail Naganove9766252024-10-03 16:56:06 -0700125 // If there is no route, always block, otherwise:
126 // - Input streams always need to block, output streams need to block when there is no sink.
127 // - When the sink exists, more sophisticated blocking algorithm is implemented by MonoPipe.
128 if (mCurrentRoute && !mIsInput && status != ::android::DEAD_OBJECT) return ::android::OK;
Mikhail Naganov06085452023-11-27 17:28:51 -0800129 const long bufferDurationUs =
130 (*actualFrameCount) * MICROS_PER_SECOND / mContext.getSampleRate();
Mikhail Naganov878afae2024-01-03 11:22:42 -0800131 const auto totalDurationUs = (::android::uptimeNanos() - mStartTimeNs) / NANOS_PER_MICROSECOND;
Mikhail Naganov06085452023-11-27 17:28:51 -0800132 const long totalOffsetUs =
133 mFramesSinceStart * MICROS_PER_SECOND / mContext.getSampleRate() - totalDurationUs;
134 LOG(VERBOSE) << __func__ << ": totalOffsetUs " << totalOffsetUs;
135 if (totalOffsetUs > 0) {
136 const long sleepTimeUs = std::min(totalOffsetUs, bufferDurationUs);
137 LOG(VERBOSE) << __func__ << ": sleeping for " << sleepTimeUs << " us";
138 usleep(sleepTimeUs);
139 }
140 return ::android::OK;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530141}
142
Mikhail Naganov459b7332023-08-03 10:26:21 -0700143::android::status_t StreamRemoteSubmix::refinePosition(StreamDescriptor::Position* position) {
Mikhail Naganove9766252024-10-03 16:56:06 -0700144 if (!mCurrentRoute) {
145 RETURN_STATUS_IF_ERROR(setCurrentRoute());
146 if (!mCurrentRoute) return ::android::OK;
147 }
Mikhail Naganov704aec42023-07-13 11:08:29 -0700148 sp<MonoPipeReader> source = mCurrentRoute->getSource();
149 if (source == nullptr) {
150 return ::android::NO_INIT;
151 }
152 const ssize_t framesInPipe = source->availableToRead();
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000153 if (framesInPipe <= 0) {
154 // No need to update the position frames
155 return ::android::OK;
Mikhail Naganov704aec42023-07-13 11:08:29 -0700156 }
157 if (mIsInput) {
158 position->frames += framesInPipe;
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000159 } else if (position->frames >= framesInPipe) {
160 position->frames -= framesInPipe;
Mikhail Naganov704aec42023-07-13 11:08:29 -0700161 }
162 return ::android::OK;
163}
164
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700165long StreamRemoteSubmix::getDelayInUsForFrameCount(size_t frameCount) {
166 return frameCount * MICROS_PER_SECOND / mStreamConfig.sampleRate;
167}
168
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530169// Calculate the maximum size of the pipe buffer in frames for the specified stream.
170size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
Mikhail Naganove9766252024-10-03 16:56:06 -0700171 if (!mCurrentRoute) return r_submix::kDefaultPipeSizeInFrames;
Mikhail Naganov3b732892023-12-20 16:05:01 -0800172 auto pipeConfig = mCurrentRoute->getPipeConfig();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530173 const size_t maxFrameSize = std::max(mStreamConfig.frameSize, pipeConfig.frameSize);
174 return (pipeConfig.frameCount * pipeConfig.frameSize) / maxFrameSize;
175}
176
177::android::status_t StreamRemoteSubmix::outWrite(void* buffer, size_t frameCount,
178 size_t* actualFrameCount) {
179 sp<MonoPipe> sink = mCurrentRoute->getSink();
180 if (sink != nullptr) {
181 if (sink->isShutdown()) {
182 sink.clear();
Mikhail Naganova41ff512024-03-25 16:04:27 +0000183 if (++mWriteShutdownCount < kMaxErrorLogs) {
184 LOG(DEBUG) << __func__ << ": pipe shutdown, ignoring the write. (limited logging)";
185 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530186 *actualFrameCount = frameCount;
Mikhail Naganova41ff512024-03-25 16:04:27 +0000187 return ::android::DEAD_OBJECT; // Induce wait in `transfer`.
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530188 }
189 } else {
190 LOG(FATAL) << __func__ << ": without a pipe!";
191 return ::android::UNKNOWN_ERROR;
192 }
Mikhail Naganova41ff512024-03-25 16:04:27 +0000193 mWriteShutdownCount = 0;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530194
Mikhail Naganove9766252024-10-03 16:56:06 -0700195 LOG(VERBOSE) << __func__ << ": " << getDeviceAddress().toString() << ", " << frameCount
Mikhail Naganov06085452023-11-27 17:28:51 -0800196 << " frames";
197
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700198 const bool shouldBlockWrite = mCurrentRoute->shouldBlockWrite();
199 size_t availableToWrite = sink->availableToWrite();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530200 // NOTE: sink has been checked above and sink and source life cycles are synchronized
201 sp<MonoPipeReader> source = mCurrentRoute->getSource();
202 // If the write to the sink should be blocked, flush enough frames from the pipe to make space
203 // to write the most recent data.
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700204 if (!shouldBlockWrite && availableToWrite < frameCount) {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530205 static uint8_t flushBuffer[64];
206 const size_t flushBufferSizeFrames = sizeof(flushBuffer) / mStreamConfig.frameSize;
207 size_t framesToFlushFromSource = frameCount - availableToWrite;
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700208 LOG(DEBUG) << __func__ << ": flushing " << framesToFlushFromSource
209 << " frames from the pipe to avoid blocking";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530210 while (framesToFlushFromSource) {
211 const size_t flushSize = std::min(framesToFlushFromSource, flushBufferSizeFrames);
212 framesToFlushFromSource -= flushSize;
213 // read does not block
214 source->read(flushBuffer, flushSize);
215 }
216 }
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700217 availableToWrite = sink->availableToWrite();
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530218
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700219 if (!shouldBlockWrite && frameCount > availableToWrite) {
Mikhail Naganov06085452023-11-27 17:28:51 -0800220 LOG(WARNING) << __func__ << ": writing " << availableToWrite << " vs. requested "
221 << frameCount;
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700222 // Truncate the request to avoid blocking.
223 frameCount = availableToWrite;
224 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530225 ssize_t writtenFrames = sink->write(buffer, frameCount);
226 if (writtenFrames < 0) {
227 if (writtenFrames == (ssize_t)::android::NEGOTIATE) {
228 LOG(ERROR) << __func__ << ": write to pipe returned NEGOTIATE";
229 sink.clear();
230 *actualFrameCount = 0;
231 return ::android::UNKNOWN_ERROR;
232 } else {
233 // write() returned UNDERRUN or WOULD_BLOCK, retry
234 LOG(ERROR) << __func__ << ": write to pipe returned unexpected " << writtenFrames;
235 writtenFrames = sink->write(buffer, frameCount);
236 }
237 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530238
239 if (writtenFrames < 0) {
240 LOG(ERROR) << __func__ << ": failed writing to pipe with " << writtenFrames;
241 *actualFrameCount = 0;
242 return ::android::UNKNOWN_ERROR;
243 }
Mikhail Naganov06085452023-11-27 17:28:51 -0800244 if (writtenFrames > 0 && frameCount > (size_t)writtenFrames) {
245 LOG(WARNING) << __func__ << ": wrote " << writtenFrames << " vs. requested " << frameCount;
246 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530247 *actualFrameCount = writtenFrames;
248 return ::android::OK;
249}
250
251::android::status_t StreamRemoteSubmix::inRead(void* buffer, size_t frameCount,
252 size_t* actualFrameCount) {
Mikhail Naganov06085452023-11-27 17:28:51 -0800253 // in any case, it is emulated that data for the entire buffer was available
254 memset(buffer, 0, mStreamConfig.frameSize * frameCount);
255 *actualFrameCount = frameCount;
256
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530257 // about to read from audio source
258 sp<MonoPipeReader> source = mCurrentRoute->getSource();
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000259 if (source == nullptr) {
Mikhail Naganova41ff512024-03-25 16:04:27 +0000260 if (++mReadErrorCount < kMaxErrorLogs) {
Shraddha Basantwani95f92322023-08-22 15:07:16 +0000261 LOG(ERROR) << __func__
262 << ": no audio pipe yet we're trying to read! (not all errors will be "
263 "logged)";
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530264 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530265 return ::android::OK;
266 }
Mikhail Naganov9eb33142024-01-09 14:06:49 -0800267 mReadErrorCount = 0;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530268
Mikhail Naganove9766252024-10-03 16:56:06 -0700269 LOG(VERBOSE) << __func__ << ": " << getDeviceAddress().toString() << ", " << frameCount
Mikhail Naganov06085452023-11-27 17:28:51 -0800270 << " frames";
Mikhail Naganove9766252024-10-03 16:56:06 -0700271
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530272 // read the data from the pipe
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530273 char* buff = (char*)buffer;
Mikhail Naganov06085452023-11-27 17:28:51 -0800274 size_t actuallyRead = 0;
275 long remainingFrames = frameCount;
Mikhail Naganov2be50782024-07-17 11:12:50 -0700276 // Try to wait as long as possible for the audio duration, but leave some time for the call to
277 // 'transfer' to complete. 'kReadAttemptSleepUs' is a good constant for this purpose because it
278 // is by definition "strictly inferior" to the typical buffer duration.
279 const long durationUs =
280 std::max(0L, getDelayInUsForFrameCount(frameCount) - kReadAttemptSleepUs);
281 const int64_t deadlineTimeNs = ::android::uptimeNanos() + durationUs * NANOS_PER_MICROSECOND;
Mikhail Naganov06085452023-11-27 17:28:51 -0800282 while (remainingFrames > 0) {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530283 ssize_t framesRead = source->read(buff, remainingFrames);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530284 LOG(VERBOSE) << __func__ << ": frames read " << framesRead;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530285 if (framesRead > 0) {
286 remainingFrames -= framesRead;
287 buff += framesRead * mStreamConfig.frameSize;
Mikhail Naganov06085452023-11-27 17:28:51 -0800288 LOG(VERBOSE) << __func__ << ": got " << framesRead
Mikhail Naganov2aab7662023-10-24 13:56:07 -0700289 << " frames, remaining =" << remainingFrames;
Mikhail Naganov06085452023-11-27 17:28:51 -0800290 actuallyRead += framesRead;
291 }
292 if (::android::uptimeNanos() >= deadlineTimeNs) break;
293 if (framesRead <= 0) {
294 LOG(VERBOSE) << __func__ << ": read returned " << framesRead
295 << ", read failure, sleeping for " << kReadAttemptSleepUs << " us";
296 usleep(kReadAttemptSleepUs);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530297 }
298 }
Mikhail Naganov06085452023-11-27 17:28:51 -0800299 if (actuallyRead < frameCount) {
Mikhail Naganov9eb33142024-01-09 14:06:49 -0800300 if (++mReadFailureCount < kMaxReadFailureAttempts) {
301 LOG(WARNING) << __func__ << ": read " << actuallyRead << " vs. requested " << frameCount
302 << " (not all errors will be logged)";
303 }
304 } else {
305 mReadFailureCount = 0;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530306 }
Mikhail Naganov06085452023-11-27 17:28:51 -0800307 mCurrentRoute->updateReadCounterFrames(*actualFrameCount);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530308 return ::android::OK;
309}
310
Mikhail Naganove9766252024-10-03 16:56:06 -0700311::android::status_t StreamRemoteSubmix::setCurrentRoute() {
312 const auto address = getDeviceAddress();
313 if (address == AudioDeviceAddress{}) {
314 return ::android::OK;
315 }
316 mCurrentRoute = SubmixRoute::findOrCreateRoute(address, mStreamConfig);
317 if (mCurrentRoute == nullptr) {
318 return ::android::NO_INIT;
319 }
320 if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
321 LOG(ERROR) << __func__ << ": invalid stream config";
322 return ::android::NO_INIT;
323 }
324 sp<MonoPipe> sink = mCurrentRoute->getSink();
325 if (sink == nullptr) {
326 LOG(ERROR) << __func__ << ": nullptr sink when opening stream";
327 return ::android::NO_INIT;
328 }
329 if ((!mIsInput || mCurrentRoute->isStreamInOpen()) && sink->isShutdown()) {
330 LOG(DEBUG) << __func__ << ": Shut down sink when opening stream";
331 if (::android::OK != mCurrentRoute->resetPipe()) {
332 LOG(ERROR) << __func__ << ": reset pipe failed";
333 return ::android::NO_INIT;
334 }
335 }
336 mCurrentRoute->openStream(mIsInput);
337 return ::android::OK;
338}
339
340ndk::ScopedAStatus StreamRemoteSubmix::prepareToClose() {
341 if (!mIsInput) {
342 const auto address = getDeviceAddress();
343 if (address == AudioDeviceAddress{}) return ndk::ScopedAStatus::ok();
344 std::shared_ptr<SubmixRoute> route = SubmixRoute::findRoute(address);
345 if (route != nullptr) {
346 sp<MonoPipe> sink = route->getSink();
347 if (sink == nullptr) {
348 ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
349 }
350 LOG(DEBUG) << __func__ << ": shutting down MonoPipe sink";
351
352 sink->shutdown(true);
353 // The client already considers this stream as closed, release the output end.
354 route->closeStream(mIsInput);
355 } else {
356 LOG(DEBUG) << __func__ << ": stream already closed.";
357 ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
358 }
359 }
360 return ndk::ScopedAStatus::ok();
361}
362
363ndk::ScopedAStatus StreamRemoteSubmix::setConnectedDevices(const ConnectedDevices& devices) {
364 if (devices.size() > 1) {
365 LOG(ERROR) << __func__ << ": Only single device supported, got " << devices.size();
366 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
367 }
368 AudioDeviceAddress newAddress;
369 if (!devices.empty()) {
370 if (auto deviceDesc = devices.front().type;
371 (mIsInput && deviceDesc.type != AudioDeviceType::IN_SUBMIX) ||
372 (!mIsInput && deviceDesc.type != AudioDeviceType::OUT_SUBMIX)) {
373 LOG(ERROR) << __func__ << ": Device type " << toString(deviceDesc.type)
374 << " not supported";
375 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
376 }
377 newAddress = devices.front().address;
378 LOG(DEBUG) << __func__ << ": connected to " << newAddress.toString();
379 } else {
380 LOG(DEBUG) << __func__ << ": disconnected";
381 }
382 RETURN_STATUS_IF_ERROR(StreamCommonImpl::setConnectedDevices(devices));
383 std::lock_guard guard(mLock);
384 if (mDeviceAddress != newAddress) {
385 mDeviceAddress = newAddress;
386 mDeviceAddressUpdated.store(true, std::memory_order_release);
387 }
388 return ndk::ScopedAStatus::ok();
389}
390
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700391StreamInRemoteSubmix::StreamInRemoteSubmix(StreamContext&& context,
392 const SinkMetadata& sinkMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530393 const std::vector<MicrophoneInfo>& microphones)
Mikhail Naganove9766252024-10-03 16:56:06 -0700394 : StreamIn(std::move(context), microphones),
395 StreamRemoteSubmix(&mContextInstance, sinkMetadata) {}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530396
397ndk::ScopedAStatus StreamInRemoteSubmix::getActiveMicrophones(
398 std::vector<MicrophoneDynamicInfo>* _aidl_return) {
399 LOG(DEBUG) << __func__ << ": not supported";
400 *_aidl_return = std::vector<MicrophoneDynamicInfo>();
401 return ndk::ScopedAStatus::ok();
402}
403
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700404StreamOutRemoteSubmix::StreamOutRemoteSubmix(StreamContext&& context,
405 const SourceMetadata& sourceMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530406 const std::optional<AudioOffloadInfo>& offloadInfo)
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700407 : StreamOut(std::move(context), offloadInfo),
Mikhail Naganove9766252024-10-03 16:56:06 -0700408 StreamRemoteSubmix(&mContextInstance, sourceMetadata) {}
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530409
410} // namespace aidl::android::hardware::audio::core