blob: f8c775f863005602671a652030e68b6b767c5f66 [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_ModuleRemoteSubmix"
18
19#include <vector>
20
21#include <android-base/logging.h>
David Lib089c0c2023-08-10 12:47:44 +080022#include <error/expected_utils.h>
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053023
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053024#include "core-impl/ModuleRemoteSubmix.h"
25#include "core-impl/StreamRemoteSubmix.h"
26
27using aidl::android::hardware::audio::common::SinkMetadata;
28using aidl::android::hardware::audio::common::SourceMetadata;
29using aidl::android::media::audio::common::AudioOffloadInfo;
30using aidl::android::media::audio::common::AudioPort;
31using aidl::android::media::audio::common::AudioPortConfig;
32using aidl::android::media::audio::common::MicrophoneInfo;
33
34namespace aidl::android::hardware::audio::core {
35
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053036ndk::ScopedAStatus ModuleRemoteSubmix::getMicMute(bool* _aidl_return __unused) {
37 LOG(DEBUG) << __func__ << ": is not supported";
38 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
39}
40
41ndk::ScopedAStatus ModuleRemoteSubmix::setMicMute(bool in_mute __unused) {
42 LOG(DEBUG) << __func__ << ": is not supported";
43 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
44}
45
46ndk::ScopedAStatus ModuleRemoteSubmix::createInputStream(
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -070047 StreamContext&& context, const SinkMetadata& sinkMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053048 const std::vector<MicrophoneInfo>& microphones, std::shared_ptr<StreamIn>* result) {
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -070049 return createStreamInstance<StreamInRemoteSubmix>(result, std::move(context), sinkMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053050 microphones);
51}
52
53ndk::ScopedAStatus ModuleRemoteSubmix::createOutputStream(
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -070054 StreamContext&& context, const SourceMetadata& sourceMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053055 const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) {
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -070056 return createStreamInstance<StreamOutRemoteSubmix>(result, std::move(context), sourceMetadata,
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053057 offloadInfo);
58}
59
60ndk::ScopedAStatus ModuleRemoteSubmix::populateConnectedDevicePort(AudioPort* audioPort) {
David Lib089c0c2023-08-10 12:47:44 +080061 // Find the corresponding mix port and copy its profiles.
David Lib089c0c2023-08-10 12:47:44 +080062 // At this moment, the port has the same ID as the template port, see connectExternalDevice.
Mikhail Naganov84bcc042023-10-05 17:36:57 -070063 std::vector<AudioRoute*> routes = getAudioRoutesForAudioPortImpl(audioPort->id);
David Lib089c0c2023-08-10 12:47:44 +080064 if (routes.empty()) {
65 LOG(ERROR) << __func__ << ": no routes found for the port " << audioPort->toString();
66 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053067 }
David Lib089c0c2023-08-10 12:47:44 +080068 const auto& route = *routes.begin();
69 AudioPort mixPort;
Mikhail Naganov84bcc042023-10-05 17:36:57 -070070 if (route->sinkPortId == audioPort->id) {
71 if (route->sourcePortIds.empty()) {
72 LOG(ERROR) << __func__ << ": invalid route " << route->toString();
David Lib089c0c2023-08-10 12:47:44 +080073 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
74 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -070075 RETURN_STATUS_IF_ERROR(getAudioPort(*route->sourcePortIds.begin(), &mixPort));
David Lib089c0c2023-08-10 12:47:44 +080076 } else {
Mikhail Naganov84bcc042023-10-05 17:36:57 -070077 RETURN_STATUS_IF_ERROR(getAudioPort(route->sinkPortId, &mixPort));
David Lib089c0c2023-08-10 12:47:44 +080078 }
79 audioPort->profiles = mixPort.profiles;
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053080 return ndk::ScopedAStatus::ok();
81}
82
83ndk::ScopedAStatus ModuleRemoteSubmix::checkAudioPatchEndpointsMatch(
84 const std::vector<AudioPortConfig*>& sources, const std::vector<AudioPortConfig*>& sinks) {
85 for (const auto& source : sources) {
86 for (const auto& sink : sinks) {
87 if (source->sampleRate != sink->sampleRate ||
88 source->channelMask != sink->channelMask || source->format != sink->format) {
89 LOG(ERROR) << __func__
90 << ": mismatch port configuration, source=" << source->toString()
91 << ", sink=" << sink->toString();
92 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
93 }
94 }
95 }
96 return ndk::ScopedAStatus::ok();
97}
98
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053099ndk::ScopedAStatus ModuleRemoteSubmix::onMasterMuteChanged(bool __unused) {
100 LOG(DEBUG) << __func__ << ": is not supported";
101 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
102}
103
104ndk::ScopedAStatus ModuleRemoteSubmix::onMasterVolumeChanged(float __unused) {
105 LOG(DEBUG) << __func__ << ": is not supported";
106 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
107}
108
109} // namespace aidl::android::hardware::audio::core