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

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: Review fixes 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 28 matching lines...) Expand all
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.
76 struct MediaStreamManager::DeviceRequest { 77 class MediaStreamManager::DeviceRequest {
no longer working on chromium 2012/10/11 09:07:25 Nice, thanks.
77 enum RequestState { 78 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 { 79 enum RequestType {
87 GENERATE_STREAM = 0, 80 GENERATE_STREAM = 0,
88 ENUMERATE_DEVICES, 81 ENUMERATE_DEVICES,
89 OPEN_DEVICE 82 OPEN_DEVICE
90 }; 83 };
91 84
92 DeviceRequest() 85 DeviceRequest()
93 : requester(NULL), 86 : requester(NULL),
94 state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED),
95 type(GENERATE_STREAM), 87 type(GENERATE_STREAM),
96 render_process_id(-1), 88 render_process_id(-1),
97 render_view_id(-1) { 89 render_view_id(-1),
90 state_(content::NUM_MEDIA_TYPES,
91 MediaStreamRequest::STATE_NOT_REQUESTED) {
98 } 92 }
99 93
100 DeviceRequest(MediaStreamRequester* requester, 94 DeviceRequest(MediaStreamRequester* requester,
101 const StreamOptions& request_options, 95 const StreamOptions& request_options,
102 int render_process_id, 96 int render_process_id,
103 int render_view_id, 97 int render_view_id,
104 const GURL& request_security_origin) 98 const GURL& request_security_origin)
105 : requester(requester), 99 : requester(requester),
106 options(request_options), 100 options(request_options),
107 state(content::NUM_MEDIA_TYPES, STATE_NOT_REQUESTED),
108 type(GENERATE_STREAM), 101 type(GENERATE_STREAM),
109 render_process_id(render_process_id), 102 render_process_id(render_process_id),
110 render_view_id(render_view_id), 103 render_view_id(render_view_id),
111 security_origin(request_security_origin) { 104 security_origin(request_security_origin),
105 state_(content::NUM_MEDIA_TYPES,
106 MediaStreamRequest::STATE_NOT_REQUESTED) {
112 DCHECK(requester); 107 DCHECK(requester);
113 } 108 }
114 109
115 ~DeviceRequest() {} 110 ~DeviceRequest() {}
116 111
117 MediaStreamRequester* requester; 112 MediaStreamRequester* requester;
118 StreamOptions options; 113 StreamOptions options;
119 std::vector<RequestState> state;
120 RequestType type; 114 RequestType type;
121 int render_process_id; 115 int render_process_id;
122 int render_view_id; 116 int render_view_id;
123 GURL security_origin; 117 GURL security_origin;
124 std::string requested_device_id; 118 std::string requested_device_id;
125 StreamDeviceInfoArray devices; 119 StreamDeviceInfoArray devices;
120
121 void setState(MediaStreamType stream_type,
122 MediaStreamRequest::RequestState new_state) {
123 state_[stream_type] = new_state;
124 }
125
126 MediaStreamRequest::RequestState getState(MediaStreamType stream_type) const {
127 return state_[stream_type];
128 }
129
130 private:
131 std::vector<MediaStreamRequest::RequestState> state_;
126 }; 132 };
127 133
134 // Helper to update the request state and notify observers.
135 static void UpdateRequestState(
wjia(left Chromium) 2012/10/11 20:21:07 I guess you need to call this function only when r
justinlin 2012/10/11 21:19:21 Done. Changed the check to just use options.{video
136 MediaStreamManager::DeviceRequest* request,
137 MediaStreamType stream_type,
138 const MediaStreamRequest::RequestState new_state) {
139 request->setState(stream_type, new_state);
140
141 content::MediaObserver* media_observer =
142 content::GetContentClient()->browser()->GetMediaObserver();
143 if (media_observer == NULL)
144 return;
145 media_observer->OnMediaRequestStateChanged(
146 request->render_process_id,
147 request->render_view_id,
148 content::MediaStreamDevice(stream_type,
149 request->requested_device_id,
no longer working on chromium 2012/10/11 09:07:25 Do we still notify the observer if requested_devic
justinlin 2012/10/11 19:41:51 Done. We could short-circuit it here with that con
150 request->requested_device_id),
151 new_state);
152 }
153
128 MediaStreamManager::EnumerationCache::EnumerationCache() 154 MediaStreamManager::EnumerationCache::EnumerationCache()
129 : valid(false) { 155 : valid(false) {
130 } 156 }
131 157
132 MediaStreamManager::EnumerationCache::~EnumerationCache() { 158 MediaStreamManager::EnumerationCache::~EnumerationCache() {
133 } 159 }
134 160
135 bool MediaStreamManager::always_use_fake_devices_ = false; 161 bool MediaStreamManager::always_use_fake_devices_ = false;
136 162
137 // static 163 // static
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 const StreamOptions& options, const std::string& device_id, 226 const StreamOptions& options, const std::string& device_id,
201 const GURL& security_origin, std::string* label) { 227 const GURL& security_origin, std::string* label) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
203 229
204 // Create a new request based on options. 230 // Create a new request based on options.
205 AddRequest(DeviceRequest(requester, options, 231 AddRequest(DeviceRequest(requester, options,
206 render_process_id, render_view_id, 232 render_process_id, render_view_id,
207 security_origin), 233 security_origin),
208 label); 234 label);
209 DeviceRequest& request = requests_[*label]; 235 DeviceRequest& request = requests_[*label];
236 request.requested_device_id = device_id;
210 237
211 // Get user confirmation to use the capture device. 238 // Get user confirmation to use the capture device.
212 device_settings_->RequestCaptureDeviceUsage(*label, 239 device_settings_->RequestCaptureDeviceUsage(*label,
213 render_process_id, 240 render_process_id,
214 render_view_id, 241 render_view_id,
215 options, 242 options,
216 security_origin); 243 security_origin);
217 // TODO(miu): We should ask the device manager whether a device with id 244 // 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 245 // |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 246 // this currently exists. Also, we don't have a user-friendly device name for
220 // the infobar UI. 247 // the infobar UI.
248 StreamDeviceInfoArray devices;
221 if (content::IsAudioMediaType(options.audio_type)) { 249 if (content::IsAudioMediaType(options.audio_type)) {
222 request.state[options.audio_type] = DeviceRequest::STATE_PENDING_APPROVAL; 250 // TODO(justinlin): Updating the state to requested and pending are no-ops
223 device_settings_->AvailableDevices( 251 // in terms of the media manager, but these are the state changes we want to
224 *label, options.audio_type, StreamDeviceInfoArray( 252 // support in terms of extensions (which is registered as an observer).
225 1, StreamDeviceInfo(options.audio_type, device_id, device_id, 253 UpdateRequestState(&request, options.audio_type,
no longer working on chromium 2012/10/11 09:07:25 Are you sure that you want to update the observer_
justinlin 2012/10/11 19:41:51 We might remove the "requested" state notification
226 false))); 254 MediaStreamRequest::STATE_REQUESTED);
255 UpdateRequestState(&request, options.audio_type,
256 MediaStreamRequest::STATE_PENDING_APPROVAL);
257 devices.push_back(
258 StreamDeviceInfo(options.audio_type, device_id, device_id, false));
227 } 259 }
228 if (content::IsVideoMediaType(options.video_type)) { 260 if (content::IsVideoMediaType(options.video_type)) {
229 request.state[options.video_type] = DeviceRequest::STATE_PENDING_APPROVAL; 261 UpdateRequestState(&request, options.video_type,
230 device_settings_->AvailableDevices( 262 MediaStreamRequest::STATE_REQUESTED);
231 *label, options.video_type, StreamDeviceInfoArray( 263 UpdateRequestState(&request, options.video_type,
232 1, StreamDeviceInfo(options.video_type, device_id, device_id, 264 MediaStreamRequest::STATE_PENDING_APPROVAL);
233 false))); 265 devices.push_back(
266 StreamDeviceInfo(options.video_type, device_id, device_id, false));
234 } 267 }
268 DevicesAccepted(*label, devices);
no longer working on chromium 2012/10/11 09:07:25 ?? It is bypassing the infobar, don't you need use
justinlin 2012/10/11 19:41:51 Yes, I think we eventually want to add a notificat
wjia(left Chromium) 2012/10/11 20:21:07 you need post a task, instead of calling DevicesAc
justinlin 2012/10/11 21:19:21 Done. Thanks.
235 } 269 }
236 270
237 void MediaStreamManager::CancelGenerateStream(const std::string& label) { 271 void MediaStreamManager::CancelGenerateStream(const std::string& label) {
238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
239 273
240 DeviceRequests::iterator it = requests_.find(label); 274 DeviceRequests::iterator it = requests_.find(label);
241 if (it != requests_.end()) { 275 if (it != requests_.end()) {
242 // The request isn't complete. 276 // The request isn't complete.
243 if (!RequestDone(it->second)) { 277 if (!RequestDone(it->second)) {
244 DeviceRequest& request = it->second; 278 DeviceRequest& request = it->second;
245 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; 279 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
246 ++i) { 280 ++i) {
247 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); 281 const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
248 if (request.state[stream_type] != DeviceRequest::STATE_OPENING) { 282 if (request.getState(stream_type) !=
283 MediaStreamRequest::STATE_OPENING) {
249 continue; 284 continue;
250 } 285 }
251 for (StreamDeviceInfoArray::const_iterator device_it = 286 for (StreamDeviceInfoArray::const_iterator device_it =
252 request.devices.begin(); 287 request.devices.begin();
253 device_it != request.devices.end(); ++device_it) { 288 device_it != request.devices.end(); ++device_it) {
254 if (device_it->stream_type == stream_type) { 289 if (device_it->stream_type == stream_type) {
255 GetDeviceManager(stream_type)->Close(device_it->session_id); 290 GetDeviceManager(stream_type)->Close(device_it->session_id);
256 } 291 }
257 } 292 }
258 } 293 }
(...skipping 14 matching lines...) Expand all
273 StopEnumerateDevices(label); 308 StopEnumerateDevices(label);
274 return; 309 return;
275 } 310 }
276 for (StreamDeviceInfoArray::const_iterator device_it = 311 for (StreamDeviceInfoArray::const_iterator device_it =
277 it->second.devices.begin(); 312 it->second.devices.begin();
278 device_it != it->second.devices.end(); ++device_it) { 313 device_it != it->second.devices.end(); ++device_it) {
279 GetDeviceManager(device_it->stream_type)->Close(device_it->session_id); 314 GetDeviceManager(device_it->stream_type)->Close(device_it->session_id);
280 } 315 }
281 if (it->second.type == DeviceRequest::GENERATE_STREAM && 316 if (it->second.type == DeviceRequest::GENERATE_STREAM &&
282 RequestDone(it->second)) { 317 RequestDone(it->second)) {
318 // Notify observers that this device is being closed.
319 for (MediaStreamType i = content::MEDIA_NO_SERVICE;
320 i != content::NUM_MEDIA_TYPES; ++i) {
321 if (it->second.getState(i) != MediaStreamRequest::STATE_NOT_REQUESTED)
322 UpdateRequestState(&it->second, i, MediaStreamRequest::STATE_CLOSING);
no longer working on chromium 2012/10/11 09:07:25 I think I have already asked the question before,
justinlin 2012/10/11 19:41:51 Right, for now probably not. Added short-circuit i
323 }
283 NotifyObserverDevicesClosed(&(it->second)); 324 NotifyObserverDevicesClosed(&(it->second));
284 } 325 }
285 requests_.erase(it); 326 requests_.erase(it);
286 } 327 }
287 } 328 }
288 329
289 void MediaStreamManager::EnumerateDevices( 330 void MediaStreamManager::EnumerateDevices(
290 MediaStreamRequester* requester, 331 MediaStreamRequester* requester,
291 int render_process_id, 332 int render_process_id,
292 int render_view_id, 333 int render_view_id,
(...skipping 19 matching lines...) Expand all
312 } 353 }
313 354
314 DeviceRequest new_request(requester, options, 355 DeviceRequest new_request(requester, options,
315 render_process_id, 356 render_process_id,
316 render_view_id, 357 render_view_id,
317 security_origin); 358 security_origin);
318 new_request.type = DeviceRequest::ENUMERATE_DEVICES; 359 new_request.type = DeviceRequest::ENUMERATE_DEVICES;
319 360
320 if (cache->valid) { 361 if (cache->valid) {
321 // Cached device list of this type exists. Just send it out. 362 // Cached device list of this type exists. Just send it out.
322 new_request.state[type] = DeviceRequest::STATE_REQUESTED; 363 UpdateRequestState(&new_request, type,
364 MediaStreamRequest::STATE_REQUESTED);
323 AddRequest(new_request, label); 365 AddRequest(new_request, label);
324 // Need to post a task since the requester won't have label till 366 // Need to post a task since the requester won't have label till
325 // this function returns. 367 // this function returns.
326 BrowserThread::PostTask(BrowserThread::IO, 368 BrowserThread::PostTask(BrowserThread::IO,
327 FROM_HERE, 369 FROM_HERE,
328 base::Bind(&MediaStreamManager::SendCachedDeviceList, 370 base::Bind(&MediaStreamManager::SendCachedDeviceList,
329 base::Unretained(this), cache, *label)); 371 base::Unretained(this), cache, *label));
330 } else { 372 } else {
331 StartEnumeration(&new_request, label); 373 StartEnumeration(&new_request, label);
332 StartMonitoring(); 374 StartMonitoring();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 458
417 void MediaStreamManager::StartEnumeration( 459 void MediaStreamManager::StartEnumeration(
418 DeviceRequest* new_request, 460 DeviceRequest* new_request,
419 std::string* label) { 461 std::string* label) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
421 463
422 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; 464 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES;
423 ++i) { 465 ++i) {
424 const MediaStreamType stream_type = static_cast<MediaStreamType>(i); 466 const MediaStreamType stream_type = static_cast<MediaStreamType>(i);
425 if (Requested(new_request->options, stream_type)) { 467 if (Requested(new_request->options, stream_type)) {
426 new_request->state[stream_type] = DeviceRequest::STATE_REQUESTED; 468 UpdateRequestState(new_request, stream_type,
469 MediaStreamRequest::STATE_REQUESTED);
427 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); 470 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
428 if (active_enumeration_ref_count_[stream_type] == 0) { 471 if (active_enumeration_ref_count_[stream_type] == 0) {
429 ++active_enumeration_ref_count_[stream_type]; 472 ++active_enumeration_ref_count_[stream_type];
430 GetDeviceManager(stream_type)->EnumerateDevices(); 473 GetDeviceManager(stream_type)->EnumerateDevices();
431 } 474 }
432 } 475 }
433 } 476 }
434 477
435 AddRequest(*new_request, label); 478 AddRequest(*new_request, label);
436 } 479 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 request = &(request_it->second); 538 request = &(request_it->second);
496 break; 539 break;
497 } 540 }
498 } 541 }
499 } 542 }
500 if (request == NULL) { 543 if (request == NULL) {
501 // The request doesn't exist. 544 // The request doesn't exist.
502 return; 545 return;
503 } 546 }
504 547
505 DCHECK_NE(request->state[stream_type], DeviceRequest::STATE_REQUESTED); 548 DCHECK_NE(request->getState(stream_type),
549 MediaStreamRequest::STATE_REQUESTED);
506 550
507 // Check if all devices for this stream type are opened. Update the state if 551 // Check if all devices for this stream type are opened. Update the state if
508 // they are. 552 // they are.
509 for (StreamDeviceInfoArray::iterator device_it = devices->begin(); 553 for (StreamDeviceInfoArray::iterator device_it = devices->begin();
510 device_it != devices->end(); ++device_it) { 554 device_it != devices->end(); ++device_it) {
511 if (device_it->stream_type != stream_type) { 555 if (device_it->stream_type != stream_type) {
512 continue; 556 continue;
513 } 557 }
514 if (device_it->in_use == false) { 558 if (device_it->in_use == false) {
515 // Wait for more devices to be opened before we're done. 559 // Wait for more devices to be opened before we're done.
516 return; 560 return;
517 } 561 }
518 } 562 }
519 request->state[stream_type] = DeviceRequest::STATE_DONE; 563
564 UpdateRequestState(request, stream_type, MediaStreamRequest::STATE_DONE);
520 565
521 if (!RequestDone(*request)) { 566 if (!RequestDone(*request)) {
522 // This stream_type is done, but not the other type. 567 // This stream_type is done, but not the other type.
523 return; 568 return;
524 } 569 }
525 570
526 switch (request->type) { 571 switch (request->type) {
527 case DeviceRequest::OPEN_DEVICE: 572 case DeviceRequest::OPEN_DEVICE:
528 request->requester->DeviceOpened(label, devices->front()); 573 request->requester->DeviceOpened(label, devices->front());
529 break; 574 break;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 need_update_clients = true; 621 need_update_clients = true;
577 } 622 }
578 623
579 // Publish the result for all requests waiting for device list(s). 624 // Publish the result for all requests waiting for device list(s).
580 // Find the requests waiting for this device list, store their labels and 625 // 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 626 // release the iterator before calling device settings. We might get a call
582 // back from device_settings that will need to iterate through devices. 627 // back from device_settings that will need to iterate through devices.
583 std::list<std::string> label_list; 628 std::list<std::string> label_list;
584 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); 629 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end();
585 ++it) { 630 ++it) {
586 if (it->second.state[stream_type] == DeviceRequest::STATE_REQUESTED && 631 if (it->second.getState(stream_type) ==
632 MediaStreamRequest::STATE_REQUESTED &&
587 Requested(it->second.options, stream_type)) { 633 Requested(it->second.options, stream_type)) {
588 if (it->second.type != DeviceRequest::ENUMERATE_DEVICES) 634 if (it->second.type != DeviceRequest::ENUMERATE_DEVICES)
589 it->second.state[stream_type] = DeviceRequest::STATE_PENDING_APPROVAL; 635 UpdateRequestState(&it->second, stream_type,
636 MediaStreamRequest::STATE_PENDING_APPROVAL);
590 label_list.push_back(it->first); 637 label_list.push_back(it->first);
591 } 638 }
592 } 639 }
593 for (std::list<std::string>::iterator it = label_list.begin(); 640 for (std::list<std::string>::iterator it = label_list.begin();
594 it != label_list.end(); ++it) { 641 it != label_list.end(); ++it) {
595 DeviceRequest& request = requests_[*it]; 642 DeviceRequest& request = requests_[*it];
596 switch (request.type) { 643 switch (request.type) {
597 case DeviceRequest::ENUMERATE_DEVICES: 644 case DeviceRequest::ENUMERATE_DEVICES:
598 if (need_update_clients) 645 if (need_update_clients)
599 request.requester->DevicesEnumerated(*it, devices); 646 request.requester->DevicesEnumerated(*it, devices);
600 break; 647 break;
601 case DeviceRequest::OPEN_DEVICE: 648 case DeviceRequest::OPEN_DEVICE:
602 DCHECK(!request.requested_device_id.empty()); 649 DCHECK(!request.requested_device_id.empty());
603 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); 650 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin();
604 device_it != devices.end(); ++device_it) { 651 device_it != devices.end(); ++device_it) {
605 if (request.requested_device_id == device_it->device_id) { 652 if (request.requested_device_id == device_it->device_id) {
606 StreamDeviceInfo device = *device_it; 653 StreamDeviceInfo device = *device_it;
607 device.in_use = false; 654 device.in_use = false;
608 device.session_id = 655 device.session_id =
609 GetDeviceManager(device_it->stream_type)->Open(device); 656 GetDeviceManager(device_it->stream_type)->Open(device);
610 request.state[device_it->stream_type] = 657 UpdateRequestState(&request, device_it->stream_type,
611 DeviceRequest::STATE_OPENING; 658 MediaStreamRequest::STATE_OPENING);
612 request.devices.push_back(device); 659 request.devices.push_back(device);
613 break; 660 break;
614 } 661 }
615 } 662 }
616 break; 663 break;
617 default: 664 default:
618 device_settings_->AvailableDevices(*it, stream_type, devices); 665 device_settings_->AvailableDevices(*it, stream_type, devices);
619 break; 666 break;
620 } 667 }
621 } 668 }
(...skipping 27 matching lines...) Expand all
649 NOTREACHED(); 696 NOTREACHED();
650 continue; 697 continue;
651 } 698 }
652 if (device_it->stream_type != stream_type || 699 if (device_it->stream_type != stream_type ||
653 device_it->session_id != capture_session_id) { 700 device_it->session_id != capture_session_id) {
654 continue; 701 continue;
655 } 702 }
656 // We've found the failing device. Find the error case: 703 // We've found the failing device. Find the error case:
657 // An error should only be reported to the MediaStreamManager if 704 // An error should only be reported to the MediaStreamManager if
658 // the request has not been fulfilled yet. 705 // the request has not been fulfilled yet.
659 DCHECK(it->second.state[stream_type] != DeviceRequest::STATE_DONE); 706 DCHECK(it->second.getState(stream_type)
660 if (it->second.state[stream_type] != DeviceRequest::STATE_DONE) { 707 != MediaStreamRequest::STATE_DONE);
708 if (it->second.getState(stream_type) != MediaStreamRequest::STATE_DONE) {
661 // Request is not done, devices are not opened in this case. 709 // Request is not done, devices are not opened in this case.
662 if (devices.size() <= 1) { 710 if (devices.size() <= 1) {
663 // 1. Device not opened and no other devices for this request -> 711 // 1. Device not opened and no other devices for this request ->
664 // signal stream error and remove the request. 712 // signal stream error and remove the request.
665 it->second.requester->StreamGenerationFailed(it->first); 713 it->second.requester->StreamGenerationFailed(it->first);
666 requests_.erase(it); 714 requests_.erase(it);
667 } else { 715 } else {
668 // 2. Not opened but other devices exists for this request -> remove 716 // 2. Not opened but other devices exists for this request -> remove
669 // device from list, but don't signal an error. 717 // device from list, but don't signal an error.
670 devices.erase(device_it); // NOTE: This invalidates device_it! 718 devices.erase(device_it); // NOTE: This invalidates device_it!
(...skipping 23 matching lines...) Expand all
694 742
695 // Process all newly-accepted devices for this request. 743 // Process all newly-accepted devices for this request.
696 bool found_audio = false, found_video = false; 744 bool found_audio = false, found_video = false;
697 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); 745 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin();
698 device_it != devices.end(); ++device_it) { 746 device_it != devices.end(); ++device_it) {
699 StreamDeviceInfo device_info = *device_it; // Make a copy. 747 StreamDeviceInfo device_info = *device_it; // Make a copy.
700 748
701 // Set in_use to false to be able to track if this device has been 749 // 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 750 // opened. in_use might be true if the device type can be used in more
703 // than one session. 751 // than one session.
704 DCHECK_EQ(request.state[device_it->stream_type], 752 DCHECK_EQ(request.getState(device_it->stream_type),
705 DeviceRequest::STATE_PENDING_APPROVAL); 753 MediaStreamRequest::STATE_PENDING_APPROVAL);
706 device_info.in_use = false; 754 device_info.in_use = false;
755
707 device_info.session_id = 756 device_info.session_id =
708 GetDeviceManager(device_info.stream_type)->Open(device_info); 757 GetDeviceManager(device_info.stream_type)->Open(device_info);
709 request.state[device_it->stream_type] = DeviceRequest::STATE_OPENING; 758 UpdateRequestState(&request, device_it->stream_type,
759 MediaStreamRequest::STATE_OPENING);
710 request.devices.push_back(device_info); 760 request.devices.push_back(device_info);
711 761
712 if (device_info.stream_type == request.options.audio_type) { 762 if (device_info.stream_type == request.options.audio_type) {
713 found_audio = true; 763 found_audio = true;
714 } else if (device_info.stream_type == request.options.video_type) { 764 } else if (device_info.stream_type == request.options.video_type) {
715 found_video = true; 765 found_video = true;
716 } 766 }
717 } 767 }
718 768
719 // Check whether we've received all stream types requested. 769 // Check whether we've received all stream types requested.
720 if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) { 770 if (!found_audio && content::IsAudioMediaType(request.options.audio_type)) {
721 request.state[request.options.audio_type] = DeviceRequest::STATE_ERROR; 771 UpdateRequestState(&request, request.options.audio_type,
772 MediaStreamRequest::STATE_ERROR);
722 } 773 }
723 if (!found_video && content::IsVideoMediaType(request.options.video_type)) { 774 if (!found_video && content::IsVideoMediaType(request.options.video_type)) {
724 request.state[request.options.video_type] = DeviceRequest::STATE_ERROR; 775 UpdateRequestState(&request, request.options.video_type,
776 MediaStreamRequest::STATE_ERROR);
725 } 777 }
726 } 778 }
727 779
728 void MediaStreamManager::SettingsError(const std::string& label) { 780 void MediaStreamManager::SettingsError(const std::string& label) {
729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 781 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
730 // Erase this request and report an error. 782 // Erase this request and report an error.
731 DeviceRequests::iterator it = requests_.find(label); 783 DeviceRequests::iterator it = requests_.find(label);
732 if (it != requests_.end()) { 784 if (it != requests_.end()) {
733 DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM); 785 DCHECK_EQ(it->second.type, DeviceRequest::GENERATE_STREAM);
734 it->second.requester->StreamGenerationFailed(label); 786 it->second.requester->StreamGenerationFailed(label);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 850
799 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const { 851 bool MediaStreamManager::RequestDone(const DeviceRequest& request) const {
800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
801 853
802 const bool requested_audio = 854 const bool requested_audio =
803 content::IsAudioMediaType(request.options.audio_type); 855 content::IsAudioMediaType(request.options.audio_type);
804 const bool requested_video = 856 const bool requested_video =
805 content::IsVideoMediaType(request.options.video_type); 857 content::IsVideoMediaType(request.options.video_type);
806 858
807 const bool audio_done = 859 const bool audio_done =
808 !requested_audio || 860 !requested_audio || request.getState(request.options.audio_type) ==
809 request.state[request.options.audio_type] == DeviceRequest::STATE_DONE || 861 MediaStreamRequest::STATE_DONE ||
810 request.state[request.options.audio_type] == DeviceRequest::STATE_ERROR; 862 request.getState(request.options.audio_type) ==
863 MediaStreamRequest::STATE_ERROR;
811 if (!audio_done) { 864 if (!audio_done) {
812 return false; 865 return false;
813 } 866 }
814 867
815 const bool video_done = 868 const bool video_done =
816 !requested_video || 869 !requested_video || request.getState(request.options.video_type) ==
817 request.state[request.options.video_type] == DeviceRequest::STATE_DONE || 870 MediaStreamRequest::STATE_DONE ||
818 request.state[request.options.video_type] == DeviceRequest::STATE_ERROR; 871 request.getState(request.options.video_type) ==
872 MediaStreamRequest::STATE_ERROR;
819 if (!video_done) { 873 if (!video_done) {
820 return false; 874 return false;
821 } 875 }
822 876
823 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin(); 877 for (StreamDeviceInfoArray::const_iterator it = request.devices.begin();
824 it != request.devices.end(); ++it) { 878 it != request.devices.end(); ++it) {
825 if (it->in_use == false) { 879 if (it->in_use == false) {
826 return false; 880 return false;
827 } 881 }
828 } 882 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 it != requests_.end(); ++it) { 946 it != requests_.end(); ++it) {
893 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES && 947 if (it->second.type == DeviceRequest::ENUMERATE_DEVICES &&
894 Requested(it->second.options, stream_type)) { 948 Requested(it->second.options, stream_type)) {
895 return true; 949 return true;
896 } 950 }
897 } 951 }
898 return false; 952 return false;
899 } 953 }
900 954
901 } // namespace media_stream 955 } // namespace media_stream
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698