Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [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 | #include <vector> |
| 18 | |
| 19 | #define LOG_TAG "AHAL_ModulePrimary" |
| 20 | #include <Utils.h> |
| 21 | #include <android-base/logging.h> |
| 22 | |
| 23 | #include "core-impl/ModulePrimary.h" |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 24 | #include "core-impl/StreamPrimary.h" |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 25 | #include "core-impl/Telephony.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 ModulePrimary::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) { |
| 37 | if (!mTelephony) { |
| 38 | mTelephony = ndk::SharedRefBase::make<Telephony>(); |
| 39 | } |
Mikhail Naganov | 780fefb | 2023-07-21 17:01:38 -0700 | [diff] [blame] | 40 | *_aidl_return = mTelephony.getInstance(); |
Mikhail Naganov | 2eabaf9 | 2023-07-19 14:28:47 -0700 | [diff] [blame] | 41 | LOG(DEBUG) << __func__ |
| 42 | << ": returning instance of ITelephony: " << _aidl_return->get()->asBinder().get(); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 43 | return ndk::ScopedAStatus::ok(); |
| 44 | } |
| 45 | |
Mikhail Naganov | 6ddefdb | 2023-07-19 17:30:06 -0700 | [diff] [blame] | 46 | ndk::ScopedAStatus ModulePrimary::createInputStream(StreamContext&& context, |
| 47 | const SinkMetadata& sinkMetadata, |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 48 | const std::vector<MicrophoneInfo>& microphones, |
| 49 | std::shared_ptr<StreamIn>* result) { |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 50 | return createStreamInstance<StreamInPrimary>(result, std::move(context), sinkMetadata, |
| 51 | microphones); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | ndk::ScopedAStatus ModulePrimary::createOutputStream( |
Mikhail Naganov | 6ddefdb | 2023-07-19 17:30:06 -0700 | [diff] [blame] | 55 | StreamContext&& context, const SourceMetadata& sourceMetadata, |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 56 | const std::optional<AudioOffloadInfo>& offloadInfo, std::shared_ptr<StreamOut>* result) { |
Mikhail Naganov | cf824f6 | 2023-07-24 14:51:36 -0700 | [diff] [blame] | 57 | return createStreamInstance<StreamOutPrimary>(result, std::move(context), sourceMetadata, |
| 58 | offloadInfo); |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Mikhail Naganov | 1350187 | 2023-10-18 16:15:46 -0700 | [diff] [blame] | 61 | int32_t ModulePrimary::getNominalLatencyMs(const AudioPortConfig&) { |
| 62 | // 85 ms is chosen considering 4096 frames @ 48 kHz. This is the value which allows |
| 63 | // the virtual Android device implementation to pass CTS. Hardware implementations |
| 64 | // should have significantly lower latency. |
| 65 | static constexpr int32_t kLatencyMs = 85; |
| 66 | return kLatencyMs; |
| 67 | } |
| 68 | |
Mikhail Naganov | 521fc49 | 2023-07-11 17:24:08 -0700 | [diff] [blame] | 69 | } // namespace aidl::android::hardware::audio::core |