• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "BTAudioProviderStub"
18 
19 #include "BluetoothAudioProvider.h"
20 
21 #include <BluetoothAudioSessionReport.h>
22 #include <android-base/logging.h>
23 
24 #include "A2dpOffloadCodecFactory.h"
25 
26 namespace aidl {
27 namespace android {
28 namespace hardware {
29 namespace bluetooth {
30 namespace audio {
31 
32 struct BluetoothAudioProviderContext {
33   SessionType session_type;
34 };
35 
binderUnlinkedCallbackAidl(void * cookie)36 static void binderUnlinkedCallbackAidl(void* cookie) {
37   LOG(INFO) << __func__;
38   BluetoothAudioProviderContext* ctx =
39       static_cast<BluetoothAudioProviderContext*>(cookie);
40   delete ctx;
41 }
42 
binderDiedCallbackAidl(void * cookie)43 static void binderDiedCallbackAidl(void* cookie) {
44   LOG(INFO) << __func__;
45   BluetoothAudioProviderContext* ctx =
46       static_cast<BluetoothAudioProviderContext*>(cookie);
47   CHECK_NE(ctx, nullptr);
48 
49   BluetoothAudioSessionReport::OnSessionEnded(ctx->session_type);
50 }
51 
BluetoothAudioProvider()52 BluetoothAudioProvider::BluetoothAudioProvider() {
53   death_recipient_ = ::ndk::ScopedAIBinder_DeathRecipient(
54       AIBinder_DeathRecipient_new(binderDiedCallbackAidl));
55   AIBinder_DeathRecipient_setOnUnlinked(death_recipient_.get(),
56                                         binderUnlinkedCallbackAidl);
57 }
58 
startSession(const std::shared_ptr<IBluetoothAudioPort> & host_if,const AudioConfiguration & audio_config,const std::vector<LatencyMode> & latencyModes,DataMQDesc * _aidl_return)59 ndk::ScopedAStatus BluetoothAudioProvider::startSession(
60     const std::shared_ptr<IBluetoothAudioPort>& host_if,
61     const AudioConfiguration& audio_config,
62     const std::vector<LatencyMode>& latencyModes,
63     DataMQDesc* _aidl_return) {
64   if (host_if == nullptr) {
65     *_aidl_return = DataMQDesc();
66     LOG(ERROR) << __func__ << " - SessionType=" << toString(session_type_)
67                << " Illegal argument";
68     return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
69   }
70 
71   latency_modes_ = latencyModes;
72   audio_config_ = std::make_unique<AudioConfiguration>(audio_config);
73   stack_iface_ = host_if;
74   BluetoothAudioProviderContext* cookie =
75       new BluetoothAudioProviderContext{session_type_};
76 
77   AIBinder_linkToDeath(stack_iface_->asBinder().get(), death_recipient_.get(),
78                        cookie);
79 
80   LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_);
81   onSessionReady(_aidl_return);
82   return ndk::ScopedAStatus::ok();
83 }
84 
endSession()85 ndk::ScopedAStatus BluetoothAudioProvider::endSession() {
86   LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_);
87 
88   if (stack_iface_ != nullptr) {
89     BluetoothAudioSessionReport::OnSessionEnded(session_type_);
90 
91     AIBinder_unlinkToDeath(stack_iface_->asBinder().get(),
92                            death_recipient_.get(), this);
93   } else {
94     LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
95               << " has NO session";
96   }
97 
98   stack_iface_ = nullptr;
99   audio_config_ = nullptr;
100 
101   return ndk::ScopedAStatus::ok();
102 }
103 
streamStarted(BluetoothAudioStatus status)104 ndk::ScopedAStatus BluetoothAudioProvider::streamStarted(
105     BluetoothAudioStatus status) {
106   if (stack_iface_ != nullptr) {
107     LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
108               << ", status=" << toString(status);
109     BluetoothAudioSessionReport::ReportControlStatus(session_type_, true,
110                                                      status);
111   } else {
112     LOG(WARNING) << __func__ << " - SessionType=" << toString(session_type_)
113                  << ", status=" << toString(status) << " has NO session";
114   }
115 
116   return ndk::ScopedAStatus::ok();
117 }
118 
streamSuspended(BluetoothAudioStatus status)119 ndk::ScopedAStatus BluetoothAudioProvider::streamSuspended(
120     BluetoothAudioStatus status) {
121   LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
122             << ", status=" << toString(status);
123 
124   if (stack_iface_ != nullptr) {
125     BluetoothAudioSessionReport::ReportControlStatus(session_type_, false,
126                                                      status);
127   } else {
128     LOG(WARNING) << __func__ << " - SessionType=" << toString(session_type_)
129                  << ", status=" << toString(status) << " has NO session";
130   }
131   return ndk::ScopedAStatus::ok();
132 }
133 
updateAudioConfiguration(const AudioConfiguration & audio_config)134 ndk::ScopedAStatus BluetoothAudioProvider::updateAudioConfiguration(
135     const AudioConfiguration& audio_config) {
136   if (stack_iface_ == nullptr || audio_config_ == nullptr) {
137     LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
138               << " has NO session";
139     return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
140   }
141 
142   if (audio_config.getTag() != audio_config_->getTag()) {
143     LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
144               << " audio config type is not match";
145     return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
146   }
147 
148   audio_config_ = std::make_unique<AudioConfiguration>(audio_config);
149   BluetoothAudioSessionReport::ReportAudioConfigChanged(session_type_,
150                                                         *audio_config_);
151   LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
152             << " | audio_config=" << audio_config.toString();
153   return ndk::ScopedAStatus::ok();
154 }
155 
setLowLatencyModeAllowed(bool allowed)156 ndk::ScopedAStatus BluetoothAudioProvider::setLowLatencyModeAllowed(
157     bool allowed) {
158   if (stack_iface_ == nullptr) {
159     LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
160               << " has NO session";
161     return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
162   }
163   LOG(INFO) << __func__ << " - allowed " << allowed;
164   BluetoothAudioSessionReport::ReportLowLatencyModeAllowedChanged(
165     session_type_, allowed);
166   return ndk::ScopedAStatus::ok();
167 }
168 
parseA2dpConfiguration(const CodecId & codec_id,const std::vector<uint8_t> & configuration,CodecParameters * codec_parameters,A2dpStatus * _aidl_return)169 ndk::ScopedAStatus BluetoothAudioProvider::parseA2dpConfiguration(
170     [[maybe_unused]] const CodecId& codec_id,
171     [[maybe_unused]] const std::vector<uint8_t>& configuration,
172     [[maybe_unused]] CodecParameters* codec_parameters,
173     [[maybe_unused]] A2dpStatus* _aidl_return) {
174   LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
175             << " is illegal";
176   return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
177 }
178 
getA2dpConfiguration(const std::vector<A2dpRemoteCapabilities> & remote_a2dp_capabilities,const A2dpConfigurationHint & hint,std::optional<audio::A2dpConfiguration> * _aidl_return)179 ndk::ScopedAStatus BluetoothAudioProvider::getA2dpConfiguration(
180     [[maybe_unused]] const std::vector<A2dpRemoteCapabilities>&
181         remote_a2dp_capabilities,
182     [[maybe_unused]] const A2dpConfigurationHint& hint,
183     [[maybe_unused]] std::optional<audio::A2dpConfiguration>* _aidl_return) {
184   LOG(INFO) << __func__ << " - SessionType=" << toString(session_type_)
185             << " is illegal";
186 
187   return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
188 }
189 
setCodecPriority(const::aidl::android::hardware::bluetooth::audio::CodecId & in_codecId,int32_t in_priority)190 ndk::ScopedAStatus BluetoothAudioProvider::setCodecPriority(
191     const ::aidl::android::hardware::bluetooth::audio::CodecId& in_codecId,
192     int32_t in_priority) {
193   /* TODO: Implement */
194   (void)in_codecId;
195   (void)in_priority;
196   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
197 };
198 
getLeAudioAseConfiguration(const std::optional<std::vector<std::optional<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioDeviceCapabilities>>> & in_remoteSinkAudioCapabilities,const std::optional<std::vector<std::optional<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioDeviceCapabilities>>> & in_remoteSourceAudioCapabilities,const std::vector<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioConfigurationRequirement> & in_requirements,std::vector<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioAseConfigurationSetting> * _aidl_return)199 ndk::ScopedAStatus BluetoothAudioProvider::getLeAudioAseConfiguration(
200     const std::optional<std::vector<std::optional<
201         ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
202             LeAudioDeviceCapabilities>>>& in_remoteSinkAudioCapabilities,
203     const std::optional<std::vector<std::optional<
204         ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
205             LeAudioDeviceCapabilities>>>& in_remoteSourceAudioCapabilities,
206     const std::vector<
207         ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
208             LeAudioConfigurationRequirement>& in_requirements,
209     std::vector<::aidl::android::hardware::bluetooth::audio::
210                     IBluetoothAudioProvider::LeAudioAseConfigurationSetting>*
211         _aidl_return) {
212   /* TODO: Implement */
213   (void)in_remoteSinkAudioCapabilities;
214   (void)in_remoteSourceAudioCapabilities;
215   (void)in_requirements;
216   (void)_aidl_return;
217   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
218 };
219 
getLeAudioAseQosConfiguration(const::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement & in_qosRequirement,::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioAseQosConfigurationPair * _aidl_return)220 ndk::ScopedAStatus BluetoothAudioProvider::getLeAudioAseQosConfiguration(
221     const ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
222         LeAudioAseQosConfigurationRequirement& in_qosRequirement,
223     ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
224         LeAudioAseQosConfigurationPair* _aidl_return) {
225   /* TODO: Implement */
226   (void)in_qosRequirement;
227   (void)_aidl_return;
228   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
229 };
230 
getLeAudioAseDatapathConfiguration(const std::optional<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::StreamConfig> & in_sinkConfig,const std::optional<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::StreamConfig> & in_sourceConfig,::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioDataPathConfigurationPair * _aidl_return)231 ndk::ScopedAStatus BluetoothAudioProvider::getLeAudioAseDatapathConfiguration(
232     const std::optional<::aidl::android::hardware::bluetooth::audio::
233                             IBluetoothAudioProvider::StreamConfig>&
234         in_sinkConfig,
235     const std::optional<::aidl::android::hardware::bluetooth::audio::
236                             IBluetoothAudioProvider::StreamConfig>&
237         in_sourceConfig,
238     ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
239         LeAudioDataPathConfigurationPair* _aidl_return) {
240   /* TODO: Implement */
241   (void)in_sinkConfig;
242   (void)in_sourceConfig;
243   (void)_aidl_return;
244   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
245 }
246 
onSinkAseMetadataChanged(::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::AseState in_state,int32_t cigId,int32_t cisId,const std::optional<std::vector<std::optional<::aidl::android::hardware::bluetooth::audio::MetadataLtv>>> & in_metadata)247 ndk::ScopedAStatus BluetoothAudioProvider::onSinkAseMetadataChanged(
248     ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
249         AseState in_state,
250     int32_t cigId, int32_t cisId,
251     const std::optional<std::vector<std::optional<
252         ::aidl::android::hardware::bluetooth::audio::MetadataLtv>>>&
253         in_metadata) {
254   /* TODO: Implement */
255   (void)in_state;
256   (void)cigId;
257   (void)cisId;
258   (void)in_metadata;
259   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
260 };
261 
onSourceAseMetadataChanged(::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::AseState in_state,int32_t cigId,int32_t cisId,const std::optional<std::vector<std::optional<::aidl::android::hardware::bluetooth::audio::MetadataLtv>>> & in_metadata)262 ndk::ScopedAStatus BluetoothAudioProvider::onSourceAseMetadataChanged(
263     ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
264         AseState in_state,
265     int32_t cigId, int32_t cisId,
266     const std::optional<std::vector<std::optional<
267         ::aidl::android::hardware::bluetooth::audio::MetadataLtv>>>&
268         in_metadata) {
269   /* TODO: Implement */
270   (void)in_state;
271   (void)cigId;
272   (void)cisId;
273   (void)in_metadata;
274   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
275 };
276 
getLeAudioBroadcastConfiguration(const std::optional<std::vector<std::optional<::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioDeviceCapabilities>>> & in_remoteSinkAudioCapabilities,const::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement & in_requirement,::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting * _aidl_return)277 ndk::ScopedAStatus BluetoothAudioProvider::getLeAudioBroadcastConfiguration(
278     const std::optional<std::vector<std::optional<
279         ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
280             LeAudioDeviceCapabilities>>>& in_remoteSinkAudioCapabilities,
281     const ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
282         LeAudioBroadcastConfigurationRequirement& in_requirement,
283     ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
284         LeAudioBroadcastConfigurationSetting* _aidl_return) {
285   /* TODO: Implement */
286   (void)in_remoteSinkAudioCapabilities;
287   (void)in_requirement;
288   (void)_aidl_return;
289   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
290 };
291 
292 ndk::ScopedAStatus
getLeAudioBroadcastDatapathConfiguration(const::aidl::android::hardware::bluetooth::audio::AudioContext & in_context,const std::vector<::aidl::android::hardware::bluetooth::audio::LeAudioBroadcastConfiguration::BroadcastStreamMap> & in_streamMap,::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::LeAudioDataPathConfiguration * _aidl_return)293 BluetoothAudioProvider::getLeAudioBroadcastDatapathConfiguration(
294     const ::aidl::android::hardware::bluetooth::audio::AudioContext& in_context,
295     const std::vector<::aidl::android::hardware::bluetooth::audio::
296                           LeAudioBroadcastConfiguration::BroadcastStreamMap>&
297         in_streamMap,
298     ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider::
299         LeAudioDataPathConfiguration* _aidl_return) {
300   /* TODO: Implement */
301   (void)in_context;
302   (void)in_streamMap;
303   (void)_aidl_return;
304   return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
305 }
306 
307 }  // namespace audio
308 }  // namespace bluetooth
309 }  // namespace hardware
310 }  // namespace android
311 }  // namespace aidl
312