1 /*
2  * Copyright 2019 HIMSA II K/S - www.himsa.com. Represented by EHIMA -
3  * www.ehima.com
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <base/functional/bind.h>
21 #include <base/functional/callback.h>
22 #include <base/functional/callback_forward.h>
23 #include <hardware/bt_le_audio.h>
24 
25 #include <vector>
26 
27 class LeAudioHalVerifier {
28 public:
29   static bool SupportsLeAudio();
30   static bool SupportsLeAudioHardwareOffload();
31   static bool SupportsLeAudioBroadcast();
32   static bool SupportsStreamActiveApi();
33 };
34 
35 typedef bool(LeAudioIsoDataCallback)(const RawAddress& address, uint16_t cis_conn_hdl,
36                                      uint8_t* data, uint16_t size, uint32_t timestamp);
37 /* Interface class */
38 class LeAudioClient {
39 public:
40   virtual ~LeAudioClient(void) = default;
41 
42   static void Initialize(
43           bluetooth::le_audio::LeAudioClientCallbacks* callbacks, base::Closure initCb,
44           base::Callback<bool()> hal_2_1_verifier,
45           const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>& offloading_preference);
46   static void Cleanup(void);
47   static LeAudioClient* Get(void);
48   static void DebugDump(int fd);
49 
50   virtual void RemoveDevice(const RawAddress& address) = 0;
51   virtual void Connect(const RawAddress& address) = 0;
52   virtual void Disconnect(const RawAddress& address) = 0;
53   virtual void SetEnableState(const RawAddress& address, bool enabled) = 0;
54   virtual void GroupAddNode(const int group_id, const RawAddress& addr) = 0;
55   virtual void GroupRemoveNode(const int group_id, const RawAddress& addr) = 0;
56   virtual void GroupStream(const int group_id, const uint16_t content_type) = 0;
57   virtual void GroupSuspend(const int group_id) = 0;
58   virtual void GroupStop(const int group_id) = 0;
59   virtual void GroupDestroy(const int group_id) = 0;
60   virtual void GroupSetActive(const int group_id) = 0;
61   virtual void SetCodecConfigPreference(
62           int group_id, bluetooth::le_audio::btle_audio_codec_config_t input_codec_config,
63           bluetooth::le_audio::btle_audio_codec_config_t output_codec_config) = 0;
64   virtual bool IsUsingPreferredCodecConfig(int group_id, int context_type) = 0;
65   virtual void SetCcidInformation(int ccid, int context_type) = 0;
66   virtual void SetInCall(bool in_call) = 0;
67   virtual bool IsInCall() = 0;
68   virtual void SetInVoipCall(bool in_call) = 0;
69   virtual void SetUnicastMonitorMode(uint8_t direction, bool enable) = 0;
70   virtual bool IsInVoipCall() = 0;
71   virtual bool IsInStreaming() = 0;
72   virtual void SendAudioProfilePreferences(const int group_id, bool is_output_preference_le_audio,
73                                            bool is_duplex_preference_le_audio) = 0;
74   virtual void SetGroupAllowedContextMask(int group_id, int sink_context_types,
75                                           int source_context_types) = 0;
76 
77   virtual bool isOutputPreferenceLeAudio(const RawAddress& address) = 0;
78   virtual bool isDuplexPreferenceLeAudio(const RawAddress& address) = 0;
79   virtual std::vector<RawAddress> GetGroupDevices(const int group_id) = 0;
80 
81   static bool RegisterIsoDataConsumer(LeAudioIsoDataCallback callback);
82 
83   static void AddFromStorage(const RawAddress& addr, bool autoconnect, int sink_audio_location,
84                              int source_audio_location, int sink_supported_context_types,
85                              int source_supported_context_types,
86                              const std::vector<uint8_t>& handles,
87                              const std::vector<uint8_t>& sink_pacs,
88                              const std::vector<uint8_t>& source_pacs,
89                              const std::vector<uint8_t>& ases);
90   static bool GetHandlesForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
91   static bool GetSinkPacsForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
92   static bool GetSourcePacsForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
93   static bool GetAsesForStorage(const RawAddress& addr, std::vector<uint8_t>& out);
94   static bool IsLeAudioClientRunning();
95   static bool IsLeAudioClientInStreaming();
96 };
97