Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 13 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 14 #include "content/browser/renderer_host/media/media_stream_device_settings.h" | 14 #include "content/browser/renderer_host/media/media_stream_device_settings.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_requester.h" | 15 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_manager.h" | 16 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 17 #include "content/common/media/media_stream_options.h" | 17 #include "content/common/media/media_stream_options.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 20 #include "content/public/browser/media_observer.h" | 20 #include "content/public/browser/media_observer.h" |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "base/win/scoped_com_initializer.h" | 24 #include "base/win/scoped_com_initializer.h" |
| 25 #endif | 25 #endif |
| 26 | 26 |
| 27 using content::BrowserThread; | 27 using content::BrowserThread; |
| 28 using content::MediaStreamRequest; | |
| 29 | |
| 30 namespace { | |
| 31 const char kExtensionScheme[] = "chrome-extension"; | |
| 32 } // namespace | |
| 28 | 33 |
| 29 namespace media_stream { | 34 namespace media_stream { |
| 30 | 35 |
| 31 // Creates a random label used to identify requests. | 36 // Creates a random label used to identify requests. |
| 32 static std::string RandomLabel() { | 37 static std::string RandomLabel() { |
| 33 // An earlier PeerConnection spec, | 38 // An earlier PeerConnection spec, |
| 34 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the | 39 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the |
| 35 // MediaStream::label alphabet as containing 36 characters from | 40 // MediaStream::label alphabet as containing 36 characters from |
| 36 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, | 41 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, |
| 37 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. | 42 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 66 com_initializer_.reset(new base::win::ScopedCOMInitializer( | 71 com_initializer_.reset(new base::win::ScopedCOMInitializer( |
| 67 base::win::ScopedCOMInitializer::kMTA)); | 72 base::win::ScopedCOMInitializer::kMTA)); |
| 68 } | 73 } |
| 69 | 74 |
| 70 void DeviceThread::CleanUp() { | 75 void DeviceThread::CleanUp() { |
| 71 com_initializer_.reset(); | 76 com_initializer_.reset(); |
| 72 } | 77 } |
| 73 #endif | 78 #endif |
| 74 | 79 |
| 75 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | 80 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. |
| 76 struct MediaStreamManager::DeviceRequest { | 81 class MediaStreamManager::DeviceRequest { |
| 77 enum RequestState { | 82 public: |
| 78 STATE_NOT_REQUESTED = 0, | |
| 79 STATE_REQUESTED, | |
| 80 STATE_PENDING_APPROVAL, | |
| 81 STATE_OPENING, | |
| 82 STATE_DONE, | |
| 83 STATE_ERROR | |
| 84 }; | |
| 85 | |
| 86 enum RequestType { | 83 enum RequestType { |
| 87 GENERATE_STREAM = 0, | 84 GENERATE_STREAM = 0, |
| 88 ENUMERATE_DEVICES, | 85 ENUMERATE_DEVICES, |
| 89 OPEN_DEVICE | 86 OPEN_DEVICE |
| 90 }; | 87 }; |
| 91 | 88 |
| 92 DeviceRequest() | 89 DeviceRequest() |
| 93 : requester(NULL), | 90 : requester(NULL), |
| 94 state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED), | |
| 95 type(GENERATE_STREAM), | 91 type(GENERATE_STREAM), |
| 96 render_process_id(-1), | 92 render_process_id(-1), |
| 97 render_view_id(-1) { | 93 render_view_id(-1), |
| 94 state_(content::NUM_MEDIA_TYPES, | |
| 95 MediaStreamRequest::STATE_NOT_REQUESTED) { | |
| 98 } | 96 } |
| 99 | 97 |
| 100 DeviceRequest(MediaStreamRequester* requester, | 98 DeviceRequest(MediaStreamRequester* requester, |
| 101 const StreamOptions& request_options, | 99 const StreamOptions& request_options, |
| 102 int render_process_id, | 100 int render_process_id, |
| 103 int render_view_id, | 101 int render_view_id, |
| 104 const GURL& request_security_origin) | 102 const GURL& request_security_origin) |
| 105 : requester(requester), | 103 : requester(requester), |
| 106 options(request_options), | 104 options(request_options), |
| 107 state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED), | |
| 108 type(GENERATE_STREAM), | 105 type(GENERATE_STREAM), |
| 109 render_process_id(render_process_id), | 106 render_process_id(render_process_id), |
| 110 render_view_id(render_view_id), | 107 render_view_id(render_view_id), |
| 111 security_origin(request_security_origin) { | 108 security_origin(request_security_origin), |
| 109 state_(content::NUM_MEDIA_TYPES, | |
| 110 MediaStreamRequest::STATE_NOT_REQUESTED) { | |
| 112 DCHECK(requester); | 111 DCHECK(requester); |
| 113 } | 112 } |
| 114 | 113 |
| 115 ~DeviceRequest() {} | 114 ~DeviceRequest() {} |
| 116 | 115 |
| 117 MediaStreamRequester* requester; | 116 MediaStreamRequester* requester; |
| 118 StreamOptions options; | 117 StreamOptions options; |
| 119 std::vector<RequestState> state; | |
| 120 RequestType type; | 118 RequestType type; |
| 121 int render_process_id; | 119 int render_process_id; |
| 122 int render_view_id; | 120 int render_view_id; |
| 123 GURL security_origin; | 121 GURL security_origin; |
| 124 std::string requested_device_id; | 122 std::string requested_device_id; |
| 125 StreamDeviceInfoArray devices; | 123 StreamDeviceInfoArray devices; |
| 124 | |
| 125 void setState(MediaStreamType stream_type, | |
| 126 MediaStreamRequest::RequestState new_state) { | |
| 127 state_[stream_type] = new_state; | |
| 128 } | |
| 129 | |
| 130 MediaStreamRequest::RequestState getState(MediaStreamType stream_type) const { | |
| 131 return state_[stream_type]; | |
| 132 } | |
| 133 | |
| 134 private: | |
| 135 std::vector<MediaStreamRequest::RequestState> state_; | |
| 126 }; | 136 }; |
| 127 | 137 |
| 138 // Helper to update the request state and notify observers. | |
| 139 static void UpdateRequestState( | |
| 140 MediaStreamManager::DeviceRequest* request, | |
| 141 MediaStreamType stream_type, | |
| 142 const MediaStreamRequest::RequestState new_state) { | |
| 143 request->setState(stream_type, new_state); | |
| 144 | |
| 145 content::MediaObserver* media_observer = | |
| 146 content::GetContentClient()->browser()->GetMediaObserver(); | |
| 147 if (media_observer == NULL || | |
| 148 (request->options.video_type != content::MEDIA_TAB_VIDEO_CAPTURE && | |
|
no longer working on chromium
2012/10/12 14:00:59
What happen if either audio_type or video_type ==
justinlin
2012/10/12 20:04:20
Not both is OK. It checks (if (!tabVideo && !tabAu
| |
| 149 request->options.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE)) | |
| 150 return; | |
| 151 media_observer->OnMediaRequestStateChanged( | |
| 152 request->render_process_id, | |
| 153 request->render_view_id, | |
| 154 content::MediaStreamDevice(stream_type, | |
| 155 request->requested_device_id, | |
| 156 request->requested_device_id), | |
| 157 new_state); | |
| 158 } | |
| 159 | |
| 128 MediaStreamManager::EnumerationCache::EnumerationCache() | 160 MediaStreamManager::EnumerationCache::EnumerationCache() |
| 129 : valid(false) { | 161 : valid(false) { |
| 130 } | 162 } |
| 131 | 163 |
| 132 MediaStreamManager::EnumerationCache::~EnumerationCache() { | 164 MediaStreamManager::EnumerationCache::~EnumerationCache() { |
| 133 } | 165 } |
| 134 | 166 |
| 135 bool MediaStreamManager::always_use_fake_devices_ = false; | 167 bool MediaStreamManager::always_use_fake_devices_ = false; |
| 136 | 168 |
| 137 // static | 169 // static |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 const StreamOptions& options, const std::string& device_id, | 232 const StreamOptions& options, const std::string& device_id, |
| 201 const GURL& security_origin, std::string* label) { | 233 const GURL& security_origin, std::string* label) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 203 | 235 |
| 204 // Create a new request based on options. | 236 // Create a new request based on options. |
| 205 AddRequest(DeviceRequest(requester, options, | 237 AddRequest(DeviceRequest(requester, options, |
| 206 render_process_id, render_view_id, | 238 render_process_id, render_view_id, |
| 207 security_origin), | 239 security_origin), |
| 208 label); | 240 label); |
| 209 DeviceRequest& request = requests_[*label]; | 241 DeviceRequest& request = requests_[*label]; |
| 242 request.requested_device_id = device_id; | |
| 210 | 243 |
| 211 // Get user confirmation to use the capture device. | 244 // Get user confirmation to use the capture device. |
| 212 device_settings_->RequestCaptureDeviceUsage(*label, | 245 device_settings_->RequestCaptureDeviceUsage(*label, |
| 213 render_process_id, | 246 render_process_id, |
| 214 render_view_id, | 247 render_view_id, |
| 215 options, | 248 options, |
| 216 security_origin); | 249 security_origin); |
| 250 | |
| 251 if (!security_origin.SchemeIs(kExtensionScheme) || | |
| 252 (options.audio_type != content::MEDIA_TAB_AUDIO_CAPTURE && | |
| 253 options.audio_type != content::MEDIA_NO_SERVICE) || | |
| 254 (options.video_type != content::MEDIA_TAB_VIDEO_CAPTURE && | |
| 255 options.video_type != content::MEDIA_NO_SERVICE)) { | |
| 256 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; | |
| 257 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 258 base::Bind(&MediaStreamManager::CancelGenerateStream, | |
| 259 base::Unretained(this), *label)); | |
| 260 return; | |
| 261 } | |
| 262 | |
| 217 // TODO(miu): We should ask the device manager whether a device with id | 263 // TODO(miu): We should ask the device manager whether a device with id |
| 218 // |device_id| actually exists. Note that no such MediaStreamProvider API for | 264 // |device_id| actually exists. Note that no such MediaStreamProvider API for |
| 219 // this currently exists. Also, we don't have a user-friendly device name for | 265 // this currently exists. Also, we don't have a user-friendly device name for |
| 220 // the infobar UI. | 266 // the infobar UI. |
| 267 StreamDeviceInfoArray devices; | |
| 221 if (content::IsAudioMediaType(options.audio_type)) { | 268 if (content::IsAudioMediaType(options.audio_type)) { |
| 222 request.state[options.audio_type] = DeviceRequest::STATE_PENDING_APPROVAL; | 269 // TODO(justinlin): Updating the state to requested and pending are no-ops |
| 223 device_settings_->AvailableDevices( | 270 // in terms of the media manager, but these are the state changes we want to |
| 224 *label, options.audio_type, StreamDeviceInfoArray( | 271 // support in terms of extensions (which is registered as an observer). |
| 225 1, StreamDeviceInfo(options.audio_type, device_id, device_id, | 272 UpdateRequestState(&request, options.audio_type, |
| 226 false))); | 273 MediaStreamRequest::STATE_REQUESTED); |
| 274 UpdateRequestState(&request, options.audio_type, | |
| 275 MediaStreamRequest::STATE_PENDING_APPROVAL); | |
| 276 devices.push_back( | |
| 277 StreamDeviceInfo(options.audio_type, device_id, device_id, false)); | |
| 227 } | 278 } |
| 228 if (content::IsVideoMediaType(options.video_type)) { | 279 if (content::IsVideoMediaType(options.video_type)) { |
| 229 request.state[options.video_type] = DeviceRequest::STATE_PENDING_APPROVAL; | 280 UpdateRequestState(&request, options.video_type, |
| 230 device_settings_->AvailableDevices( | 281 MediaStreamRequest::STATE_REQUESTED); |
| 231 *label, options.video_type, StreamDeviceInfoArray( | 282 UpdateRequestState(&request, options.video_type, |
| 232 1, StreamDeviceInfo(options.video_type, device_id, device_id, | 283 MediaStreamRequest::STATE_PENDING_APPROVAL); |
| 233 false))); | 284 devices.push_back( |
| 285 StreamDeviceInfo(options.video_type, device_id, device_id, false)); | |
| 234 } | 286 } |
| 287 | |
| 288 // Bypass the user authorization dropdown for tab capture. | |
| 289 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 290 base::Bind(&MediaStreamManager::DevicesAccepted, | |
| 291 base::Unretained(this), *label, devices)); | |
| 235 } | 292 } |
| 236 | 293 |
| 237 void MediaStreamManager::CancelGenerateStream(const std::string& label) { | 294 void MediaStreamManager::CancelGenerateStream(const std::string& label) { |
| 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 239 | 296 |
| 240 DeviceRequests::iterator it = requests_.find(label); | 297 DeviceRequests::iterator it = requests_.find(label); |
| 241 if (it != requests_.end()) { | 298 if (it != requests_.end()) { |
| 242 // The request isn't complete. | 299 // The request isn't complete. |
| 243 if (!RequestDone(it->second)) { | 300 if (!RequestDone(it->second)) { |
| 244 DeviceRequest& request = it->second; | 301 DeviceRequest& request = it->second; |
| 245 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; | 302 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; |
| 246 ++i) { | 303 ++i) { |
| 247 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); | 304 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); |
| 248 if (request.state[stream_type] != DeviceRequest::STATE_OPENING) { | 305 if (request.getState(stream_type) != |
| 306 MediaStreamRequest::STATE_OPENING) { | |
| 249 continue; | 307 continue; |
| 250 } | 308 } |
| 251 for (StreamDeviceInfoArray::const_iterator device_it = | 309 for (StreamDeviceInfoArray::const_iterator device_it = |
| 252 request.devices.begin(); | 310 request.devices.begin(); |
| 253 device_it != request.devices.end(); ++device_it) { | 311 device_it != request.devices.end(); ++device_it) { |
| 254 if (device_it->stream_type == stream_type) { | 312 if (device_it->stream_type == stream_type) { |
| 255 GetDeviceManager(stream_type)->Close(device_it->session_id); | 313 GetDeviceManager(stream_type)->Close(device_it->session_id); |
| 256 } | 314 } |
| 257 } | 315 } |
| 258 } | 316 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 273 StopEnumerateDevices(label); | 331 StopEnumerateDevices(label); |
| 274 return; | 332 return; |
| 275 } | 333 } |
| 276 for (StreamDeviceInfoArray::const_iterator device_it = | 334 for (StreamDeviceInfoArray::const_iterator device_it = |
| 277 it->second.devices.begin(); | 335 it->second.devices.begin(); |
| 278 device_it != it->second.devices.end(); ++device_it) { | 336 device_it != it->second.devices.end(); ++device_it) { |
| 279 GetDeviceManager(device_it->stream_type)->Close(device_it->session_id); | 337 GetDeviceManager(device_it->stream_type)->Close(device_it->session_id); |
| 280 } | 338 } |
| 281 if (it->second.type == DeviceRequest::GENERATE_STREAM && | 339 if (it->second.type == DeviceRequest::GENERATE_STREAM && |
| 282 RequestDone(it->second)) { | 340 RequestDone(it->second)) { |
| 341 // Notify observers that this device is being closed. | |
| 342 for (int i = content::MEDIA_NO_SERVICE + 1; | |
| 343 i != content::NUM_MEDIA_TYPES; ++i) { | |
| 344 if (it->second.getState(static_cast<MediaStreamType>(i)) != | |
| 345 MediaStreamRequest::STATE_NOT_REQUESTED) | |
| 346 UpdateRequestState(&it->second, static_cast<MediaStreamType>(i), | |
| 347 MediaStreamRequest::STATE_CLOSING); | |
| 348 } | |
| 283 NotifyObserverDevicesClosed(&(it->second)); | 349 NotifyObserverDevicesClosed(&(it->second)); |
| 284 } | 350 } |
| 285 requests_.erase(it); | 351 requests_.erase(it); |
| 286 } | 352 } |
| 287 } | 353 } |
| 288 | 354 |
| 289 void MediaStreamManager::EnumerateDevices( | 355 void MediaStreamManager::EnumerateDevices( |
| 290 MediaStreamRequester* requester, | 356 MediaStreamRequester* requester, |
| 291 int render_process_id, | 357 int render_process_id, |
| 292 int render_view_id, | 358 int render_view_id, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 312 } | 378 } |
| 313 | 379 |
| 314 DeviceRequest new_request(requester, options, | 380 DeviceRequest new_request(requester, options, |
| 315 render_process_id, | 381 render_process_id, |
| 316 render_view_id, | 382 render_view_id, |
| 317 security_origin); | 383 security_origin); |
| 318 new_request.type = DeviceRequest::ENUMERATE_DEVICES; | 384 new_request.type = DeviceRequest::ENUMERATE_DEVICES; |
| 319 | 385 |
| 320 if (cache->valid) { | 386 if (cache->valid) { |
| 321 // Cached device list of this type exists. Just send it out. | 387 // Cached device list of this type exists. Just send it out. |
| 322 new_request.state[type] = DeviceRequest::STATE_REQUESTED; | 388 UpdateRequestState(&new_request, type, |
| 389 MediaStreamRequest::STATE_REQUESTED); | |
| 323 AddRequest(new_request, label); | 390 AddRequest(new_request, label); |
| 324 // Need to post a task since the requester won't have label till | 391 // Need to post a task since the requester won't have label till |
| 325 // this function returns. | 392 // this function returns. |
| 326 BrowserThread::PostTask(BrowserThread::IO, | 393 BrowserThread::PostTask(BrowserThread::IO, |
| 327 FROM_HERE, | 394 FROM_HERE, |
| 328 base::Bind(&MediaStreamManager::SendCachedDeviceList, | 395 base::Bind(&MediaStreamManager::SendCachedDeviceList, |
| 329 base::Unretained(this), cache, *label)); | 396 base::Unretained(this), cache, *label)); |
| 330 } else { | 397 } else { |
| 331 StartEnumeration(&new_request, label); | 398 StartEnumeration(&new_request, label); |
| 332 StartMonitoring(); | 399 StartMonitoring(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 | 483 |
| 417 void MediaStreamManager::StartEnumeration( | 484 void MediaStreamManager::StartEnumeration( |
| 418 DeviceRequest* new_request, | 485 DeviceRequest* new_request, |
| 419 std::string* label) { | 486 std::string* label) { |
| 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 421 | 488 |
| 422 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; | 489 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; |
| 423 ++i) { | 490 ++i) { |
| 424 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); | 491 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); |
| 425 if (Requested(new_request->options, stream_type)) { | 492 if (Requested(new_request->options, stream_type)) { |
| 426 new_request->state[stream_type] = DeviceRequest::STATE_REQUESTED; | 493 UpdateRequestState(new_request, stream_type, |
| 494 MediaStreamRequest::STATE_REQUESTED); | |
| 427 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 495 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
| 428 if (active_enumeration_ref_count_[stream_type] == 0) { | 496 if (active_enumeration_ref_count_[stream_type] == 0) { |
| 429 ++active_enumeration_ref_count_[stream_type]; | 497 ++active_enumeration_ref_count_[stream_type]; |
| 430 GetDeviceManager(stream_type)->EnumerateDevices(); | 498 GetDeviceManager(stream_type)->EnumerateDevices(); |
| 431 } | 499 } |
| 432 } | 500 } |
| 433 } | 501 } |
| 434 | 502 |
| 435 AddRequest(*new_request, label); | 503 AddRequest(*new_request, label); |
| 436 } | 504 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 495 request = &(request_it->second); | 563 request = &(request_it->second); |
| 496 break; | 564 break; |
| 497 } | 565 } |
| 498 } | 566 } |
| 499 } | 567 } |
| 500 if (request == NULL) { | 568 if (request == NULL) { |
| 501 // The request doesn't exist. | 569 // The request doesn't exist. |
| 502 return; | 570 return; |
| 503 } | 571 } |
| 504 | 572 |
| 505 DCHECK_NE(request->state[stream_type], DeviceRequest::STATE_REQUESTED); | 573 DCHECK_NE(request->getState(stream_type), |
| 574 MediaStreamRequest::STATE_REQUESTED); | |
| 506 | 575 |
| 507 // Check if all devices for this stream type are opened. Update the state if | 576 // Check if all devices for this stream type are opened. Update the state if |
| 508 // they are. | 577 // they are. |
| 509 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); | 578 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); |
| 510 device_it != devices->end(); ++device_it) { | 579 device_it != devices->end(); ++device_it) { |
| 511 if (device_it->stream_type != stream_type) { | 580 if (device_it->stream_type != stream_type) { |
| 512 continue; | 581 continue; |
| 513 } | 582 } |
| 514 if (device_it->in_use == false) { | 583 if (device_it->in_use == false) { |
| 515 // Wait for more devices to be opened before we're done. | 584 // Wait for more devices to be opened before we're done. |
| 516 return; | 585 return; |
| 517 } | 586 } |
| 518 } | 587 } |
| 519 request->state[stream_type] = DeviceRequest::STATE_DONE; | 588 |
| 589 UpdateRequestState(request, stream_type, MediaStreamRequest::STATE_DONE); | |
| 520 | 590 |
| 521 if (!RequestDone(*request)) { | 591 if (!RequestDone(*request)) { |
| 522 // This stream_type is done, but not the other type. | 592 // This stream_type is done, but not the other type. |
| 523 return; | 593 return; |
| 524 } | 594 } |
| 525 | 595 |
| 526 switch (request->type) { | 596 switch (request->type) { |
| 527 case DeviceRequest::OPEN_DEVICE: | 597 case DeviceRequest::OPEN_DEVICE: |
| 528 request->requester->DeviceOpened(label, devices->front()); | 598 request->requester->DeviceOpened(label, devices->front()); |
| 529 break; | 599 break; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 need_update_clients = true; | 646 need_update_clients = true; |
| 577 } | 647 } |
| 578 | 648 |
| 579 // Publish the result for all requests waiting for device list(s). | 649 // Publish the result for all requests waiting for device list(s). |
| 580 // Find the requests waiting for this device list, store their labels and | 650 // Find the requests waiting for this device list, store their labels and |
| 581 // release the iterator before calling device settings. We might get a call | 651 // release the iterator before calling device settings. We might get a call |
| 582 // back from device_settings that will need to iterate through devices. | 652 // back from device_settings that will need to iterate through devices. |
| 583 std::list<std::string> label_list; | 653 std::list<std::string> label_list; |
| 584 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | 654 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
| 585 ++it) { | 655 ++it) { |
| 586 if (it->second.state[stream_type] == DeviceRequest::STATE_REQUESTED && | 656 if (it->second.getState(stream_type) == |
| 657 MediaStreamRequest::STATE_REQUESTED && | |
| 587 Requested(it->second.options, stream_type)) { | 658 Requested(it->second.options, stream_type)) { |
| 588 if (it->second.type != DeviceRequest::ENUMERATE_DEVICES) | 659 if (it->second.type != DeviceRequest::ENUMERATE_DEVICES) |
| 589 it->second.state[stream_type] = DeviceRequest::STATE_PENDING_APPROVAL; | 660 UpdateRequestState(&it->second, stream_type, |
| 661 MediaStreamRequest::STATE_PENDING_APPROVAL); | |
| 590 label_list.push_back(it->first); | 662 label_list.push_back(it->first); |
| 591 } | 663 } |
| 592 } | 664 } |
| 593 for (std::list<std::string>::iterator it = label_list.begin(); | 665 for (std::list<std::string>::iterator it = label_list.begin(); |
| 594 it != label_list.end(); ++it) { | 666 it != label_list.end(); ++it) { |
| 595 DeviceRequest& request = requests_[*it]; | 667 DeviceRequest& request = requests_[*it]; |
| 596 switch (request.type) { | 668 switch (request.type) { |
| 597 case DeviceRequest::ENUMERATE_DEVICES: | 669 case DeviceRequest::ENUMERATE_DEVICES: |
| 598 if (need_update_clients) | 670 if (need_update_clients) |
| 599 request.requester->DevicesEnumerated(*it, devices); | 671 request.requester->DevicesEnumerated(*it, devices); |
| 600 break; | 672 break; |
| 601 case DeviceRequest::OPEN_DEVICE: | 673 case DeviceRequest::OPEN_DEVICE: |
| 602 DCHECK(!request.requested_device_id.empty()); | 674 DCHECK(!request.requested_device_id.empty()); |
| 603 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); | 675 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); |
| 604 device_it != devices.end(); ++device_it) { | 676 device_it != devices.end(); ++device_it) { |
| 605 if (request.requested_device_id == device_it->device_id) { | 677 if (request.requested_device_id == device_it->device_id) { |
| 606 StreamDeviceInfo device = *device_it; | 678 StreamDeviceInfo device = *device_it; |
| 607 device.in_use = false; | 679 device.in_use = false; |
| 608 device.session_id = | 680 device.session_id = |
| 609 GetDeviceManager(device_it->stream_type)->Open(device); | 681 GetDeviceManager(device_it->stream_type)->Open(device); |
| 610 request.state[device_it->stream_type] = | 682 UpdateRequestState(&request, device_it->stream_type, |
| 611 DeviceRequest::STATE_OPENING; | 683 MediaStreamRequest::STATE_OPENING); |
| 612 request.devices.push_back(device); | 684 request.devices.push_back(device); |
| 613 break; | 685 break; |
| 614 } | 686 } |
| 615 } | 687 } |
| 616 break; | 688 break; |
| 617 default: | 689 default: |
| 618 device_settings_->AvailableDevices(*it, stream_type, devices); | 690 device_settings_->AvailableDevices(*it, stream_type, devices); |
| 619 break; | 691 break; |
| 620 } | 692 } |
| 621 } | 693 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 649 NOTREACHED(); | 721 NOTREACHED(); |
| 650 continue; | 722 continue; |
| 651 } | 723 } |
| 652 if (device_it->stream_type != stream_type || | 724 if (device_it->stream_type != stream_type || |
| 653 device_it->session_id != capture_session_id) { | 725 device_it->session_id != capture_session_id) { |
| 654 continue; | 726 continue; |
| 655 } | 727 } |
| 656 // We've found the failing device. Find the error case: | 728 // We've found the failing device. Find the error case: |
| 657 // An error should only be reported to the MediaStreamManager if | 729 // An error should only be reported to the MediaStreamManager if |
| 658 // the request has not been fulfilled yet. | 730 // the request has not been fulfilled yet. |
| 659 DCHECK(it->second.state[stream_type] != DeviceRequest::STATE_DONE); | 731 DCHECK(it->second.getState(stream_type) |
| 660 if (it->second.state[stream_type] != DeviceRequest::STATE_DONE) { | 732 != MediaStreamRequest::STATE_DONE); |
| 733 if (it->second.getState(stream_type) != MediaStreamRequest::STATE_DONE) { | |
| 661 // Request is not done, devices are not opened in this case. | 734 // Request is not done, devices are not opened in this case. |
| 662 if (devices.size() <= 1) { | 735 if (devices.size() <= 1) { |
| 663 // 1. Device not opened and no other devices for this request -> | 736 // 1. Device not opened and no other devices for this request -> |
| 664 // signal stream error and remove the request. | 737 // signal stream error and remove the request. |
| 665 it->second.requester->StreamGenerationFailed(it->first); | 738 it->second.requester->StreamGenerationFailed(it->first); |
| 666 requests_.erase(it); | 739 requests_.erase(it); |
| 667 } else { | 740 } else { |
| 668 // 2. Not opened but other devices exists for this request -> remove | 741 // 2. Not opened but other devices exists for this request -> remove |
| 669 // device from list, but don't signal an error. | 742 // device from list, but don't signal an error. |
| 670 devices.erase(device_it); // NOTE: This invalidates device_it! | 743 devices.erase(device_it); // NOTE: This invalidates device_it! |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 694 | 767 |
| 695 // Process all newly-accepted devices for this request. | 768 // Process all newly-accepted devices for this request. |
| 696 bool found_audio = false, found_video = false; | 769 bool found_audio = false, found_video = false; |
| 697 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); | 770 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); |
| 698 device_it != devices.end(); ++device_it) { | 771 device_it != devices.end(); ++device_it) { |
| 699 StreamDeviceInfo device_info = *device_it; // Make a copy. | 772 StreamDeviceInfo device_info = *device_it; // Make a copy. |
| 700 | 773 |
| 701 // Set in_use to false to be able to track if this device has been | 774 // Set in_use to false to be able to track if this device has been |
| 702 // opened. in_use might be true if the device type can be used in more | 775 // opened. in_use might be true if the device type can be used in more |
| 703 // than one session. | 776 // than one session. |
| 704 DCHECK_EQ(request.state[device_it->stream_type], | 777 DCHECK_EQ(request.getState(device_it->stream_type), |
| 705 DeviceRequest::STATE_PENDING_APPROVAL); | 778 MediaStreamRequest::STATE_PENDING_APPROVAL); |
| 706 device_info.in_use = false; | 779 device_info.in_use = false; |
| 780 | |
| 707 device_info.session_id = | 781 device_info.session_id = |
| 708 GetDeviceManager(device_info.stream_type)->Open(device_info); | 782 GetDeviceManager(device_info.stream_type)->Open(device_info); |
| 709 request.state[device_it->stream_type] = DeviceRequest::STATE_OPENING; | 783 UpdateRequestState(&request, device_it->stream_type, |
| 784 MediaStreamRequest::STATE_OPENING); | |
| 710 request.devices.push_back(device_info); | 785 request.devices.push_back(device_info); |
| 711 | 786 |
| 712 if (device_info.stream_type == request.options.audio_type) { | 787 if (device_info.stream_type == request.options.audio_type) { |
| 713 found_audio = true; | 788 found_audio = true; |
| 714 } else if (device_info.stream_type == request.options.video_type) { | 789 } else if (device_info.stream_type == request.options.video_type) { |
| 715 found_video = true; | 790 found_video = true; |
| 716 } | 791 } |
| 717 } | 792 } |
| 718 | 793 |
| 719 // Check whether we've received all stream types requested. | 794 // Check whether we've received all stream types requested. |
| 720 if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) { | 795 if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) { |
| 721 request.state[request.options.audio_type] = DeviceRequest::STATE_ERROR; | 796 UpdateRequestState(&request, request.options.audio_type, |
| 797 MediaStreamRequest::STATE_ERROR); | |
| 722 } | 798 } |
| 723 if (!found_video && content::IsVideoMediaType(request.options.video_type)) { | 799 if (!found_video && content::IsVideoMediaType(request.options.video_type)) { |
| 724 request.state[request.options.video_type] = DeviceRequest::STATE_ERROR; | 800 UpdateRequestState(&request, request.options.video_type, |
| 801 MediaStreamRequest::STATE_ERROR); | |
| 725 } | 802 } |
| 726 } | 803 } |
| 727 | 804 |
| 728 void MediaStreamManager::SettingsError(const std::string& label) { | 805 void MediaStreamManager::SettingsError(const std::string& label) { |
| 729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 730 // Erase this request and report an error. | 807 // Erase this request and report an error. |
| 731 DeviceRequests::iterator it = requests_.find(label); | 808 DeviceRequests::iterator it = requests_.find(label); |
| 732 if (it != requests_.end()) { | 809 if (it != requests_.end()) { |
| 733 DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM); | 810 DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM); |
| 734 it->second.requester->StreamGenerationFailed(label); | 811 it->second.requester->StreamGenerationFailed(label); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 | 875 |
| 799 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { | 876 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { |
| 800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 877 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 801 | 878 |
| 802 const bool requested_audio = | 879 const bool requested_audio = |
| 803 content::IsAudioMediaType(request.options.audio_type); | 880 content::IsAudioMediaType(request.options.audio_type); |
| 804 const bool requested_video = | 881 const bool requested_video = |
| 805 content::IsVideoMediaType(request.options.video_type); | 882 content::IsVideoMediaType(request.options.video_type); |
| 806 | 883 |
| 807 const bool audio_done = | 884 const bool audio_done = |
| 808 !requested_audio || | 885 !requested_audio || request.getState(request.options.audio_type) == |
| 809 request.state[request.options.audio_type] == DeviceRequest::STATE_DONE || | 886 MediaStreamRequest::STATE_DONE || |
| 810 request.state[request.options.audio_type] == DeviceRequest::STATE_ERROR; | 887 request.getState(request.options.audio_type) == |
| 888 MediaStreamRequest::STATE_ERROR; | |
| 811 if (!audio_done) { | 889 if (!audio_done) { |
| 812 return false; | 890 return false; |
| 813 } | 891 } |
| 814 | 892 |
| 815 const bool video_done = | 893 const bool video_done = |
| 816 !requested_video || | 894 !requested_video || request.getState(request.options.video_type) == |
| 817 request.state[request.options.video_type] == DeviceRequest::STATE_DONE || | 895 MediaStreamRequest::STATE_DONE || |
| 818 request.state[request.options.video_type] == DeviceRequest::STATE_ERROR; | 896 request.getState(request.options.video_type) == |
| 897 MediaStreamRequest::STATE_ERROR; | |
| 819 if (!video_done) { | 898 if (!video_done) { |
| 820 return false; | 899 return false; |
| 821 } | 900 } |
| 822 | 901 |
| 823 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); | 902 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); |
| 824 it != request.devices.end(); ++it) { | 903 it != request.devices.end(); ++it) { |
| 825 if (it->in_use == false) { | 904 if (it->in_use == false) { |
| 826 return false; | 905 return false; |
| 827 } | 906 } |
| 828 } | 907 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 it != requests_.end(); ++it) { | 971 it != requests_.end(); ++it) { |
| 893 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && | 972 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && |
| 894 Requested(it->second.options, stream_type)) { | 973 Requested(it->second.options, stream_type)) { |
| 895 return true; | 974 return true; |
| 896 } | 975 } |
| 897 } | 976 } |
| 898 return false; | 977 return false; |
| 899 } | 978 } |
| 900 | 979 |
| 901 } // namespace media_stream | 980 } // namespace media_stream |
| OLD | NEW |