Chromium Code Reviews| 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 "base/logging.h" | |
| 8 | |
| 9 namespace chromeos { | |
| 10 | |
| 11 BluetoothAudioSinkChromeOS::BluetoothAudioSinkChromeOS( | |
| 12 BluetoothAdapterChromeOS* adapter) | |
| 13 : state_(device::BluetoothAudioSink::STATE_INVALID), | |
| 14 volume_(0), | |
| 15 adapter_(adapter) { | |
|
Ben Chan
2015/01/20 19:29:08
initialize all POD member variables, e.g. |read_mt
Miao
2015/01/20 22:32:46
Done.
| |
| 16 adapter_->AddObserver(this); | |
| 17 } | |
| 18 | |
| 19 BluetoothAudioSinkChromeOS::~BluetoothAudioSinkChromeOS() { | |
| 20 DCHECK(adapter_); | |
| 21 adapter_->RemoveObserver(this); | |
| 22 } | |
| 23 | |
| 24 void BluetoothAudioSinkChromeOS::AddObserver( | |
| 25 device::BluetoothAudioSink::Observer* observer) { | |
| 26 DCHECK(observer); | |
| 27 observers_.AddObserver(observer); | |
| 28 } | |
| 29 | |
| 30 void BluetoothAudioSinkChromeOS::RemoveObserver( | |
| 31 device::BluetoothAudioSink::Observer* observer) { | |
| 32 DCHECK(observer); | |
| 33 observers_.RemoveObserver(observer); | |
| 34 } | |
| 35 | |
| 36 device::BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const { | |
| 37 return state_; | |
| 38 } | |
| 39 | |
| 40 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const { | |
| 41 return volume_; | |
| 42 } | |
| 43 | |
| 44 void BluetoothAudioSinkChromeOS::AdapterPresentChanged( | |
| 45 device::BluetoothAdapter* adapter, | |
| 46 bool present) { | |
| 47 // TODO(mcchou): BUG=441581 | |
| 48 // If |persent| is true, change state to |STATE_DISCONNECTED| and call | |
| 49 // StateChanged(). Otherwise, change state to |STATE_INVALID| and call | |
| 50 // StateChanged. | |
| 51 } | |
| 52 | |
| 53 void BluetoothAudioSinkChromeOS::AdapterPoweredChanged( | |
| 54 device::BluetoothAdapter* adapter, | |
| 55 bool powered) { | |
| 56 // TODO(mcchou): BUG=441581 | |
| 57 // If |powered| is true, change state to |STATE_DISCONNECTED| and call | |
| 58 // StateChanged(). Otherwise, change state to |STATE_INVALID| and call | |
| 59 // StateChanged. | |
| 60 } | |
| 61 | |
| 62 void BluetoothAudioSinkChromeOS::MediaAdded( | |
| 63 const dbus::ObjectPath& object_path) { | |
| 64 // Do nothing for now. | |
| 65 } | |
| 66 | |
| 67 void BluetoothAudioSinkChromeOS::MediaRemoved( | |
| 68 const dbus::ObjectPath& object_path) { | |
| 69 // TODO(mcchou): BUG=441581 | |
| 70 // Check if |object_path| equals to |media_path_|. If true, change the state | |
| 71 // of the audio sink, call StateChanged and reset the audio sink. | |
| 72 } | |
| 73 | |
| 74 void BluetoothAudioSinkChromeOS::MediaTransportAdded( | |
| 75 const dbus::ObjectPath& object_path) { | |
| 76 // Do nothing for now. | |
| 77 } | |
| 78 | |
| 79 void BluetoothAudioSinkChromeOS::MediaTransportRemoved( | |
| 80 const dbus::ObjectPath& object_path) { | |
| 81 // TODO(mcchou): BUG=441581 | |
| 82 // Check if |object_path| equals to |transport_path_|. If true, change the | |
| 83 // state of the audio sink, call StateChanged and reset the audio sink. | |
| 84 } | |
| 85 | |
| 86 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged( | |
| 87 const dbus::ObjectPath& object_path, | |
| 88 const std::string& property_name) { | |
| 89 // TODO(mcchou): BUG=441581 | |
| 90 // Call StateChanged and VolumeChanged accordingly if there is any change on | |
| 91 // state/volume. | |
| 92 } | |
| 93 | |
| 94 void BluetoothAudioSinkChromeOS::SetConfiguration( | |
| 95 const dbus::ObjectPath& transport_path, | |
| 96 const dbus::MessageReader& properties) { | |
| 97 // TODO(mcchou): BUG=441581 | |
| 98 // Update |transport_path_| and store properties if needed. | |
| 99 } | |
| 100 | |
| 101 void BluetoothAudioSinkChromeOS::SelectConfiguration( | |
| 102 const std::vector<uint8_t>& capabilities, | |
| 103 const SelectConfigurationCallback& callback) { | |
| 104 // TODO(mcchou): BUG=441581 | |
| 105 // Use SelectConfigurationCallback to return the agreed capabilities. | |
| 106 } | |
| 107 | |
| 108 void BluetoothAudioSinkChromeOS::ClearConfiguration( | |
| 109 const dbus::ObjectPath& transport_path) { | |
| 110 // TODO(mcchou): BUG=441581 | |
| 111 // Reset the configuration to the default one and close IOBuffer. | |
| 112 } | |
| 113 | |
| 114 void BluetoothAudioSinkChromeOS::Release() { | |
| 115 // TODO(mcchou): BUG=441581 | |
| 116 // Let the audio sink does the clean-up and do nothing here. | |
| 117 } | |
| 118 | |
| 119 void Register( | |
| 120 const device::BluetoothAudioSink::Options& options, | |
| 121 const base::Closure& callback, | |
| 122 const device::BluetoothAudioSink::ErrorCallback& error_callback) { | |
| 123 // TODO(mcchou): BUG=441581 | |
| 124 // Get Media object, initiate an Media Endpoint with options, and return the | |
| 125 // audio sink via callback. Add the audio sink as observer of both Media and | |
| 126 // Media Transport. | |
| 127 } | |
| 128 | |
| 129 void Unregister( | |
| 130 const base::Closure& callback, | |
| 131 const device::BluetoothAudioSink::ErrorCallback& error_callback) { | |
| 132 // TODO(mcchou): BUG=441581 | |
| 133 // Clean |observers_| and transport_path_ and reset state_ and volume. | |
| 134 } | |
| 135 | |
| 136 void BluetoothAudioSinkChromeOS::StateChanged( | |
| 137 device::BluetoothAudioSink::State state) { | |
| 138 DCHECK_NE(state, state_); | |
| 139 VLOG(1) << "Bluetooth audio sink state changed: " << state; | |
| 140 state_ = state; | |
| 141 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, | |
| 142 BluetoothAudioSinkStateChanged(this, state_)); | |
| 143 } | |
| 144 | |
| 145 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) { | |
| 146 DCHECK_NE(volume, volume_); | |
| 147 VLOG(1) << "Bluetooth audio sink volume changed: " << volume; | |
| 148 volume_ = volume; | |
| 149 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, | |
| 150 BluetoothAudioSinkVolumeChanged(this, volume_)); | |
| 151 } | |
| 152 | |
| 153 void BluetoothAudioSinkChromeOS::OnRegisterSucceeded( | |
| 154 const base::Closure& callback) { | |
| 155 VLOG(1) << "Bluetooth audio sink registerd: " << sequence_number; | |
| 156 | |
| 157 // TODO(mcchou): BUG=441581 | |
| 158 // Change |state_| to STATE_DISCONNECTED and run the callback after Register | |
| 159 // is done successfully. | |
| 160 } | |
| 161 | |
| 162 void BluetoothAudioSinkChromeOS::OnRegisterFailed( | |
| 163 const BluetoothAudioSink::ErrorCallback& error_callback, | |
| 164 const std::string& error_name, | |
| 165 const std::string& error_message) { | |
| 166 DCHECK(media_endpoint_); | |
| 167 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message; | |
| 168 | |
| 169 // TODO(mcchou): BUG=441581 | |
| 170 // Reset |endpoint_path_|, reset |media_endpoint_| and run error_callback with | |
| 171 // ERROR_NOT_REGISTERED. | |
| 172 } | |
| 173 | |
| 174 void BluetoothAudioSinkChromeOS::OnAcquireSucceeded( | |
| 175 const dbus::FileDescriptor& fd, | |
| 176 const uint16_t read_mtu, | |
|
Ben Chan
2015/01/20 19:29:08
'const' isn't necessary for |read_mtu| and |write_
Miao
2015/01/20 22:32:46
Removed.
| |
| 177 const uint16_t write_mtu) { | |
| 178 // TODO(mcchou): BUG=441581 | |
| 179 // Set |fd_|, |read_mtu_| and |write_mtu_| if media transport is acquired | |
|
Ben Chan
2015/01/20 19:29:08
when you later assign |fd| to |fd_|, you should pr
Miao
2015/01/20 22:32:46
Done.
| |
| 180 // successfully. | |
| 181 } | |
| 182 | |
| 183 void BluetoothAudioSinkChromeOS::OnAcquireFailed( | |
| 184 const std::string& error_name, | |
| 185 const std::string& error_message) { | |
| 186 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message; | |
| 187 | |
| 188 // TODO(mcchou): BUG=441581 | |
| 189 // Reset |fd_|, |read_mtu_| and |write_mtu|. | |
| 190 } | |
| 191 | |
| 192 dbus::ObjectPath BluetoothAudioSinkChromeOS::GenerateEndpointPath() { | |
| 193 // TODO(mcchou): BUG=441581 | |
| 194 // Generate an unique object path for the new media endpoint. | |
| 195 } | |
| 196 | |
| 197 void BluetoothAudioSinkChromeOS::ReadFromFD() { | |
| 198 DCHECK_NE(fd_.value(), -1); | |
|
Ben Chan
2015/01/20 19:29:07
Note: If dbus::FileDescriptor defines a kInvalidFD
Miao
2015/01/20 22:32:46
It looks like there is no constant value defined f
| |
| 199 | |
| 200 // TODO(mcchou): BUG=441581 | |
| 201 // Read from file descriptor using watcher and create a buffer to contain the | |
| 202 // data. Notify |Observers_| while there is audio data available. | |
| 203 } | |
| 204 | |
| 205 } // namespace chromeos | |
| OLD | NEW |