Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.cc

Issue 10928043: Media Related changes for TabCapture API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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;
28 29
29 namespace media_stream { 30 namespace media_stream {
30 31
31 // Creates a random label used to identify requests. 32 // Creates a random label used to identify requests.
32 static std::string RandomLabel() { 33 static std::string RandomLabel() {
33 // An earlier PeerConnection spec, 34 // An earlier PeerConnection spec,
34 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the 35 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the
35 // MediaStream::label alphabet as containing 36 characters from 36 // 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, 37 // 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. 38 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E.
(...skipping 27 matching lines...) Expand all
65 void DeviceThread::Init() { 66 void DeviceThread::Init() {
66 com_initializer_.reset(new base::win::ScopedCOMInitializer( 67 com_initializer_.reset(new base::win::ScopedCOMInitializer(
67 base::win::ScopedCOMInitializer::kMTA)); 68 base::win::ScopedCOMInitializer::kMTA));
68 } 69 }
69 70
70 void DeviceThread::CleanUp() { 71 void DeviceThread::CleanUp() {
71 com_initializer_.reset(); 72 com_initializer_.reset();
72 } 73 }
73 #endif 74 #endif
74 75
75 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. 76 // TODO(xians): Merge DeviceRequest with MediaStreamRequest.
perkj_chrome 2012/10/04 08:19:25 Is this todo fixed by this?
justinlin 2012/10/08 08:59:45 Not quite.
76 struct MediaStreamManager::DeviceRequest { 77 struct MediaStreamManager::DeviceRequest {
77 enum RequestState {
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 { 78 enum RequestType {
87 GENERATE_STREAM = 0, 79 GENERATE_STREAM = 0,
88 ENUMERATE_DEVICES, 80 ENUMERATE_DEVICES,
89 OPEN_DEVICE 81 OPEN_DEVICE
90 }; 82 };
91 83
92 DeviceRequest() 84 DeviceRequest()
93 : requester(NULL), 85 : requester(NULL),
94 state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED),
95 type(GENERATE_STREAM), 86 type(GENERATE_STREAM),
96 render_process_id(-1), 87 render_process_id(-1),
97 render_view_id(-1) { 88 render_view_id(-1),
89 state_(content::NUM_MEDIA_TYPES,
90 MediaStreamRequest::STATE_NOT_REQUESTED) {
perkj_chrome 2012/10/04 08:19:25 indentation
justinlin 2012/10/08 08:59:45 Done.
98 } 91 }
99 92
100 DeviceRequest(MediaStreamRequester* requester, 93 DeviceRequest(MediaStreamRequester* requester,
101 const StreamOptions& request_options, 94 const StreamOptions& request_options,
102 int render_process_id, 95 int render_process_id,
103 int render_view_id, 96 int render_view_id,
104 const GURL& request_security_origin) 97 const GURL& request_security_origin)
105 : requester(requester), 98 : requester(requester),
106 options(request_options), 99 options(request_options),
107 state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED),
108 type(GENERATE_STREAM), 100 type(GENERATE_STREAM),
109 render_process_id(render_process_id), 101 render_process_id(render_process_id),
110 render_view_id(render_view_id), 102 render_view_id(render_view_id),
111 security_origin(request_security_origin) { 103 security_origin(request_security_origin),
104 state_(content::NUM_MEDIA_TYPES,
no longer working on chromium 2012/10/04 18:41:49 This is a struct, use state or make the struct int
justinlin 2012/10/08 08:59:45 Done. It's kind of in an awkward state now, not su
105 MediaStreamRequest::STATE_NOT_REQUESTED) {
perkj_chrome 2012/10/04 08:19:25 indentation
justinlin 2012/10/08 08:59:45 Done.
112 DCHECK(requester); 106 DCHECK(requester);
113 } 107 }
114 108
115 ~DeviceRequest() {} 109 ~DeviceRequest() {}
116 110
117 MediaStreamRequester* requester; 111 MediaStreamRequester* requester;
118 StreamOptions options; 112 StreamOptions options;
119 std::vector<RequestState> state;
120 RequestType type; 113 RequestType type;
121 int render_process_id; 114 int render_process_id;
122 int render_view_id; 115 int render_view_id;
123 GURL security_origin; 116 GURL security_origin;
124 std::string requested_device_id; 117 std::string requested_device_id;
125 StreamDeviceInfoArray devices; 118 StreamDeviceInfoArray devices;
119
120 void setState(int index, MediaStreamRequest::RequestState newState) {
no longer working on chromium 2012/10/04 18:41:49 Oh, since you are adding functions to this struct,
justinlin 2012/10/08 08:59:45 Done.
121 state_[index] = newState;
122 }
123
124 MediaStreamRequest::RequestState getState(int index) const {
125 return state_[index];
126 }
perkj_chrome 2012/10/04 08:19:25 empty line before privat: section
justinlin 2012/10/08 08:59:45 Done.
127 private:
128 std::vector<MediaStreamRequest::RequestState> state_;
126 }; 129 };
127 130
131 static void NotifyObserverRequestStateChange(
132 MediaStreamManager::DeviceRequest* request,
133 MediaStreamType stream_type,
134 const MediaStreamRequest::RequestState newState,
135 const std::string& device_id) {
136 content::MediaObserver* media_observer =
137 content::GetContentClient()->browser()->GetMediaObserver();
perkj_chrome 2012/10/04 08:19:25 I am not familiar with GetMediaObserver. Why is th
justinlin 2012/10/08 08:59:45 Same as the other methods that notify observers.
138 if (media_observer == NULL)
139 return;
140 media_observer->OnMediaRequestStateChange(
141 request->render_process_id,
142 request->render_view_id,
143 content::MediaStreamDevice(stream_type,device_id, ""),
no longer working on chromium 2012/10/04 18:41:49 one space
justinlin 2012/10/08 08:59:45 Done.
144 newState);
145 }
146
147 // Helper to update the request state and notify observers.
148 static void UpdateRequestState(
149 MediaStreamManager::DeviceRequest* request,
150 MediaStreamType stream_type,
151 const MediaStreamRequest::RequestState newState,
152 const std::string& device_id = "") {
153 request->setState(stream_type, newState);
154 NotifyObserverRequestStateChange(request, stream_type, newState, device_id);
no longer working on chromium 2012/10/04 18:41:49 It does not gain anything to break it into two fun
justinlin 2012/10/08 08:59:45 Done.
155 }
156
128 MediaStreamManager::EnumerationCache::EnumerationCache() 157 MediaStreamManager::EnumerationCache::EnumerationCache()
129 : valid(false) { 158 : valid(false) {
130 } 159 }
131 160
132 MediaStreamManager::EnumerationCache::~EnumerationCache() { 161 MediaStreamManager::EnumerationCache::~EnumerationCache() {
133 } 162 }
134 163
135 bool MediaStreamManager::always_use_fake_devices_ = false; 164 bool MediaStreamManager::always_use_fake_devices_ = false;
136 165
137 // static 166 // static
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 device_settings_->RequestCaptureDeviceUsage(*label, 241 device_settings_->RequestCaptureDeviceUsage(*label,
213 render_process_id, 242 render_process_id,
214 render_view_id, 243 render_view_id,
215 options, 244 options,
216 security_origin); 245 security_origin);
217 // TODO(miu): We should ask the device manager whether a device with id 246 // 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 247 // |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 248 // this currently exists. Also, we don't have a user-friendly device name for
220 // the infobar UI. 249 // the infobar UI.
221 if (content::IsAudioMediaType(options.audio_type)) { 250 if (content::IsAudioMediaType(options.audio_type)) {
222 request.state[options.audio_type] = DeviceRequest::STATE_PENDING_APPROVAL; 251 UpdateRequestState(&request, options.audio_type,
252 MediaStreamRequest::STATE_PENDING_APPROVAL,
253 device_id);
223 device_settings_->AvailableDevices( 254 device_settings_->AvailableDevices(
224 *label, options.audio_type, StreamDeviceInfoArray( 255 *label, options.audio_type, StreamDeviceInfoArray(
225 1, StreamDeviceInfo(options.audio_type, device_id, device_id, 256 1, StreamDeviceInfo(options.audio_type, device_id, device_id,
226 false))); 257 false)));
227 } 258 }
228 if (content::IsVideoMediaType(options.video_type)) { 259 if (content::IsVideoMediaType(options.video_type)) {
229 request.state[options.video_type] = DeviceRequest::STATE_PENDING_APPROVAL; 260 UpdateRequestState(&request, options.video_type,
261 MediaStreamRequest::STATE_PENDING_APPROVAL,
262 device_id);
230 device_settings_->AvailableDevices( 263 device_settings_->AvailableDevices(
231 *label, options.video_type, StreamDeviceInfoArray( 264 *label, options.video_type, StreamDeviceInfoArray(
232 1, StreamDeviceInfo(options.video_type, device_id, device_id, 265 1, StreamDeviceInfo(options.video_type, device_id, device_id,
233 false))); 266 false)));
234 } 267 }
235 } 268 }
236 269
237 void MediaStreamManager::CancelGenerateStream(const std::string& label) { 270 void MediaStreamManager::CancelGenerateStream(const std::string& label) {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
239 272
240 DeviceRequests::iterator it = requests_.find(label); 273 DeviceRequests::iterator it = requests_.find(label);
241 if (it != requests_.end()) { 274 if (it != requests_.end()) {
242 // The request isn't complete. 275 // The request isn't complete.
243 if (!RequestDone(it->second)) { 276 if (!RequestDone(it->second)) {
244 DeviceRequest& request = it->second; 277 DeviceRequest& request = it->second;
245 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; 278 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
246 ++i) { 279 ++i) {
247 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); 280 const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
248 if (request.state[stream_type] != DeviceRequest::STATE_OPENING) { 281 if (request.getState(stream_type) !=
282 MediaStreamRequest::STATE_OPENING) {
249 continue; 283 continue;
250 } 284 }
251 for (StreamDeviceInfoArray::const_iterator device_it = 285 for (StreamDeviceInfoArray::const_iterator device_it =
252 request.devices.begin(); 286 request.devices.begin();
253 device_it != request.devices.end(); ++device_it) { 287 device_it != request.devices.end(); ++device_it) {
254 if (device_it->stream_type == stream_type) { 288 if (device_it->stream_type == stream_type) {
255 GetDeviceManager(stream_type)->Close(device_it->session_id); 289 GetDeviceManager(stream_type)->Close(device_it->session_id);
256 } 290 }
257 } 291 }
258 } 292 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 346 }
313 347
314 DeviceRequest new_request(requester, options, 348 DeviceRequest new_request(requester, options,
315 render_process_id, 349 render_process_id,
316 render_view_id, 350 render_view_id,
317 security_origin); 351 security_origin);
318 new_request.type = DeviceRequest::ENUMERATE_DEVICES; 352 new_request.type = DeviceRequest::ENUMERATE_DEVICES;
319 353
320 if (cache->valid) { 354 if (cache->valid) {
321 // Cached device list of this type exists. Just send it out. 355 // Cached device list of this type exists. Just send it out.
322 new_request.state[type] = DeviceRequest::STATE_REQUESTED; 356 UpdateRequestState(&new_request, type,
357 MediaStreamRequest::STATE_REQUESTED);
323 AddRequest(new_request, label); 358 AddRequest(new_request, label);
324 // Need to post a task since the requester won't have label till 359 // Need to post a task since the requester won't have label till
325 // this function returns. 360 // this function returns.
326 BrowserThread::PostTask(BrowserThread::IO, 361 BrowserThread::PostTask(BrowserThread::IO,
327 FROM_HERE, 362 FROM_HERE,
328 base::Bind(&MediaStreamManager::SendCachedDeviceList, 363 base::Bind(&MediaStreamManager::SendCachedDeviceList,
329 base::Unretained(this), cache, *label)); 364 base::Unretained(this), cache, *label));
330 } else { 365 } else {
331 StartEnumeration(&new_request, label); 366 StartEnumeration(&new_request, label);
332 StartMonitoring(); 367 StartMonitoring();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 451
417 void MediaStreamManager::StartEnumeration( 452 void MediaStreamManager::StartEnumeration(
418 DeviceRequest* new_request, 453 DeviceRequest* new_request,
419 std::string* label) { 454 std::string* label) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
421 456
422 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; 457 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
423 ++i) { 458 ++i) {
424 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); 459 const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
425 if (Requested(new_request->options, stream_type)) { 460 if (Requested(new_request->options, stream_type)) {
426 new_request->state[stream_type] = DeviceRequest::STATE_REQUESTED; 461 UpdateRequestState(new_request, stream_type,
462 MediaStreamRequest::STATE_REQUESTED);
427 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); 463 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
428 if (active_enumeration_ref_count_[stream_type] == 0) { 464 if (active_enumeration_ref_count_[stream_type] == 0) {
429 ++active_enumeration_ref_count_[stream_type]; 465 ++active_enumeration_ref_count_[stream_type];
430 GetDeviceManager(stream_type)->EnumerateDevices(); 466 GetDeviceManager(stream_type)->EnumerateDevices();
431 } 467 }
432 } 468 }
433 } 469 }
434 470
435 AddRequest(*new_request, label); 471 AddRequest(*new_request, label);
436 } 472 }
(...skipping 28 matching lines...) Expand all
465 device_thread_->message_loop_proxy()); 501 device_thread_->message_loop_proxy());
466 502
467 video_capture_manager_ = new media_stream::VideoCaptureManager(); 503 video_capture_manager_ = new media_stream::VideoCaptureManager();
468 video_capture_manager_->Register(this, 504 video_capture_manager_->Register(this,
469 device_thread_->message_loop_proxy()); 505 device_thread_->message_loop_proxy());
470 506
471 // We want to be notified of IO message loop destruction to delete the thread 507 // We want to be notified of IO message loop destruction to delete the thread
472 // and the device managers. 508 // and the device managers.
473 io_loop_ = MessageLoop::current(); 509 io_loop_ = MessageLoop::current();
474 io_loop_->AddDestructionObserver(this); 510 io_loop_->AddDestructionObserver(this);
475 } 511 }
no longer working on chromium 2012/10/04 18:41:49 add back one empty line
justinlin 2012/10/08 08:59:45 Done.
476
477 void MediaStreamManager::Opened(MediaStreamType stream_type, 512 void MediaStreamManager::Opened(MediaStreamType stream_type,
478 int capture_session_id) { 513 int capture_session_id) {
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
480 515
481 // Find the request containing this device and mark it as used. 516 // Find the request containing this device and mark it as used.
482 DeviceRequest* request = NULL; 517 DeviceRequest* request = NULL;
483 StreamDeviceInfoArray* devices = NULL; 518 StreamDeviceInfoArray* devices = NULL;
484 std::string label; 519 std::string label;
485 for (DeviceRequests::iterator request_it = requests_.begin(); 520 for (DeviceRequests::iterator request_it = requests_.begin();
486 request_it != requests_.end() && request == NULL; ++request_it) { 521 request_it != requests_.end() && request == NULL; ++request_it) {
487 devices = &(request_it->second.devices); 522 devices = &(request_it->second.devices);
488 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); 523 for (StreamDeviceInfoArray::iterator device_it = devices->begin();
489 device_it != devices->end(); ++device_it) { 524 device_it != devices->end(); ++device_it) {
490 if (device_it->stream_type == stream_type && 525 if (device_it->stream_type == stream_type &&
491 device_it->session_id == capture_session_id) { 526 device_it->session_id == capture_session_id) {
492 // We've found the request. 527 // We've found the request.
493 device_it->in_use = true; 528 device_it->in_use = true;
494 label = request_it->first; 529 label = request_it->first;
495 request = &(request_it->second); 530 request = &(request_it->second);
496 break; 531 break;
497 } 532 }
498 } 533 }
499 } 534 }
500 if (request == NULL) { 535 if (request == NULL) {
501 // The request doesn't exist. 536 // The request doesn't exist.
502 return; 537 return;
503 } 538 }
504 539
505 DCHECK_NE(request->state[stream_type], DeviceRequest::STATE_REQUESTED); 540 DCHECK_NE(request->getState(stream_type),
541 MediaStreamRequest::STATE_REQUESTED);
506 542
507 // Check if all devices for this stream type are opened. Update the state if 543 // Check if all devices for this stream type are opened. Update the state if
508 // they are. 544 // they are.
509 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); 545 for (StreamDeviceInfoArray::iterator device_it = devices->begin();
510 device_it != devices->end(); ++device_it) { 546 device_it != devices->end(); ++device_it) {
511 if (device_it->stream_type != stream_type) { 547 if (device_it->stream_type != stream_type) {
512 continue; 548 continue;
513 } 549 }
514 if (device_it->in_use == false) { 550 if (device_it->in_use == false) {
515 // Wait for more devices to be opened before we're done. 551 // Wait for more devices to be opened before we're done.
516 return; 552 return;
517 } 553 }
518 } 554 }
519 request->state[stream_type] = DeviceRequest::STATE_DONE; 555 UpdateRequestState(request, stream_type, MediaStreamRequest::STATE_DONE);
520 556
521 if (!RequestDone(*request)) { 557 if (!RequestDone(*request)) {
522 // This stream_type is done, but not the other type. 558 // This stream_type is done, but not the other type.
523 return; 559 return;
524 } 560 }
525 561
526 switch (request->type) { 562 switch (request->type) {
527 case DeviceRequest::OPEN_DEVICE: 563 case DeviceRequest::OPEN_DEVICE:
528 request->requester->DeviceOpened(label, devices->front()); 564 request->requester->DeviceOpened(label, devices->front());
529 break; 565 break;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 need_update_clients = true; 612 need_update_clients = true;
577 } 613 }
578 614
579 // Publish the result for all requests waiting for device list(s). 615 // Publish the result for all requests waiting for device list(s).
580 // Find the requests waiting for this device list, store their labels and 616 // 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 617 // release the iterator before calling device settings. We might get a call
582 // back from device_settings that will need to iterate through devices. 618 // back from device_settings that will need to iterate through devices.
583 std::list<std::string> label_list; 619 std::list<std::string> label_list;
584 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); 620 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end();
585 ++it) { 621 ++it) {
586 if (it->second.state[stream_type] == DeviceRequest::STATE_REQUESTED && 622 if (it->second.getState(stream_type) ==
623 MediaStreamRequest::STATE_REQUESTED &&
587 Requested(it->second.options, stream_type)) { 624 Requested(it->second.options, stream_type)) {
588 if (it->second.type != DeviceRequest::ENUMERATE_DEVICES) 625 if (it->second.type != DeviceRequest::ENUMERATE_DEVICES)
589 it->second.state[stream_type] = DeviceRequest::STATE_PENDING_APPROVAL; 626 UpdateRequestState(&it->second, stream_type,
no longer working on chromium 2012/10/04 18:41:49 Are you sure you want this? The request might not
justinlin 2012/10/08 08:59:45 Yes, we filter by the stream type later in the ext
627 MediaStreamRequest::STATE_PENDING_APPROVAL);
590 label_list.push_back(it->first); 628 label_list.push_back(it->first);
591 } 629 }
592 } 630 }
593 for (std::list<std::string>::iterator it = label_list.begin(); 631 for (std::list<std::string>::iterator it = label_list.begin();
594 it != label_list.end(); ++it) { 632 it != label_list.end(); ++it) {
595 DeviceRequest& request = requests_[*it]; 633 DeviceRequest& request = requests_[*it];
596 switch (request.type) { 634 switch (request.type) {
597 case DeviceRequest::ENUMERATE_DEVICES: 635 case DeviceRequest::ENUMERATE_DEVICES:
598 if (need_update_clients) 636 if (need_update_clients)
599 request.requester->DevicesEnumerated(*it, devices); 637 request.requester->DevicesEnumerated(*it, devices);
600 break; 638 break;
601 case DeviceRequest::OPEN_DEVICE: 639 case DeviceRequest::OPEN_DEVICE:
602 DCHECK(!request.requested_device_id.empty()); 640 DCHECK(!request.requested_device_id.empty());
603 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); 641 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin();
604 device_it != devices.end(); ++device_it) { 642 device_it != devices.end(); ++device_it) {
605 if (request.requested_device_id == device_it->device_id) { 643 if (request.requested_device_id == device_it->device_id) {
606 StreamDeviceInfo device = *device_it; 644 StreamDeviceInfo device = *device_it;
607 device.in_use = false; 645 device.in_use = false;
608 device.session_id = 646 device.session_id =
609 GetDeviceManager(device_it->stream_type)->Open(device); 647 GetDeviceManager(device_it->stream_type)->Open(device);
610 request.state[device_it->stream_type] = 648 UpdateRequestState(&request, device_it->stream_type,
611 DeviceRequest::STATE_OPENING; 649 MediaStreamRequest::STATE_OPENING);
612 request.devices.push_back(device); 650 request.devices.push_back(device);
613 break; 651 break;
614 } 652 }
615 } 653 }
616 break; 654 break;
617 default: 655 default:
618 device_settings_->AvailableDevices(*it, stream_type, devices); 656 device_settings_->AvailableDevices(*it, stream_type, devices);
619 break; 657 break;
620 } 658 }
621 } 659 }
(...skipping 27 matching lines...) Expand all
649 NOTREACHED(); 687 NOTREACHED();
650 continue; 688 continue;
651 } 689 }
652 if (device_it->stream_type != stream_type || 690 if (device_it->stream_type != stream_type ||
653 device_it->session_id != capture_session_id) { 691 device_it->session_id != capture_session_id) {
654 continue; 692 continue;
655 } 693 }
656 // We've found the failing device. Find the error case: 694 // We've found the failing device. Find the error case:
657 // An error should only be reported to the MediaStreamManager if 695 // An error should only be reported to the MediaStreamManager if
658 // the request has not been fulfilled yet. 696 // the request has not been fulfilled yet.
659 DCHECK(it->second.state[stream_type] != DeviceRequest::STATE_DONE); 697 DCHECK(it->second.getState(stream_type)
660 if (it->second.state[stream_type] != DeviceRequest::STATE_DONE) { 698 != MediaStreamRequest::STATE_DONE);
699 if (it->second.getState(stream_type) != MediaStreamRequest::STATE_DONE) {
661 // Request is not done, devices are not opened in this case. 700 // Request is not done, devices are not opened in this case.
662 if (devices.size() <= 1) { 701 if (devices.size() <= 1) {
663 // 1. Device not opened and no other devices for this request -> 702 // 1. Device not opened and no other devices for this request ->
664 // signal stream error and remove the request. 703 // signal stream error and remove the request.
665 it->second.requester->StreamGenerationFailed(it->first); 704 it->second.requester->StreamGenerationFailed(it->first);
666 requests_.erase(it); 705 requests_.erase(it);
667 } else { 706 } else {
668 // 2. Not opened but other devices exists for this request -> remove 707 // 2. Not opened but other devices exists for this request -> remove
669 // device from list, but don't signal an error. 708 // device from list, but don't signal an error.
670 devices.erase(device_it); // NOTE: This invalidates device_it! 709 devices.erase(device_it); // NOTE: This invalidates device_it!
(...skipping 23 matching lines...) Expand all
694 733
695 // Process all newly-accepted devices for this request. 734 // Process all newly-accepted devices for this request.
696 bool found_audio = false, found_video = false; 735 bool found_audio = false, found_video = false;
697 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); 736 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin();
698 device_it != devices.end(); ++device_it) { 737 device_it != devices.end(); ++device_it) {
699 StreamDeviceInfo device_info = *device_it; // Make a copy. 738 StreamDeviceInfo device_info = *device_it; // Make a copy.
700 739
701 // Set in_use to false to be able to track if this device has been 740 // 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 741 // opened. in_use might be true if the device type can be used in more
703 // than one session. 742 // than one session.
704 DCHECK_EQ(request.state[device_it->stream_type], 743 DCHECK_EQ(request.getState(device_it->stream_type),
705 DeviceRequest::STATE_PENDING_APPROVAL); 744 MediaStreamRequest::STATE_PENDING_APPROVAL);
706 device_info.in_use = false; 745 device_info.in_use = false;
707 device_info.session_id = 746 device_info.session_id =
708 GetDeviceManager(device_info.stream_type)->Open(device_info); 747 GetDeviceManager(device_info.stream_type)->Open(device_info);
709 request.state[device_it->stream_type] = DeviceRequest::STATE_OPENING; 748 UpdateRequestState(&request, device_it->stream_type,
749 MediaStreamRequest::STATE_OPENING,
750 device_info.device_id);
710 request.devices.push_back(device_info); 751 request.devices.push_back(device_info);
711 752
712 if (device_info.stream_type == request.options.audio_type) { 753 if (device_info.stream_type == request.options.audio_type) {
713 found_audio = true; 754 found_audio = true;
714 } else if (device_info.stream_type == request.options.video_type) { 755 } else if (device_info.stream_type == request.options.video_type) {
715 found_video = true; 756 found_video = true;
716 } 757 }
717 } 758 }
718 759
719 // Check whether we've received all stream types requested. 760 // Check whether we've received all stream types requested.
720 if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) { 761 if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) {
721 request.state[request.options.audio_type] = DeviceRequest::STATE_ERROR; 762 UpdateRequestState(&request, request.options.audio_type,
763 MediaStreamRequest::STATE_ERROR);
722 } 764 }
723 if (!found_video && content::IsVideoMediaType(request.options.video_type)) { 765 if (!found_video && content::IsVideoMediaType(request.options.video_type)) {
724 request.state[request.options.video_type] = DeviceRequest::STATE_ERROR; 766 UpdateRequestState(&request, request.options.video_type,
767 MediaStreamRequest::STATE_ERROR);
725 } 768 }
726 } 769 }
727 770
728 void MediaStreamManager::SettingsError(const std::string& label) { 771 void MediaStreamManager::SettingsError(const std::string& label) {
729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
730 // Erase this request and report an error. 773 // Erase this request and report an error.
731 DeviceRequests::iterator it = requests_.find(label); 774 DeviceRequests::iterator it = requests_.find(label);
732 if (it != requests_.end()) { 775 if (it != requests_.end()) {
733 DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM); 776 DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM);
734 it->second.requester->StreamGenerationFailed(label); 777 it->second.requester->StreamGenerationFailed(label);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { 842 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
801 844
802 const bool requested_audio = 845 const bool requested_audio =
803 content::IsAudioMediaType(request.options.audio_type); 846 content::IsAudioMediaType(request.options.audio_type);
804 const bool requested_video = 847 const bool requested_video =
805 content::IsVideoMediaType(request.options.video_type); 848 content::IsVideoMediaType(request.options.video_type);
806 849
807 const bool audio_done = 850 const bool audio_done =
808 !requested_audio || 851 !requested_audio ||
809 request.state[request.options.audio_type] == DeviceRequest::STATE_DONE || 852 request.getState(request.options.audio_type) ==
810 request.state[request.options.audio_type] == DeviceRequest::STATE_ERROR; 853 MediaStreamRequest::STATE_DONE ||
854 request.getState(request.options.audio_type) ==
855 MediaStreamRequest::STATE_ERROR;
811 if (!audio_done) { 856 if (!audio_done) {
812 return false; 857 return false;
813 } 858 }
814 859
815 const bool video_done = 860 const bool video_done =
816 !requested_video || 861 !requested_video ||
817 request.state[request.options.video_type] == DeviceRequest::STATE_DONE || 862 request.getState(request.options.video_type) ==
818 request.state[request.options.video_type] == DeviceRequest::STATE_ERROR; 863 MediaStreamRequest::STATE_DONE ||
perkj_chrome 2012/10/04 08:19:25 Fits on line above, here and elsewhere?
justinlin 2012/10/08 08:59:45 Done.
864 request.getState(request.options.video_type) ==
865 MediaStreamRequest::STATE_ERROR;
819 if (!video_done) { 866 if (!video_done) {
820 return false; 867 return false;
821 } 868 }
822 869
823 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); 870 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin();
824 it != request.devices.end(); ++it) { 871 it != request.devices.end(); ++it) {
825 if (it->in_use == false) { 872 if (it->in_use == false) {
826 return false; 873 return false;
827 } 874 }
828 } 875 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 it != requests_.end(); ++it) { 939 it != requests_.end(); ++it) {
893 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && 940 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES &&
894 Requested(it->second.options, stream_type)) { 941 Requested(it->second.options, stream_type)) {
895 return true; 942 return true;
896 } 943 }
897 } 944 }
898 return false; 945 return false;
899 } 946 }
900 947
901 } // namespace media_stream 948 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698