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