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

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

Powered by Google App Engine
This is Rietveld 408576698