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