Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: device/bluetooth/bluetooth_audio_sink_chromeos.h

Issue 787743002: device/bluetooth: Add BluetoothAudioSinkChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change copyright year and add some functions. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // A global sequence number used to generate unique path for Media Endpoint
35 // object.
36 static uint16_t sequence_number;
37
38 explicit BluetoothAudioSinkChromeOS(BluetoothAdapterChromeOS* adapter);
39
40 // device::BluetoothAudioSink overrides.
41 void AddObserver(BluetoothAudioSink::Observer* observer) override;
42 void RemoveObserver(BluetoothAudioSink::Observer* observer) override;
43 device::BluetoothAudioSink::State GetState() const override;
44 uint16_t GetVolume() const override;
45
46 // device::BluetoothAdapter::Observer overrides.
47 void AdapterPresentChanged(device::BluetoothAdapter* adapter,
48 bool present) override;
49 void AdapterPoweredChanged(device::BluetoothAdapter* adapter,
50 bool powered) override;
51
52 // BluetoothMediaClient::Observer overrides.
53 void MediaAdded(const dbus::ObjectPath& object_path) override;
54 void MediaRemoved(const dbus::ObjectPath& object_path) override;
55
56 // BluetoothMediaTransportClient::Observer overrides.
57 void MediaTransportAdded(const dbus::ObjectPath& object_path) override;
58 void MediaTransportRemoved(const dbus::ObjectPath& object_path) override;
59 void MediaTransportPropertyChanged(const dbus::ObjectPath& object_path,
60 const std::string& property_name) override;
61
62 // BluetoothMediaEndpointServiceProvider::Delegate overrides.
63 void SetConfiguration(const dbus::ObjectPath& transport_path,
64 const dbus::MessageReader& properties) override;
65 void SelectConfiguration(
66 const std::vector<uint8_t>& capabilities,
67 const SelectConfigurationCallback& callback) override;
68 void ClearConfiguration(const dbus::ObjectPath& transport_path) override;
69 void Release() override;
70
71 // Registers a BluetoothAudioSink. User applications can use |options| to
72 // configure the audio sink. |callback| will be executed if the audio sink is
73 // successfully registered, otherwise |error_callback| will be called.
armansito 2015/01/17 02:09:06 Can you add a note here at the end saying "Called
Miao 2015/01/17 04:09:53 Done.
74 virtual void Register(
armansito 2015/01/17 02:09:06 nit: This probably doesn't need to be virtual.
Miao 2015/01/17 04:09:53 Done.
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 // Called when the registration of Media Endpoint Done.
97 void OnRegisterSucceeded(const base::Closure& callback);
98
99 // Called when the registration of Media Endpoint failed.
100 void OnRegisterFailed(const BluetoothAudioSink::ErrorCallback& error_back,
101 const std::string& error_name,
102 const std::string& error_message);
103
104 // Called when the audio sink successfully acquired a file descriptor and MTUs
105 // from the transport object with |transport_path_|.
106 void OnAcquireSucceeded(const dbus::FileDescriptor& fd,
107 const uint16_t read_mtu,
108 const uint16_t write_mtu);
109
110 // Called when the audio sink failed to retrieve a file descroptor and MTUs.
111 void OnAcquireFailed(const std::string& error_name,
112 const std::string& error_message);
armansito 2015/01/17 02:09:06 nit: Remove all of the On* methods, since these ar
Miao 2015/01/17 04:09:53 Done.
113
114 // Generates an unique path for initiating a Media Endpoint.
115 dbus::ObjectPath GenerateEndpointPath();
116
117 // Reads from the file descriptor acquired via Media Transport object and
118 // notify |observer_| while the audio data is available.
119 void ReadFromFD();
120
121 // The connection state between the BluetoothAudioSinkChromeOS and the remote
122 // device.
123 device::BluetoothAudioSink::State state_;
124
125 // Indicates whether the adapter is present.
126 bool present_;
127
128 // Indicates whether the adapter is powered.
129 bool powered_;
130
131 // The volume control by the remote device during the streaming.
132 uint16_t volume_;
133
134 // Read MTU of the file descriptor acquired via Media Transport object.
135 uint16_t read_mtu_;
136
137 // Write MTU of the file descriptor acquired via Media Transport object.
138 uint16_t write_mtu_;
139
140 // File descriptor acquired via Media Transport object.
141 dbus::FileDescriptor fd_;
142
143 // Object path of the media object being used.
144 dbus::ObjectPath media_path_;
145
146 // Object path of the transport object being used.
147 dbus::ObjectPath transport_path_;
148
149 // Object path of the media endpoint object being used.
150 dbus::ObjectPath endpoint_path_;
151
152 // BT adapter which the audio sink binds to.
153 BluetoothAdapterChromeOS* adapter_;
154
155 // Options used to initiate Media Endpoint and select configuration for the
156 // transport.
157 device::BluetoothAudioSink::Options options_;
158
159 // Media Endpoint object owned by the audio sink object.
160 scoped_ptr<BluetoothMediaEndpointServiceProvider> media_endpoint_;
161
162 // List of observers interested in event notifications from us.
163 ObserverList<BluetoothAudioSink::Observer> observers_;
164
165 // Note: This should remain the last member so it'll be destroyed and
166 // invalidate its weak pointers before any other members are destroyed.
167 base::WeakPtrFactory<BluetoothAudioSinkChromeOS> weak_ptr_factory_;
168
169 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSinkChromeOS);
170 };
171
172 } // namespace chromeos
173
174 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_CHROMEOS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698