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

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

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/stl_util.h" 18 #include "base/stl_util.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 114
114 namespace content { 115 namespace content {
115 116
116 VideoCaptureManager::DeviceEntry::DeviceEntry( 117 VideoCaptureManager::DeviceEntry::DeviceEntry(
117 MediaStreamType stream_type, 118 MediaStreamType stream_type,
118 const std::string& id, 119 const std::string& id,
119 scoped_ptr<VideoCaptureController> controller) 120 scoped_ptr<VideoCaptureController> controller)
120 : serial_id(g_device_start_id++), 121 : serial_id(g_device_start_id++),
121 stream_type(stream_type), 122 stream_type(stream_type),
122 id(id), 123 id(id),
123 video_capture_controller_(controller.Pass()) {} 124 video_capture_controller_(std::move(controller)) {}
124 125
125 VideoCaptureManager::DeviceEntry::~DeviceEntry() { 126 VideoCaptureManager::DeviceEntry::~DeviceEntry() {
126 DCHECK(thread_checker_.CalledOnValidThread()); 127 DCHECK(thread_checker_.CalledOnValidThread());
127 // DCHECK that this DeviceEntry does not still own a 128 // DCHECK that this DeviceEntry does not still own a
128 // media::VideoCaptureDevice. media::VideoCaptureDevice must be deleted on 129 // media::VideoCaptureDevice. media::VideoCaptureDevice must be deleted on
129 // the device thread. 130 // the device thread.
130 DCHECK(video_capture_device_ == nullptr); 131 DCHECK(video_capture_device_ == nullptr);
131 } 132 }
132 133
133 void VideoCaptureManager::DeviceEntry::SetVideoCaptureDevice( 134 void VideoCaptureManager::DeviceEntry::SetVideoCaptureDevice(
134 scoped_ptr<media::VideoCaptureDevice> device) { 135 scoped_ptr<media::VideoCaptureDevice> device) {
135 DCHECK(thread_checker_.CalledOnValidThread()); 136 DCHECK(thread_checker_.CalledOnValidThread());
136 video_capture_device_.swap(device); 137 video_capture_device_.swap(device);
137 } 138 }
138 139
139 scoped_ptr<media::VideoCaptureDevice> 140 scoped_ptr<media::VideoCaptureDevice>
140 VideoCaptureManager::DeviceEntry::ReleaseVideoCaptureDevice() { 141 VideoCaptureManager::DeviceEntry::ReleaseVideoCaptureDevice() {
141 DCHECK(thread_checker_.CalledOnValidThread()); 142 DCHECK(thread_checker_.CalledOnValidThread());
142 return video_capture_device_.Pass(); 143 return std::move(video_capture_device_);
143 } 144 }
144 145
145 VideoCaptureController* 146 VideoCaptureController*
146 VideoCaptureManager::DeviceEntry::video_capture_controller() { 147 VideoCaptureManager::DeviceEntry::video_capture_controller() {
147 DCHECK(thread_checker_.CalledOnValidThread()); 148 DCHECK(thread_checker_.CalledOnValidThread());
148 return video_capture_controller_.get(); 149 return video_capture_controller_.get();
149 } 150 }
150 151
151 media::VideoCaptureDevice* 152 media::VideoCaptureDevice*
152 VideoCaptureManager::DeviceEntry::video_capture_device() { 153 VideoCaptureManager::DeviceEntry::video_capture_device() {
153 DCHECK(thread_checker_.CalledOnValidThread()); 154 DCHECK(thread_checker_.CalledOnValidThread());
154 return video_capture_device_.get(); 155 return video_capture_device_.get();
155 } 156 }
156 157
157 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest( 158 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest(
158 int serial_id, 159 int serial_id,
159 media::VideoCaptureSessionId session_id, 160 media::VideoCaptureSessionId session_id,
160 const media::VideoCaptureParams& params) 161 const media::VideoCaptureParams& params)
161 : serial_id_(serial_id), 162 : serial_id_(serial_id),
162 session_id_(session_id), 163 session_id_(session_id),
163 params_(params), 164 params_(params),
164 abort_start_(false) { 165 abort_start_(false) {
165 } 166 }
166 167
167 VideoCaptureManager::VideoCaptureManager( 168 VideoCaptureManager::VideoCaptureManager(
168 scoped_ptr<media::VideoCaptureDeviceFactory> factory) 169 scoped_ptr<media::VideoCaptureDeviceFactory> factory)
169 : listener_(NULL), 170 : listener_(NULL),
170 new_capture_session_id_(1), 171 new_capture_session_id_(1),
171 video_capture_device_factory_(factory.Pass()) { 172 video_capture_device_factory_(std::move(factory)) {}
172 }
173 173
174 VideoCaptureManager::~VideoCaptureManager() { 174 VideoCaptureManager::~VideoCaptureManager() {
175 DCHECK(devices_.empty()); 175 DCHECK(devices_.empty());
176 DCHECK(device_start_queue_.empty()); 176 DCHECK(device_start_queue_.empty());
177 } 177 }
178 178
179 void VideoCaptureManager::Register( 179 void VideoCaptureManager::Register(
180 MediaStreamProviderListener* listener, 180 MediaStreamProviderListener* listener,
181 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { 181 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) {
182 DCHECK_CURRENTLY_ON(BrowserThread::IO); 182 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 438 }
439 } else { 439 } else {
440 DeviceEntries::iterator entry_it = std::find_if( 440 DeviceEntries::iterator entry_it = std::find_if(
441 devices_.begin(), devices_.end(), 441 devices_.begin(), devices_.end(),
442 [serial_id] (const DeviceEntry* e) { 442 [serial_id] (const DeviceEntry* e) {
443 return e->serial_id == serial_id; 443 return e->serial_id == serial_id;
444 }); 444 });
445 DCHECK(entry_it != devices_.end()); 445 DCHECK(entry_it != devices_.end());
446 DeviceEntry* entry = *entry_it; 446 DeviceEntry* entry = *entry_it;
447 DCHECK(!entry->video_capture_device()); 447 DCHECK(!entry->video_capture_device());
448 entry->SetVideoCaptureDevice(device.Pass()); 448 entry->SetVideoCaptureDevice(std::move(device));
449 449
450 if (entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { 450 if (entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE) {
451 const media::VideoCaptureSessionId session_id = 451 const media::VideoCaptureSessionId session_id =
452 device_start_queue_.front().session_id(); 452 device_start_queue_.front().session_id();
453 MaybePostDesktopCaptureWindowId(session_id); 453 MaybePostDesktopCaptureWindowId(session_id);
454 } 454 }
455 } 455 }
456 456
457 device_start_queue_.pop_front(); 457 device_start_queue_.pop_front();
458 HandleQueuedStartRequest(); 458 HandleQueuedStartRequest();
459 } 459 }
460 460
461 scoped_ptr<media::VideoCaptureDevice> 461 scoped_ptr<media::VideoCaptureDevice>
462 VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread( 462 VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread(
463 const media::VideoCaptureDevice::Name& name, 463 const media::VideoCaptureDevice::Name& name,
464 const media::VideoCaptureParams& params, 464 const media::VideoCaptureParams& params,
465 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 465 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
466 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 466 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
467 DCHECK(IsOnDeviceThread()); 467 DCHECK(IsOnDeviceThread());
468 468
469 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 469 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
470 video_capture_device = video_capture_device_factory_->Create(name); 470 video_capture_device = video_capture_device_factory_->Create(name);
471 471
472 if (!video_capture_device) { 472 if (!video_capture_device) {
473 device_client->OnError(FROM_HERE, "Could not create capture device"); 473 device_client->OnError(FROM_HERE, "Could not create capture device");
474 return nullptr; 474 return nullptr;
475 } 475 }
476 476
477 video_capture_device->AllocateAndStart(params, device_client.Pass()); 477 video_capture_device->AllocateAndStart(params, std::move(device_client));
478 return video_capture_device.Pass(); 478 return video_capture_device;
479 } 479 }
480 480
481 scoped_ptr<media::VideoCaptureDevice> 481 scoped_ptr<media::VideoCaptureDevice>
482 VideoCaptureManager::DoStartTabCaptureOnDeviceThread( 482 VideoCaptureManager::DoStartTabCaptureOnDeviceThread(
483 const std::string& id, 483 const std::string& id,
484 const media::VideoCaptureParams& params, 484 const media::VideoCaptureParams& params,
485 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 485 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
486 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 486 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
487 DCHECK(IsOnDeviceThread()); 487 DCHECK(IsOnDeviceThread());
488 488
489 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 489 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
490 video_capture_device.reset(WebContentsVideoCaptureDevice::Create(id)); 490 video_capture_device.reset(WebContentsVideoCaptureDevice::Create(id));
491 491
492 if (!video_capture_device) { 492 if (!video_capture_device) {
493 device_client->OnError(FROM_HERE, "Could not create capture device"); 493 device_client->OnError(FROM_HERE, "Could not create capture device");
494 return nullptr; 494 return nullptr;
495 } 495 }
496 496
497 video_capture_device->AllocateAndStart(params, device_client.Pass()); 497 video_capture_device->AllocateAndStart(params, std::move(device_client));
498 return video_capture_device.Pass(); 498 return video_capture_device;
499 } 499 }
500 500
501 scoped_ptr<media::VideoCaptureDevice> 501 scoped_ptr<media::VideoCaptureDevice>
502 VideoCaptureManager::DoStartDesktopCaptureOnDeviceThread( 502 VideoCaptureManager::DoStartDesktopCaptureOnDeviceThread(
503 const std::string& id, 503 const std::string& id,
504 const media::VideoCaptureParams& params, 504 const media::VideoCaptureParams& params,
505 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 505 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
506 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 506 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
507 DCHECK(IsOnDeviceThread()); 507 DCHECK(IsOnDeviceThread());
508 508
509 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 509 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
510 #if defined(ENABLE_SCREEN_CAPTURE) 510 #if defined(ENABLE_SCREEN_CAPTURE)
511 DesktopMediaID desktop_id = DesktopMediaID::Parse(id); 511 DesktopMediaID desktop_id = DesktopMediaID::Parse(id);
512 if (!desktop_id.is_null()) { 512 if (!desktop_id.is_null()) {
513 #if defined(USE_AURA) 513 #if defined(USE_AURA)
514 video_capture_device = DesktopCaptureDeviceAura::Create(desktop_id); 514 video_capture_device = DesktopCaptureDeviceAura::Create(desktop_id);
515 #endif 515 #endif
516 if (!video_capture_device) 516 if (!video_capture_device)
517 video_capture_device = DesktopCaptureDevice::Create(desktop_id); 517 video_capture_device = DesktopCaptureDevice::Create(desktop_id);
518 } 518 }
519 #endif // defined(ENABLE_SCREEN_CAPTURE) 519 #endif // defined(ENABLE_SCREEN_CAPTURE)
520 520
521 if (!video_capture_device) { 521 if (!video_capture_device) {
522 device_client->OnError(FROM_HERE, "Could not create capture device"); 522 device_client->OnError(FROM_HERE, "Could not create capture device");
523 return nullptr; 523 return nullptr;
524 } 524 }
525 525
526 video_capture_device->AllocateAndStart(params, device_client.Pass()); 526 video_capture_device->AllocateAndStart(params, std::move(device_client));
527 return video_capture_device.Pass(); 527 return video_capture_device;
528 } 528 }
529 529
530 void VideoCaptureManager::StartCaptureForClient( 530 void VideoCaptureManager::StartCaptureForClient(
531 media::VideoCaptureSessionId session_id, 531 media::VideoCaptureSessionId session_id,
532 const media::VideoCaptureParams& params, 532 const media::VideoCaptureParams& params,
533 base::ProcessHandle client_render_process, 533 base::ProcessHandle client_render_process,
534 VideoCaptureControllerID client_id, 534 VideoCaptureControllerID client_id,
535 VideoCaptureControllerEventHandler* client_handler, 535 VideoCaptureControllerEventHandler* client_handler,
536 const DoneCB& done_cb) { 536 const DoneCB& done_cb) {
537 DCHECK_CURRENTLY_ON(BrowserThread::IO); 537 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 GetDeviceEntryForMediaStreamDevice(device_info); 917 GetDeviceEntryForMediaStreamDevice(device_info);
918 if (existing_device) { 918 if (existing_device) {
919 DCHECK_EQ(device_info.type, existing_device->stream_type); 919 DCHECK_EQ(device_info.type, existing_device->stream_type);
920 return existing_device; 920 return existing_device;
921 } 921 }
922 922
923 const int max_buffers = device_info.type == MEDIA_TAB_VIDEO_CAPTURE ? 923 const int max_buffers = device_info.type == MEDIA_TAB_VIDEO_CAPTURE ?
924 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers; 924 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers;
925 scoped_ptr<VideoCaptureController> video_capture_controller( 925 scoped_ptr<VideoCaptureController> video_capture_controller(
926 new VideoCaptureController(max_buffers)); 926 new VideoCaptureController(max_buffers));
927 DeviceEntry* new_device = new DeviceEntry(device_info.type, 927 DeviceEntry* new_device = new DeviceEntry(
928 device_info.id, 928 device_info.type, device_info.id, std::move(video_capture_controller));
929 video_capture_controller.Pass());
930 devices_.push_back(new_device); 929 devices_.push_back(new_device);
931 return new_device; 930 return new_device;
932 } 931 }
933 932
934 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById( 933 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById(
935 const std::string& id, 934 const std::string& id,
936 media::VideoCaptureDeviceInfos& device_vector) { 935 media::VideoCaptureDeviceInfos& device_vector) {
937 for (auto& it : device_vector) { 936 for (auto& it : device_vector) {
938 if (it.name.id() == id) 937 if (it.name.id() == id)
939 return &(it); 938 return &(it);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 DCHECK_CURRENTLY_ON(BrowserThread::IO); 972 DCHECK_CURRENTLY_ON(BrowserThread::IO);
974 BrowserThread::PostTaskAndReply( 973 BrowserThread::PostTaskAndReply(
975 BrowserThread::UI, FROM_HERE, 974 BrowserThread::UI, FROM_HERE,
976 base::Bind(&AVFoundationGlue::InitializeAVFoundation), 975 base::Bind(&AVFoundationGlue::InitializeAVFoundation),
977 base::Bind(&VideoCaptureManager::OnDeviceLayerInitialized, this, 976 base::Bind(&VideoCaptureManager::OnDeviceLayerInitialized, this,
978 and_then)); 977 and_then));
979 } 978 }
980 #endif 979 #endif
981 980
982 } // namespace content 981 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698