Chromium Code Reviews| 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 <list> | 7 #include <list> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "content/browser/browser_main_loop.h" | |
| 17 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 18 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 18 #include "content/browser/renderer_host/media/device_request_message_filter.h" | 19 #include "content/browser/renderer_host/media/device_request_message_filter.h" |
| 19 #include "content/browser/renderer_host/media/media_stream_requester.h" | 20 #include "content/browser/renderer_host/media/media_stream_requester.h" |
| 20 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 21 #include "content/browser/renderer_host/media/video_capture_manager.h" | 22 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 22 #include "content/browser/renderer_host/media/web_contents_capture_util.h" | 23 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
| 24 #include "content/browser/renderer_host/render_process_host_impl.h" | |
| 23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
| 25 #include "content/public/browser/media_device_id.h" | 27 #include "content/public/browser/media_device_id.h" |
| 26 #include "content/public/browser/media_observer.h" | 28 #include "content/public/browser/media_observer.h" |
| 27 #include "content/public/browser/media_request_state.h" | 29 #include "content/public/browser/media_request_state.h" |
| 30 #include "content/public/browser/render_process_host.h" | |
| 28 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 29 #include "content/public/common/media_stream_request.h" | 32 #include "content/public/common/media_stream_request.h" |
| 30 #include "media/audio/audio_manager_base.h" | 33 #include "media/audio/audio_manager_base.h" |
| 31 #include "media/audio/audio_parameters.h" | 34 #include "media/audio/audio_parameters.h" |
| 32 #include "media/base/channel_layout.h" | 35 #include "media/base/channel_layout.h" |
| 33 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 34 | 37 |
| 35 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 36 #include "base/win/scoped_com_initializer.h" | 39 #include "base/win/scoped_com_initializer.h" |
| 37 #endif | 40 #endif |
| 38 | 41 |
| 42 static void DoAddLogMessage(const std::string& message) { | |
|
tommi (sloooow) - chröme
2014/01/24 12:34:54
I think //content prefers anonymous namespaces (ev
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done.
| |
| 43 // Must be on the UI thread to access BrowserMainLoop. | |
| 44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 45 // May be null in tests. | |
| 46 // TODO(vrk): Handle this more elegantly by having native log messages become | |
| 47 // no-ops until MediaStreamManager is aware that a renderer process has | |
| 48 // started logging. crbug.com/333894 | |
| 49 if (content::BrowserMainLoop::GetInstance()) { | |
| 50 content::BrowserMainLoop::GetInstance()-> | |
| 51 media_stream_manager()->AddLogMessageOnUIThread(message); | |
| 52 } | |
| 53 } | |
| 54 | |
| 39 namespace content { | 55 namespace content { |
| 40 | 56 |
| 41 namespace { | 57 namespace { |
| 42 // Creates a random label used to identify requests. | 58 // Creates a random label used to identify requests. |
| 43 std::string RandomLabel() { | 59 std::string RandomLabel() { |
| 44 // An earlier PeerConnection spec, | 60 // An earlier PeerConnection spec, |
| 45 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the | 61 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the |
| 46 // MediaStream::label alphabet as containing 36 characters from | 62 // MediaStream::label alphabet as containing 36 characters from |
| 47 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, | 63 // range: U+0021, U+0023 to U+0027, U+002A to U+002B, U+002D to U+002E, |
| 48 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. | 64 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 ++it) { | 855 ++it) { |
| 840 if (content::DoesMediaDeviceIDMatchHMAC(rc, security_origin, source_id, | 856 if (content::DoesMediaDeviceIDMatchHMAC(rc, security_origin, source_id, |
| 841 it->device.id)) { | 857 it->device.id)) { |
| 842 *device_id = it->device.id; | 858 *device_id = it->device.id; |
| 843 return true; | 859 return true; |
| 844 } | 860 } |
| 845 } | 861 } |
| 846 return false; | 862 return false; |
| 847 } | 863 } |
| 848 | 864 |
| 865 void MediaStreamManager::LogDevicesToNativeLogs( | |
| 866 MediaStreamType stream_type, | |
| 867 const StreamDeviceInfoArray& devices) { | |
| 868 std::stringstream devices_msg; | |
| 869 devices_msg << "Devices found for stream type " << stream_type << ":" | |
| 870 << std::endl; | |
| 871 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); | |
| 872 it != devices.end(); ++it) { | |
| 873 devices_msg << " " << it->device.name << " (" | |
| 874 << it->device.id << ")" << std::endl; | |
|
no longer working on chromium
2014/01/24 09:54:38
btw, are you supposed to log the device_id? has th
tommi (sloooow) - chröme
2014/01/24 12:34:54
Agreed. To be safe we should either skip logging t
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Removed. (Fwiw I also sent a mail to kaichou@ with
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done, just omitted.
| |
| 875 } | |
| 876 if (devices.empty()) | |
|
no longer working on chromium
2014/01/24 09:54:38
nit, I think it is cleaner to do:
if (devices.empt
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done.
| |
| 877 devices_msg << "No devices found."; | |
| 878 | |
| 879 DVLOG(1) << devices_msg; | |
| 880 SendMessageToNativeLog(devices_msg.str()); | |
| 881 } | |
| 882 | |
| 849 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { | 883 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
| 850 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 884 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| 851 cache->valid = false; | 885 cache->valid = false; |
| 852 } | 886 } |
| 853 | 887 |
| 854 bool MediaStreamManager::EnumerationRequired(EnumerationCache* cache, | 888 bool MediaStreamManager::EnumerationRequired(EnumerationCache* cache, |
| 855 MediaStreamType stream_type) { | 889 MediaStreamType stream_type) { |
| 856 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 890 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
| 857 if (stream_type == MEDIA_NO_SERVICE) | 891 if (stream_type == MEDIA_NO_SERVICE) |
| 858 return false; | 892 return false; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 FinalizeRequestFailed(label, request); | 1041 FinalizeRequestFailed(label, request); |
| 1008 return; | 1042 return; |
| 1009 } | 1043 } |
| 1010 | 1044 |
| 1011 if (!is_web_contents_capture && !is_screen_capture) { | 1045 if (!is_web_contents_capture && !is_screen_capture) { |
| 1012 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || | 1046 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || |
| 1013 EnumerationRequired(&video_enumeration_cache_, video_type)) { | 1047 EnumerationRequired(&video_enumeration_cache_, video_type)) { |
| 1014 // Enumerate the devices if there is no valid device lists to be used. | 1048 // Enumerate the devices if there is no valid device lists to be used. |
| 1015 StartEnumeration(request); | 1049 StartEnumeration(request); |
| 1016 return; | 1050 return; |
| 1051 } else { | |
| 1052 // Cache is valid, so log the cached devices. | |
|
no longer working on chromium
2014/01/24 09:54:38
are you sure you want to log the cache for each Se
no longer working on chromium
2014/01/24 10:36:17
Per pointed out that only media stream requests we
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Thanks for letting me know. I don't think there wi
| |
| 1053 SendMessageToNativeLog("Using cached devices for request."); | |
|
tommi (sloooow) - chröme
2014/01/24 12:34:54
Would it make sense to aggregate all these message
| |
| 1054 LogDevicesToNativeLogs(audio_type, audio_enumeration_cache_.devices); | |
| 1055 LogDevicesToNativeLogs(video_type, video_enumeration_cache_.devices); | |
|
no longer working on chromium
2014/01/24 09:54:38
what do you log if the type is MEDIA_NO_SERVICE ?
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
See LogDevicesToNativeLogs - it would log the MEDI
| |
| 1017 } | 1056 } |
| 1018 | 1057 |
| 1019 if (!SetupDeviceCaptureRequest(request)) { | 1058 if (!SetupDeviceCaptureRequest(request)) { |
| 1020 FinalizeRequestFailed(label, request); | 1059 FinalizeRequestFailed(label, request); |
| 1021 return; | 1060 return; |
| 1022 } | 1061 } |
| 1023 } | 1062 } |
| 1024 PostRequestToUI(label, request); | 1063 PostRequestToUI(label, request); |
| 1025 } | 1064 } |
| 1026 | 1065 |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1396 | 1435 |
| 1397 void MediaStreamManager::Closed(MediaStreamType stream_type, | 1436 void MediaStreamManager::Closed(MediaStreamType stream_type, |
| 1398 int capture_session_id) { | 1437 int capture_session_id) { |
| 1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1400 } | 1439 } |
| 1401 | 1440 |
| 1402 void MediaStreamManager::DevicesEnumerated( | 1441 void MediaStreamManager::DevicesEnumerated( |
| 1403 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { | 1442 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { |
| 1404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1405 DVLOG(1) << "DevicesEnumerated(" | 1444 DVLOG(1) << "DevicesEnumerated(" |
| 1406 << ", {stream_type = " << stream_type << "})"; | 1445 << "{stream_type = " << stream_type << "})" << std::endl; |
| 1446 | |
| 1447 SendMessageToNativeLog("New device enumeration result:"); | |
| 1448 LogDevicesToNativeLogs(stream_type, devices); | |
| 1407 | 1449 |
| 1408 // Only cache the device list when the device list has been changed. | 1450 // Only cache the device list when the device list has been changed. |
| 1409 bool need_update_clients = false; | 1451 bool need_update_clients = false; |
| 1410 EnumerationCache* cache = | 1452 EnumerationCache* cache = |
| 1411 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? | 1453 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
| 1412 &audio_enumeration_cache_ : &video_enumeration_cache_; | 1454 &audio_enumeration_cache_ : &video_enumeration_cache_; |
| 1413 if (!cache->valid || | 1455 if (!cache->valid || |
| 1414 devices.size() != cache->devices.size() || | 1456 devices.size() != cache->devices.size() || |
| 1415 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), | 1457 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), |
| 1416 StreamDeviceInfo::IsEqual)) { | 1458 StreamDeviceInfo::IsEqual)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1469 else | 1511 else |
| 1470 PostRequestToUI(*it, request); | 1512 PostRequestToUI(*it, request); |
| 1471 break; | 1513 break; |
| 1472 } | 1514 } |
| 1473 } | 1515 } |
| 1474 label_list.clear(); | 1516 label_list.clear(); |
| 1475 --active_enumeration_ref_count_[stream_type]; | 1517 --active_enumeration_ref_count_[stream_type]; |
| 1476 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 1518 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
| 1477 } | 1519 } |
| 1478 | 1520 |
| 1521 // static | |
| 1522 void MediaStreamManager::SendMessageToNativeLog(const std::string& message) { | |
| 1523 BrowserThread::PostTask( | |
| 1524 BrowserThread::UI, FROM_HERE, | |
|
no longer working on chromium
2014/01/24 09:54:38
I have some concern on the thread safety here. Pre
tommi (sloooow) - chröme
2014/01/24 12:34:54
Actually, this method is static and the task that
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
I believe so as well, so leaving as is.
| |
| 1525 base::Bind(::DoAddLogMessage, message)); | |
| 1526 } | |
| 1527 | |
| 1528 void MediaStreamManager::AddLogMessageOnUIThread(const std::string& message) { | |
| 1529 // Must be on the UI thread to access RenderProcessHost from process ID. | |
| 1530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1531 | |
| 1532 // Add logs for each pending request. | |
| 1533 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | |
| 1534 ++it) { | |
| 1535 DeviceRequest* request = it->second; | |
| 1536 // Log the message to all renderers that are requesting a MediaStream or | |
|
perkj_chrome
2014/01/24 09:15:10
Can you expand the comment : that are requesting a
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Done.
| |
| 1537 // device enumeration. | |
| 1538 if (request->request_type == MEDIA_GENERATE_STREAM || | |
| 1539 request->request_type == MEDIA_ENUMERATE_DEVICES) { | |
|
perkj_chrome
2014/01/24 09:15:10
Fyi- MEDIA_ENUMERATE_DEVICES is called by flash fo
vrk (LEFT CHROMIUM)
2014/01/25 00:50:21
Pepper flash? I don't understand why MediaStreamMa
| |
| 1540 content::RenderProcessHostImpl* render_process_host_impl = | |
| 1541 static_cast<content::RenderProcessHostImpl*>( | |
| 1542 content::RenderProcessHost::FromID( | |
| 1543 request->requesting_process_id)); | |
| 1544 if (render_process_host_impl) | |
| 1545 render_process_host_impl->WebRtcLogMessage(message); | |
| 1546 } | |
| 1547 } | |
| 1548 } | |
| 1549 | |
| 1479 void MediaStreamManager::HandleAccessRequestResponse( | 1550 void MediaStreamManager::HandleAccessRequestResponse( |
| 1480 const std::string& label, | 1551 const std::string& label, |
| 1481 const MediaStreamDevices& devices) { | 1552 const MediaStreamDevices& devices) { |
| 1482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1483 DVLOG(1) << "HandleAccessRequestResponse(" | 1554 DVLOG(1) << "HandleAccessRequestResponse(" |
| 1484 << ", {label = " << label << "})"; | 1555 << ", {label = " << label << "})"; |
| 1485 | 1556 |
| 1486 DeviceRequest* request = FindRequest(label); | 1557 DeviceRequest* request = FindRequest(label); |
| 1487 if (!request) { | 1558 if (!request) { |
| 1488 // The request has been canceled before the UI returned. | 1559 // The request has been canceled before the UI returned. |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1704 } | 1775 } |
| 1705 | 1776 |
| 1706 // Always do enumeration even though some enumeration is in progress, | 1777 // Always do enumeration even though some enumeration is in progress, |
| 1707 // because those enumeration commands could be sent before these devices | 1778 // because those enumeration commands could be sent before these devices |
| 1708 // change. | 1779 // change. |
| 1709 ++active_enumeration_ref_count_[stream_type]; | 1780 ++active_enumeration_ref_count_[stream_type]; |
| 1710 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1781 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
| 1711 } | 1782 } |
| 1712 | 1783 |
| 1713 } // namespace content | 1784 } // namespace content |
| OLD | NEW |