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 #ifndef OHOS_BLUETOOTH_STANDARD_A2DP_SRC_PROXY_H
17 #define OHOS_BLUETOOTH_STANDARD_A2DP_SRC_PROXY_H
18 
19 #include "iremote_proxy.h"
20 #include "i_bluetooth_a2dp_src.h"
21 #include "raw_address.h"
22 
23 namespace OHOS {
24 namespace Bluetooth {
25 using namespace OHOS::bluetooth;
26 class BluetoothA2dpSrcProxy : public IRemoteProxy<IBluetoothA2dpSrc> {
27 public:
BluetoothA2dpSrcProxy(const sptr<IRemoteObject> & impl)28     explicit BluetoothA2dpSrcProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IBluetoothA2dpSrc>(impl)
29     {}
~BluetoothA2dpSrcProxy()30     ~BluetoothA2dpSrcProxy()
31     {}
32 
33     int Connect(const RawAddress &device) override;
34     int Disconnect(const RawAddress &device) override;
35     void RegisterObserver(const sptr<IBluetoothA2dpSourceObserver> &observer) override;
36     void DeregisterObserver(const sptr<IBluetoothA2dpSourceObserver> &observer) override;
37     int GetDevicesByStates(const std::vector<int32_t> &states, std::vector<RawAddress> &rawAddrs) override;
38     int GetDeviceState(const RawAddress &device, int &state) override;
39     int GetPlayingState(const RawAddress &device, int &state) override;
40     int SetConnectStrategy(const RawAddress &device, int32_t strategy) override;
41     int GetConnectStrategy(const RawAddress &device, int &strategy) override;
42     int SetActiveSinkDevice(const RawAddress &device) override;
43     RawAddress GetActiveSinkDevice() override;
44     BluetoothA2dpCodecStatus GetCodecStatus(const RawAddress &device) override;
45     int GetCodecPreference(const RawAddress &device, BluetoothA2dpCodecInfo &info) override;
46     int SetCodecPreference(const RawAddress &device, const BluetoothA2dpCodecInfo &info) override;
47     void SwitchOptionalCodecs(const RawAddress &device, bool isEnable) override;
48     int GetOptionalCodecsSupportState(const RawAddress &device) override;
49     int StartPlaying(const RawAddress &device) override;
50     int SuspendPlaying(const RawAddress &device) override;
51     int StopPlaying(const RawAddress &device) override;
52     int WriteFrame(const uint8_t *data, uint32_t size) override;
53     int GetRenderPosition(const RawAddress &device, uint32_t &delayValue, uint64_t &sendDataSize,
54                           uint32_t &timeStamp) override;
55     int OffloadStartPlaying(const RawAddress &device, const std::vector<int32_t> &sessionId) override;
56     int OffloadStopPlaying(const RawAddress &device, const std::vector<int32_t> &sessionId) override;
57     int A2dpOffloadSessionPathRequest(const RawAddress &device,
58         const std::vector<BluetoothA2dpStreamInfo> &info) override;
59     BluetoothA2dpOffloadCodecStatus GetOffloadCodecStatus(const RawAddress &device) override;
60     int EnableAutoPlay(const RawAddress &device) override;
61     int DisableAutoPlay(const RawAddress &device, const int duration) override;
62     int GetAutoPlayDisabledDuration(const RawAddress &device, int &duration) override;
63     void GetVirtualDeviceList(std::vector<std::string> &device) override;
64     void UpdateVirtualDevice(int32_t action, const std::string &address) override;
65 
66 private:
67     static inline BrokerDelegator<BluetoothA2dpSrcProxy> delegator_;
68     /**
69      * @brief Write the serializable data
70      * @param parcelableVector The communication data of IPC
71      * @param reply Serializable data
72      * @return true: Write the serializable data successfully; otherwise is not.
73      */
74     bool WriteParcelableInt32Vector(const std::vector<int32_t> &parcelableVector, Parcel &reply);
75 
76     /**
77      * @brief control offload play or stop action
78      * @param device the remote connected sink device
79      * @param sessionsId audio control streams sessions id
80      * @param control audio control action request playing or stop playing.
81      * @return true: control remote sink device successfully; otherwise is not.
82      */
83     int OffloadPlayingControl(const RawAddress &device, const std::vector<int32_t> &sessionsId, int32_t control);
84 };
85 }  // namespace Bluetooth
86 }  // namespace OHOS
87 #endif  // OHOS_BLUETOOTH_STANDARD_A2DP_SRC_PROXY_H