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

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

Issue 787743002: device/bluetooth: Add BluetoothAudioSinkChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove all OnAction callbacks and fill in GeneratePath function. 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 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h"
6
7 #include <limits>
8 #include <sstream>
9
10 #include "base/logging.h"
11
12 namespace {
13
14 // TODO(mcchou): Add the constant to dbus/service_constants.h.
15 const char kBluetoothAudioSinkServicePath[] = "/org/chromium/AudioSink";
16
17 } // namespace
18
19 namespace chromeos {
20
21 uint16_t BluetoothAudioSinkChromeOS::sequence_number = 0;
22
23 BluetoothAudioSinkChromeOS::BluetoothAudioSinkChromeOS(
24 BluetoothAdapterChromeOS* adapter)
25 : state_(device::BluetoothAudioSink::STATE_INVALID),
26 present_(false),
27 powered_(false),
28 volume_(0),
29 read_mtu_(0),
30 write_mtu_(0),
31 adapter_(adapter),
32 weak_ptr_factory_(this) {
33 DCHECK(adapter_);
34
35 present_ = adapter_->IsPresent();
36 powered_ = adapter_->IsPowered();
37 if (present_ && powered_)
38 state_ = device::BluetoothAudioSink::STATE_DISCONNECTED;
39 adapter_->AddObserver(this);
40 }
41
42 BluetoothAudioSinkChromeOS::~BluetoothAudioSinkChromeOS() {
43 DCHECK(adapter_);
44 adapter_->RemoveObserver(this);
45 }
46
47 void BluetoothAudioSinkChromeOS::AddObserver(
48 device::BluetoothAudioSink::Observer* observer) {
49 DCHECK(observer);
50 observers_.AddObserver(observer);
51 }
52
53 void BluetoothAudioSinkChromeOS::RemoveObserver(
54 device::BluetoothAudioSink::Observer* observer) {
55 DCHECK(observer);
56 observers_.RemoveObserver(observer);
57 }
58
59 device::BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const {
60 return state_;
61 }
62
63 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const {
64 return volume_;
65 }
66
67 void BluetoothAudioSinkChromeOS::AdapterPresentChanged(
68 device::BluetoothAdapter* adapter,
69 bool present) {
70 // TODO(mcchou): BUG=441581
71 // If |persent| is true, change state to |STATE_DISCONNECTED| and call
72 // StateChanged(). Otherwise, change state to |STATE_INVALID| and call
73 // StateChanged.
74 }
75
76 void BluetoothAudioSinkChromeOS::AdapterPoweredChanged(
77 device::BluetoothAdapter* adapter,
78 bool powered) {
79 // TODO(mcchou): BUG=441581
80 // If |powered| is true, change state to |STATE_DISCONNECTED| and call
81 // StateChanged(). Otherwise, change state to |STATE_INVALID| and call
82 // StateChanged.
83 }
84
85 void BluetoothAudioSinkChromeOS::MediaAdded(
86 const dbus::ObjectPath& object_path) {
87 // Do nothing for now.
88 }
89
90 void BluetoothAudioSinkChromeOS::MediaRemoved(
91 const dbus::ObjectPath& object_path) {
92 // TODO(mcchou): BUG=441581
93 // Check if |object_path| equals to |media_path_|. If true, change the state
94 // of the audio sink, call StateChanged and reset the audio sink.
95 }
96
97 void BluetoothAudioSinkChromeOS::MediaTransportAdded(
98 const dbus::ObjectPath& object_path) {
99 // Do nothing for now.
100 }
101
102 void BluetoothAudioSinkChromeOS::MediaTransportRemoved(
103 const dbus::ObjectPath& object_path) {
104 // TODO(mcchou): BUG=441581
105 // Check if |object_path| equals to |transport_path_|. If true, change the
106 // state of the audio sink, call StateChanged and reset the audio sink.
107 }
108
109 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged(
110 const dbus::ObjectPath& object_path,
111 const std::string& property_name) {
112 // TODO(mcchou): BUG=441581
113 // Call StateChanged and VolumeChanged accordingly if there is any change on
114 // state/volume.
115 }
116
117 void BluetoothAudioSinkChromeOS::SetConfiguration(
118 const dbus::ObjectPath& transport_path,
119 const dbus::MessageReader& properties) {
120 // TODO(mcchou): BUG=441581
121 // Update |transport_path_| and store properties if needed.
122 }
123
124 void BluetoothAudioSinkChromeOS::SelectConfiguration(
125 const std::vector<uint8_t>& capabilities,
126 const SelectConfigurationCallback& callback) {
127 // TODO(mcchou): BUG=441581
128 // Use SelectConfigurationCallback to return the agreed capabilities.
129 }
130
131 void BluetoothAudioSinkChromeOS::ClearConfiguration(
132 const dbus::ObjectPath& transport_path) {
133 // TODO(mcchou): BUG=441581
134 // Reset the configuration to the default one and close IOBuffer.
135 }
136
137 void BluetoothAudioSinkChromeOS::Release() {
138 // TODO(mcchou): BUG=441581
139 // Let the audio sink does the clean-up and do nothing here.
140 }
141
142 void Register(
143 const device::BluetoothAudioSink::Options& options,
144 const base::Closure& callback,
145 const device::BluetoothAudioSink::ErrorCallback& error_callback) {
146 // TODO(mcchou): BUG=441581
147 // Get Media object, initiate an Media Endpoint with options, and return the
148 // audio sink via callback. Add the audio sink as observer of both Media and
149 // Media Transport.
150 }
151
152 void Unregister(
153 const base::Closure& callback,
154 const device::BluetoothAudioSink::ErrorCallback& error_callback) {
155 // TODO(mcchou): BUG=441581
156 // Clean |observers_| and transport_path_ and reset state_ and volume.
157 }
158
159 void BluetoothAudioSinkChromeOS::StateChanged(
160 device::BluetoothAudioSink::State state) {
161 DCHECK_NE(state, state_);
162 VLOG(1) << "Bluetooth audio sink state changed: " << state;
163 state_ = state;
164 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_,
165 BluetoothAudioSinkStateChanged(this, state_));
166 }
167
168 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) {
169 DCHECK_NE(volume, volume_);
170 VLOG(1) << "Bluetooth audio sink volume changed: " << volume;
171 volume_ = volume;
172 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_,
173 BluetoothAudioSinkVolumeChanged(this, volume_));
174 }
175
176 dbus::ObjectPath BluetoothAudioSinkChromeOS::GenerateEndpointPath() {
177 if (sequence_number == std::numeric_limits<uint16_t>::max()) {
Ben Chan 2015/01/20 22:46:51 this function should be static. also move the dec
Miao 2015/01/21 00:10:54 Done.
178 sequence_number = 0;
179 } else {
180 ++sequence_number;
Ben Chan 2015/01/20 22:46:51 ++sequence_number is sufficient as it will wrap ar
Miao 2015/01/21 00:10:54 Done.
181 }
armansito 2015/01/20 22:47:49 This is unnecessary, since unsigned integer overfl
Miao 2015/01/21 00:10:54 Done.
182 std::stringstream path;
183 path << kBluetoothAudioSinkServicePath << "/endpoint" << sequence_number;
184 return dbus::ObjectPath(path.str());
185 }
186
187 void BluetoothAudioSinkChromeOS::ReadFromFD() {
188 DCHECK_NE(fd_.value(), -1);
189
190 // TODO(mcchou): BUG=441581
191 // Read from file descriptor using watcher and create a buffer to contain the
192 // data. Notify |Observers_| while there is audio data available.
193 }
194
195 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698