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