Shraddha Basantwani | 6bb6963 | 2023-04-25 15:26:38 +0530 | [diff] [blame^] | 1 | /* |
| 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> |
| 22 | |
| 23 | #include "RemoteSubmixUtils.h" |
| 24 | #include "core-impl/ModuleRemoteSubmix.h" |
| 25 | #include "core-impl/StreamRemoteSubmix.h" |
| 26 | |
| 27 | using aidl::android::hardware::audio::common::SinkMetadata; |
| 28 | using aidl::android::hardware::audio::common::SourceMetadata; |
| 29 | using aidl::android::media::audio::common::AudioOffloadInfo; |
| 30 | using aidl::android::media::audio::common::AudioPort; |
| 31 | using aidl::android::media::audio::common::AudioPortConfig; |
| 32 | using aidl::android::media::audio::common::MicrophoneInfo; |
| 33 | |
| 34 | namespace aidl::android::hardware::audio::core { |
| 35 | |
| 36 | ndk::ScopedAStatus ModuleRemoteSubmix::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) { |
| 37 | *_aidl_return = nullptr; |
| 38 | LOG(DEBUG) << __func__ << ": returning null"; |
| 39 | return ndk::ScopedAStatus::ok(); |
| 40 | } |
| 41 | |
| 42 | ndk::ScopedAStatus ModuleRemoteSubmix::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) { |
| 43 | *_aidl_return = nullptr; |
| 44 | LOG(DEBUG) << __func__ << ": returning null"; |
| 45 | return ndk::ScopedAStatus::ok(); |
| 46 | } |
| 47 | |
| 48 | ndk::ScopedAStatus ModuleRemoteSubmix::getMicMute(bool* _aidl_return __unused) { |
| 49 | LOG(DEBUG) << __func__ << ": is not supported"; |
| 50 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 51 | } |
| 52 | |
| 53 | ndk::ScopedAStatus ModuleRemoteSubmix::setMicMute(bool in_mute __unused) { |
| 54 | LOG(DEBUG) << __func__ << ": is not supported"; |
| 55 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 56 | } |
| 57 | |
| 58 | ndk::ScopedAStatus ModuleRemoteSubmix::createInputStream( |
| 59 | const SinkMetadata& sinkMetadata, StreamContext&& context, |
| 60 | const std::vector<MicrophoneInfo>& microphones, std::shared_ptr<StreamIn>* result) { |
| 61 | return createStreamInstance<StreamInRemoteSubmix>(result, sinkMetadata, std::move(context), |
| 62 | microphones); |
| 63 | } |
| 64 | |
| 65 | ndk::ScopedAStatus ModuleRemoteSubmix::createOutputStream( |
| 66 | const SourceMetadata& sourceMetadata, StreamContext&& context, |
| 67 | const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) { |
| 68 | return createStreamInstance<StreamOutRemoteSubmix>(result, sourceMetadata, std::move(context), |
| 69 | offloadInfo); |
| 70 | } |
| 71 | |
| 72 | ndk::ScopedAStatus ModuleRemoteSubmix::populateConnectedDevicePort(AudioPort* audioPort) { |
| 73 | LOG(VERBOSE) << __func__ << ": Profiles already populated by Configuration"; |
| 74 | for (auto profile : audioPort->profiles) { |
| 75 | for (auto channelMask : profile.channelMasks) { |
| 76 | if (!r_submix::isChannelMaskSupported(channelMask)) { |
| 77 | LOG(ERROR) << __func__ << ": the profile " << profile.name |
| 78 | << " has unsupported channel mask : " << channelMask.toString(); |
| 79 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 80 | } |
| 81 | } |
| 82 | for (auto sampleRate : profile.sampleRates) { |
| 83 | if (!r_submix::isSampleRateSupported(sampleRate)) { |
| 84 | LOG(ERROR) << __func__ << ": the profile " << profile.name |
| 85 | << " has unsupported sample rate : " << sampleRate; |
| 86 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | return ndk::ScopedAStatus::ok(); |
| 91 | } |
| 92 | |
| 93 | ndk::ScopedAStatus ModuleRemoteSubmix::checkAudioPatchEndpointsMatch( |
| 94 | const std::vector<AudioPortConfig*>& sources, const std::vector<AudioPortConfig*>& sinks) { |
| 95 | for (const auto& source : sources) { |
| 96 | for (const auto& sink : sinks) { |
| 97 | if (source->sampleRate != sink->sampleRate || |
| 98 | source->channelMask != sink->channelMask || source->format != sink->format) { |
| 99 | LOG(ERROR) << __func__ |
| 100 | << ": mismatch port configuration, source=" << source->toString() |
| 101 | << ", sink=" << sink->toString(); |
| 102 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | return ndk::ScopedAStatus::ok(); |
| 107 | } |
| 108 | |
| 109 | void ModuleRemoteSubmix::onExternalDeviceConnectionChanged( |
| 110 | const ::aidl::android::media::audio::common::AudioPort& audioPort __unused, |
| 111 | bool connected __unused) { |
| 112 | LOG(DEBUG) << __func__ << ": do nothing and return"; |
| 113 | } |
| 114 | |
| 115 | ndk::ScopedAStatus ModuleRemoteSubmix::onMasterMuteChanged(bool __unused) { |
| 116 | LOG(DEBUG) << __func__ << ": is not supported"; |
| 117 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 118 | } |
| 119 | |
| 120 | ndk::ScopedAStatus ModuleRemoteSubmix::onMasterVolumeChanged(float __unused) { |
| 121 | LOG(DEBUG) << __func__ << ": is not supported"; |
| 122 | return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION); |
| 123 | } |
| 124 | |
| 125 | } // namespace aidl::android::hardware::audio::core |