| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" | 5 #include "device/bluetooth/bluetooth_audio_sink_chromeos.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/debug/stack_trace.h" | 12 #include "base/debug/stack_trace.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 16 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 16 | 17 |
| 17 using dbus::ObjectPath; | 18 using dbus::ObjectPath; |
| 18 using device::BluetoothAudioSink; | 19 using device::BluetoothAudioSink; |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // TODO(mcchou): Add the constant to dbus/service_constants.h. | 23 // TODO(mcchou): Add the constant to dbus/service_constants.h. |
| 23 const char kBluetoothAudioSinkServicePath[] = "/org/chromium/AudioSink"; | 24 const char kBluetoothAudioSinkServicePath[] = "/org/chromium/AudioSink"; |
| 24 | 25 |
| 25 ObjectPath GenerateEndpointPath() { | 26 ObjectPath GenerateEndpointPath() { |
| 26 static unsigned int sequence_number = 0; | 27 static unsigned int sequence_number = 0; |
| 27 ++sequence_number; | 28 ++sequence_number; |
| 28 std::stringstream path; | 29 std::stringstream path; |
| 29 path << kBluetoothAudioSinkServicePath << "/endpoint" << sequence_number; | 30 path << kBluetoothAudioSinkServicePath << "/endpoint" << sequence_number; |
| 30 return ObjectPath(path.str()); | 31 return ObjectPath(path.str()); |
| 31 } | 32 } |
| 32 | 33 |
| 34 std::string StateToString(const BluetoothAudioSink::State& state) { |
| 35 switch (state) { |
| 36 case BluetoothAudioSink::STATE_INVALID: |
| 37 return "invalid"; |
| 38 case BluetoothAudioSink::STATE_DISCONNECTED: |
| 39 return "disconnected"; |
| 40 case BluetoothAudioSink::STATE_IDLE: |
| 41 return "idle"; |
| 42 case BluetoothAudioSink::STATE_PENDING: |
| 43 return "pending"; |
| 44 case BluetoothAudioSink::STATE_ACTIVE: |
| 45 return "active"; |
| 46 default: |
| 47 return "unknown"; |
| 48 } |
| 49 } |
| 50 |
| 51 std::string ErrorCodeToString(const BluetoothAudioSink::ErrorCode& error_code) { |
| 52 switch (error_code) { |
| 53 case BluetoothAudioSink::ERROR_UNSUPPORTED_PLATFORM: |
| 54 return "unsupported platform"; |
| 55 case BluetoothAudioSink::ERROR_INVALID_ADAPTER: |
| 56 return "invalid adapter"; |
| 57 case BluetoothAudioSink::ERROR_NOT_REGISTERED: |
| 58 return "not registered"; |
| 59 case BluetoothAudioSink::ERROR_NOT_UNREGISTERED: |
| 60 return "not unregistered"; |
| 61 default: |
| 62 return "unknown"; |
| 63 } |
| 64 } |
| 65 |
| 33 // A dummy error callback for calling Unregister() in destructor. | 66 // A dummy error callback for calling Unregister() in destructor. |
| 34 void UnregisterErrorCallback( | 67 void UnregisterErrorCallback( |
| 35 device::BluetoothAudioSink::ErrorCode error_code) { | 68 device::BluetoothAudioSink::ErrorCode error_code) { |
| 36 VLOG(1) << "Bluetooth audio sink: Error code: " << error_code; | 69 VLOG(1) << "UnregisterErrorCallback - " << ErrorCodeToString(error_code) |
| 70 << "(" << error_code << ")"; |
| 37 } | 71 } |
| 38 | 72 |
| 39 } // namespace | 73 } // namespace |
| 40 | 74 |
| 41 namespace chromeos { | 75 namespace chromeos { |
| 42 | 76 |
| 43 BluetoothAudioSinkChromeOS::BluetoothAudioSinkChromeOS( | 77 BluetoothAudioSinkChromeOS::BluetoothAudioSinkChromeOS( |
| 44 scoped_refptr<device::BluetoothAdapter> adapter) | 78 scoped_refptr<device::BluetoothAdapter> adapter) |
| 45 : state_(BluetoothAudioSink::STATE_INVALID), | 79 : state_(BluetoothAudioSink::STATE_INVALID), |
| 46 volume_(BluetoothAudioSink::kInvalidVolume), | 80 volume_(BluetoothAudioSink::kInvalidVolume), |
| 47 read_mtu_(nullptr), | 81 read_mtu_(nullptr), |
| 48 write_mtu_(nullptr), | 82 write_mtu_(nullptr), |
| 49 adapter_(adapter), | 83 adapter_(adapter), |
| 50 weak_ptr_factory_(this) { | 84 weak_ptr_factory_(this) { |
| 85 VLOG(1) << "BluetoothAudioSinkChromeOS created"; |
| 86 |
| 51 DCHECK(adapter_.get()); | 87 DCHECK(adapter_.get()); |
| 52 DCHECK(adapter_->IsPresent()); | 88 DCHECK(adapter_->IsPresent()); |
| 53 | 89 |
| 54 adapter_->AddObserver(this); | 90 adapter_->AddObserver(this); |
| 55 | 91 |
| 56 chromeos::BluetoothMediaClient* media = | 92 chromeos::BluetoothMediaClient* media = |
| 57 DBusThreadManager::Get()->GetBluetoothMediaClient(); | 93 DBusThreadManager::Get()->GetBluetoothMediaClient(); |
| 58 DCHECK(media); | 94 DCHECK(media); |
| 59 media->AddObserver(this); | 95 media->AddObserver(this); |
| 60 | 96 |
| 61 chromeos::BluetoothMediaTransportClient *transport = | 97 chromeos::BluetoothMediaTransportClient *transport = |
| 62 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient(); | 98 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient(); |
| 63 DCHECK(transport); | 99 DCHECK(transport); |
| 64 transport->AddObserver(this); | 100 transport->AddObserver(this); |
| 65 | 101 |
| 66 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); | 102 StateChanged(device::BluetoothAudioSink::STATE_DISCONNECTED); |
| 67 } | 103 } |
| 68 | 104 |
| 69 BluetoothAudioSinkChromeOS::~BluetoothAudioSinkChromeOS() { | 105 BluetoothAudioSinkChromeOS::~BluetoothAudioSinkChromeOS() { |
| 106 VLOG(1) << "BluetoothAudioSinkChromeOS destroyed"; |
| 107 |
| 70 DCHECK(adapter_.get()); | 108 DCHECK(adapter_.get()); |
| 71 | 109 |
| 72 if (state_ != BluetoothAudioSink::STATE_INVALID && media_endpoint_.get()) { | 110 if (state_ != BluetoothAudioSink::STATE_INVALID && media_endpoint_.get()) { |
| 73 Unregister(base::Bind(&base::DoNothing), | 111 Unregister(base::Bind(&base::DoNothing), |
| 74 base::Bind(&UnregisterErrorCallback)); | 112 base::Bind(&UnregisterErrorCallback)); |
| 75 } | 113 } |
| 76 | 114 |
| 77 adapter_->RemoveObserver(this); | 115 adapter_->RemoveObserver(this); |
| 78 | 116 |
| 79 chromeos::BluetoothMediaClient* media = | 117 chromeos::BluetoothMediaClient* media = |
| 80 DBusThreadManager::Get()->GetBluetoothMediaClient(); | 118 DBusThreadManager::Get()->GetBluetoothMediaClient(); |
| 81 DCHECK(media); | 119 DCHECK(media); |
| 82 media->RemoveObserver(this); | 120 media->RemoveObserver(this); |
| 83 | 121 |
| 84 chromeos::BluetoothMediaTransportClient *transport = | 122 chromeos::BluetoothMediaTransportClient *transport = |
| 85 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient(); | 123 chromeos::DBusThreadManager::Get()->GetBluetoothMediaTransportClient(); |
| 86 DCHECK(transport); | 124 DCHECK(transport); |
| 87 transport->RemoveObserver(this); | 125 transport->RemoveObserver(this); |
| 88 } | 126 } |
| 89 | 127 |
| 90 void BluetoothAudioSinkChromeOS::Unregister( | 128 void BluetoothAudioSinkChromeOS::Unregister( |
| 91 const base::Closure& callback, | 129 const base::Closure& callback, |
| 92 const device::BluetoothAudioSink::ErrorCallback& error_callback) { | 130 const device::BluetoothAudioSink::ErrorCallback& error_callback) { |
| 131 VLOG(1) << "Unregister"; |
| 132 |
| 93 if (!DBusThreadManager::IsInitialized()) | 133 if (!DBusThreadManager::IsInitialized()) |
| 94 error_callback.Run(BluetoothAudioSink::ERROR_NOT_UNREGISTERED); | 134 error_callback.Run(BluetoothAudioSink::ERROR_NOT_UNREGISTERED); |
| 95 | 135 |
| 96 chromeos::BluetoothMediaClient* media = | 136 chromeos::BluetoothMediaClient* media = |
| 97 DBusThreadManager::Get()->GetBluetoothMediaClient(); | 137 DBusThreadManager::Get()->GetBluetoothMediaClient(); |
| 98 DCHECK(media); | 138 DCHECK(media); |
| 99 | 139 |
| 100 media->UnregisterEndpoint( | 140 media->UnregisterEndpoint( |
| 101 media_path_, | 141 media_path_, |
| 102 endpoint_path_, | 142 endpoint_path_, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const { | 161 BluetoothAudioSink::State BluetoothAudioSinkChromeOS::GetState() const { |
| 122 return state_; | 162 return state_; |
| 123 } | 163 } |
| 124 | 164 |
| 125 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const { | 165 uint16_t BluetoothAudioSinkChromeOS::GetVolume() const { |
| 126 return volume_; | 166 return volume_; |
| 127 } | 167 } |
| 128 | 168 |
| 129 void BluetoothAudioSinkChromeOS::AdapterPresentChanged( | 169 void BluetoothAudioSinkChromeOS::AdapterPresentChanged( |
| 130 device::BluetoothAdapter* adapter, bool present) { | 170 device::BluetoothAdapter* adapter, bool present) { |
| 131 VLOG(1) << "Bluetooth audio sink: Bluetooth adapter present changed: " | 171 VLOG(1) << "AdapterPresentChanged: " << present; |
| 132 << present; | |
| 133 | 172 |
| 134 if (adapter->IsPresent()) { | 173 if (adapter->IsPresent()) { |
| 135 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); | 174 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); |
| 136 } else { | 175 } else { |
| 137 adapter_->RemoveObserver(this); | 176 adapter_->RemoveObserver(this); |
| 138 StateChanged(BluetoothAudioSink::STATE_INVALID); | 177 StateChanged(BluetoothAudioSink::STATE_INVALID); |
| 139 } | 178 } |
| 140 } | 179 } |
| 141 | 180 |
| 142 void BluetoothAudioSinkChromeOS::AdapterPoweredChanged( | 181 void BluetoothAudioSinkChromeOS::AdapterPoweredChanged( |
| 143 device::BluetoothAdapter* adapter, bool powered) { | 182 device::BluetoothAdapter* adapter, bool powered) { |
| 144 VLOG(1) << "Bluetooth audio sink: Bluetooth adapter powered changed: " | 183 VLOG(1) << "AdapterPoweredChanged: " << powered; |
| 145 << powered; | |
| 146 | 184 |
| 147 // Regardless of the new powered state, |state_| goes to STATE_DISCONNECTED. | 185 // Regardless of the new powered state, |state_| goes to STATE_DISCONNECTED. |
| 148 // If false, the transport is closed, but the endpoint is still valid for use. | 186 // If false, the transport is closed, but the endpoint is still valid for use. |
| 149 // If true, the previous transport has been torn down, so the |state_| has to | 187 // If true, the previous transport has been torn down, so the |state_| has to |
| 150 // be disconnected before SetConfigruation is called. | 188 // be disconnected before SetConfigruation is called. |
| 151 if (state_ != BluetoothAudioSink::STATE_INVALID) | 189 if (state_ != BluetoothAudioSink::STATE_INVALID) |
| 152 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); | 190 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); |
| 153 } | 191 } |
| 154 | 192 |
| 155 void BluetoothAudioSinkChromeOS::MediaRemoved(const ObjectPath& object_path) { | 193 void BluetoothAudioSinkChromeOS::MediaRemoved(const ObjectPath& object_path) { |
| 156 if (object_path == media_path_) { | 194 if (object_path == media_path_) { |
| 195 VLOG(1) << "MediaRemoved: " << object_path.value(); |
| 157 StateChanged(BluetoothAudioSink::STATE_INVALID); | 196 StateChanged(BluetoothAudioSink::STATE_INVALID); |
| 158 } | 197 } |
| 159 } | 198 } |
| 160 | 199 |
| 161 void BluetoothAudioSinkChromeOS::MediaTransportRemoved( | 200 void BluetoothAudioSinkChromeOS::MediaTransportRemoved( |
| 162 const ObjectPath& object_path) { | 201 const ObjectPath& object_path) { |
| 163 // Whenever powered of |adapter_| turns false while present stays true, media | 202 // Whenever powered of |adapter_| turns false while present stays true, media |
| 164 // transport object should be removed accordingly, and the state should be | 203 // transport object should be removed accordingly, and the state should be |
| 165 // changed to STATE_DISCONNECTED. | 204 // changed to STATE_DISCONNECTED. |
| 166 if (object_path == transport_path_) { | 205 if (object_path == transport_path_) { |
| 206 VLOG(1) << "MediaTransportRemoved: " << object_path.value(); |
| 167 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); | 207 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); |
| 168 } | 208 } |
| 169 } | 209 } |
| 170 | 210 |
| 171 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged( | 211 void BluetoothAudioSinkChromeOS::MediaTransportPropertyChanged( |
| 172 const ObjectPath& object_path, | 212 const ObjectPath& object_path, |
| 173 const std::string& property_name) { | 213 const std::string& property_name) { |
| 174 if (object_path != transport_path_) | 214 if (object_path != transport_path_) |
| 175 return; | 215 return; |
| 176 | 216 |
| 217 VLOG(1) << "MediaTransportPropertyChanged: " << property_name; |
| 218 |
| 177 // Retrieves the property set of the transport object with |object_path|. | 219 // Retrieves the property set of the transport object with |object_path|. |
| 178 chromeos::BluetoothMediaTransportClient::Properties* properties = | 220 chromeos::BluetoothMediaTransportClient::Properties* properties = |
| 179 DBusThreadManager::Get() | 221 DBusThreadManager::Get() |
| 180 ->GetBluetoothMediaTransportClient() | 222 ->GetBluetoothMediaTransportClient() |
| 181 ->GetProperties(object_path); | 223 ->GetProperties(object_path); |
| 182 | 224 |
| 183 // Dispatches a property changed event to the corresponding handler. | 225 // Dispatches a property changed event to the corresponding handler. |
| 184 if (property_name == properties->state.name()) { | 226 if (property_name == properties->state.name()) { |
| 185 if (properties->state.value() == | 227 if (properties->state.value() == |
| 186 BluetoothMediaTransportClient::kStateIdle) { | 228 BluetoothMediaTransportClient::kStateIdle) { |
| 187 StateChanged(BluetoothAudioSink::STATE_IDLE); | 229 StateChanged(BluetoothAudioSink::STATE_IDLE); |
| 188 } else if (properties->state.value() == | 230 } else if (properties->state.value() == |
| 189 BluetoothMediaTransportClient::kStatePending) { | 231 BluetoothMediaTransportClient::kStatePending) { |
| 190 StateChanged(BluetoothAudioSink::STATE_PENDING); | 232 StateChanged(BluetoothAudioSink::STATE_PENDING); |
| 191 } else if (properties->state.value() == | 233 } else if (properties->state.value() == |
| 192 BluetoothMediaTransportClient::kStateActive) { | 234 BluetoothMediaTransportClient::kStateActive) { |
| 193 StateChanged(BluetoothAudioSink::STATE_ACTIVE); | 235 StateChanged(BluetoothAudioSink::STATE_ACTIVE); |
| 194 } | 236 } |
| 195 } else if (property_name == properties->volume.name()) { | 237 } else if (property_name == properties->volume.name()) { |
| 196 VolumeChanged(properties->volume.value()); | 238 VolumeChanged(properties->volume.value()); |
| 197 } else { | |
| 198 VLOG(1) << "Bluetooth audio sink: transport property " << property_name | |
| 199 << " changed"; | |
| 200 } | 239 } |
| 201 } | 240 } |
| 202 | 241 |
| 203 void BluetoothAudioSinkChromeOS::SetConfiguration( | 242 void BluetoothAudioSinkChromeOS::SetConfiguration( |
| 204 const ObjectPath& transport_path, | 243 const ObjectPath& transport_path, |
| 205 const TransportProperties& properties) { | 244 const TransportProperties& properties) { |
| 206 VLOG(1) << "Bluetooth audio sink: SetConfiguration called"; | 245 VLOG(1) << "SetConfiguration"; |
| 207 transport_path_ = transport_path; | 246 transport_path_ = transport_path; |
| 208 | 247 |
| 209 // The initial state for a connection should be "idle". | 248 // The initial state for a connection should be "idle". |
| 210 if (properties.state != BluetoothMediaTransportClient::kStateIdle) { | 249 if (properties.state != BluetoothMediaTransportClient::kStateIdle) { |
| 211 VLOG(1) << "Bluetooth Audio Sink: unexpected state " << properties.state; | 250 VLOG(1) << "SetConfiugration - unexpected state :" << properties.state; |
| 212 return; | 251 return; |
| 213 } | 252 } |
| 214 | 253 |
| 215 // Updates |volume_| if the volume level is provided in |properties|. | 254 // Updates |volume_| if the volume level is provided in |properties|. |
| 216 if (properties.volume.get()) { | 255 if (properties.volume.get()) { |
| 217 VolumeChanged(*properties.volume); | 256 VolumeChanged(*properties.volume); |
| 218 } | 257 } |
| 219 | 258 |
| 220 StateChanged(BluetoothAudioSink::STATE_IDLE); | 259 StateChanged(BluetoothAudioSink::STATE_IDLE); |
| 221 } | 260 } |
| 222 | 261 |
| 223 void BluetoothAudioSinkChromeOS::SelectConfiguration( | 262 void BluetoothAudioSinkChromeOS::SelectConfiguration( |
| 224 const std::vector<uint8_t>& capabilities, | 263 const std::vector<uint8_t>& capabilities, |
| 225 const SelectConfigurationCallback& callback) { | 264 const SelectConfigurationCallback& callback) { |
| 226 VLOG(1) << "Bluetooth audio sink: SelectConfiguration called"; | 265 VLOG(1) << "SelectConfiguration"; |
| 227 callback.Run(options_.capabilities); | 266 callback.Run(options_.capabilities); |
| 228 } | 267 } |
| 229 | 268 |
| 230 void BluetoothAudioSinkChromeOS::ClearConfiguration( | 269 void BluetoothAudioSinkChromeOS::ClearConfiguration( |
| 231 const ObjectPath& transport_path) { | 270 const ObjectPath& transport_path) { |
| 232 if (transport_path != transport_path_) | 271 if (transport_path != transport_path_) |
| 233 return; | 272 return; |
| 234 VLOG(1) << "Bluetooth audio sink: ClearConfiguration called"; | 273 VLOG(1) << "ClearConfiguration"; |
| 235 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); | 274 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); |
| 236 } | 275 } |
| 237 | 276 |
| 238 void BluetoothAudioSinkChromeOS::Released() { | 277 void BluetoothAudioSinkChromeOS::Released() { |
| 239 VLOG(1) << "Bluetooth audio sink: Released called"; | 278 VLOG(1) << "Released"; |
| 240 StateChanged(BluetoothAudioSink::STATE_INVALID); | 279 StateChanged(BluetoothAudioSink::STATE_INVALID); |
| 241 } | 280 } |
| 242 | 281 |
| 243 void BluetoothAudioSinkChromeOS::Register( | 282 void BluetoothAudioSinkChromeOS::Register( |
| 244 const BluetoothAudioSink::Options& options, | 283 const BluetoothAudioSink::Options& options, |
| 245 const base::Closure& callback, | 284 const base::Closure& callback, |
| 246 const BluetoothAudioSink::ErrorCallback& error_callback) { | 285 const BluetoothAudioSink::ErrorCallback& error_callback) { |
| 286 VLOG(1) << "Register"; |
| 287 |
| 247 DCHECK(adapter_.get()); | 288 DCHECK(adapter_.get()); |
| 248 DCHECK_EQ(state_, BluetoothAudioSink::STATE_DISCONNECTED); | 289 DCHECK_EQ(state_, BluetoothAudioSink::STATE_DISCONNECTED); |
| 249 | 290 |
| 250 // Gets system bus. | 291 // Gets system bus. |
| 251 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); | 292 dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus(); |
| 252 | 293 |
| 253 // Creates a Media Endpoint with newly-generated path. | 294 // Creates a Media Endpoint with newly-generated path. |
| 254 endpoint_path_ = GenerateEndpointPath(); | 295 endpoint_path_ = GenerateEndpointPath(); |
| 255 media_endpoint_.reset( | 296 media_endpoint_.reset( |
| 256 BluetoothMediaEndpointServiceProvider::Create( | 297 BluetoothMediaEndpointServiceProvider::Create( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 284 BluetoothMediaEndpointServiceProvider* | 325 BluetoothMediaEndpointServiceProvider* |
| 285 BluetoothAudioSinkChromeOS::GetEndpointServiceProvider() { | 326 BluetoothAudioSinkChromeOS::GetEndpointServiceProvider() { |
| 286 return media_endpoint_.get(); | 327 return media_endpoint_.get(); |
| 287 } | 328 } |
| 288 | 329 |
| 289 void BluetoothAudioSinkChromeOS::StateChanged( | 330 void BluetoothAudioSinkChromeOS::StateChanged( |
| 290 BluetoothAudioSink::State state) { | 331 BluetoothAudioSink::State state) { |
| 291 if (state == state_) | 332 if (state == state_) |
| 292 return; | 333 return; |
| 293 | 334 |
| 294 VLOG(1) << "Bluetooth audio sink state changed: " << state; | 335 VLOG(1) << "StateChnaged: " << StateToString(state); |
| 336 |
| 295 switch (state) { | 337 switch (state) { |
| 296 case BluetoothAudioSink::STATE_INVALID: | 338 case BluetoothAudioSink::STATE_INVALID: |
| 297 ResetMedia(); | 339 ResetMedia(); |
| 298 ResetEndpoint(); | 340 ResetEndpoint(); |
| 299 case BluetoothAudioSink::STATE_DISCONNECTED: | 341 case BluetoothAudioSink::STATE_DISCONNECTED: |
| 300 ResetTransport(); | 342 ResetTransport(); |
| 301 break; | 343 break; |
| 302 case BluetoothAudioSink::STATE_IDLE: | 344 case BluetoothAudioSink::STATE_IDLE: |
| 303 // TODO(mcchou): BUG=441581 | 345 // TODO(mcchou): BUG=441581 |
| 304 // Triggered by MediaTransportPropertyChanged and SetConfiguration. | 346 // Triggered by MediaTransportPropertyChanged and SetConfiguration. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 319 | 361 |
| 320 state_ = state; | 362 state_ = state; |
| 321 FOR_EACH_OBSERVER(BluetoothAudioSink::Observer, observers_, | 363 FOR_EACH_OBSERVER(BluetoothAudioSink::Observer, observers_, |
| 322 BluetoothAudioSinkStateChanged(this, state_)); | 364 BluetoothAudioSinkStateChanged(this, state_)); |
| 323 } | 365 } |
| 324 | 366 |
| 325 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) { | 367 void BluetoothAudioSinkChromeOS::VolumeChanged(uint16_t volume) { |
| 326 if (volume == volume_) | 368 if (volume == volume_) |
| 327 return; | 369 return; |
| 328 | 370 |
| 329 VLOG(1) << "Bluetooth audio sink volume changed: " << volume; | 371 VLOG(1) << "VolumeChanged: " << volume; |
| 372 |
| 330 volume_ = std::min(volume, BluetoothAudioSink::kInvalidVolume); | 373 volume_ = std::min(volume, BluetoothAudioSink::kInvalidVolume); |
| 331 | |
| 332 FOR_EACH_OBSERVER(BluetoothAudioSink::Observer, observers_, | 374 FOR_EACH_OBSERVER(BluetoothAudioSink::Observer, observers_, |
| 333 BluetoothAudioSinkVolumeChanged(this, volume_)); | 375 BluetoothAudioSinkVolumeChanged(this, volume_)); |
| 334 } | 376 } |
| 335 | 377 |
| 336 void BluetoothAudioSinkChromeOS::OnRegisterSucceeded( | 378 void BluetoothAudioSinkChromeOS::OnRegisterSucceeded( |
| 337 const base::Closure& callback) { | 379 const base::Closure& callback) { |
| 338 DCHECK(media_endpoint_.get()); | 380 DCHECK(media_endpoint_.get()); |
| 339 VLOG(1) << "Bluetooth audio sink registerd"; | 381 VLOG(1) << "OnRegisterSucceeded"; |
| 340 | 382 |
| 341 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); | 383 StateChanged(BluetoothAudioSink::STATE_DISCONNECTED); |
| 342 callback.Run(); | 384 callback.Run(); |
| 343 } | 385 } |
| 344 | 386 |
| 345 void BluetoothAudioSinkChromeOS::OnRegisterFailed( | 387 void BluetoothAudioSinkChromeOS::OnRegisterFailed( |
| 346 const BluetoothAudioSink::ErrorCallback& error_callback, | 388 const BluetoothAudioSink::ErrorCallback& error_callback, |
| 347 const std::string& error_name, | 389 const std::string& error_name, |
| 348 const std::string& error_message) { | 390 const std::string& error_message) { |
| 349 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message; | 391 VLOG(1) << "OnRegisterFailed - error name: " << error_name |
| 392 << ", error message: " << error_message; |
| 350 | 393 |
| 351 ResetEndpoint(); | 394 ResetEndpoint(); |
| 352 error_callback.Run(BluetoothAudioSink::ERROR_NOT_REGISTERED); | 395 error_callback.Run(BluetoothAudioSink::ERROR_NOT_REGISTERED); |
| 353 } | 396 } |
| 354 | 397 |
| 355 void BluetoothAudioSinkChromeOS::OnUnregisterSucceeded( | 398 void BluetoothAudioSinkChromeOS::OnUnregisterSucceeded( |
| 356 const base::Closure& callback) { | 399 const base::Closure& callback) { |
| 357 VLOG(1) << "Bluetooth audio sink unregisterd"; | 400 VLOG(1) << "Unregisterd"; |
| 358 | 401 |
| 359 // Once the state becomes STATE_INVALID, media, media transport and media | 402 // Once the state becomes STATE_INVALID, media, media transport and media |
| 360 // endpoint will be reset. | 403 // endpoint will be reset. |
| 361 StateChanged(BluetoothAudioSink::STATE_INVALID); | 404 StateChanged(BluetoothAudioSink::STATE_INVALID); |
| 362 callback.Run(); | 405 callback.Run(); |
| 363 } | 406 } |
| 364 | 407 |
| 365 void BluetoothAudioSinkChromeOS::OnUnregisterFailed( | 408 void BluetoothAudioSinkChromeOS::OnUnregisterFailed( |
| 366 const device::BluetoothAudioSink::ErrorCallback& error_callback, | 409 const device::BluetoothAudioSink::ErrorCallback& error_callback, |
| 367 const std::string& error_name, | 410 const std::string& error_name, |
| 368 const std::string& error_message) { | 411 const std::string& error_message) { |
| 369 VLOG(1) << "Bluetooth audio sink: " << error_name << ": " << error_message; | 412 VLOG(1) << "OnUnregisterFailed - error name: " << error_name |
| 413 << ", error message: " << error_message; |
| 414 |
| 370 error_callback.Run(BluetoothAudioSink::ERROR_NOT_UNREGISTERED); | 415 error_callback.Run(BluetoothAudioSink::ERROR_NOT_UNREGISTERED); |
| 371 } | 416 } |
| 372 | 417 |
| 373 void BluetoothAudioSinkChromeOS::ReadFromFD() { | 418 void BluetoothAudioSinkChromeOS::ReadFromFD() { |
| 374 DCHECK_GE(fd_.value(), 0); | 419 DCHECK_GE(fd_.value(), 0); |
| 375 | 420 |
| 376 // TODO(mcchou): BUG=441581 | 421 // TODO(mcchou): BUG=441581 |
| 377 // Read from file descriptor using watcher and create a buffer to contain the | 422 // Read from file descriptor using watcher and create a buffer to contain the |
| 378 // data. Notify |Observers_| while there is audio data available. | 423 // data. Notify |Observers_| while there is audio data available. |
| 379 } | 424 } |
| 380 | 425 |
| 381 void BluetoothAudioSinkChromeOS::ResetMedia() { | 426 void BluetoothAudioSinkChromeOS::ResetMedia() { |
| 427 VLOG(1) << "ResetMedia"; |
| 428 |
| 382 media_path_ = dbus::ObjectPath(""); | 429 media_path_ = dbus::ObjectPath(""); |
| 383 } | 430 } |
| 384 | 431 |
| 385 void BluetoothAudioSinkChromeOS::ResetTransport() { | 432 void BluetoothAudioSinkChromeOS::ResetTransport() { |
| 433 VLOG(1) << "ResetTransport"; |
| 434 |
| 386 if (transport_path_.value() == "") | 435 if (transport_path_.value() == "") |
| 387 return; | 436 return; |
| 388 transport_path_ = dbus::ObjectPath(""); | 437 transport_path_ = dbus::ObjectPath(""); |
| 389 VolumeChanged(BluetoothAudioSink::kInvalidVolume); | 438 VolumeChanged(BluetoothAudioSink::kInvalidVolume); |
| 390 read_mtu_ = 0; | 439 read_mtu_ = 0; |
| 391 write_mtu_ = 0; | 440 write_mtu_ = 0; |
| 392 fd_.PutValue(-1); | 441 fd_.PutValue(-1); |
| 393 } | 442 } |
| 394 | 443 |
| 395 void BluetoothAudioSinkChromeOS::ResetEndpoint() { | 444 void BluetoothAudioSinkChromeOS::ResetEndpoint() { |
| 445 VLOG(1) << "ResetEndpoint"; |
| 446 |
| 396 endpoint_path_ = ObjectPath(""); | 447 endpoint_path_ = ObjectPath(""); |
| 397 media_endpoint_ = nullptr; | 448 media_endpoint_ = nullptr; |
| 398 } | 449 } |
| 399 | 450 |
| 400 } // namespace chromeos | 451 } // namespace chromeos |
| OLD | NEW |