xref: /aosp_15_r20/hardware/interfaces/bluetooth/audio/2.1/default/LeAudioOffloadAudioProvider.cpp (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1 /*
2  * Copyright 2021 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 "BTAudioProviderLeAudioOffload"
18 
19 #include "LeAudioOffloadAudioProvider.h"
20 
21 #include <android-base/logging.h>
22 
23 #include "BluetoothAudioSessionReport_2_1.h"
24 #include "BluetoothAudioSupportedCodecsDB_2_1.h"
25 
26 namespace android {
27 namespace hardware {
28 namespace bluetooth {
29 namespace audio {
30 namespace V2_1 {
31 namespace implementation {
32 
33 using ::android::bluetooth::audio::BluetoothAudioSessionReport_2_1;
34 using ::android::hardware::Void;
35 using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
36 using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
37 using ::android::hardware::bluetooth::audio::V2_1::SampleRate;
38 
39 using DataMQ = MessageQueue<uint8_t, kSynchronizedReadWrite>;
40 
LeAudioOffloadOutputAudioProvider()41 LeAudioOffloadOutputAudioProvider::LeAudioOffloadOutputAudioProvider()
42     : LeAudioOffloadAudioProvider() {
43   session_type_ = SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
44 }
45 
LeAudioOffloadInputAudioProvider()46 LeAudioOffloadInputAudioProvider::LeAudioOffloadInputAudioProvider()
47     : LeAudioOffloadAudioProvider() {
48   session_type_ = SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH;
49 }
50 
LeAudioOffloadAudioProvider()51 LeAudioOffloadAudioProvider::LeAudioOffloadAudioProvider()
52     : BluetoothAudioProvider() {}
53 
isValid(const V2_0::SessionType & sessionType)54 bool LeAudioOffloadAudioProvider::isValid(const V2_0::SessionType& sessionType) {
55   LOG(ERROR) << __func__ << ", invalid session type for Offloaded Le Audio provider: "
56              << toString(sessionType);
57 
58   return false;
59 }
60 
isValid(const SessionType & sessionType)61 bool LeAudioOffloadAudioProvider::isValid(const SessionType& sessionType) {
62   return (sessionType == session_type_);
63 }
64 
startSession_2_1(const sp<V2_0::IBluetoothAudioPort> & hostIf,const AudioConfiguration & audioConfig,startSession_cb _hidl_cb)65 Return<void> LeAudioOffloadAudioProvider::startSession_2_1(
66     const sp<V2_0::IBluetoothAudioPort>& hostIf,
67     const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
68   /**
69    * Initialize the audio platform if audioConfiguration is supported.
70    * Save the IBluetoothAudioPort interface, so that it can be used
71    * later to send stream control commands to the HAL client, based on
72    * interaction with Audio framework.
73    */
74   if (audioConfig.getDiscriminator() !=
75       AudioConfiguration::hidl_discriminator::leAudioCodecConfig) {
76     LOG(WARNING) << __func__
77                  << " - Invalid Audio Configuration=" << toString(audioConfig);
78     _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
79              DataMQ::Descriptor());
80     return Void();
81   }
82 
83   if (!android::bluetooth::audio::IsOffloadLeAudioConfigurationValid(session_type_,
84                  audioConfig.leAudioCodecConfig())) {
85     LOG(WARNING) << __func__ << " - Unsupported LC3 Offloaded Configuration="
86                  << toString(audioConfig.leAudioCodecConfig());
87     _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
88              DataMQ::Descriptor());
89     return Void();
90   }
91 
92   return BluetoothAudioProvider::startSession_2_1(hostIf, audioConfig,
93                                                   _hidl_cb);
94 }
95 
onSessionReady(startSession_cb _hidl_cb)96 Return<void> LeAudioOffloadAudioProvider::onSessionReady(startSession_cb _hidl_cb) {
97   BluetoothAudioSessionReport_2_1::OnSessionStarted(session_type_, stack_iface_,
98                                                     nullptr, audio_config_);
99   _hidl_cb(BluetoothAudioStatus::SUCCESS, DataMQ::Descriptor());
100   return Void();
101 }
102 
103 }  // namespace implementation
104 }  // namespace V2_1
105 }  // namespace audio
106 }  // namespace bluetooth
107 }  // namespace hardware
108 }  // namespace android
109