• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 AUDIO_BLUETOOTH_MANAGERI_H
17 #define AUDIO_BLUETOOTH_MANAGERI_H
18 
19 #include "bluetooth_a2dp_src.h"
20 #include "bluetooth_a2dp_codec.h"
21 #include "bluetooth_avrcp_tg.h"
22 #include "bluetooth_hfp_ag.h"
23 #include "audio_info.h"
24 
25 namespace OHOS {
26 namespace Bluetooth {
27 
28 // Audio bluetooth a2dp feature support
29 class AudioA2dpListener : public A2dpSourceObserver {
30 public:
31     AudioA2dpListener() = default;
32     virtual ~AudioA2dpListener() = default;
33 
34     virtual void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state);
35     virtual void OnConfigurationChanged(const BluetoothRemoteDevice &device, const A2dpCodecInfo &info, int error);
36     virtual void OnPlayingStatusChanged(const BluetoothRemoteDevice &device, int playingState, int error);
37     virtual void OnMediaStackChanged(const BluetoothRemoteDevice &device, int action);
38 
39 private:
40     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AudioA2dpListener);
41 };
42 
43 class AudioA2dpManager {
44 public:
45     AudioA2dpManager() = default;
46     virtual ~AudioA2dpManager() = default;
47     static void RegisterBluetoothA2dpListener();
48     static void UnregisterBluetoothA2dpListener();
49     static void DisconnectBluetoothA2dpSink();
50     static int32_t SetActiveA2dpDevice(const std::string& macAddress);
51     static std::string GetActiveA2dpDevice();
52     static int32_t SetDeviceAbsVolume(const std::string& macAddress, int32_t volume);
53     static int32_t GetA2dpDeviceStreamInfo(const std::string& macAddress,
54         AudioStandard::AudioStreamInfo &streamInfo);
55     static bool HasA2dpDeviceConnected();
56     static int32_t A2dpOffloadSessionRequest(const std::vector<A2dpStreamInfo> &info);
57     static int32_t OffloadStartPlaying(const std::vector<int32_t> &sessionsID);
58     static int32_t OffloadStopPlaying(const std::vector<int32_t> &sessionsID);
59 
SetConnectionState(int state)60     static void SetConnectionState(int state)
61     {
62         connectionState_ = state;
63     }
GetConnectionState()64     static int GetConnectionState()
65     {
66         return connectionState_;
67     }
GetCurrentActiveA2dpDevice()68     static BluetoothRemoteDevice GetCurrentActiveA2dpDevice()
69     {
70         return activeA2dpDevice_;
71     }
72 
73 private:
74     static A2dpSource *a2dpInstance_;
75     static std::shared_ptr<AudioA2dpListener> a2dpListener_;
76     static int connectionState_;
77     static BluetoothRemoteDevice activeA2dpDevice_;
78 };
79 
80 // Audio bluetooth sco feature support
81 class AudioHfpListener : public HandsFreeAudioGatewayObserver {
82 public:
83     AudioHfpListener() = default;
84     virtual ~AudioHfpListener() = default;
85 
86     void OnScoStateChanged(const BluetoothRemoteDevice &device, int state);
87     void OnConnectionStateChanged(const BluetoothRemoteDevice &device, int state);
OnActiveDeviceChanged(const BluetoothRemoteDevice & device)88     void OnActiveDeviceChanged(const BluetoothRemoteDevice &device) {}
OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice & device,int indValue)89     void OnHfEnhancedDriverSafetyChanged(const BluetoothRemoteDevice &device, int indValue) {}
90     virtual void OnHfpStackChanged(const BluetoothRemoteDevice &device, int action);
91 
92 private:
93     BLUETOOTH_DISALLOW_COPY_AND_ASSIGN(AudioHfpListener);
94 };
95 
96 class AudioHfpManager {
97 public:
98     AudioHfpManager() = default;
99     virtual ~AudioHfpManager() = default;
100     static void RegisterBluetoothScoListener();
101     static void UnregisterBluetoothScoListener();
102     static int32_t SetActiveHfpDevice(const std::string &macAddress);
103     static std::string GetActiveHfpDevice();
104     static int32_t ConnectScoWithAudioScene(AudioStandard::AudioScene scene);
105     static int32_t DisconnectSco();
106     static int8_t GetScoCategoryFromScene(AudioStandard::AudioScene scene);
107     static void DisconnectBluetoothHfpSink();
108     static void UpdateCurrentActiveHfpDevice(const BluetoothRemoteDevice &device);
109     static std::string GetCurrentActiveHfpDevice();
110     static void UpdateAudioScene(AudioStandard::AudioScene scene);
111 
112 private:
113     static HandsFreeAudioGateway *hfpInstance_;
114     static std::shared_ptr<AudioHfpListener> hfpListener_;
115     static AudioStandard::AudioScene scene_;
116     static BluetoothRemoteDevice activeHfpDevice_;
117 };
118 }
119 }
120 #endif  // AUDIO_BLUETOOTH_MANAGERI_H
121