OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "chromeos/dbus/bluetooth_media_client.h" | 15 #include "chromeos/dbus/bluetooth_media_client.h" |
16 #include "chromeos/dbus/bluetooth_media_endpoint_service_provider.h" | 16 #include "chromeos/dbus/bluetooth_media_endpoint_service_provider.h" |
17 #include "chromeos/dbus/bluetooth_media_transport_client.h" | 17 #include "chromeos/dbus/bluetooth_media_transport_client.h" |
18 #include "dbus/file_descriptor.h" | 18 #include "dbus/file_descriptor.h" |
19 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
20 #include "device/bluetooth/bluetooth_adapter.h" | 20 #include "device/bluetooth/bluetooth_adapter.h" |
21 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | |
22 #include "device/bluetooth/bluetooth_audio_sink.h" | 21 #include "device/bluetooth/bluetooth_audio_sink.h" |
23 #include "device/bluetooth/bluetooth_export.h" | 22 #include "device/bluetooth/bluetooth_export.h" |
24 | 23 |
25 namespace chromeos { | 24 namespace chromeos { |
26 | 25 |
27 class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS | 26 class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS |
28 : public device::BluetoothAudioSink, | 27 : public device::BluetoothAudioSink, |
29 public device::BluetoothAdapter::Observer, | 28 public device::BluetoothAdapter::Observer, |
30 public BluetoothMediaClient::Observer, | 29 public BluetoothMediaClient::Observer, |
31 public BluetoothMediaTransportClient::Observer, | 30 public BluetoothMediaTransportClient::Observer, |
32 public BluetoothMediaEndpointServiceProvider::Delegate { | 31 public BluetoothMediaEndpointServiceProvider::Delegate { |
33 public: | 32 public: |
34 explicit BluetoothAudioSinkChromeOS(BluetoothAdapterChromeOS* adapter); | 33 explicit BluetoothAudioSinkChromeOS( |
| 34 scoped_refptr<device::BluetoothAdapter> adapter); |
35 | 35 |
36 // device::BluetoothAudioSink overrides. | 36 // device::BluetoothAudioSink overrides. |
37 void AddObserver(BluetoothAudioSink::Observer* observer) override; | 37 void AddObserver(BluetoothAudioSink::Observer* observer) override; |
38 void RemoveObserver(BluetoothAudioSink::Observer* observer) override; | 38 void RemoveObserver(BluetoothAudioSink::Observer* observer) override; |
39 device::BluetoothAudioSink::State GetState() const override; | 39 device::BluetoothAudioSink::State GetState() const override; |
40 uint16_t GetVolume() const override; | 40 uint16_t GetVolume() const override; |
41 | 41 |
42 // device::BluetoothAdapter::Observer overrides. | 42 // device::BluetoothAdapter::Observer overrides. |
43 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 43 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
44 bool present) override; | 44 bool present) override; |
45 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | |
46 bool powered) override; | |
47 | 45 |
48 // BluetoothMediaClient::Observer overrides. | 46 // BluetoothMediaClient::Observer overrides. |
49 void MediaRemoved(const dbus::ObjectPath& object_path) override; | 47 void MediaRemoved(const dbus::ObjectPath& object_path) override; |
50 | 48 |
51 // BluetoothMediaTransportClient::Observer overrides. | 49 // BluetoothMediaTransportClient::Observer overrides. |
52 void MediaTransportRemoved(const dbus::ObjectPath& object_path) override; | 50 void MediaTransportRemoved(const dbus::ObjectPath& object_path) override; |
53 void MediaTransportPropertyChanged(const dbus::ObjectPath& object_path, | 51 void MediaTransportPropertyChanged(const dbus::ObjectPath& object_path, |
54 const std::string& property_name) override; | 52 const std::string& property_name) override; |
55 | 53 |
56 // BluetoothMediaEndpointServiceProvider::Delegate overrides. | 54 // BluetoothMediaEndpointServiceProvider::Delegate overrides. |
57 void SetConfiguration(const dbus::ObjectPath& transport_path, | 55 void SetConfiguration(const dbus::ObjectPath& transport_path, |
58 const dbus::MessageReader& properties) override; | 56 const dbus::MessageReader& properties) override; |
59 void SelectConfiguration( | 57 void SelectConfiguration( |
60 const std::vector<uint8_t>& capabilities, | 58 const std::vector<uint8_t>& capabilities, |
61 const SelectConfigurationCallback& callback) override; | 59 const SelectConfigurationCallback& callback) override; |
62 void ClearConfiguration(const dbus::ObjectPath& transport_path) override; | 60 void ClearConfiguration(const dbus::ObjectPath& transport_path) override; |
63 void Release() override; | 61 void Release() override; |
64 | 62 |
65 // Registers a BluetoothAudioSink. User applications can use |options| to | 63 // Registers a BluetoothAudioSink. User applications can use |options| to |
66 // configure the audio sink. |callback| will be executed if the audio sink is | 64 // configure the audio sink. |callback| will be executed if the audio sink is |
67 // successfully registered, otherwise |error_callback| will be called. Called | 65 // successfully registered, otherwise |error_callback| will be called. Called |
68 // from BluetoothAdapterChromeOS. | 66 // by BluetoothAdapterChromeOS. |
69 void Register( | 67 void Register( |
70 const device::BluetoothAudioSink::Options& options, | 68 const device::BluetoothAudioSink::Options& options, |
71 const base::Closure& callback, | 69 const base::Closure& callback, |
72 const device::BluetoothAudioSink::ErrorCallback& error_callback); | 70 const device::BluetoothAudioSink::ErrorCallback& error_callback); |
73 | 71 |
74 // Unregisters a BluetoothAudioSink. |callback| should handle | 72 // Unregisters a BluetoothAudioSink. |callback| should handle |
75 // the clean-up after the audio sink is deleted successfully, otherwise | 73 // the clean-up after the audio sink is deleted successfully, otherwise |
76 // |error_callback| will be called. | 74 // |error_callback| will be called. |
77 void Unregister( | 75 void Unregister( |
78 const base::Closure& callback, | 76 const base::Closure& callback, |
79 const device::BluetoothAudioSink::ErrorCallback& error_callback) override; | 77 const device::BluetoothAudioSink::ErrorCallback& error_callback) override; |
80 | 78 |
81 private: | 79 private: |
82 ~BluetoothAudioSinkChromeOS() override; | 80 ~BluetoothAudioSinkChromeOS() override; |
83 | 81 |
84 // Called when the state property of BluetoothMediaTransport has been updated. | 82 // Called when the state property of BluetoothMediaTransport has been updated. |
85 void StateChanged(device::BluetoothAudioSink::State state); | 83 void StateChanged(device::BluetoothAudioSink::State state); |
86 | 84 |
87 // Called when the volume property of BluetoothMediaTransport has been | 85 // Called when the volume property of BluetoothMediaTransport has been |
88 // updated. | 86 // updated. |
89 void VolumeChanged(uint16_t volume); | 87 void VolumeChanged(uint16_t volume); |
90 | 88 |
| 89 // Called when the registration of Media Endpoint has succeeded. |
| 90 void OnRegisterSucceeded(const base::Closure& callback); |
| 91 |
| 92 // Called when the registration of Media Endpoint failed. |
| 93 void OnRegisterFailed(const BluetoothAudioSink::ErrorCallback& error_callback, |
| 94 const std::string& error_name, |
| 95 const std::string& error_message); |
| 96 |
91 // Reads from the file descriptor acquired via Media Transport object and | 97 // Reads from the file descriptor acquired via Media Transport object and |
92 // notify |observer_| while the audio data is available. | 98 // notify |observer_| while the audio data is available. |
93 void ReadFromFD(); | 99 void ReadFromFD(); |
94 | 100 |
95 // The connection state between the BluetoothAudioSinkChromeOS and the remote | 101 // The connection state between the BluetoothAudioSinkChromeOS and the remote |
96 // device. | 102 // device. |
97 device::BluetoothAudioSink::State state_; | 103 device::BluetoothAudioSink::State state_; |
98 | 104 |
99 // Indicates whether the adapter is present. | |
100 bool present_; | |
101 | |
102 // Indicates whether the adapter is powered. | |
103 bool powered_; | |
104 | |
105 // The volume control by the remote device during the streaming. | 105 // The volume control by the remote device during the streaming. |
106 uint16_t volume_; | 106 uint16_t volume_; |
107 | 107 |
108 // Read MTU of the file descriptor acquired via Media Transport object. | 108 // Read MTU of the file descriptor acquired via Media Transport object. |
109 uint16_t read_mtu_; | 109 uint16_t read_mtu_; |
110 | 110 |
111 // Write MTU of the file descriptor acquired via Media Transport object. | 111 // Write MTU of the file descriptor acquired via Media Transport object. |
112 uint16_t write_mtu_; | 112 uint16_t write_mtu_; |
113 | 113 |
114 // File descriptor acquired via Media Transport object. | 114 // File descriptor acquired via Media Transport object. |
115 dbus::FileDescriptor fd_; | 115 dbus::FileDescriptor fd_; |
116 | 116 |
117 // Object path of the media object being used. | 117 // Object path of the media object being used. |
118 dbus::ObjectPath media_path_; | 118 dbus::ObjectPath media_path_; |
119 | 119 |
120 // Object path of the transport object being used. | 120 // Object path of the transport object being used. |
121 dbus::ObjectPath transport_path_; | 121 dbus::ObjectPath transport_path_; |
122 | 122 |
123 // Object path of the media endpoint object being used. | 123 // Object path of the media endpoint object being used. |
124 dbus::ObjectPath endpoint_path_; | 124 dbus::ObjectPath endpoint_path_; |
125 | 125 |
126 // BT adapter which the audio sink binds to. |adapter_| should outlive | 126 // BT adapter which the audio sink binds to. |adapter_| should outlive |
127 // a BluetoothAudioSinkChromeOS object. | 127 // a BluetoothAudioSinkChromeOS object. |
128 BluetoothAdapterChromeOS* adapter_; | 128 scoped_refptr<device::BluetoothAdapter> adapter_; |
129 | 129 |
130 // Options used to initiate Media Endpoint and select configuration for the | 130 // Options used to initiate Media Endpoint and select configuration for the |
131 // transport. | 131 // transport. |
132 device::BluetoothAudioSink::Options options_; | 132 device::BluetoothAudioSink::Options options_; |
133 | 133 |
134 // Media Endpoint object owned by the audio sink object. | 134 // Media Endpoint object owned by the audio sink object. |
135 scoped_ptr<BluetoothMediaEndpointServiceProvider> media_endpoint_; | 135 scoped_ptr<BluetoothMediaEndpointServiceProvider> media_endpoint_; |
136 | 136 |
137 // List of observers interested in event notifications from us. Objects in | 137 // List of observers interested in event notifications from us. Objects in |
138 // |observers_| are expected to outlive a BluetoothAudioSinkChromeOS object. | 138 // |observers_| are expected to outlive a BluetoothAudioSinkChromeOS object. |
139 ObserverList<BluetoothAudioSink::Observer> observers_; | 139 ObserverList<BluetoothAudioSink::Observer> observers_; |
140 | 140 |
141 // Note: This should remain the last member so it'll be destroyed and | 141 // Note: This should remain the last member so it'll be destroyed and |
142 // invalidate its weak pointers before any other members are destroyed. | 142 // invalidate its weak pointers before any other members are destroyed. |
143 base::WeakPtrFactory<BluetoothAudioSinkChromeOS> weak_ptr_factory_; | 143 base::WeakPtrFactory<BluetoothAudioSinkChromeOS> weak_ptr_factory_; |
144 | 144 |
145 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSinkChromeOS); | 145 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSinkChromeOS); |
146 }; | 146 }; |
147 | 147 |
148 } // namespace chromeos | 148 } // namespace chromeos |
149 | 149 |
150 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ | 150 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ |
OLD | NEW |