Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 "BTAudioProviderLeAudioSW" |
| 18 | |
| 19 | #include "LeAudioOffloadAudioProvider.h" |
| 20 | |
| 21 | #include <BluetoothAudioCodecs.h> |
| 22 | #include <BluetoothAudioSessionReport.h> |
| 23 | #include <android-base/logging.h> |
| 24 | |
| 25 | namespace aidl { |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace bluetooth { |
| 29 | namespace audio { |
| 30 | |
| 31 | LeAudioOffloadOutputAudioProvider::LeAudioOffloadOutputAudioProvider() |
| 32 | : LeAudioOffloadAudioProvider() { |
| 33 | session_type_ = SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH; |
| 34 | } |
| 35 | |
| 36 | LeAudioOffloadInputAudioProvider::LeAudioOffloadInputAudioProvider() |
| 37 | : LeAudioOffloadAudioProvider() { |
| 38 | session_type_ = SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH; |
| 39 | } |
| 40 | |
| 41 | LeAudioOffloadAudioProvider::LeAudioOffloadAudioProvider() |
| 42 | : BluetoothAudioProvider() {} |
| 43 | |
| 44 | bool LeAudioOffloadAudioProvider::isValid(const SessionType& sessionType) { |
| 45 | return (sessionType == session_type_); |
| 46 | } |
| 47 | |
| 48 | ndk::ScopedAStatus LeAudioOffloadAudioProvider::startSession( |
| 49 | const std::shared_ptr<IBluetoothAudioPort>& host_if, |
| 50 | const AudioConfiguration& audio_config, DataMQDesc* _aidl_return) { |
| 51 | if (audio_config.getTag() != AudioConfiguration::leAudioConfig) { |
| 52 | LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" |
| 53 | << audio_config.toString(); |
| 54 | *_aidl_return = DataMQDesc(); |
| 55 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 56 | } |
| 57 | const auto& le_audio_config = |
| 58 | audio_config.get<AudioConfiguration::leAudioConfig>(); |
| 59 | if (!BluetoothAudioCodecs::IsOffloadLeAudioConfigurationValid( |
| 60 | session_type_, le_audio_config)) { |
| 61 | LOG(WARNING) << __func__ << " - Unsupported LC3 Offloaded Configuration=" |
| 62 | << le_audio_config.toString(); |
| 63 | *_aidl_return = DataMQDesc(); |
| 64 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 65 | } |
| 66 | |
| 67 | return BluetoothAudioProvider::startSession(host_if, audio_config, |
| 68 | _aidl_return); |
| 69 | } |
| 70 | |
| 71 | ndk::ScopedAStatus LeAudioOffloadAudioProvider::onSessionReady( |
| 72 | DataMQDesc* _aidl_return) { |
| 73 | BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_, |
| 74 | nullptr, *audio_config_); |
| 75 | *_aidl_return = DataMQDesc(); |
| 76 | return ndk::ScopedAStatus::ok(); |
| 77 | } |
| 78 | |
| 79 | } // namespace audio |
| 80 | } // namespace bluetooth |
| 81 | } // namespace hardware |
| 82 | } // namespace android |
| 83 | } // namespace aidl |