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