• 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     virtual bool MandatoryCodecPreferredCallback(BluetoothAvInterface* iface,
45                                                  const RawAddress& bd_addr);
46 
47    protected:
48     virtual ~A2dpSourceObserver() = default;
49   };
50 
51   class A2dpSinkObserver {
52    public:
53     virtual void ConnectionStateCallback(BluetoothAvInterface* iface,
54                                          const RawAddress& bd_addr,
55                                          btav_connection_state_t state);
56     virtual void AudioStateCallback(BluetoothAvInterface* iface,
57                                     const RawAddress& bd_addr,
58                                     btav_audio_state_t state);
59     virtual void AudioConfigCallback(BluetoothAvInterface* iface,
60                                      const RawAddress& bd_addr,
61                                      uint32_t sample_rate,
62                                      uint8_t channel_count);
63 
64    protected:
65     virtual ~A2dpSinkObserver() = default;
66   };
67 
68   static bool Initialize();
69   static void CleanUp();
70   static bool IsInitialized();
71   static void InitializeForTesting(BluetoothAvInterface* test_instance);
72 
73   static BluetoothAvInterface* Get();
74 
75   virtual bool A2dpSourceEnable(
76       std::vector<btav_a2dp_codec_config_t> codec_priorities) = 0;
77   virtual void A2dpSourceDisable() = 0;
78   virtual bool A2dpSinkEnable() = 0;
79   virtual void A2dpSinkDisable() = 0;
80 
81   virtual void AddA2dpSourceObserver(A2dpSourceObserver* observer) = 0;
82   virtual void RemoveA2dpSourceObserver(A2dpSourceObserver* observer) = 0;
83   virtual void AddA2dpSinkObserver(A2dpSinkObserver* observer) = 0;
84   virtual void RemoveA2dpSinkObserver(A2dpSinkObserver* observer) = 0;
85 
86   virtual const btav_source_interface_t* GetA2dpSourceHALInterface() = 0;
87   virtual const btav_sink_interface_t* GetA2dpSinkHALInterface() = 0;
88 
89  protected:
90   BluetoothAvInterface() = default;
91   virtual ~BluetoothAvInterface() = default;
92 
93  private:
94   DISALLOW_COPY_AND_ASSIGN(BluetoothAvInterface);
95 };
96 
97 }  // namespace hal
98 }  // namespace bluetooth
99