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 "BTAudioProviderA2dpHW" |
| 18 | |
| 19 | #include "A2dpOffloadAudioProvider.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 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 31 | A2dpOffloadEncodingAudioProvider::A2dpOffloadEncodingAudioProvider() |
| 32 | : A2dpOffloadAudioProvider() { |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 33 | session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH; |
| 34 | } |
| 35 | |
Alice Kuo | adcceec | 2022-03-28 13:28:43 +0800 | [diff] [blame] | 36 | A2dpOffloadDecodingAudioProvider::A2dpOffloadDecodingAudioProvider() |
| 37 | : A2dpOffloadAudioProvider() { |
| 38 | session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH; |
| 39 | } |
| 40 | |
| 41 | A2dpOffloadAudioProvider::A2dpOffloadAudioProvider() {} |
| 42 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 43 | bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) { |
| 44 | return (session_type == session_type_); |
| 45 | } |
| 46 | |
| 47 | ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession( |
| 48 | const std::shared_ptr<IBluetoothAudioPort>& host_if, |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 49 | const AudioConfiguration& audio_config, |
Cheney Ni | 6ecbc76 | 2022-03-03 00:12:48 +0800 | [diff] [blame] | 50 | const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) { |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 51 | if (audio_config.getTag() != AudioConfiguration::a2dpConfig) { |
| 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 | if (!BluetoothAudioCodecs::IsOffloadCodecConfigurationValid( |
| 58 | session_type_, audio_config.get<AudioConfiguration::a2dpConfig>())) { |
| 59 | LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" |
| 60 | << audio_config.toString(); |
| 61 | *_aidl_return = DataMQDesc(); |
| 62 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 63 | } |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 64 | return BluetoothAudioProvider::startSession( |
| 65 | host_if, audio_config, latency_modes, _aidl_return); |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady( |
| 69 | DataMQDesc* _aidl_return) { |
| 70 | *_aidl_return = DataMQDesc(); |
Cheney Ni | 6ecbc76 | 2022-03-03 00:12:48 +0800 | [diff] [blame] | 71 | BluetoothAudioSessionReport::OnSessionStarted( |
| 72 | session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_); |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 73 | return ndk::ScopedAStatus::ok(); |
| 74 | } |
| 75 | |
| 76 | } // namespace audio |
| 77 | } // namespace bluetooth |
| 78 | } // namespace hardware |
| 79 | } // namespace android |
Cheney Ni | 6ecbc76 | 2022-03-03 00:12:48 +0800 | [diff] [blame] | 80 | } // namespace aidl |