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::MediaRemoved( |
| 76 const dbus::ObjectPath& object_path) { |
| 77 // TODO(mcchou): BUG=441581 |
| 78 // Check if |object_path| equals to |media_path_|. If true, change the state |
| 79 // of the audio sink, call StateChanged and reset the audio sink. |
| 80 } |
| 81 |
| 82 void BluetoothAudioSinkChromeOS::MediaTransportRemoved( |
| 83 const dbus::ObjectPath& object_path) { |
| 84 // TODO(mcchou): BUG=441581 |
| 85 // Check if |object_path| equals to |transport_path_|. If true, change the |
| 86 // state of the audio sink, call StateChanged and reset the audio sink. |
| 87 } |
| 88 |
| 89 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged( |
| 90 const dbus::ObjectPath& object_path, |
| 91 const std::string& property_name) { |
| 92 // TODO(mcchou): BUG=441581 |
| 93 // Call StateChanged and VolumeChanged accordingly if there is any change on |
| 94 // state/volume. |
| 95 } |
| 96 |
| 97 void BluetoothAudioSinkChromeOS::SetConfiguration( |
| 98 const dbus::ObjectPath& transport_path, |
| 99 const dbus::MessageReader& properties) { |
| 100 // TODO(mcchou): BUG=441581 |
| 101 // Update |transport_path_| and store properties if needed. |
| 102 } |
| 103 |
| 104 void BluetoothAudioSinkChromeOS::SelectConfiguration( |
| 105 const std::vector<uint8_t>& capabilities, |
| 106 const SelectConfigurationCallback& callback) { |
| 107 // TODO(mcchou): BUG=441581 |
| 108 // Use SelectConfigurationCallback to return the agreed capabilities. |
| 109 } |
| 110 |
| 111 void BluetoothAudioSinkChromeOS::ClearConfiguration( |
| 112 const dbus::ObjectPath& transport_path) { |
| 113 // TODO(mcchou): BUG=441581 |
| 114 // Reset the configuration to the default one and close IOBuffer. |
| 115 } |
| 116 |
| 117 void BluetoothAudioSinkChromeOS::Release() { |
| 118 // TODO(mcchou): BUG=441581 |
| 119 // Let the audio sink does the clean-up and do nothing here. |
| 120 } |
| 121 |
| 122 void BluetoothAudioSinkChromeOS::Register( |
| 123 const device::BluetoothAudioSink::Options& options, |
| 124 const base::Closure& callback, |
| 125 const device::BluetoothAudioSink::ErrorCallback& error_callback) { |
| 126 // TODO(mcchou): BUG=441581 |
| 127 // Get Media object, initiate an Media Endpoint with options, and return the |
| 128 // audio sink via callback. Add the audio sink as observer of both Media and |
| 129 // Media Transport. |
| 130 } |
| 131 |
| 132 void BluetoothAudioSinkChromeOS::Unregister( |
| 133 const base::Closure& callback, |
| 134 const device::BluetoothAudioSink::ErrorCallback& error_callback) { |
| 135 // TODO(mcchou): BUG=441581 |
| 136 // Clean |observers_| and |transport_path_| and reset |state_| and |volume_|. |
| 137 } |
| 138 |
| 139 void BluetoothAudioSinkChromeOS::StateChanged( |
| 140 device::BluetoothAudioSink::State state) { |
| 141 DCHECK_NE(state, state_); |
| 142 VLOG(1) << "Bluetooth audio sink state changed: " << state; |
| 143 state_ = state; |
| 144 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, |
| 145 BluetoothAudioSinkStateChanged(this, state_)); |
| 146 } |
| 147 |
| 148 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) { |
| 149 DCHECK_NE(volume, volume_); |
| 150 VLOG(1) << "Bluetooth audio sink volume changed: " << volume; |
| 151 volume_ = volume; |
| 152 FOR_EACH_OBSERVER(device::BluetoothAudioSink::Observer, observers_, |
| 153 BluetoothAudioSinkVolumeChanged(this, volume_)); |
| 154 } |
| 155 |
| 156 void BluetoothAudioSinkChromeOS::ReadFromFD() { |
| 157 DCHECK_GE(fd_.value(), 0); |
| 158 |
| 159 // TODO(mcchou): BUG=441581 |
| 160 // Read from file descriptor using watcher and create a buffer to contain the |
| 161 // data. Notify |Observers_| while there is audio data available. |
| 162 } |
| 163 |
| 164 } // namespace chromeos |
OLD | NEW |