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