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
A2dpOffloadEncodingAudioProvider()31 A2dpOffloadEncodingAudioProvider::A2dpOffloadEncodingAudioProvider()
32 : A2dpOffloadAudioProvider() {
33 session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
34 }
35
A2dpOffloadDecodingAudioProvider()36 A2dpOffloadDecodingAudioProvider::A2dpOffloadDecodingAudioProvider()
37 : A2dpOffloadAudioProvider() {
38 session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_DECODING_DATAPATH;
39 }
40
A2dpOffloadAudioProvider()41 A2dpOffloadAudioProvider::A2dpOffloadAudioProvider() {}
42
isValid(const SessionType & session_type)43 bool A2dpOffloadAudioProvider::isValid(const SessionType& session_type) {
44 return (session_type == session_type_);
45 }
46
startSession(const std::shared_ptr<IBluetoothAudioPort> & host_if,const AudioConfiguration & audio_config,const std::vector<LatencyMode> & latency_modes,DataMQDesc * _aidl_return)47 ndk::ScopedAStatus A2dpOffloadAudioProvider::startSession(
48 const std::shared_ptr<IBluetoothAudioPort>& host_if,
49 const AudioConfiguration& audio_config,
50 const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return) {
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 }
64 return BluetoothAudioProvider::startSession(
65 host_if, audio_config, latency_modes, _aidl_return);
66 }
67
onSessionReady(DataMQDesc * _aidl_return)68 ndk::ScopedAStatus A2dpOffloadAudioProvider::onSessionReady(
69 DataMQDesc* _aidl_return) {
70 *_aidl_return = DataMQDesc();
71 BluetoothAudioSessionReport::OnSessionStarted(
72 session_type_, stack_iface_, nullptr, *audio_config_, latency_modes_);
73 return ndk::ScopedAStatus::ok();
74 }
75
76 } // namespace audio
77 } // namespace bluetooth
78 } // namespace hardware
79 } // namespace android
80 } // namespace aidl
81