| 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_BLUEZ_H_ |
| 6 #define DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_BLUEZ_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/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "dbus/file_descriptor.h" | 18 #include "dbus/file_descriptor.h" |
| 18 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
| 19 #include "device/bluetooth/bluetooth_adapter.h" | 20 #include "device/bluetooth/bluetooth_adapter.h" |
| 20 #include "device/bluetooth/bluetooth_audio_sink.h" | 21 #include "device/bluetooth/bluetooth_audio_sink.h" |
| 21 #include "device/bluetooth/bluetooth_export.h" | 22 #include "device/bluetooth/bluetooth_export.h" |
| 22 #include "device/bluetooth/dbus/bluetooth_media_client.h" | 23 #include "device/bluetooth/dbus/bluetooth_media_client.h" |
| 23 #include "device/bluetooth/dbus/bluetooth_media_endpoint_service_provider.h" | 24 #include "device/bluetooth/dbus/bluetooth_media_endpoint_service_provider.h" |
| 24 #include "device/bluetooth/dbus/bluetooth_media_transport_client.h" | 25 #include "device/bluetooth/dbus/bluetooth_media_transport_client.h" |
| 25 | 26 |
| 26 namespace chromeos { | 27 namespace bluez { |
| 27 | 28 |
| 28 class BluetoothAudioSinkChromeOSTest; | 29 class BluetoothAudioSinkBlueZTest; |
| 29 | 30 |
| 30 class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS | 31 class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkBlueZ |
| 31 : public device::BluetoothAudioSink, | 32 : public device::BluetoothAudioSink, |
| 32 public device::BluetoothAdapter::Observer, | 33 public device::BluetoothAdapter::Observer, |
| 33 public bluez::BluetoothMediaClient::Observer, | 34 public bluez::BluetoothMediaClient::Observer, |
| 34 public bluez::BluetoothMediaTransportClient::Observer, | 35 public bluez::BluetoothMediaTransportClient::Observer, |
| 35 public bluez::BluetoothMediaEndpointServiceProvider::Delegate, | 36 public bluez::BluetoothMediaEndpointServiceProvider::Delegate, |
| 36 public base::MessageLoopForIO::Watcher { | 37 public base::MessageLoopForIO::Watcher { |
| 37 public: | 38 public: |
| 38 explicit BluetoothAudioSinkChromeOS( | 39 explicit BluetoothAudioSinkBlueZ( |
| 39 scoped_refptr<device::BluetoothAdapter> adapter); | 40 scoped_refptr<device::BluetoothAdapter> adapter); |
| 40 | 41 |
| 41 // device::BluetoothAudioSink overrides. | 42 // device::BluetoothAudioSink overrides. |
| 42 // Unregisters a BluetoothAudioSink. |callback| should handle | 43 // Unregisters a BluetoothAudioSink. |callback| should handle |
| 43 // the clean-up after the audio sink is deleted successfully, otherwise | 44 // the clean-up after the audio sink is deleted successfully, otherwise |
| 44 // |error_callback| will be called. | 45 // |error_callback| will be called. |
| 45 void Unregister( | 46 void Unregister( |
| 46 const base::Closure& callback, | 47 const base::Closure& callback, |
| 47 const device::BluetoothAudioSink::ErrorCallback& error_callback) override; | 48 const device::BluetoothAudioSink::ErrorCallback& error_callback) override; |
| 48 void AddObserver(BluetoothAudioSink::Observer* observer) override; | 49 void AddObserver(BluetoothAudioSink::Observer* observer) override; |
| 49 void RemoveObserver(BluetoothAudioSink::Observer* observer) override; | 50 void RemoveObserver(BluetoothAudioSink::Observer* observer) override; |
| 50 device::BluetoothAudioSink::State GetState() const override; | 51 device::BluetoothAudioSink::State GetState() const override; |
| 51 uint16_t GetVolume() const override; | 52 uint16_t GetVolume() const override; |
| 52 | 53 |
| 53 // Registers a BluetoothAudioSink. User applications can use |options| to | 54 // Registers a BluetoothAudioSink. User applications can use |options| to |
| 54 // configure the audio sink. |callback| will be executed if the audio sink is | 55 // configure the audio sink. |callback| will be executed if the audio sink is |
| 55 // successfully registered, otherwise |error_callback| will be called. Called | 56 // successfully registered, otherwise |error_callback| will be called. Called |
| 56 // by BluetoothAdapterChromeOS. | 57 // by BluetoothAdapterBlueZ. |
| 57 void Register( | 58 void Register( |
| 58 const device::BluetoothAudioSink::Options& options, | 59 const device::BluetoothAudioSink::Options& options, |
| 59 const base::Closure& callback, | 60 const base::Closure& callback, |
| 60 const device::BluetoothAudioSink::ErrorCallback& error_callback); | 61 const device::BluetoothAudioSink::ErrorCallback& error_callback); |
| 61 | 62 |
| 62 // Returns a pointer to the media endpoint object. This function should be | 63 // Returns a pointer to the media endpoint object. This function should be |
| 63 // used for testing purpose only. | 64 // used for testing purpose only. |
| 64 bluez::BluetoothMediaEndpointServiceProvider* GetEndpointServiceProvider(); | 65 bluez::BluetoothMediaEndpointServiceProvider* GetEndpointServiceProvider(); |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 ~BluetoothAudioSinkChromeOS() override; | 68 ~BluetoothAudioSinkBlueZ() override; |
| 68 | 69 |
| 69 // device::BluetoothAdapter::Observer overrides. | 70 // device::BluetoothAdapter::Observer overrides. |
| 70 void AdapterPresentChanged(device::BluetoothAdapter* adapter, | 71 void AdapterPresentChanged(device::BluetoothAdapter* adapter, |
| 71 bool present) override; | 72 bool present) override; |
| 72 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 73 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
| 73 bool powered) override; | 74 bool powered) override; |
| 74 | 75 |
| 75 // bluez::BluetoothMediaClient::Observer overrides. | 76 // bluez::BluetoothMediaClient::Observer overrides. |
| 76 void MediaRemoved(const dbus::ObjectPath& object_path) override; | 77 void MediaRemoved(const dbus::ObjectPath& object_path) override; |
| 77 | 78 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void OnReleaseFDFailed(const std::string& error_name, | 151 void OnReleaseFDFailed(const std::string& error_name, |
| 151 const std::string& error_message); | 152 const std::string& error_message); |
| 152 | 153 |
| 153 // Helper functions to clean up media, media transport and media endpoint. | 154 // Helper functions to clean up media, media transport and media endpoint. |
| 154 // Called when the |state_| changes to either STATE_INVALID or | 155 // Called when the |state_| changes to either STATE_INVALID or |
| 155 // STATE_DISCONNECTED. | 156 // STATE_DISCONNECTED. |
| 156 void ResetMedia(); | 157 void ResetMedia(); |
| 157 void ResetTransport(); | 158 void ResetTransport(); |
| 158 void ResetEndpoint(); | 159 void ResetEndpoint(); |
| 159 | 160 |
| 160 // The connection state between the BluetoothAudioSinkChromeOS and the remote | 161 // The connection state between the BluetoothAudioSinkBlueZ and the remote |
| 161 // device. | 162 // device. |
| 162 device::BluetoothAudioSink::State state_; | 163 device::BluetoothAudioSink::State state_; |
| 163 | 164 |
| 164 // The volume control by the remote device during the streaming. The valid | 165 // The volume control by the remote device during the streaming. The valid |
| 165 // range of volume is 0-127, and 128 is used to represent invalid volume. | 166 // range of volume is 0-127, and 128 is used to represent invalid volume. |
| 166 uint16_t volume_; | 167 uint16_t volume_; |
| 167 | 168 |
| 168 // Read MTU of the file descriptor acquired via Media Transport object. | 169 // Read MTU of the file descriptor acquired via Media Transport object. |
| 169 uint16_t read_mtu_; | 170 uint16_t read_mtu_; |
| 170 | 171 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 189 // Object path of the media object being used. | 190 // Object path of the media object being used. |
| 190 dbus::ObjectPath media_path_; | 191 dbus::ObjectPath media_path_; |
| 191 | 192 |
| 192 // Object path of the transport object being used. | 193 // Object path of the transport object being used. |
| 193 dbus::ObjectPath transport_path_; | 194 dbus::ObjectPath transport_path_; |
| 194 | 195 |
| 195 // Object path of the media endpoint object being used. | 196 // Object path of the media endpoint object being used. |
| 196 dbus::ObjectPath endpoint_path_; | 197 dbus::ObjectPath endpoint_path_; |
| 197 | 198 |
| 198 // BT adapter which the audio sink binds to. |adapter_| should outlive | 199 // BT adapter which the audio sink binds to. |adapter_| should outlive |
| 199 // a BluetoothAudioSinkChromeOS object. | 200 // a BluetoothAudioSinkBlueZ object. |
| 200 scoped_refptr<device::BluetoothAdapter> adapter_; | 201 scoped_refptr<device::BluetoothAdapter> adapter_; |
| 201 | 202 |
| 202 // Options used to initiate Media Endpoint and select configuration for the | 203 // Options used to initiate Media Endpoint and select configuration for the |
| 203 // transport. | 204 // transport. |
| 204 device::BluetoothAudioSink::Options options_; | 205 device::BluetoothAudioSink::Options options_; |
| 205 | 206 |
| 206 // Media Endpoint object owned by the audio sink object. | 207 // Media Endpoint object owned by the audio sink object. |
| 207 scoped_ptr<bluez::BluetoothMediaEndpointServiceProvider> media_endpoint_; | 208 scoped_ptr<bluez::BluetoothMediaEndpointServiceProvider> media_endpoint_; |
| 208 | 209 |
| 209 // List of observers interested in event notifications from us. Objects in | 210 // List of observers interested in event notifications from us. Objects in |
| 210 // |observers_| are expected to outlive a BluetoothAudioSinkChromeOS object. | 211 // |observers_| are expected to outlive a BluetoothAudioSinkBlueZ object. |
| 211 base::ObserverList<BluetoothAudioSink::Observer> observers_; | 212 base::ObserverList<BluetoothAudioSink::Observer> observers_; |
| 212 | 213 |
| 213 // Note: This should remain the last member so it'll be destroyed and | 214 // Note: This should remain the last member so it'll be destroyed and |
| 214 // invalidate its weak pointers before any other members are destroyed. | 215 // invalidate its weak pointers before any other members are destroyed. |
| 215 base::WeakPtrFactory<BluetoothAudioSinkChromeOS> weak_ptr_factory_; | 216 base::WeakPtrFactory<BluetoothAudioSinkBlueZ> weak_ptr_factory_; |
| 216 | 217 |
| 217 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSinkChromeOS); | 218 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSinkBlueZ); |
| 218 }; | 219 }; |
| 219 | 220 |
| 220 } // namespace chromeos | 221 } // namespace bluez |
| 221 | 222 |
| 222 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_ | 223 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_BLUEZ_H_ |
| OLD | NEW |