• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 "BTAudioProviderA2dpOffload"
18 
19 #include "A2dpOffloadAudioProvider.h"
20 
21 #include <android-base/logging.h>
22 #include <fmq/MessageQueue.h>
23 #include <hidl/MQDescriptor.h>
24 
25 #include "BluetoothAudioSessionReport_2_1.h"
26 #include "BluetoothAudioSupportedCodecsDB_2_1.h"
27 
28 namespace android {
29 namespace hardware {
30 namespace bluetooth {
31 namespace audio {
32 namespace V2_1 {
33 namespace implementation {
34 
35 using ::android::bluetooth::audio::BluetoothAudioSessionReport_2_1;
36 using ::android::hardware::kSynchronizedReadWrite;
37 using ::android::hardware::MessageQueue;
38 using ::android::hardware::Void;
39 using ::android::hardware::bluetooth::audio::V2_0::AudioConfiguration;
40 
41 using DataMQ = MessageQueue<uint8_t, kSynchronizedReadWrite>;
42 
A2dpOffloadAudioProvider()43 A2dpOffloadAudioProvider::A2dpOffloadAudioProvider()
44     : BluetoothAudioProvider() {
45   session_type_ = SessionType::A2DP_HARDWARE_OFFLOAD_DATAPATH;
46 }
47 
isValid(const V2_0::SessionType & sessionType)48 bool A2dpOffloadAudioProvider::isValid(const V2_0::SessionType& sessionType) {
49   return isValid(static_cast<SessionType>(sessionType));
50 }
51 
isValid(const SessionType & sessionType)52 bool A2dpOffloadAudioProvider::isValid(const SessionType& sessionType) {
53   return (sessionType == session_type_);
54 }
55 
startSession(const sp<IBluetoothAudioPort> & hostIf,const AudioConfiguration & audioConfig,startSession_cb _hidl_cb)56 Return<void> A2dpOffloadAudioProvider::startSession(
57     const sp<IBluetoothAudioPort>& hostIf,
58     const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
59   /**
60    * Initialize the audio platform if audioConfiguration is supported.
61    * Save the IBluetoothAudioPort interface, so that it can be used
62    * later to send stream control commands to the HAL client, based on
63    * interaction with Audio framework.
64    */
65   if (audioConfig.getDiscriminator() !=
66       AudioConfiguration::hidl_discriminator::codecConfig) {
67     LOG(WARNING) << __func__
68                  << " - Invalid Audio Configuration=" << toString(audioConfig);
69     _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
70              DataMQ::Descriptor());
71     return Void();
72   } else if (!android::bluetooth::audio::IsOffloadCodecConfigurationValid(
73                  session_type_, audioConfig.codecConfig())) {
74     _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
75              DataMQ::Descriptor());
76     return Void();
77   }
78 
79   return BluetoothAudioProvider::startSession(hostIf, audioConfig, _hidl_cb);
80 }
81 
onSessionReady(startSession_cb _hidl_cb)82 Return<void> A2dpOffloadAudioProvider::onSessionReady(
83     startSession_cb _hidl_cb) {
84   BluetoothAudioSessionReport_2_1::OnSessionStarted(session_type_, stack_iface_,
85                                                     nullptr, audio_config_);
86   _hidl_cb(BluetoothAudioStatus::SUCCESS, DataMQ::Descriptor());
87   return Void();
88 }
89 
90 }  // namespace implementation
91 }  // namespace V2_1
92 }  // namespace audio
93 }  // namespace bluetooth
94 }  // namespace hardware
95 }  // namespace android
96