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 | |
| 31 | A2dpOffloadAudioProvider::A2dpOffloadAudioProvider() { |
| 32 | session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH; |
| 33 | } |
| 34 | |
| 35 | bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) { |
| 36 | return (session_type == session_type_); |
| 37 | } |
| 38 | |
| 39 | ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession( |
| 40 | const std::shared_ptr<IBluetoothAudioPort>& host_if, |
| 41 | const AudioConfiguration& audio_config, DataMQDesc* _aidl_return) { |
| 42 | if (audio_config.getTag() != AudioConfiguration::a2dpConfig) { |
| 43 | LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" |
| 44 | << audio_config.toString(); |
| 45 | *_aidl_return = DataMQDesc(); |
| 46 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 47 | } |
| 48 | if (!BluetoothAudioCodecs::IsOffloadCodecConfigurationValid( |
| 49 | session_type_, audio_config.get<AudioConfiguration::a2dpConfig>())) { |
| 50 | LOG(WARNING) << __func__ << " - Invalid Audio Configuration=" |
| 51 | << audio_config.toString(); |
| 52 | *_aidl_return = DataMQDesc(); |
| 53 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT); |
| 54 | } |
| 55 | return BluetoothAudioProvider::startSession(host_if, audio_config, |
| 56 | _aidl_return); |
| 57 | } |
| 58 | |
| 59 | ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady( |
| 60 | DataMQDesc* _aidl_return) { |
| 61 | *_aidl_return = DataMQDesc(); |
| 62 | BluetoothAudioSessionReport::OnSessionStarted(session_type_, stack_iface_, |
| 63 | nullptr, *audio_config_); |
| 64 | return ndk::ScopedAStatus::ok(); |
| 65 | } |
| 66 | |
| 67 | } // namespace audio |
| 68 | } // namespace bluetooth |
| 69 | } // namespace hardware |
| 70 | } // namespace android |
| 71 | } // namespace aidl |