OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
25 #include "base/task_runner_util.h" | 25 #include "base/task_runner_util.h" |
26 #include "base/threading/thread.h" | 26 #include "base/threading/thread.h" |
27 #include "base/threading/thread_local.h" | 27 #include "base/threading/thread_local.h" |
28 #include "build/build_config.h" | 28 #include "build/build_config.h" |
29 #include "content/browser/child_process_security_policy_impl.h" | 29 #include "content/browser/child_process_security_policy_impl.h" |
30 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 30 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 31 #include "content/browser/renderer_host/media/in_process_video_capture_provider.
h" |
31 #include "content/browser/renderer_host/media/media_capture_devices_impl.h" | 32 #include "content/browser/renderer_host/media/media_capture_devices_impl.h" |
32 #include "content/browser/renderer_host/media/media_devices_manager.h" | 33 #include "content/browser/renderer_host/media/media_devices_manager.h" |
33 #include "content/browser/renderer_host/media/media_stream_requester.h" | 34 #include "content/browser/renderer_host/media/media_stream_requester.h" |
34 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 35 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
35 #include "content/browser/renderer_host/media/video_capture_manager.h" | 36 #include "content/browser/renderer_host/media/video_capture_manager.h" |
36 #include "content/browser/renderer_host/render_process_host_impl.h" | 37 #include "content/browser/renderer_host/render_process_host_impl.h" |
37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
38 #include "content/public/browser/content_browser_client.h" | 39 #include "content/public/browser/content_browser_client.h" |
39 #include "content/public/browser/desktop_media_id.h" | 40 #include "content/public/browser/desktop_media_id.h" |
40 #include "content/public/browser/media_observer.h" | 41 #include "content/public/browser/media_observer.h" |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 MediaStreamManager* msm = g_media_stream_manager_tls_ptr.Pointer()->Get(); | 388 MediaStreamManager* msm = g_media_stream_manager_tls_ptr.Pointer()->Get(); |
388 if (!msm) { | 389 if (!msm) { |
389 DLOG(ERROR) << "No MediaStreamManager on the IO thread. " << message; | 390 DLOG(ERROR) << "No MediaStreamManager on the IO thread. " << message; |
390 return; | 391 return; |
391 } | 392 } |
392 | 393 |
393 msm->AddLogMessageOnIOThread(message); | 394 msm->AddLogMessageOnIOThread(message); |
394 } | 395 } |
395 | 396 |
396 MediaStreamManager::MediaStreamManager(media::AudioSystem* audio_system) | 397 MediaStreamManager::MediaStreamManager(media::AudioSystem* audio_system) |
397 : MediaStreamManager(audio_system, nullptr, nullptr) {} | 398 : MediaStreamManager(audio_system, nullptr) {} |
398 | 399 |
399 MediaStreamManager::MediaStreamManager( | 400 MediaStreamManager::MediaStreamManager( |
400 media::AudioSystem* audio_system, | 401 media::AudioSystem* audio_system, |
401 std::unique_ptr<media::VideoCaptureSystem> video_capture_system, | 402 std::unique_ptr<VideoCaptureProvider> video_capture_provider) |
402 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner) | |
403 : audio_system_(audio_system), | 403 : audio_system_(audio_system), |
404 #if defined(OS_WIN) | 404 #if defined(OS_WIN) |
405 video_capture_thread_("VideoCaptureThread"), | 405 video_capture_thread_("VideoCaptureThread"), |
406 #endif | 406 #endif |
407 use_fake_ui_(base::CommandLine::ForCurrentProcess()->HasSwitch( | 407 use_fake_ui_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
408 switches::kUseFakeUIForMediaStream)) { | 408 switches::kUseFakeUIForMediaStream)) { |
409 DCHECK(audio_system_); | 409 DCHECK(audio_system_); |
410 | 410 |
411 if (!video_capture_system) { | 411 if (!video_capture_provider) { |
412 video_capture_system = base::MakeUnique<media::VideoCaptureSystemImpl>( | 412 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner = |
413 media::VideoCaptureDeviceFactory::CreateFactory( | 413 audio_system_->GetTaskRunner(); |
414 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); | |
415 } | |
416 if (!device_task_runner) { | |
417 device_task_runner = audio_system_->GetTaskRunner(); | |
418 #if defined(OS_WIN) | 414 #if defined(OS_WIN) |
419 // Use an STA Video Capture Thread to try to avoid crashes on enumeration of | 415 // Use an STA Video Capture Thread to try to avoid crashes on enumeration of |
420 // buggy third party Direct Show modules, http://crbug.com/428958. | 416 // buggy third party Direct Show modules, http://crbug.com/428958. |
421 video_capture_thread_.init_com_with_mta(false); | 417 video_capture_thread_.init_com_with_mta(false); |
422 CHECK(video_capture_thread_.Start()); | 418 CHECK(video_capture_thread_.Start()); |
423 device_task_runner = video_capture_thread_.task_runner(); | 419 device_task_runner = video_capture_thread_.task_runner(); |
424 #endif | 420 #endif |
| 421 video_capture_provider = base::MakeUnique<InProcessVideoCaptureProvider>( |
| 422 base::MakeUnique<media::VideoCaptureSystemImpl>( |
| 423 media::VideoCaptureDeviceFactory::CreateFactory( |
| 424 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))), |
| 425 std::move(device_task_runner)); |
425 } | 426 } |
426 InitializeMaybeAsync(std::move(video_capture_system), | 427 InitializeMaybeAsync(std::move(video_capture_provider)); |
427 std::move(device_task_runner)); | |
428 | 428 |
429 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 429 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
430 // BrowserMainLoop always creates the PowerMonitor instance before creating | 430 // BrowserMainLoop always creates the PowerMonitor instance before creating |
431 // MediaStreamManager, but power_monitor may be NULL in unit tests. | 431 // MediaStreamManager, but power_monitor may be NULL in unit tests. |
432 if (power_monitor) | 432 if (power_monitor) |
433 power_monitor->AddObserver(this); | 433 power_monitor->AddObserver(this); |
434 } | 434 } |
435 | 435 |
436 MediaStreamManager::~MediaStreamManager() { | 436 MediaStreamManager::~MediaStreamManager() { |
437 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::IO)); | 437 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::IO)); |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 DeviceRequest* request, | 1222 DeviceRequest* request, |
1223 const MediaStreamDevices& devices) { | 1223 const MediaStreamDevices& devices) { |
1224 if (!request->callback.is_null()) | 1224 if (!request->callback.is_null()) |
1225 request->callback.Run(devices, std::move(request->ui_proxy)); | 1225 request->callback.Run(devices, std::move(request->ui_proxy)); |
1226 | 1226 |
1227 // Delete the request since it is done. | 1227 // Delete the request since it is done. |
1228 DeleteRequest(label); | 1228 DeleteRequest(label); |
1229 } | 1229 } |
1230 | 1230 |
1231 void MediaStreamManager::InitializeMaybeAsync( | 1231 void MediaStreamManager::InitializeMaybeAsync( |
1232 std::unique_ptr<media::VideoCaptureSystem> video_capture_system, | 1232 std::unique_ptr<VideoCaptureProvider> video_capture_provider) { |
1233 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner) { | |
1234 // Some unit tests initialize the MSM in the IO thread and assume the | 1233 // Some unit tests initialize the MSM in the IO thread and assume the |
1235 // initialization is done synchronously. Other clients call this from a | 1234 // initialization is done synchronously. Other clients call this from a |
1236 // different thread and expect initialization to run asynchronously. | 1235 // different thread and expect initialization to run asynchronously. |
1237 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 1236 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
1238 BrowserThread::PostTask( | 1237 BrowserThread::PostTask( |
1239 BrowserThread::IO, FROM_HERE, | 1238 BrowserThread::IO, FROM_HERE, |
1240 base::Bind(&MediaStreamManager::InitializeMaybeAsync, | 1239 base::Bind(&MediaStreamManager::InitializeMaybeAsync, |
1241 base::Unretained(this), base::Passed(&video_capture_system), | 1240 base::Unretained(this), |
1242 std::move(device_task_runner))); | 1241 base::Passed(&video_capture_provider))); |
1243 return; | 1242 return; |
1244 } | 1243 } |
1245 | 1244 |
1246 // Store a pointer to |this| on the IO thread to avoid having to jump to the | 1245 // Store a pointer to |this| on the IO thread to avoid having to jump to the |
1247 // UI thread to fetch a pointer to the MSM. In particular on Android, it can | 1246 // UI thread to fetch a pointer to the MSM. In particular on Android, it can |
1248 // be problematic to post to a UI thread from arbitrary worker threads since | 1247 // be problematic to post to a UI thread from arbitrary worker threads since |
1249 // attaching to the VM is required and we may have to access the MSM from | 1248 // attaching to the VM is required and we may have to access the MSM from |
1250 // callback threads that we don't own and don't want to attach. | 1249 // callback threads that we don't own and don't want to attach. |
1251 g_media_stream_manager_tls_ptr.Pointer()->Set(this); | 1250 g_media_stream_manager_tls_ptr.Pointer()->Set(this); |
1252 | 1251 |
(...skipping 20 matching lines...) Expand all Loading... |
1273 // We want to be notified of IO message loop destruction to delete the thread | 1272 // We want to be notified of IO message loop destruction to delete the thread |
1274 // and the device managers. | 1273 // and the device managers. |
1275 base::MessageLoop::current()->AddDestructionObserver(this); | 1274 base::MessageLoop::current()->AddDestructionObserver(this); |
1276 | 1275 |
1277 // TODO(dalecurtis): Remove ScopedTracker below once crbug.com/457525 is | 1276 // TODO(dalecurtis): Remove ScopedTracker below once crbug.com/457525 is |
1278 // fixed. | 1277 // fixed. |
1279 tracked_objects::ScopedTracker tracking_profile4( | 1278 tracked_objects::ScopedTracker tracking_profile4( |
1280 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1279 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1281 "457525 MediaStreamManager::InitializeDeviceManagersOnIOThread 4")); | 1280 "457525 MediaStreamManager::InitializeDeviceManagersOnIOThread 4")); |
1282 | 1281 |
1283 video_capture_manager_ = new VideoCaptureManager( | 1282 video_capture_manager_ = |
1284 std::move(video_capture_system), std::move(device_task_runner)); | 1283 new VideoCaptureManager(std::move(video_capture_provider)); |
1285 video_capture_manager_->RegisterListener(this); | 1284 video_capture_manager_->RegisterListener(this); |
1286 | 1285 |
1287 media_devices_manager_.reset( | 1286 media_devices_manager_.reset( |
1288 new MediaDevicesManager(audio_system_, video_capture_manager_, this)); | 1287 new MediaDevicesManager(audio_system_, video_capture_manager_, this)); |
1289 } | 1288 } |
1290 | 1289 |
1291 void MediaStreamManager::Opened(MediaStreamType stream_type, | 1290 void MediaStreamManager::Opened(MediaStreamType stream_type, |
1292 int capture_session_id) { | 1291 int capture_session_id) { |
1293 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1292 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
1294 DVLOG(1) << "Opened({stream_type = " << stream_type << "} " | 1293 DVLOG(1) << "Opened({stream_type = " << stream_type << "} " |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 request->ui_proxy->OnStarted( | 1774 request->ui_proxy->OnStarted( |
1776 base::Bind(&MediaStreamManager::StopMediaStreamFromBrowser, | 1775 base::Bind(&MediaStreamManager::StopMediaStreamFromBrowser, |
1777 base::Unretained(this), label), | 1776 base::Unretained(this), label), |
1778 base::Bind(&MediaStreamManager::OnMediaStreamUIWindowId, | 1777 base::Bind(&MediaStreamManager::OnMediaStreamUIWindowId, |
1779 base::Unretained(this), request->video_type(), | 1778 base::Unretained(this), request->video_type(), |
1780 request->devices)); | 1779 request->devices)); |
1781 } | 1780 } |
1782 } | 1781 } |
1783 | 1782 |
1784 } // namespace content | 1783 } // namespace content |
OLD | NEW |