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,
36                                      uint16_t cis_conn_hdl, uint8_t* data,
37                                      uint16_t size, uint32_t timestamp);
38 /* Interface class */
39 class LeAudioClient {
40  public:
41   virtual ~LeAudioClient(void) = default;
42 
43   static void Initialize(
44       bluetooth::le_audio::LeAudioClientCallbacks* callbacks,
45       base::Closure initCb, base::Callback<bool()> hal_2_1_verifier,
46       const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>&
47           offloading_preference);
48   static void Cleanup(void);
49   static LeAudioClient* Get(void);
50   static void DebugDump(int fd);
51 
52   virtual void RemoveDevice(const RawAddress& address) = 0;
53   virtual void Connect(const RawAddress& address) = 0;
54   virtual void Disconnect(const RawAddress& address) = 0;
55   virtual void SetEnableState(const RawAddress& address, bool enabled) = 0;
56   virtual void GroupAddNode(const int group_id, const RawAddress& addr) = 0;
57   virtual void GroupRemoveNode(const int group_id, const RawAddress& addr) = 0;
58   virtual void GroupStream(const int group_id, const uint16_t content_type) = 0;
59   virtual void GroupSuspend(const int group_id) = 0;
60   virtual void GroupStop(const int group_id) = 0;
61   virtual void GroupDestroy(const int group_id) = 0;
62   virtual void GroupSetActive(const int group_id) = 0;
63   virtual void SetCodecConfigPreference(
64       int group_id,
65       bluetooth::le_audio::btle_audio_codec_config_t input_codec_config,
66       bluetooth::le_audio::btle_audio_codec_config_t output_codec_config) = 0;
67   virtual void SetCcidInformation(int ccid, int context_type) = 0;
68   virtual void SetInCall(bool in_call) = 0;
69   virtual bool IsInCall() = 0;
70   virtual void SetInVoipCall(bool in_call) = 0;
71   virtual void SetUnicastMonitorMode(uint8_t direction, bool enable) = 0;
72   virtual bool IsInVoipCall() = 0;
73   virtual bool IsInStreaming() = 0;
74   virtual void SendAudioProfilePreferences(
75       const int group_id, bool is_output_preference_le_audio,
76       bool is_duplex_preference_le_audio) = 0;
77   virtual void SetGroupAllowedContextMask(int group_id, int sink_context_types,
78                                           int source_context_types) = 0;
79 
80   virtual bool isOutputPreferenceLeAudio(const RawAddress& address) = 0;
81   virtual bool isDuplexPreferenceLeAudio(const RawAddress& address) = 0;
82   virtual std::vector<RawAddress> GetGroupDevices(const int group_id) = 0;
83 
84   static bool RegisterIsoDataConsumer(LeAudioIsoDataCallback callback);
85 
86   static void AddFromStorage(const RawAddress& addr, bool autoconnect,
87                              int sink_audio_location, int source_audio_location,
88                              int sink_supported_context_types,
89                              int source_supported_context_types,
90                              const std::vector<uint8_t>& handles,
91                              const std::vector<uint8_t>& sink_pacs,
92                              const std::vector<uint8_t>& source_pacs,
93                              const std::vector<uint8_t>& ases);
94   static bool GetHandlesForStorage(const RawAddress& addr,
95                                    std::vector<uint8_t>& out);
96   static bool GetSinkPacsForStorage(const RawAddress& addr,
97                                     std::vector<uint8_t>& out);
98   static bool GetSourcePacsForStorage(const RawAddress& addr,
99                                       std::vector<uint8_t>& out);
100   static bool GetAsesForStorage(const RawAddress& addr,
101                                 std::vector<uint8_t>& out);
102   static bool IsLeAudioClientRunning();
103   static bool IsLeAudioClientInStreaming();
104 };
105