1 /*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bluetooth_a2dp_src.h"
17 #include "bluetooth_a2dp_codec.h"
18 #include "bluetooth_a2dp_src_proxy.h"
19 #include "bluetooth_a2dp_src_observer_stub.h"
20 #include "bluetooth_host_proxy.h"
21 #include "bluetooth_observer_list.h"
22 #include "raw_address.h"
23 #include "bluetooth_def.h"
24 #include "bluetooth_host.h"
25
26 #include "bluetooth_log.h"
27 #include "iservice_registry.h"
28 #include "system_ability_definition.h"
29
30 namespace OHOS {
31 namespace Bluetooth {
32 using namespace bluetooth;
33
34 struct A2dpSource::impl {
35 impl();
36 ~impl();
37
38 BluetoothObserverList<A2dpSourceObserver> observers_;
39 sptr<IBluetoothA2dpSrc> proxy_ = nullptr;
40 class BluetoothA2dpSourceObserverImp;
41 sptr<BluetoothA2dpSourceObserverImp> observerImp_ = nullptr;
42 class BluetoothA2dpSourceDeathRecipient;
43 sptr<BluetoothA2dpSourceDeathRecipient> deathRecipient_ = nullptr;
44
45 private:
46 void GetProxy();
47 };
48
49 class A2dpSource::impl::BluetoothA2dpSourceObserverImp : public BluetoothA2dpSrcObserverStub {
50 public:
BluetoothA2dpSourceObserverImp(A2dpSource::impl & a2dpSource)51 BluetoothA2dpSourceObserverImp(A2dpSource::impl &a2dpSource) : a2dpSource_(a2dpSource) {};
~BluetoothA2dpSourceObserverImp()52 ~BluetoothA2dpSourceObserverImp() override{};
53
Register(std::shared_ptr<A2dpSourceObserver> & observer)54 void Register(std::shared_ptr<A2dpSourceObserver> &observer)
55 {
56 HILOGD("%{public}s start.", __func__);
57 a2dpSource_.observers_.Register(observer);
58 }
59
Deregister(std::shared_ptr<A2dpSourceObserver> & observer)60 void Deregister(std::shared_ptr<A2dpSourceObserver> &observer)
61 {
62 HILOGD("%{public}s start.", __func__);
63 a2dpSource_.observers_.Deregister(observer);
64 }
65
OnConnectionStateChanged(const RawAddress & device,int state)66 void OnConnectionStateChanged(const RawAddress &device, int state) override
67 {
68 HILOGD("%{public}s start.", __func__);
69 a2dpSource_.observers_.ForEach([device, state](std::shared_ptr<A2dpSourceObserver> observer) {
70 observer->OnConnectionStateChanged(BluetoothRemoteDevice(device.GetAddress(), 0), state);
71 });
72 }
73
OnPlayingStatusChanged(const RawAddress & device,int playingState,int error)74 void OnPlayingStatusChanged(const RawAddress &device, int playingState, int error) override
75 {
76 HILOGD("%{public}s start.", __func__);
77 a2dpSource_.observers_.ForEach([device, playingState, error](std::shared_ptr<A2dpSourceObserver> observer) {
78 observer->OnPlayingStatusChanged(BluetoothRemoteDevice(device.GetAddress(), 0), playingState, error);
79 });
80 }
81
OnConfigurationChanged(const RawAddress & device,const BluetoothA2dpCodecInfo & info,int error)82 void OnConfigurationChanged(const RawAddress &device, const BluetoothA2dpCodecInfo &info, int error) override
83 {
84 HILOGD("%{public}s start.", __func__);
85 a2dpSource_.observers_.ForEach([device, info, error](std::shared_ptr<A2dpSourceObserver> observer) {
86 A2dpCodecInfo codecInfo;
87
88 codecInfo.bitsPerSample = info.bitsPerSample;
89 codecInfo.channelMode = info.channelMode;
90 codecInfo.codecPriority = info.codecPriority;
91 codecInfo.codecType = info.codecType;
92 codecInfo.sampleRate = info.sampleRate;
93
94 observer->OnConfigurationChanged(BluetoothRemoteDevice(device.GetAddress(), 0), codecInfo, error);
95 });
96 };
97
98 private:
99 A2dpSource::impl &a2dpSource_;
100 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothA2dpSourceObserverImp);
101 };
102
103 class A2dpSource::impl::BluetoothA2dpSourceDeathRecipient final : public IRemoteObject::DeathRecipient {
104 public:
BluetoothA2dpSourceDeathRecipient(A2dpSource::impl & a2dpSrcDeath)105 BluetoothA2dpSourceDeathRecipient(A2dpSource::impl &a2dpSrcDeath) : a2dpSrcDeath_(a2dpSrcDeath)
106 {};
107 ~BluetoothA2dpSourceDeathRecipient() final = default;
108 BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(BluetoothA2dpSourceDeathRecipient);
109
OnRemoteDied(const wptr<IRemoteObject> & remote)110 void OnRemoteDied(const wptr<IRemoteObject> &remote) final
111 {
112 HILOGI("A2dpSource::impl::BluetoothA2dpSourceDeathRecipient::OnRemoteDied starts");
113 a2dpSrcDeath_.proxy_->AsObject()->RemoveDeathRecipient(a2dpSrcDeath_.deathRecipient_);
114 a2dpSrcDeath_.proxy_ = nullptr;
115 }
116
117 private:
118 A2dpSource::impl &a2dpSrcDeath_;
119 };
120
impl()121 A2dpSource::impl::impl()
122 {
123 HILOGE("A2dpSource::impl::impl start");
124 GetProxy();
125 if (proxy_ == nullptr) {
126 HILOGI("A2dpSource::get proxy_ failed");
127 return;
128 }
129 deathRecipient_ = new BluetoothA2dpSourceDeathRecipient(*this);
130 proxy_->AsObject()->AddDeathRecipient(deathRecipient_);
131
132 observerImp_ = new (std::nothrow) BluetoothA2dpSourceObserverImp(*this);
133 proxy_->RegisterObserver(observerImp_);
134 };
135
~impl()136 A2dpSource::impl::~impl()
137 {
138 HILOGD("A2dpSource::impl::~impl start");
139 if (proxy_ != nullptr) {
140 proxy_->DeregisterObserver(observerImp_);
141 proxy_->AsObject()->RemoveDeathRecipient(deathRecipient_);
142 }
143 }
144
GetProxy()145 void A2dpSource::impl::GetProxy()
146 {
147 HILOGI("A2dpSource::impl::GetProxy start");
148 sptr<ISystemAbilityManager> samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
149 if (!samgr) {
150 HILOGE("A2dpSource::impl::GetProxy error: no samgr");
151 return;
152 }
153
154 sptr<IRemoteObject> hostRemote = samgr->GetSystemAbility(BLUETOOTH_HOST_SYS_ABILITY_ID);
155 if (!hostRemote) {
156 HILOGE("A2dpSource::impl:GetProxy failed: no hostRemote");
157 return;
158 }
159
160 sptr<IBluetoothHost> hostProxy = iface_cast<IBluetoothHost>(hostRemote);
161 if (!hostProxy) {
162 HILOGE("A2dpSource::impl::GetProxy error: host no proxy");
163 return;
164 }
165
166 sptr<IRemoteObject> remote = hostProxy->GetProfile(PROFILE_A2DP_SRC);
167 if (!remote) {
168 HILOGE("A2dpSource::impl::GetProxy error: no remote");
169 return;
170 }
171
172 proxy_ = iface_cast<IBluetoothA2dpSrc>(remote);
173 if (!proxy_) {
174 HILOGE("A2dpSource::impl::GetProxy error: no proxy");
175 return;
176 }
177 }
178
A2dpSource()179 A2dpSource::A2dpSource()
180 {
181 pimpl = std::make_unique<impl>();
182 if (!pimpl) {
183 HILOGE("A2dpSource::A2dpSource fails: no pimpl");
184 }
185 }
186
~A2dpSource()187 A2dpSource::~A2dpSource()
188 {
189 HILOGE("A2dpSource::~A2dpSource start");
190 }
191
RegisterObserver(A2dpSourceObserver * observer)192 void A2dpSource::RegisterObserver(A2dpSourceObserver *observer)
193 {
194 HILOGD("%{public}s start.", __func__);
195 std::shared_ptr<A2dpSourceObserver> pointer(observer, [](A2dpSourceObserver *) {});
196 pimpl->observers_.Register(pointer);
197 }
198
DeregisterObserver(A2dpSourceObserver * observer)199 void A2dpSource::DeregisterObserver(A2dpSourceObserver *observer)
200 {
201 HILOGD("%{public}s start.", __func__);
202 std::shared_ptr<A2dpSourceObserver> pointer(observer, [](A2dpSourceObserver *) {});
203 pimpl->observers_.Deregister(pointer);
204 }
205
GetDevicesByStates(std::vector<int> states) const206 std::vector<BluetoothRemoteDevice> A2dpSource::GetDevicesByStates(std::vector<int> states) const
207 {
208 HILOGI("[A2dpSource] %{public}s\n", __func__);
209 std::vector<BluetoothRemoteDevice> devices;
210 std::vector<BluetoothRawAddress> devicesRaw;
211
212 for (int state : states) {
213 if ((static_cast<int>(BTConnectState::CONNECTED) != state) &&
214 (static_cast<int>(BTConnectState::CONNECTING) != state) &&
215 (static_cast<int>(BTConnectState::DISCONNECTING) != state) &&
216 (static_cast<int>(BTConnectState::DISCONNECTED) != state)) {
217 HILOGI("[A2dpSource] input parameter error.");
218 return devices;
219 }
220 }
221
222 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
223 pimpl->proxy_->GetDevicesByStates(states);
224 }
225
226 for (RawAddress it : devicesRaw) {
227 BluetoothRemoteDevice remoteDevice(it.GetAddress(), 0);
228 devices.push_back(remoteDevice);
229 }
230
231 return devices;
232 }
233
GetDeviceState(const BluetoothRemoteDevice & device) const234 int A2dpSource::GetDeviceState(const BluetoothRemoteDevice &device) const
235 {
236 HILOGI("[A2dpSource] %{public}s\n", __func__);
237
238 if (!device.IsValidBluetoothRemoteDevice()) {
239 HILOGI("[A2dpSource] input parameter error.");
240 return RET_BAD_STATUS;
241 }
242
243 int ret = RET_NO_ERROR;
244 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
245 ret = pimpl->proxy_->GetDeviceState(RawAddress(device.GetDeviceAddr()));
246 } else {
247 HILOGI("[A2dpSource] proxy or bt disable.");
248 return RET_BAD_STATUS;
249 }
250
251 return ret;
252 }
253
GetPlayingState(const BluetoothRemoteDevice & device) const254 int A2dpSource::GetPlayingState(const BluetoothRemoteDevice &device) const
255 {
256 HILOGI("[A2dpSource] %{public}s\n", __func__);
257
258 if (!device.IsValidBluetoothRemoteDevice()) {
259 HILOGI("[A2dpSource] input parameter error.");
260 return RET_BAD_STATUS;
261 }
262
263 int ret = RET_NO_ERROR;
264 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
265 ret = pimpl->proxy_->GetPlayingState(RawAddress(device.GetDeviceAddr()));
266 } else {
267 HILOGI("[A2dpSource] proxy or bt disable.");
268 return RET_BAD_STATUS;
269 }
270
271 return ret;
272 }
273
Connect(const BluetoothRemoteDevice & device)274 bool A2dpSource::Connect(const BluetoothRemoteDevice &device)
275 {
276 HILOGI("[A2dpSource] %{public}s\n", __func__);
277
278 if (!device.IsValidBluetoothRemoteDevice()) {
279 HILOGI("[A2dpSource] input parameter error.");
280 return false;
281 }
282
283 int ret = RET_NO_ERROR;
284 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
285 ret= pimpl->proxy_->Connect(RawAddress(device.GetDeviceAddr()));
286 } else {
287 HILOGI("[A2dpSource] proxy or bt disable.");
288 return false;
289 }
290 return (RET_NO_ERROR == ret);
291 }
292
Disconnect(const BluetoothRemoteDevice & device)293 bool A2dpSource::Disconnect(const BluetoothRemoteDevice &device)
294 {
295 HILOGI("[A2dpSource] %{public}s\n", __func__);
296
297 if (!device.IsValidBluetoothRemoteDevice()) {
298 HILOGI("[A2dpSource] input parameter error.");
299 return false;
300 }
301
302 int ret = RET_NO_ERROR;
303 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
304 ret = pimpl->proxy_->Disconnect(RawAddress(device.GetDeviceAddr()));
305 } else {
306 HILOGI("[A2dpSource] proxy or bt disable.");
307 return false;
308 }
309 return (RET_NO_ERROR == ret);
310 }
311
GetProfile()312 A2dpSource *A2dpSource::GetProfile()
313 {
314 HILOGI("[A2dpSource] %{public}s\n", __func__);
315 static A2dpSource service;
316 return &service;
317 }
318
SetActiveSinkDevice(const BluetoothRemoteDevice & device)319 int A2dpSource::SetActiveSinkDevice(const BluetoothRemoteDevice &device)
320 {
321 HILOGI("[A2dpSource] %{public}s\n", __func__);
322
323 if (!device.IsValidBluetoothRemoteDevice()) {
324 HILOGI("[A2dpSource] input parameter error.");
325 return RET_BAD_PARAM;
326 }
327
328 int ret = RET_NO_ERROR;
329 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
330 ret = pimpl->proxy_->SetActiveSinkDevice(RawAddress(device.GetDeviceAddr()));
331 } else {
332 HILOGI("[A2dpSource] proxy or bt disable.");
333 return false;
334 }
335
336 return ret;
337 }
338
GetActiveSinkDevice() const339 const BluetoothRemoteDevice &A2dpSource::GetActiveSinkDevice() const
340 {
341 HILOGI("[A2dpSource] %{public}s", __func__);
342
343 BluetoothRawAddress rawAddress;
344 static BluetoothRemoteDevice deviceInfo;
345
346 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
347 pimpl->proxy_->GetActiveSinkDevice();
348 }
349
350 deviceInfo = BluetoothRemoteDevice(rawAddress.GetAddress(), 0);
351 return deviceInfo;
352 }
353
SetConnectStrategy(const BluetoothRemoteDevice & device,int strategy)354 bool A2dpSource::SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy)
355 {
356 HILOGI("[A2dpSource] %{public}s", __func__);
357
358 if ((!device.IsValidBluetoothRemoteDevice()) || (((int)BTStrategyType::CONNECTION_ALLOWED != strategy) &&
359 ((int)BTStrategyType::CONNECTION_FORBIDDEN != strategy))) {
360 HILOGI("[A2dpSource] input parameter error.");
361 return false;
362 }
363
364 int ret = RET_NO_ERROR;
365 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
366 ret = pimpl->proxy_->SetConnectStrategy(RawAddress(device.GetDeviceAddr()), strategy);
367 } else {
368 HILOGI("[A2dpSource] proxy or bt disable.");
369 return false;
370 }
371
372 return (RET_NO_ERROR == ret);
373 }
374
GetConnectStrategy(const BluetoothRemoteDevice & device) const375 int A2dpSource::GetConnectStrategy(const BluetoothRemoteDevice &device) const
376 {
377 HILOGI("[A2dpSource] %{public}s\n", __func__);
378
379 if (!device.IsValidBluetoothRemoteDevice()) {
380 HILOGI("[A2dpSource] input parameter error.");
381 return RET_BAD_PARAM;
382 }
383
384 int ret = RET_NO_ERROR;
385 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
386 ret = pimpl->proxy_->GetConnectStrategy(RawAddress(device.GetDeviceAddr()));
387 } else {
388 HILOGI("[A2dpSource] proxy or bt disable.");
389 return RET_BAD_STATUS;
390 }
391
392 return ret;
393 }
394
GetCodecStatus(const BluetoothRemoteDevice & device) const395 A2dpCodecStatus A2dpSource::GetCodecStatus(const BluetoothRemoteDevice &device) const
396 {
397 HILOGI("[A2dpSource] %{public}s\n", __func__);
398
399 A2dpCodecStatus ret;
400 BluetoothA2dpCodecStatus codecStatus;
401 A2dpCodecInfo serviceInfo;
402
403 if (!device.IsValidBluetoothRemoteDevice()) {
404 HILOGI("[A2dpSource] input parameter error.");
405 return ret;
406 }
407
408 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
409 codecStatus = pimpl->proxy_->GetCodecStatus(RawAddress(device.GetDeviceAddr()));
410 }
411
412 ret.codecInfo.codecType = codecStatus.codecInfo.codecType;
413 ret.codecInfo.sampleRate = codecStatus.codecInfo.sampleRate;
414 ret.codecInfo.channelMode = codecStatus.codecInfo.channelMode;
415 ret.codecInfo.codecPriority = codecStatus.codecInfo.codecPriority;
416 ret.codecInfo.bitsPerSample = codecStatus.codecInfo.bitsPerSample;
417
418 for (auto it = codecStatus.codecInfoConfirmCap.begin(); it != codecStatus.codecInfoConfirmCap.end(); it++) {
419 serviceInfo.codecType = it->codecType;
420 serviceInfo.sampleRate = it->sampleRate;
421 serviceInfo.channelMode = it->channelMode;
422 serviceInfo.codecPriority = it->codecPriority;
423 serviceInfo.bitsPerSample = it->bitsPerSample;
424 ret.codecInfoConfirmedCap.push_back(serviceInfo);
425 }
426
427 for (auto it = codecStatus.codecInfoLocalCap.begin(); it != codecStatus.codecInfoLocalCap.end(); it++) {
428 serviceInfo.codecType = it->codecType;
429 serviceInfo.sampleRate = it->sampleRate;
430 serviceInfo.channelMode = it->channelMode;
431 serviceInfo.codecPriority = it->codecPriority;
432 serviceInfo.bitsPerSample = it->bitsPerSample;
433 ret.codecInfoLocalCap.push_back(serviceInfo);
434 }
435 return ret;
436 }
437
SetCodecPreference(const BluetoothRemoteDevice & device,const A2dpCodecInfo & info)438 int A2dpSource::SetCodecPreference(const BluetoothRemoteDevice &device, const A2dpCodecInfo &info)
439 {
440 HILOGI("[A2dpSource] %{public}s\n", __func__);
441
442 int ret = RET_NO_ERROR;
443 if (!device.IsValidBluetoothRemoteDevice()) {
444 HILOGI("[A2dpSource] input parameter error.");
445 ret = RET_BAD_PARAM;
446 return ret;
447 }
448 BluetoothA2dpCodecInfo serviceInfo;
449
450 serviceInfo.codecType = info.codecType;
451 serviceInfo.sampleRate = info.sampleRate;
452 serviceInfo.channelMode = info.channelMode;
453 serviceInfo.bitsPerSample = info.bitsPerSample;
454 serviceInfo.codecPriority = info.codecPriority;
455 serviceInfo.codecSpecific1 = info.codecSpecific1;
456 serviceInfo.codecSpecific2 = info.codecSpecific2;
457 serviceInfo.codecSpecific3 = info.codecSpecific3;
458 serviceInfo.codecSpecific4 = info.codecSpecific4;
459
460 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
461 ret = pimpl->proxy_->SetCodecPreference(RawAddress(device.GetDeviceAddr()), serviceInfo);
462 } else {
463 HILOGI("[A2dpSource] proxy or bt disable.");
464 return RET_BAD_STATUS;
465 }
466
467 return ret;
468 }
469
SwitchOptionalCodecs(const BluetoothRemoteDevice & device,bool isEnable)470 void A2dpSource::SwitchOptionalCodecs(const BluetoothRemoteDevice &device, bool isEnable)
471 {
472 HILOGI("[A2dpSource] %{public}s\n", __func__);
473
474 if (!device.IsValidBluetoothRemoteDevice()) {
475 HILOGI("[A2dpSource] input parameter error.");
476 return;
477 }
478
479 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
480 pimpl->proxy_->SwitchOptionalCodecs(RawAddress(device.GetDeviceAddr()), isEnable);
481 } else {
482 HILOGI("[A2dpSource] proxy or bt disable.");
483 return;
484 }
485 }
486
GetOptionalCodecsSupportState(const BluetoothRemoteDevice & device) const487 int A2dpSource::GetOptionalCodecsSupportState(const BluetoothRemoteDevice &device) const
488 {
489 HILOGI("[A2dpSource] %{public}s\n", __func__);
490
491 if (!device.IsValidBluetoothRemoteDevice()) {
492 HILOGI("[A2dpSource] input parameter error.");
493 return RET_BAD_PARAM;
494 }
495
496 int ret = RET_NO_ERROR;
497 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
498 pimpl->proxy_->GetOptionalCodecsSupportState(RawAddress(device.GetDeviceAddr()));
499 } else {
500 HILOGI("[A2dpSource] proxy or bt disable.");
501 return RET_BAD_STATUS;
502 }
503
504 return ret;
505 }
506
StartPlaying(const BluetoothRemoteDevice & device)507 int A2dpSource::StartPlaying(const BluetoothRemoteDevice &device)
508 {
509 HILOGI("[A2dpSource] %{public}s\n", __func__);
510
511 if (!device.IsValidBluetoothRemoteDevice()) {
512 HILOGI("[A2dpSource] input parameter error.");
513 return RET_BAD_PARAM;
514 }
515
516 int ret = RET_NO_ERROR;
517 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
518 ret = pimpl->proxy_->StartPlaying(RawAddress(device.GetDeviceAddr()));
519 } else {
520 HILOGI("[A2dpSource] proxy or bt disable.");
521 return RET_BAD_STATUS;
522 }
523
524 return ret;
525 }
526
SuspendPlaying(const BluetoothRemoteDevice & device)527 int A2dpSource::SuspendPlaying(const BluetoothRemoteDevice &device)
528 {
529 HILOGI("[A2dpSource] %{public}s\n", __func__);
530
531 if (!device.IsValidBluetoothRemoteDevice()) {
532 HILOGI("[A2dpSource] input parameter error.");
533 return RET_BAD_PARAM;
534 }
535
536 int ret = RET_NO_ERROR;
537 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
538 ret = pimpl->proxy_->SuspendPlaying(RawAddress(device.GetDeviceAddr()));
539 } else {
540 HILOGI("[A2dpSource] proxy or bt disable.");
541 return RET_BAD_STATUS;
542 }
543
544 return ret;
545 }
546
StopPlaying(const BluetoothRemoteDevice & device)547 int A2dpSource::StopPlaying(const BluetoothRemoteDevice &device)
548 {
549 HILOGI("[A2dpSource] %{public}s\n", __func__);
550
551 if (!device.IsValidBluetoothRemoteDevice()) {
552 HILOGI("[A2dpSource] input parameter error.");
553 return RET_BAD_PARAM;
554 }
555
556 int ret = RET_NO_ERROR;
557 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
558 ret = pimpl->proxy_->StopPlaying(RawAddress(device.GetDeviceAddr()));
559 } else {
560 HILOGI("[A2dpSource] proxy or bt disable.");
561 return RET_BAD_STATUS;
562 }
563
564 return ret;
565 }
566
SetAudioConfigure(const BluetoothRemoteDevice & device,uint32_t sampleRate,uint32_t bits,uint8_t channel)567 void A2dpSource::SetAudioConfigure(
568 const BluetoothRemoteDevice &device, uint32_t sampleRate, uint32_t bits, uint8_t channel)
569 {
570 HILOGI("[A2dpSource] %{public}s\n", __func__);
571 if (!device.IsValidBluetoothRemoteDevice()) {
572 HILOGI("[A2dpSource] input parameter error.");
573 return;
574 }
575
576 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
577 pimpl->proxy_->SetAudioConfigure(
578 RawAddress(device.GetDeviceAddr()), (int)sampleRate, (int)bits, (int)channel);
579 } else {
580 HILOGI("[A2dpSource] proxy or bt disable.");
581 return;
582 }
583 return;
584 }
585
WriteFrame(const uint8_t * data,uint32_t size)586 int A2dpSource::WriteFrame(const uint8_t *data, uint32_t size)
587 {
588 HILOGI("[A2dpSource] %{public}s\n", __func__);
589 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
590 return pimpl->proxy_->WriteFrame(data, size);
591 } else {
592 HILOGI("[A2dpSource] proxy or bt disable.");
593 return RET_BAD_STATUS;
594 }
595 return RET_BAD_STATUS;
596 }
597
GetRenderPosition(uint16_t & delayValue,uint16_t & sendDataSize,uint32_t & timeStamp)598 void A2dpSource::GetRenderPosition(uint16_t &delayValue, uint16_t &sendDataSize, uint32_t &timeStamp)
599 {
600 HILOGI("[A2dpSource] %{public}s\n", __func__);
601 if (pimpl->proxy_ != nullptr && IS_BT_ENABLED()) {
602 pimpl->proxy_->GetRenderPosition(delayValue, sendDataSize, timeStamp);
603 } else {
604 HILOGI("[A2dpSource] proxy or bt disable.");
605 return;
606 }
607 return;
608 }
609
610 } // namespace Bluetooth
611 } // namespace OHOS