blob: 7b70654ba818e82af8884e70d8ca35e3e8e0a801 [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 "BTAudioProviderLeAudioOffload"
18
19#include "LeAudioOffloadAudioProvider.h"
20
21#include <android-base/logging.h>
22
23#include "BluetoothAudioSessionReport_2_2.h"
24#include "BluetoothAudioSupportedCodecsDB_2_1.h"
25#include "BluetoothAudioSupportedCodecsDB_2_2.h"
26
27namespace android {
28namespace hardware {
29namespace bluetooth {
30namespace audio {
31namespace V2_2 {
32namespace implementation {
33
34using ::android::bluetooth::audio::BluetoothAudioSessionReport_2_2;
35using ::android::hardware::Void;
36using ::android::hardware::bluetooth::audio::V2_0::BitsPerSample;
37using ::android::hardware::bluetooth::audio::V2_0::ChannelMode;
38using ::android::hardware::bluetooth::audio::V2_1::SampleRate;
39
40using DataMQ = MessageQueue<uint8_t, kSynchronizedReadWrite>;
41
42LeAudioOffloadOutputAudioProvider::LeAudioOffloadOutputAudioProvider()
43 : LeAudioOffloadAudioProvider() {
44 session_type_ =
45 V2_1::SessionType::LE_AUDIO_HARDWARE_OFFLOAD_ENCODING_DATAPATH;
46}
47
48LeAudioOffloadInputAudioProvider::LeAudioOffloadInputAudioProvider()
49 : LeAudioOffloadAudioProvider() {
50 session_type_ =
51 V2_1::SessionType::LE_AUDIO_HARDWARE_OFFLOAD_DECODING_DATAPATH;
52}
53
54LeAudioOffloadAudioProvider::LeAudioOffloadAudioProvider()
55 : BluetoothAudioProvider() {}
56
57bool LeAudioOffloadAudioProvider::isValid(
58 const V2_0::SessionType& sessionType) {
59 LOG(ERROR) << __func__
60 << ", invalid session type for Offloaded Le Audio provider: "
61 << toString(sessionType);
62
63 return false;
64}
65
66bool LeAudioOffloadAudioProvider::isValid(
67 const V2_1::SessionType& sessionType) {
68 return (sessionType == session_type_);
69}
70
71Return<void> LeAudioOffloadAudioProvider::startSession_2_1(
72 const sp<V2_0::IBluetoothAudioPort>& hostIf,
73 const V2_1::AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
74 if (audioConfig.getDiscriminator() !=
75 V2_1::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 AudioConfiguration audioConfig_2_2;
84 audioConfig_2_2.leAudioConfig().mode = LeAudioMode::UNKNOWN;
85 audioConfig_2_2.leAudioConfig().config.unicastConfig() = {
86 .streamMap = {{
87 .streamHandle = 0xFFFF,
88 .audioChannelAllocation =
89 audioConfig.leAudioCodecConfig().audioChannelAllocation,
90 }},
91 .peerDelay = 0,
92 .lc3Config = audioConfig.leAudioCodecConfig().lc3Config};
93
94 return startSession_2_2(hostIf, audioConfig_2_2, _hidl_cb);
95}
96
97Return<void> LeAudioOffloadAudioProvider::startSession_2_2(
98 const sp<V2_0::IBluetoothAudioPort>& hostIf,
99 const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
100 /**
101 * Initialize the audio platform if audioConfiguration is supported.
102 * Save the IBluetoothAudioPort interface, so that it can be used
103 * later to send stream control commands to the HAL client, based on
104 * interaction with Audio framework.
105 */
106 if (audioConfig.getDiscriminator() !=
107 AudioConfiguration::hidl_discriminator::leAudioConfig) {
108 LOG(WARNING) << __func__
109 << " - Invalid Audio Configuration=" << toString(audioConfig);
110 _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
111 DataMQ::Descriptor());
112 return Void();
113 }
114
115 if (!android::bluetooth::audio::IsOffloadLeAudioConfigurationValid(
116 session_type_, audioConfig.leAudioConfig())) {
117 LOG(WARNING) << __func__ << " - Unsupported LC3 Offloaded Configuration="
118 << toString(audioConfig.leAudioConfig());
119 _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
120 DataMQ::Descriptor());
121 return Void();
122 }
123
124 return BluetoothAudioProvider::startSession_2_2(hostIf, audioConfig,
125 _hidl_cb);
126}
127
128Return<void> LeAudioOffloadAudioProvider::onSessionReady(
129 startSession_cb _hidl_cb) {
130 BluetoothAudioSessionReport_2_2::OnSessionStarted(session_type_, stack_iface_,
131 nullptr, audio_config_);
132 _hidl_cb(BluetoothAudioStatus::SUCCESS, DataMQ::Descriptor());
133 return Void();
134}
135
136} // namespace implementation
137} // namespace V2_2
138} // namespace audio
139} // namespace bluetooth
140} // namespace hardware
141} // namespace android