blob: 2b0c02f09de902c3e12492bdcaefe2df45a649fd [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
Jakub Pawlowski8d87eb72021-12-06 15:22:03 +010023#include "AudioPort_2_0_to_2_2_Wrapper.h"
Alice Kuo84e87672021-10-28 12:53:38 +080024#include "BluetoothAudioSessionReport_2_2.h"
Alice Kuo84e87672021-10-28 12:53:38 +080025#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
Jakub Pawlowski8d87eb72021-12-06 15:22:03 +010094 sp<V2_2::IBluetoothAudioPort> hostIf_2_2 =
95 new AudioPort_2_0_to_2_2_Wrapper(hostIf);
96 return startSession_2_2(hostIf_2_2, audioConfig_2_2, _hidl_cb);
Alice Kuo84e87672021-10-28 12:53:38 +080097}
98
99Return<void> LeAudioOffloadAudioProvider::startSession_2_2(
Jakub Pawlowski8d87eb72021-12-06 15:22:03 +0100100 const sp<V2_2::IBluetoothAudioPort>& hostIf,
Alice Kuo84e87672021-10-28 12:53:38 +0800101 const AudioConfiguration& audioConfig, startSession_cb _hidl_cb) {
102 /**
103 * Initialize the audio platform if audioConfiguration is supported.
104 * Save the IBluetoothAudioPort interface, so that it can be used
105 * later to send stream control commands to the HAL client, based on
106 * interaction with Audio framework.
107 */
108 if (audioConfig.getDiscriminator() !=
109 AudioConfiguration::hidl_discriminator::leAudioConfig) {
110 LOG(WARNING) << __func__
111 << " - Invalid Audio Configuration=" << toString(audioConfig);
112 _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
113 DataMQ::Descriptor());
114 return Void();
115 }
116
117 if (!android::bluetooth::audio::IsOffloadLeAudioConfigurationValid(
118 session_type_, audioConfig.leAudioConfig())) {
119 LOG(WARNING) << __func__ << " - Unsupported LC3 Offloaded Configuration="
120 << toString(audioConfig.leAudioConfig());
121 _hidl_cb(BluetoothAudioStatus::UNSUPPORTED_CODEC_CONFIGURATION,
122 DataMQ::Descriptor());
123 return Void();
124 }
125
126 return BluetoothAudioProvider::startSession_2_2(hostIf, audioConfig,
127 _hidl_cb);
128}
129
130Return<void> LeAudioOffloadAudioProvider::onSessionReady(
131 startSession_cb _hidl_cb) {
132 BluetoothAudioSessionReport_2_2::OnSessionStarted(session_type_, stack_iface_,
133 nullptr, audio_config_);
134 _hidl_cb(BluetoothAudioStatus::SUCCESS, DataMQ::Descriptor());
135 return Void();
136}
137
138} // namespace implementation
139} // namespace V2_2
140} // namespace audio
141} // namespace bluetooth
142} // namespace hardware
143} // namespace android