195489c19Sopenharmony_ci/*
295489c19Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
395489c19Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
495489c19Sopenharmony_ci * you may not use this file except in compliance with the License.
595489c19Sopenharmony_ci * You may obtain a copy of the License at
695489c19Sopenharmony_ci *
795489c19Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
895489c19Sopenharmony_ci *
995489c19Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1095489c19Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1195489c19Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1295489c19Sopenharmony_ci * See the License for the specific language governing permissions and
1395489c19Sopenharmony_ci * limitations under the License.
1495489c19Sopenharmony_ci */
1595489c19Sopenharmony_ci
1695489c19Sopenharmony_ci/**
1795489c19Sopenharmony_ci * @addtogroup Bluetooth
1895489c19Sopenharmony_ci * @{
1995489c19Sopenharmony_ci *
2095489c19Sopenharmony_ci * @brief The framework interface and callback function of a2dp source are defined.
2195489c19Sopenharmony_ci *
2295489c19Sopenharmony_ci * @since 6
2395489c19Sopenharmony_ci */
2495489c19Sopenharmony_ci
2595489c19Sopenharmony_ci#ifndef BLUETOOTH_A2DP_SRC_H
2695489c19Sopenharmony_ci#define BLUETOOTH_A2DP_SRC_H
2795489c19Sopenharmony_ci
2895489c19Sopenharmony_ci#include <vector>
2995489c19Sopenharmony_ci
3095489c19Sopenharmony_ci#include "bluetooth_def.h"
3195489c19Sopenharmony_ci#include "bluetooth_types.h"
3295489c19Sopenharmony_ci#include "bluetooth_remote_device.h"
3395489c19Sopenharmony_ci#include "bluetooth_a2dp_codec.h"
3495489c19Sopenharmony_ci#include "bluetooth_no_destructor.h"
3595489c19Sopenharmony_ci
3695489c19Sopenharmony_cinamespace OHOS {
3795489c19Sopenharmony_cinamespace Bluetooth {
3895489c19Sopenharmony_ci/**
3995489c19Sopenharmony_ci * @brief A2dp source API callback function.
4095489c19Sopenharmony_ci *
4195489c19Sopenharmony_ci * @since 6.0
4295489c19Sopenharmony_ci */
4395489c19Sopenharmony_ciclass A2dpSourceObserver {
4495489c19Sopenharmony_cipublic:
4595489c19Sopenharmony_ci    /**
4695489c19Sopenharmony_ci     * @brief A destructor used to delete the a2dp source Observer instance.
4795489c19Sopenharmony_ci     *
4895489c19Sopenharmony_ci     * @since 6.0
4995489c19Sopenharmony_ci     */
5095489c19Sopenharmony_ci    virtual ~A2dpSourceObserver() = default;
5195489c19Sopenharmony_ci
5295489c19Sopenharmony_ci    /**
5395489c19Sopenharmony_ci     * @brief The callback function after device's playing state changed.
5495489c19Sopenharmony_ci     *
5595489c19Sopenharmony_ci     * @param device  the remote bluetooth device.
5695489c19Sopenharmony_ci     * @param playingState  the playing state after changing.
5795489c19Sopenharmony_ci     * @param error  the error information.
5895489c19Sopenharmony_ci     * @since 6.0
5995489c19Sopenharmony_ci     */
6095489c19Sopenharmony_ci    virtual void OnPlayingStatusChanged(const BluetoothRemoteDevice &device, int playingState, int error)
6195489c19Sopenharmony_ci    {}
6295489c19Sopenharmony_ci
6395489c19Sopenharmony_ci    /**
6495489c19Sopenharmony_ci     * @brief The callback function after device's codec information changed.
6595489c19Sopenharmony_ci     *
6695489c19Sopenharmony_ci     * @param device  the remote bluetooth device.
6795489c19Sopenharmony_ci     * @param info  the device's codec information.
6895489c19Sopenharmony_ci     * @param error  the error information.
6995489c19Sopenharmony_ci     * @since 6.0
7095489c19Sopenharmony_ci     */
7195489c19Sopenharmony_ci    virtual void OnConfigurationChanged(const BluetoothRemoteDevice &device, const A2dpCodecInfo &info, int error)
7295489c19Sopenharmony_ci    {}
7395489c19Sopenharmony_ci
7495489c19Sopenharmony_ci    /**
7595489c19Sopenharmony_ci     * @brief ConnectionState Changed observer.
7695489c19Sopenharmony_ci     * @param device bluetooth device address.
7795489c19Sopenharmony_ci     * @param state Connection state.
7895489c19Sopenharmony_ci     * @param cause Connecton cause.
7995489c19Sopenharmony_ci     * @since 12
8095489c19Sopenharmony_ci     */
8195489c19Sopenharmony_ci    virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state, int cause)
8295489c19Sopenharmony_ci    {}
8395489c19Sopenharmony_ci
8495489c19Sopenharmony_ci    /**
8595489c19Sopenharmony_ci     * @brief Media Stack Changed observer.
8695489c19Sopenharmony_ci     * @param device bluetooth device address.
8795489c19Sopenharmony_ci     * @param Action on the device.
8895489c19Sopenharmony_ci     * @since 11.0
8995489c19Sopenharmony_ci     */
9095489c19Sopenharmony_ci    virtual void OnMediaStackChanged(const BluetoothRemoteDevice &device, int action)
9195489c19Sopenharmony_ci    {}
9295489c19Sopenharmony_ci
9395489c19Sopenharmony_ci    /**
9495489c19Sopenharmony_ci     * @brief The observer function to notify virtual device changed.
9595489c19Sopenharmony_ci     *
9695489c19Sopenharmony_ci     * @param Action on the device.
9795489c19Sopenharmony_ci     * @param device bluetooth device address.
9895489c19Sopenharmony_ci     * @since 12
9995489c19Sopenharmony_ci     */
10095489c19Sopenharmony_ci    virtual void OnVirtualDeviceChanged(int32_t action, std::string address)
10195489c19Sopenharmony_ci    {}
10295489c19Sopenharmony_ci};
10395489c19Sopenharmony_ci
10495489c19Sopenharmony_ci/**
10595489c19Sopenharmony_ci * @brief audio stream details.
10695489c19Sopenharmony_ci *
10795489c19Sopenharmony_ci * @since 11.0
10895489c19Sopenharmony_ci */
10995489c19Sopenharmony_cistruct A2dpStreamInfo {
11095489c19Sopenharmony_ci    int32_t sessionId;
11195489c19Sopenharmony_ci    int32_t streamType;
11295489c19Sopenharmony_ci    int32_t sampleRate;
11395489c19Sopenharmony_ci    bool isSpatialAudio;
11495489c19Sopenharmony_ci};
11595489c19Sopenharmony_ci
11695489c19Sopenharmony_ci/**
11795489c19Sopenharmony_ci * @brief a2dp audio stream encode type.
11895489c19Sopenharmony_ci *
11995489c19Sopenharmony_ci * @since 11.0
12095489c19Sopenharmony_ci */
12195489c19Sopenharmony_cienum A2dpStreamEncodeType : uint8_t {
12295489c19Sopenharmony_ci    A2DP_STREAM_ENCODE_UNKNOWN = 0,
12395489c19Sopenharmony_ci    A2DP_STREAM_ENCODE_SOFTWARE,
12495489c19Sopenharmony_ci    A2DP_STREAM_ENCODE_HARDWARE,
12595489c19Sopenharmony_ci};
12695489c19Sopenharmony_ci
12795489c19Sopenharmony_ci/**
12895489c19Sopenharmony_ci * @brief A2dp source API.
12995489c19Sopenharmony_ci *
13095489c19Sopenharmony_ci * @since 6.0
13195489c19Sopenharmony_ci */
13295489c19Sopenharmony_ciclass BLUETOOTH_API A2dpSource {
13395489c19Sopenharmony_cipublic:
13495489c19Sopenharmony_ci    /**
13595489c19Sopenharmony_ci     * @brief Get a2dp source instance.
13695489c19Sopenharmony_ci     *
13795489c19Sopenharmony_ci     * @return Returns an instance of a2dp source.
13895489c19Sopenharmony_ci     * @since 6.0
13995489c19Sopenharmony_ci     */
14095489c19Sopenharmony_ci    static A2dpSource *GetProfile();
14195489c19Sopenharmony_ci
14295489c19Sopenharmony_ci    /**
14395489c19Sopenharmony_ci     * @brief Get devices by connection states.
14495489c19Sopenharmony_ci     *
14595489c19Sopenharmony_ci     * @param states The connection states of the bluetooth device.
14695489c19Sopenharmony_ci     * @return Returns devices that match the connection states.
14795489c19Sopenharmony_ci     * @since 6.0
14895489c19Sopenharmony_ci     */
14995489c19Sopenharmony_ci    int GetDevicesByStates(const std::vector<int> &states, std::vector<BluetoothRemoteDevice> &devices) const;
15095489c19Sopenharmony_ci
15195489c19Sopenharmony_ci    /**
15295489c19Sopenharmony_ci     * @brief Get device connection state by address.
15395489c19Sopenharmony_ci     *
15495489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
15595489c19Sopenharmony_ci     * @return Returns <b>A2DP_DISCONNECTED</b> if device connect state is disconnected;
15695489c19Sopenharmony_ci     *         Returns <b>A2DP_DISCONNECTING</b> if device connect state is disconnecting;
15795489c19Sopenharmony_ci     *         Returns <b>A2DP_CONNECTED</b> if device connect state is connected;
15895489c19Sopenharmony_ci     *         Returns <b>A2DP_CONNECTING</b> if device connect state is connecting;
15995489c19Sopenharmony_ci     *         Returns <b>A2DP_INVALID_STATUS</b> if can not find peer device.
16095489c19Sopenharmony_ci     * @since 6.0
16195489c19Sopenharmony_ci     */
16295489c19Sopenharmony_ci    int GetDeviceState(const BluetoothRemoteDevice &device, int &state) const;
16395489c19Sopenharmony_ci
16495489c19Sopenharmony_ci    /**
16595489c19Sopenharmony_ci     * @brief Get device playing state by address when peer device is on connected.
16695489c19Sopenharmony_ci     *
16795489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
16895489c19Sopenharmony_ci     * @return Returns <b>1</b> if device is on playing;
16995489c19Sopenharmony_ci     *         Returns <b>0</b> if device is not on playing.
17095489c19Sopenharmony_ci     * @since 6.0
17195489c19Sopenharmony_ci     */
17295489c19Sopenharmony_ci    int GetPlayingState(const BluetoothRemoteDevice &device) const;
17395489c19Sopenharmony_ci
17495489c19Sopenharmony_ci    /**
17595489c19Sopenharmony_ci     * @brief Get device playing state by address when peer device is on connected.
17695489c19Sopenharmony_ci     *
17795489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
17895489c19Sopenharmony_ci     * @param state The playing state of the peer bluetooth device.
17995489c19Sopenharmony_ci     * @return Returns operation result;
18095489c19Sopenharmony_ci     * @since 6.0
18195489c19Sopenharmony_ci     */
18295489c19Sopenharmony_ci    int GetPlayingState(const BluetoothRemoteDevice &device, int &state) const;
18395489c19Sopenharmony_ci
18495489c19Sopenharmony_ci    /**
18595489c19Sopenharmony_ci     * @brief Connect to the peer bluetooth device.
18695489c19Sopenharmony_ci     *
18795489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
18895489c19Sopenharmony_ci     * @return Returns <b>true</b> Perform normal connection processing.
18995489c19Sopenharmony_ci     *         Returns <b>false</b> Target device is on connected,or connecting,
19095489c19Sopenharmony_ci                                    or device is not allowed to connect,or the connection fails.
19195489c19Sopenharmony_ci     * @since 6.0
19295489c19Sopenharmony_ci     */
19395489c19Sopenharmony_ci    int32_t Connect(const BluetoothRemoteDevice &device);
19495489c19Sopenharmony_ci
19595489c19Sopenharmony_ci    /**
19695489c19Sopenharmony_ci     * @brief Disconnect with the peer bluetooth service.
19795489c19Sopenharmony_ci     *
19895489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
19995489c19Sopenharmony_ci     * @return Returns <b>true</b> if perform normal disconnection processing.
20095489c19Sopenharmony_ci     *         Returns <b>false</b> if target device is on disconnected,or disconnecting,or disconnection fails.
20195489c19Sopenharmony_ci     * @since 6.0
20295489c19Sopenharmony_ci     */
20395489c19Sopenharmony_ci    int32_t Disconnect(const BluetoothRemoteDevice &device);
20495489c19Sopenharmony_ci
20595489c19Sopenharmony_ci    /**
20695489c19Sopenharmony_ci     * @brief Set target device as active device.
20795489c19Sopenharmony_ci     *
20895489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
20995489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> Target device has already been active, or perform normal setting processing.
21095489c19Sopenharmony_ci     *         Returns <b>RET_BAD_PARAM</b> Input error.
21195489c19Sopenharmony_ci     *         Returns <b>RET_BAD_STATUS</b> Target device is not on connected, or set fails.
21295489c19Sopenharmony_ci     * @since 6.0
21395489c19Sopenharmony_ci     */
21495489c19Sopenharmony_ci    int SetActiveSinkDevice(const BluetoothRemoteDevice &device);
21595489c19Sopenharmony_ci
21695489c19Sopenharmony_ci    /**
21795489c19Sopenharmony_ci     * @brief Get active device.
21895489c19Sopenharmony_ci     * @return Returns active device.
21995489c19Sopenharmony_ci     * @since 6.0
22095489c19Sopenharmony_ci     */
22195489c19Sopenharmony_ci    const BluetoothRemoteDevice &GetActiveSinkDevice() const;
22295489c19Sopenharmony_ci
22395489c19Sopenharmony_ci    /**
22495489c19Sopenharmony_ci     * @brief Set connection strategy for peer bluetooth device.
22595489c19Sopenharmony_ci     *        If peer device is connected and the policy is set not allowed,then perform disconnect operation.
22695489c19Sopenharmony_ci     *        If peer device is disconnected and the policy is set allowed,then perform connect operation.
22795489c19Sopenharmony_ci     *
22895489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
22995489c19Sopenharmony_ci     * @param strategy The device connect strategy.
23095489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
23195489c19Sopenharmony_ci     *         Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied.
23295489c19Sopenharmony_ci     *         Returns <b>BT_ERR_INVALID_PARAM</b> Input error.
23395489c19Sopenharmony_ci     *         Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE.
23495489c19Sopenharmony_ci     *         Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed.
23595489c19Sopenharmony_ci     * @since 6.0
23695489c19Sopenharmony_ci     */
23795489c19Sopenharmony_ci    int SetConnectStrategy(const BluetoothRemoteDevice &device, int strategy);
23895489c19Sopenharmony_ci
23995489c19Sopenharmony_ci    /**
24095489c19Sopenharmony_ci     * @brief Get connection strategy of peer bluetooth device.
24195489c19Sopenharmony_ci     *
24295489c19Sopenharmony_ci     * @param device The address of the peer bluetooth device.
24395489c19Sopenharmony_ci     * @param strategy The device connect strategy.
24495489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
24595489c19Sopenharmony_ci     *         Returns <b>BT_ERR_PERMISSION_FAILED</b> Permission denied.
24695489c19Sopenharmony_ci     *         Returns <b>BT_ERR_INVALID_PARAM</b> Input error.
24795489c19Sopenharmony_ci     *         Returns <b>BT_ERR_INVALID_STATE</b> BT_ERR_INVALID_STATE.
24895489c19Sopenharmony_ci     *         Returns <b>BT_ERR_INTERNAL_ERROR</b> Operation failed.
24995489c19Sopenharmony_ci     * @since 6.0
25095489c19Sopenharmony_ci     */
25195489c19Sopenharmony_ci    int GetConnectStrategy(const BluetoothRemoteDevice &device, int &strategy) const;
25295489c19Sopenharmony_ci
25395489c19Sopenharmony_ci    /**
25495489c19Sopenharmony_ci     * @brief Get codec status information of connected device.
25595489c19Sopenharmony_ci     *
25695489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
25795489c19Sopenharmony_ci     * @return Returns codec status information of connected device.
25895489c19Sopenharmony_ci     * @since 6.0
25995489c19Sopenharmony_ci     */
26095489c19Sopenharmony_ci    A2dpCodecStatus GetCodecStatus(const BluetoothRemoteDevice &device) const;
26195489c19Sopenharmony_ci
26295489c19Sopenharmony_ci    /**
26395489c19Sopenharmony_ci    * @brief Get the codec encoding preferences of the specified device.
26495489c19Sopenharmony_ci    *
26595489c19Sopenharmony_ci    * @param device The address of the bluetooth device.
26695489c19Sopenharmony_ci    * @param info The codec encoding information.
26795489c19Sopenharmony_ci    * @return Return the result getted.
26895489c19Sopenharmony_ci    * @since 6.0
26995489c19Sopenharmony_ci    */
27095489c19Sopenharmony_ci    int GetCodecPreference(const BluetoothRemoteDevice &device, A2dpCodecInfo &info);
27195489c19Sopenharmony_ci
27295489c19Sopenharmony_ci    /**
27395489c19Sopenharmony_ci     * @brief Set the codec encoding preferences of the specified device.
27495489c19Sopenharmony_ci     *
27595489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
27695489c19Sopenharmony_ci     * @param info The codec encoding information.
27795489c19Sopenharmony_ci     * @return Return the result setted.
27895489c19Sopenharmony_ci     * @since 6.0
27995489c19Sopenharmony_ci     */
28095489c19Sopenharmony_ci    int SetCodecPreference(const BluetoothRemoteDevice &device, const A2dpCodecInfo &info);
28195489c19Sopenharmony_ci
28295489c19Sopenharmony_ci    /**
28395489c19Sopenharmony_ci     * @brief Set whether enables the optional codec.
28495489c19Sopenharmony_ci     *
28595489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
28695489c19Sopenharmony_ci     * @param isEnable Set true if enables the optional codec and set optional codec's priority high.
28795489c19Sopenharmony_ci     *                 Set false if disables the optional codec and set optional codec's priority low.
28895489c19Sopenharmony_ci     * @since 6.0
28995489c19Sopenharmony_ci     */
29095489c19Sopenharmony_ci    void SwitchOptionalCodecs(const BluetoothRemoteDevice &device, bool isEnable);
29195489c19Sopenharmony_ci
29295489c19Sopenharmony_ci    /**
29395489c19Sopenharmony_ci     * @brief Get whether the peer bluetooth device supports optional codec.
29495489c19Sopenharmony_ci     *
29595489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
29695489c19Sopenharmony_ci     * @return Returns <b>A2DP_OPTIONAL_SUPPORT</b> The device supports optional codec.
29795489c19Sopenharmony_ci     *         Returns <b>A2DP_OPTIONAL_NOT_SUPPORT</b> The device dosn't support optional codec.
29895489c19Sopenharmony_ci     *         Returns <b>A2DP_OPTIONAL_SUPPORT_UNKNOWN</b> Don't know if the device support optional codec.
29995489c19Sopenharmony_ci     * @since 6.0
30095489c19Sopenharmony_ci     */
30195489c19Sopenharmony_ci    int GetOptionalCodecsSupportState(const BluetoothRemoteDevice &device) const;
30295489c19Sopenharmony_ci
30395489c19Sopenharmony_ci    /**
30495489c19Sopenharmony_ci     * @brief Audio start streaming.
30595489c19Sopenharmony_ci     *
30695489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
30795489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
30895489c19Sopenharmony_ci     *         Returns <b>RET_BAD_PARAM</b> Input error.
30995489c19Sopenharmony_ci     *         Returns <b>RET_BAD_STATUS</b> if the operation fails.
31095489c19Sopenharmony_ci     * @since 6.0
31195489c19Sopenharmony_ci     */
31295489c19Sopenharmony_ci    int StartPlaying(const BluetoothRemoteDevice &device);
31395489c19Sopenharmony_ci
31495489c19Sopenharmony_ci    /**
31595489c19Sopenharmony_ci     * @brief Audio suspend streaming.
31695489c19Sopenharmony_ci     *
31795489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
31895489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
31995489c19Sopenharmony_ci     *         Returns <b>RET_BAD_PARAM</b> Input error.
32095489c19Sopenharmony_ci     *         Returns <b>RET_BAD_STATUS</b> if the operation fails.
32195489c19Sopenharmony_ci     * @since 6.0
32295489c19Sopenharmony_ci     */
32395489c19Sopenharmony_ci    int SuspendPlaying(const BluetoothRemoteDevice &device);
32495489c19Sopenharmony_ci
32595489c19Sopenharmony_ci    /**
32695489c19Sopenharmony_ci     * @brief Audio stop streaming.
32795489c19Sopenharmony_ci     *
32895489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
32995489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
33095489c19Sopenharmony_ci     *         Returns <b>RET_BAD_PARAM</b> Input error.
33195489c19Sopenharmony_ci     *         Returns <b>RET_BAD_STATUS</b> if the operation fails.
33295489c19Sopenharmony_ci     * @since 6.0
33395489c19Sopenharmony_ci     */
33495489c19Sopenharmony_ci    int StopPlaying(const BluetoothRemoteDevice &device);
33595489c19Sopenharmony_ci
33695489c19Sopenharmony_ci    /**
33795489c19Sopenharmony_ci     * @brief Register callback function of framework.
33895489c19Sopenharmony_ci     *
33995489c19Sopenharmony_ci     * @param observer Reference to the a2dp source observer.
34095489c19Sopenharmony_ci     * @since 6.0
34195489c19Sopenharmony_ci     */
34295489c19Sopenharmony_ci    void RegisterObserver(std::shared_ptr<A2dpSourceObserver> observer);
34395489c19Sopenharmony_ci
34495489c19Sopenharmony_ci    /**
34595489c19Sopenharmony_ci     * @brief Deregister callback function of framework.
34695489c19Sopenharmony_ci     *
34795489c19Sopenharmony_ci     * @param observer Reference to the a2dp source observer.
34895489c19Sopenharmony_ci     * @since 6.0
34995489c19Sopenharmony_ci     */
35095489c19Sopenharmony_ci    void DeregisterObserver(std::shared_ptr<A2dpSourceObserver> observer);
35195489c19Sopenharmony_ci
35295489c19Sopenharmony_ci    /**
35395489c19Sopenharmony_ci     * @brief Write the pcm data to a2dp source profile.
35495489c19Sopenharmony_ci     *
35595489c19Sopenharmony_ci     * @param data Pointer of the data.
35695489c19Sopenharmony_ci     * @param size Size of the data
35795489c19Sopenharmony_ci     * @return Returns <b>RET_NO_ERROR</b> if the operation is successful.
35895489c19Sopenharmony_ci     *         Returns <b>RET_BAD_PARAM</b> Input error.
35995489c19Sopenharmony_ci     *         Returns <b>RET_BAD_STATUS</b> if the operation fails.
36095489c19Sopenharmony_ci     *         Returns <b>RET_NO_SPACE</b> if the buffer of a2dp source profile is full.
36195489c19Sopenharmony_ci     * @since 6.0
36295489c19Sopenharmony_ci     */
36395489c19Sopenharmony_ci    int WriteFrame(const uint8_t *data, uint32_t size);
36495489c19Sopenharmony_ci
36595489c19Sopenharmony_ci    /**
36695489c19Sopenharmony_ci     * @brief Get the information of the current rendered position.
36795489c19Sopenharmony_ci     * @param device The address of the bluetooth device.
36895489c19Sopenharmony_ci     * @param[out] dalayValue is the delayed time
36995489c19Sopenharmony_ci     * @param[out] sendDataSize is the data size that has been sent
37095489c19Sopenharmony_ci     * @param[out] timeStamp is the current time stamp
37195489c19Sopenharmony_ci     * @return Returns general <b>enum BtErrCode</b> for the operation.
37295489c19Sopenharmony_ci     * @since 6.0
37395489c19Sopenharmony_ci     */
37495489c19Sopenharmony_ci    int GetRenderPosition(const BluetoothRemoteDevice &device, uint32_t &delayValue, uint64_t &sendDataSize,
37595489c19Sopenharmony_ci                          uint32_t &timeStamp);
37695489c19Sopenharmony_ci
37795489c19Sopenharmony_ci    /**
37895489c19Sopenharmony_ci     * @brief Audio start offload streaming for hardware encoding datapath.
37995489c19Sopenharmony_ci     *
38095489c19Sopenharmony_ci     * @param device remote bluetooth sink device.
38195489c19Sopenharmony_ci     * @return Returns general <b>enum BtErrCode</b> for the operation.
38295489c19Sopenharmony_ci     * @since 6.0
38395489c19Sopenharmony_ci     */
38495489c19Sopenharmony_ci    int OffloadStartPlaying(const BluetoothRemoteDevice &device, const std::vector<int32_t> &sessionsId);
38595489c19Sopenharmony_ci
38695489c19Sopenharmony_ci    /**
38795489c19Sopenharmony_ci     * @brief Audio stop offload streaming for hardware encoding datapath.
38895489c19Sopenharmony_ci     *
38995489c19Sopenharmony_ci     * @param device remote bluetooth sink device.
39095489c19Sopenharmony_ci     * @return Returns general <b>enum BtErrCode</b> for the operation.
39195489c19Sopenharmony_ci     * @since 6.0
39295489c19Sopenharmony_ci     */
39395489c19Sopenharmony_ci    int OffloadStopPlaying(const BluetoothRemoteDevice &device, const std::vector<int32_t> &sessionsId);
39495489c19Sopenharmony_ci
39595489c19Sopenharmony_ci    /**
39695489c19Sopenharmony_ci     * brief Get a2dp encoding data path information of connected sink device.
39795489c19Sopenharmony_ci     *
39895489c19Sopenharmony_ci     * @param device remote bluetooth sink device.
39995489c19Sopenharmony_ci     * @info streams detail information
40095489c19Sopenharmony_ci     * @return Returns <b>UNKNOWN_ENCODING_PATH: 0</b>, bt unable to judge encoding data path
40195489c19Sopenharmony_ci     *         Returns <b>SOFTWARE_ENCODING_PATH: 1</b>, a2dp audio encoding path should select a2dp hdi.
40295489c19Sopenharmony_ci     *         Returns <b>HARDWARE_ENCODING_PATH: 2</b>, a2dp audio encoding path should select a2dp offload hdi.
40395489c19Sopenharmony_ci     *         Returns general <b>enum BtErrCode</b> for the operation.
40495489c19Sopenharmony_ci     */
40595489c19Sopenharmony_ci    int A2dpOffloadSessionRequest(const BluetoothRemoteDevice &device, const std::vector<A2dpStreamInfo> &info);
40695489c19Sopenharmony_ci
40795489c19Sopenharmony_ci    /**
40895489c19Sopenharmony_ci     * @brief Get A2dp Offload codec status information of connected device.
40995489c19Sopenharmony_ci     *
41095489c19Sopenharmony_ci     * @param device remote bluetooth sink device.
41195489c19Sopenharmony_ci     * @return a2dp offload configration information of connected device.
41295489c19Sopenharmony_ci     * @since 6.0
41395489c19Sopenharmony_ci     */
41495489c19Sopenharmony_ci    A2dpOffloadCodecStatus GetOffloadCodecStatus(const BluetoothRemoteDevice &device) const;
41595489c19Sopenharmony_ci
41695489c19Sopenharmony_ci    /**
41795489c19Sopenharmony_ci     * Allow devices to automatically play music when connected.
41895489c19Sopenharmony_ci     *
41995489c19Sopenharmony_ci     * @param device Remote bluetooth sink device.
42095489c19Sopenharmony_ci     * @return Returns general <b>enum BtErrCode</b> for the operation.
42195489c19Sopenharmony_ci     * @since 12
42295489c19Sopenharmony_ci     */
42395489c19Sopenharmony_ci    int EnableAutoPlay(const BluetoothRemoteDevice &device);
42495489c19Sopenharmony_ci
42595489c19Sopenharmony_ci    /**
42695489c19Sopenharmony_ci     * Restriction devices to play music within {@code duration} milliseconds of connection.
42795489c19Sopenharmony_ci     *
42895489c19Sopenharmony_ci     * @param device Remote bluetooth sink device.
42995489c19Sopenharmony_ci     * @param duration Restricted duration <milliseconds>.
43095489c19Sopenharmony_ci     * @return Returns general <b>enum BtErrCode</b> for the operation.
43195489c19Sopenharmony_ci     * @since 12
43295489c19Sopenharmony_ci     */
43395489c19Sopenharmony_ci    int DisableAutoPlay(const BluetoothRemoteDevice &device, const int duration);
43495489c19Sopenharmony_ci
43595489c19Sopenharmony_ci    /**
43695489c19Sopenharmony_ci     * Obtains the duration for which automatic playback is disabled.
43795489c19Sopenharmony_ci     *
43895489c19Sopenharmony_ci     * @param device Remote bluetooth sink device.
43995489c19Sopenharmony_ci     * @param duration Restricted duration <milliseconds>.
44095489c19Sopenharmony_ci     * @return Returns general <b>enum BtErrCode</b> for the operation.
44195489c19Sopenharmony_ci     * @since 12
44295489c19Sopenharmony_ci     */
44395489c19Sopenharmony_ci    int GetAutoPlayDisabledDuration(const BluetoothRemoteDevice &device, int &duration);
44495489c19Sopenharmony_ci
44595489c19Sopenharmony_ci    /**
44695489c19Sopenharmony_ci     * get virtual device list.
44795489c19Sopenharmony_ci     *
44895489c19Sopenharmony_ci     * @param devices virtual device list.
44995489c19Sopenharmony_ci     * @since 12
45095489c19Sopenharmony_ci     */
45195489c19Sopenharmony_ci    void GetVirtualDeviceList(std::vector<std::string> &devices);
45295489c19Sopenharmony_ciprivate:
45395489c19Sopenharmony_ci    /**
45495489c19Sopenharmony_ci     * @brief A constructor used to create a a2dp source instance.
45595489c19Sopenharmony_ci     *
45695489c19Sopenharmony_ci     * @since 6.0
45795489c19Sopenharmony_ci     */
45895489c19Sopenharmony_ci    A2dpSource(void);
45995489c19Sopenharmony_ci
46095489c19Sopenharmony_ci    /**
46195489c19Sopenharmony_ci     * @brief A destructor used to delete the a2dp source instance.
46295489c19Sopenharmony_ci     *
46395489c19Sopenharmony_ci     * @since 6.0
46495489c19Sopenharmony_ci     */
46595489c19Sopenharmony_ci    ~A2dpSource(void);
46695489c19Sopenharmony_ci    BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(A2dpSource);
46795489c19Sopenharmony_ci    BLUETOOTH_DECLARE_IMPL();
46895489c19Sopenharmony_ci
46995489c19Sopenharmony_ci#ifdef DTFUZZ_TEST
47095489c19Sopenharmony_ci    friend class BluetoothNoDestructor<A2dpSource>;
47195489c19Sopenharmony_ci#endif
47295489c19Sopenharmony_ci};
47395489c19Sopenharmony_ci}  // namespace Bluetooth
47495489c19Sopenharmony_ci}  // namespace OHOS
47595489c19Sopenharmony_ci#endif  // BLUETOOTH_A2DP_SRC_H
476