blob: 126bc9efddff6b072258b9d6de4e4926e094d5cd [file] [log] [blame]
Alice Kuo84e87672021-10-28 12:53:38 +08001/*
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 "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_2.h"
26#include "BluetoothAudioSupportedCodecsDB_2_1.h"
27
28namespace android {
29namespace hardware {
30namespace bluetooth {
31namespace audio {
32namespace V2_2 {
33namespace implementation {
34
35using ::android::bluetooth::audio::BluetoothAudioSessionReport_2_2;
36using ::android::hardware::kSynchronizedReadWrite;
37using ::android::hardware::MessageQueue;
38using ::android::hardware::Void;
39using ::android::hardware::bluetooth::audio::V2_0::AudioConfiguration;
40
41using DataMQ = MessageQueue<uint8_t, kSynchronizedReadWrite>;
42
43A2dpOffloadAudioProvider::A2dpOffloadAudioProvider()
44 : BluetoothAudioProvider() {
45 session_type_ = V2_1::SessionType::A2DP_HARDWARE_OFFLOAD_DATAPATH;
46}
47
48bool A2dpOffloadAudioProvider::isValid(const V2_0::SessionType& sessionType) {
49 return isValid(static_cast<V2_1::SessionType>(sessionType));
50}
51
52bool A2dpOffloadAudioProvider::isValid(const V2_1::SessionType& sessionType) {
53 return (sessionType == session_type_);
54}
55
56Return<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
82Return<void> A2dpOffloadAudioProvider::onSessionReady(
83 startSession_cb _hidl_cb) {
84 BluetoothAudioSessionReport_2_2::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_2
92} // namespace audio
93} // namespace bluetooth
94} // namespace hardware
95} // namespace android