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 | |
Josh Wu | 98d7e08 | 2022-01-21 03:04:21 -0800 | [diff] [blame] | 17 | #define LOG_TAG "BTAudioProviderLeAudioHW" |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 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 | |
Alice Kuo | e80a576 | 2022-02-09 14:44:29 +0800 | [diff] [blame] | 41 | LeAudioOffloadBroadcastAudioProvider::LeAudioOffloadBroadcastAudioProvider() |
| 42 | : LeAudioOffloadAudioProvider() { |
| 43 | session_type_ = |
| 44 | SessionType::LE_AUDIO_BROADCAST_HARDWARE_OFFLOAD_ENCODING_DATAPATH; |
| 45 | } |
| 46 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 47 | LeAudioOffloadAudioProvider::LeAudioOffloadAudioProvider() |
| 48 | : BluetoothAudioProvider() {} |
| 49 | |
| 50 | bool LeAudioOffloadAudioProvider::isValid(const SessionType& sessionType) { |
| 51 | return (sessionType == session_type_); |
| 52 | } |
| 53 | |
| 54 | ndk::ScopedAStatus LeAudioOffloadAudioProvider::startSession( |
| 55 | const std::shared_ptr<IBluetoothAudioPort>& host_if, |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 56 | const AudioConfiguration& audio_config, |
Cheney Ni | 6ecbc76 | 2022-03-03 00:12:48 +0800 | [diff] [blame] | 57 | const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) { |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 58 | if (audio_config.getTag() != AudioConfiguration::leAudioConfig) { |
| 59 | LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" |
| 60 | << audio_config.toString(); |
| 61 | *_aidl_return = DataMQDesc(); |
| 62 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 63 | } |
| 64 | const auto& le_audio_config = |
| 65 | audio_config.get<AudioConfiguration::leAudioConfig>(); |
| 66 | if (!BluetoothAudioCodecs::IsOffloadLeAudioConfigurationValid( |
| 67 | session_type_, le_audio_config)) { |
| 68 | LOG(WARNING) << __func__ << " - Unsupported LC3 Offloaded Configuration=" |
| 69 | << le_audio_config.toString(); |
| 70 | *_aidl_return = DataMQDesc(); |
| 71 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 72 | } |
| 73 | |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 74 | return BluetoothAudioProvider::startSession( |
| 75 | host_if, audio_config, latency_modes, _aidl_return); |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | ndk::ScopedAStatus LeAudioOffloadAudioProvider::onSessionReady( |
| 79 | DataMQDesc* _aidl_return) { |
Cheney Ni | 6ecbc76 | 2022-03-03 00:12:48 +0800 | [diff] [blame] | 80 | BluetoothAudioSessionReport::OnSessionStarted( |
| 81 | session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_); |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 82 | *_aidl_return = DataMQDesc(); |
| 83 | return ndk::ScopedAStatus::ok(); |
| 84 | } |
| 85 | |
| 86 | } // namespace audio |
| 87 | } // namespace bluetooth |
| 88 | } // namespace hardware |
| 89 | } // namespace android |
Cheney Ni | 6ecbc76 | 2022-03-03 00:12:48 +0800 | [diff] [blame] | 90 | } // namespace aidl |