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

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

Issue 17846002: Refactor the VideoCaptureDevice::Name struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TabCaptureApiTest tests. Created 7 years, 6 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/video_capture_manager.h" 5 #include "content/browser/renderer_host/media/video_capture_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 DCHECK(IsOnDeviceThread()); 135 DCHECK(IsOnDeviceThread());
136 136
137 media::VideoCaptureDevice::Names device_names; 137 media::VideoCaptureDevice::Names device_names;
138 GetAvailableDevices(stream_type, &device_names); 138 GetAvailableDevices(stream_type, &device_names);
139 139
140 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray()); 140 scoped_ptr<StreamDeviceInfoArray> devices(new StreamDeviceInfoArray());
141 for (media::VideoCaptureDevice::Names::iterator it = 141 for (media::VideoCaptureDevice::Names::iterator it =
142 device_names.begin(); it != device_names.end(); ++it) { 142 device_names.begin(); it != device_names.end(); ++it) {
143 bool opened = DeviceOpened(*it); 143 bool opened = DeviceOpened(*it);
144 devices->push_back(StreamDeviceInfo( 144 devices->push_back(StreamDeviceInfo(
145 stream_type, it->device_name, it->unique_id, opened)); 145 stream_type, it->name(), it->id(), opened));
146 } 146 }
147 147
148 PostOnDevicesEnumerated(stream_type, devices.Pass()); 148 PostOnDevicesEnumerated(stream_type, devices.Pass());
149 } 149 }
150 150
151 void VideoCaptureManager::OnOpen(int capture_session_id, 151 void VideoCaptureManager::OnOpen(int capture_session_id,
152 const StreamDeviceInfo& device) { 152 const StreamDeviceInfo& device) {
153 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.OnOpenTime"); 153 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.OnOpenTime");
154 DCHECK(IsOnDeviceThread()); 154 DCHECK(IsOnDeviceThread());
155 DCHECK(devices_.find(capture_session_id) == devices_.end()); 155 DCHECK(devices_.find(capture_session_id) == devices_.end());
156 DVLOG(1) << "VideoCaptureManager::OnOpen, id " << capture_session_id; 156 DVLOG(1) << "VideoCaptureManager::OnOpen, id " << capture_session_id;
157 157
158 // Check if another session has already opened this device. If so, just 158 // Check if another session has already opened this device. If so, just
159 // use that opened device. 159 // use that opened device.
160 media::VideoCaptureDevice* video_capture_device = GetOpenedDevice(device); 160 media::VideoCaptureDevice* video_capture_device = GetOpenedDevice(device);
161 if (video_capture_device) { 161 if (video_capture_device) {
162 DeviceEntry& new_entry = devices_[capture_session_id]; 162 DeviceEntry& new_entry = devices_[capture_session_id];
163 new_entry.stream_type = device.device.type; 163 new_entry.stream_type = device.device.type;
164 new_entry.capture_device = video_capture_device; 164 new_entry.capture_device = video_capture_device;
165 PostOnOpened(device.device.type, capture_session_id); 165 PostOnOpened(device.device.type, capture_session_id);
166 return; 166 return;
167 } 167 }
168 168
169 // Open the device. 169 // Open the device.
170
171 // FindById will return NULL on failure.
170 media::VideoCaptureDevice::Name vc_device_name; 172 media::VideoCaptureDevice::Name vc_device_name;
171 vc_device_name.device_name = device.device.name; 173 if (device.device.type == MEDIA_DEVICE_VIDEO_CAPTURE) {
172 vc_device_name.unique_id = device.device.id; 174 // We look up the device id from the renderer in our local enumeration
175 // since the renderer does not have all the information that might be
176 // held in the browser-side VideoCaptureDevice::Name structure.
177 media::VideoCaptureDevice::Names device_names;
178 GetAvailableDevices(device.device.type, &device_names);
179 media::VideoCaptureDevice::Name* found =
180 device_names.FindById(device.device.id);
181 if (found)
182 vc_device_name = *found;
183 }
wjia(left Chromium) 2013/06/26 18:16:44 What's the reason to add this logic (of enumeratio
tommi (sloooow) - chröme 2013/06/27 14:46:02 Yes, currently that's going to be the case. The r
184
185 if (vc_device_name.id().empty()) {
186 vc_device_name = media::VideoCaptureDevice::Name(
187 device.device.name, device.device.id);
188 }
173 189
174 if (use_fake_device_) { 190 if (use_fake_device_) {
175 video_capture_device = 191 video_capture_device =
176 media::FakeVideoCaptureDevice::Create(vc_device_name); 192 media::FakeVideoCaptureDevice::Create(vc_device_name);
177 } else { 193 } else {
178 switch (device.device.type) { 194 switch (device.device.type) {
179 case MEDIA_DEVICE_VIDEO_CAPTURE: { 195 case MEDIA_DEVICE_VIDEO_CAPTURE: {
180 video_capture_device = 196 video_capture_device =
181 media::VideoCaptureDevice::Create(vc_device_name); 197 media::VideoCaptureDevice::Create(vc_device_name);
182 break; 198 break;
183 } 199 }
184 case MEDIA_TAB_VIDEO_CAPTURE: { 200 case MEDIA_TAB_VIDEO_CAPTURE: {
185 video_capture_device = WebContentsVideoCaptureDevice::Create( 201 video_capture_device = WebContentsVideoCaptureDevice::Create(
186 vc_device_name.unique_id); 202 vc_device_name.id());
187 break; 203 break;
188 } 204 }
189 case MEDIA_SCREEN_VIDEO_CAPTURE: { 205 case MEDIA_SCREEN_VIDEO_CAPTURE: {
190 #if defined(ENABLE_SCREEN_CAPTURE) 206 #if defined(ENABLE_SCREEN_CAPTURE)
191 scoped_refptr<base::SequencedWorkerPool> blocking_pool = 207 scoped_refptr<base::SequencedWorkerPool> blocking_pool =
192 BrowserThread::GetBlockingPool(); 208 BrowserThread::GetBlockingPool();
193 video_capture_device = new ScreenCaptureDevice( 209 video_capture_device = new ScreenCaptureDevice(
194 blocking_pool->GetSequencedTaskRunner( 210 blocking_pool->GetSequencedTaskRunner(
195 blocking_pool->GetSequenceToken())); 211 blocking_pool->GetSequenceToken()));
196 #endif // defined(ENABLE_SCREEN_CAPTURE) 212 #endif // defined(ENABLE_SCREEN_CAPTURE)
197 break; 213 break;
198 } 214 }
199 default: { 215 default: {
200 NOTIMPLEMENTED(); 216 NOTIMPLEMENTED();
201 break; 217 break;
202 } 218 }
203 } 219 }
204 } 220 }
221
205 if (!video_capture_device) { 222 if (!video_capture_device) {
206 PostOnError(capture_session_id, kDeviceNotAvailable); 223 PostOnError(capture_session_id, kDeviceNotAvailable);
207 return; 224 return;
208 } 225 }
209 226
210 DeviceEntry& new_entry = devices_[capture_session_id]; 227 DeviceEntry& new_entry = devices_[capture_session_id];
211 new_entry.stream_type = device.device.type; 228 new_entry.stream_type = device.device.type;
212 new_entry.capture_device = video_capture_device; 229 new_entry.capture_device = video_capture_device;
213 PostOnOpened(device.device.type, capture_session_id); 230 PostOnOpened(device.device.type, capture_session_id);
214 } 231 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 break; 441 break;
425 } 442 }
426 } 443 }
427 444
428 bool VideoCaptureManager::DeviceOpened( 445 bool VideoCaptureManager::DeviceOpened(
429 const media::VideoCaptureDevice::Name& device_name) { 446 const media::VideoCaptureDevice::Name& device_name) {
430 DCHECK(IsOnDeviceThread()); 447 DCHECK(IsOnDeviceThread());
431 448
432 for (VideoCaptureDevices::iterator it = devices_.begin(); 449 for (VideoCaptureDevices::iterator it = devices_.begin();
433 it != devices_.end(); ++it) { 450 it != devices_.end(); ++it) {
434 if (device_name.unique_id == 451 if (device_name.id() == it->second.capture_device->device_name().id()) {
435 it->second.capture_device->device_name().unique_id) {
436 // We've found the device! 452 // We've found the device!
437 return true; 453 return true;
438 } 454 }
439 } 455 }
440 return false; 456 return false;
441 } 457 }
442 458
443 media::VideoCaptureDevice* VideoCaptureManager::GetOpenedDevice( 459 media::VideoCaptureDevice* VideoCaptureManager::GetOpenedDevice(
444 const StreamDeviceInfo& device_info) { 460 const StreamDeviceInfo& device_info) {
445 DCHECK(IsOnDeviceThread()); 461 DCHECK(IsOnDeviceThread());
446 462
447 for (VideoCaptureDevices::iterator it = devices_.begin(); 463 for (VideoCaptureDevices::iterator it = devices_.begin();
448 it != devices_.end(); it++) { 464 it != devices_.end(); it++) {
449 if (device_info.device.id == 465 if (device_info.device.id ==
450 it->second.capture_device->device_name().unique_id) { 466 it->second.capture_device->device_name().id()) {
451 return it->second.capture_device; 467 return it->second.capture_device;
452 } 468 }
453 } 469 }
454 return NULL; 470 return NULL;
455 } 471 }
456 472
457 bool VideoCaptureManager::DeviceInUse( 473 bool VideoCaptureManager::DeviceInUse(
458 const media::VideoCaptureDevice* video_capture_device) { 474 const media::VideoCaptureDevice* video_capture_device) {
459 DCHECK(IsOnDeviceThread()); 475 DCHECK(IsOnDeviceThread());
460 476
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // Solution for not using MediaStreamManager. 564 // Solution for not using MediaStreamManager.
549 // This session id won't be returned by Open(). 565 // This session id won't be returned by Open().
550 if (capture_session_id == kStartOpenSessionId) { 566 if (capture_session_id == kStartOpenSessionId) {
551 media::VideoCaptureDevice::Names device_names; 567 media::VideoCaptureDevice::Names device_names;
552 GetAvailableDevices(MEDIA_DEVICE_VIDEO_CAPTURE, &device_names); 568 GetAvailableDevices(MEDIA_DEVICE_VIDEO_CAPTURE, &device_names);
553 if (device_names.empty()) { 569 if (device_names.empty()) {
554 // No devices available. 570 // No devices available.
555 return NULL; 571 return NULL;
556 } 572 }
557 StreamDeviceInfo device(MEDIA_DEVICE_VIDEO_CAPTURE, 573 StreamDeviceInfo device(MEDIA_DEVICE_VIDEO_CAPTURE,
558 device_names.front().device_name, 574 device_names.front().name(),
559 device_names.front().unique_id, false); 575 device_names.front().id(),
576 false);
560 577
561 // Call OnOpen to open using the first device in the list. 578 // Call OnOpen to open using the first device in the list.
562 OnOpen(capture_session_id, device); 579 OnOpen(capture_session_id, device);
563 580
564 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); 581 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id);
565 if (dit != devices_.end()) { 582 if (dit != devices_.end()) {
566 return dit->second.capture_device; 583 return dit->second.capture_device;
567 } 584 }
568 } 585 }
569 return NULL; 586 return NULL;
570 } 587 }
571 588
572 } // namespace content 589 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698