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 void BluetoothAudioSinkChromeOS::AddObserver( | |
45 device::BluetoothAudioSink::Observer* observer) { | |
46 DCHECK(observer); | |
47 observers_.AddObserver(observer); | |
48 } | |
49 | |
50 void BluetoothAudioSinkChromeOS::RemoveObserver( | |
51 device::BluetoothAudioSink::Observer* observer) { | |
52 DCHECK(observer); | |
53 observers_.RemoveObserver(observer); | |
54 } | |
55 | |
56 device::BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const { | |
57 return state_; | |
58 } | |
59 | |
60 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const { | |
61 return volume_; | |
62 } | |
63 | |
64 void BluetoothAudioSinkChromeOS::AdapterPresentChanged( | |
65 device::BluetoothAdapter* adapter, | |
66 bool present) { | |
67 // TODO(mcchou): BUG=441581 | |
68 // If |persent| is true, change state to |STATE_DISCONNECTED| and call | |
69 // StateChanged(). Otherwise, change state to |STATE_INVALID| and call | |
70 // StateChanged. | |
71 } | |
72 | |
73 void BluetoothAudioSinkChromeOS::AdapterPoweredChanged( | |
74 device::BluetoothAdapter* adapter, | |
75 bool powered) { | |
76 // TODO(mcchou): BUG=441581 | |
77 // If |powered| is true, change state to |STATE_DISCONNECTED| and call | |
78 // StateChanged(). Otherwise, change state to |STATE_INVALID| and call | |
79 // StateChanged. | |
80 } | |
81 | |
82 void BluetoothAudioSinkChromeOS::MediaAdded( | |
83 const dbus::ObjectPath& object_path) { | |
84 // Do nothing for now. | |
85 } | |
86 | |
87 void BluetoothAudioSinkChromeOS::MediaRemoved( | |
88 const dbus::ObjectPath& object_path) { | |
89 // TODO(mcchou): BUG=441581 | |
90 // Check if |object_path| equals to |media_path_|. If true, change the state | |
91 // of the audio sink, call StateChanged and reset the audio sink. | |
92 } | |
93 | |
94 void BluetoothAudioSinkChromeOS::MediaTransportAdded( | |
95 const dbus::ObjectPath& object_path) { | |
96 // Do nothing for now. | |
97 } | |
98 | |
99 void BluetoothAudioSinkChromeOS::MediaTransportRemoved( | |
100 const dbus::ObjectPath& object_path) { | |
101 // TODO(mcchou): BUG=441581 | |
102 // Check if |object_path| equals to |transport_path_|. If true, change the | |
103 // state of the audio sink, call StateChanged and reset the audio sink. | |
104 } | |
105 | |
106 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged( | |
107 const dbus::ObjectPath& object_path, | |
108 const std::string& property_name) { | |
109 // TODO(mcchou): BUG=441581 | |
110 // Call StateChanged and VolumeChanged accordingly if there is any change on | |
111 // state/volume. | |
112 } | |
113 | |
114 void BluetoothAudioSinkChromeOS::SetConfiguration( | |
115 const dbus::ObjectPath& transport_path, | |
116 const dbus::MessageReader& properties) { | |
117 // TODO(mcchou): BUG=441581 | |
118 // Update |transport_path_| and store properties if needed. | |
119 } | |
120 | |
121 void BluetoothAudioSinkChromeOS::SelectConfiguration( | |
122 const std::vector<uint8_t>& capabilities, | |
123 const SelectConfigurationCallback& callback) { | |
124 // TODO(mcchou): BUG=441581 | |
125 // Use SelectConfigurationCallback to return the agreed capabilities. | |
126 } | |
127 | |
128 void BluetoothAudioSinkChromeOS::ClearConfiguration( | |
129 const dbus::ObjectPath& transport_path) { | |
130 // TODO(mcchou): BUG=441581 | |
131 // Reset the configuration to the default one and close IOBuffer. | |
132 } | |
133 | |
134 void BluetoothAudioSinkChromeOS::Release() { | |
135 // TODO(mcchou): BUG=441581 | |
136 // Let the audio sink does the clean-up and do nothing here. | |
137 } | |
138 | |
139 void Register( | |
Miao
2015/01/21 23:24:45
BluetoothAudioSinkChromeOS::
| |
140 const device::BluetoothAudioSink::Options& options, | |
141 const base::Closure& callback, | |
142 const device::BluetoothAudioSink::ErrorCallback& error_callback) { | |
143 // TODO(mcchou): BUG=441581 | |
144 // Get Media object, initiate an Media Endpoint with options, and return the | |
145 // audio sink via callback. Add the audio sink as observer of both Media and | |
146 // Media Transport. | |
147 } | |
148 | |
149 void Unregister( | |
Miao
2015/01/21 23:24:45
BluetoothAudioSinkChromeOS::
| |
150 const base::Closure& callback, | |
151 const device::BluetoothAudioSink::ErrorCallback& error_callback) { | |
152 // TODO(mcchou): BUG=441581 | |
153 // Clean |observers_| and transport_path_ and reset state_ and volume. | |
154 } | |
155 | |
156 void BluetoothAudioSinkChromeOS::StateChanged( | |
157 device::BluetoothAudioSink::State state) { | |
158 DCHECK_NE(state, state_); | |
159 VLOG(1) << "Bluetooth audio sink state changed: " << state; | |
160 state_ = state; | |
161 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, | |
162 BluetoothAudioSinkStateChanged(this, state_)); | |
163 } | |
164 | |
165 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) { | |
166 DCHECK_NE(volume, volume_); | |
167 VLOG(1) << "Bluetooth audio sink volume changed: " << volume; | |
168 volume_ = volume; | |
169 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, | |
170 BluetoothAudioSinkVolumeChanged(this, volume_)); | |
171 } | |
172 | |
173 void BluetoothAudioSinkChromeOS::ReadFromFD() { | |
174 DCHECK_NE(fd_.value(), -1); | |
175 | |
176 // TODO(mcchou): BUG=441581 | |
177 // Read from file descriptor using watcher and create a buffer to contain the | |
178 // data. Notify |Observers_| while there is audio data available. | |
179 } | |
180 | |
181 } // namespace chromeos | |
OLD | NEW |