• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  Copyright (C) 2017 Google, Inc.
3 //
4 //  Licensed under the Apache License, Version 2.0 (the "License");
5 //  you may not use this file except in compliance with the License.
6 //  You may obtain a copy of the License at:
7 //
8 //  http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //  Unless required by applicable law or agreed to in writing, software
11 //  distributed under the License is distributed on an "AS IS" BASIS,
12 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //  See the License for the specific language governing permissions and
14 //  limitations under the License.
15 //
16 
17 #pragma once
18 
19 #include <base/macros.h>
20 #include <hardware/bluetooth.h>
21 #include <hardware/bt_av.h>
22 
23 #include <vector>
24 
25 namespace bluetooth {
26 namespace hal {
27 
28 class BluetoothAvInterface {
29  public:
30   class A2dpSourceObserver {
31    public:
32     virtual void ConnectionStateCallback(BluetoothAvInterface* iface,
33                                          const RawAddress& bd_addr,
34                                          btav_connection_state_t state);
35     virtual void AudioStateCallback(BluetoothAvInterface* iface,
36                                     const RawAddress& bd_addr,
37                                     btav_audio_state_t state);
38     virtual void AudioConfigCallback(
39         BluetoothAvInterface* iface, const RawAddress& bd_addr,
40         const btav_a2dp_codec_config_t& codec_config,
41         const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities,
42         const std::vector<btav_a2dp_codec_config_t>
43             codecs_selectable_capabilities);
44 
45    protected:
46     virtual ~A2dpSourceObserver() = default;
47   };
48 
49   class A2dpSinkObserver {
50    public:
51     virtual void ConnectionStateCallback(BluetoothAvInterface* iface,
52                                          const RawAddress& bd_addr,
53                                          btav_connection_state_t state);
54     virtual void AudioStateCallback(BluetoothAvInterface* iface,
55                                     const RawAddress& bd_addr,
56                                     btav_audio_state_t state);
57     virtual void AudioConfigCallback(BluetoothAvInterface* iface,
58                                      const RawAddress& bd_addr,
59                                      uint32_t sample_rate,
60                                      uint8_t channel_count);
61 
62    protected:
63     virtual ~A2dpSinkObserver() = default;
64   };
65 
66   static bool Initialize();
67   static void CleanUp();
68   static bool IsInitialized();
69   static void InitializeForTesting(BluetoothAvInterface* test_instance);
70 
71   static BluetoothAvInterface* Get();
72 
73   virtual bool A2dpSourceEnable(
74       std::vector<btav_a2dp_codec_config_t> codec_priorities) = 0;
75   virtual void A2dpSourceDisable() = 0;
76   virtual bool A2dpSinkEnable() = 0;
77   virtual void A2dpSinkDisable() = 0;
78 
79   virtual void AddA2dpSourceObserver(A2dpSourceObserver* observer) = 0;
80   virtual void RemoveA2dpSourceObserver(A2dpSourceObserver* observer) = 0;
81   virtual void AddA2dpSinkObserver(A2dpSinkObserver* observer) = 0;
82   virtual void RemoveA2dpSinkObserver(A2dpSinkObserver* observer) = 0;
83 
84   virtual const btav_source_interface_t* GetA2dpSourceHALInterface() = 0;
85   virtual const btav_sink_interface_t* GetA2dpSinkHALInterface() = 0;
86 
87  protected:
88   BluetoothAvInterface() = default;
89   virtual ~BluetoothAvInterface() = default;
90 
91  private:
92   DISALLOW_COPY_AND_ASSIGN(BluetoothAvInterface);
93 };
94 
95 }  // namespace hal
96 }  // namespace bluetooth
97