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

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

Issue 140633004: Reland CL to implement browser-side logging to WebRtc log. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: This is the original CL, untouched Created 6 years, 10 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 #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/strings/stringprintf.h"
16 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "content/browser/browser_main_loop.h"
17 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 19 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
18 #include "content/browser/renderer_host/media/device_request_message_filter.h" 20 #include "content/browser/renderer_host/media/device_request_message_filter.h"
19 #include "content/browser/renderer_host/media/media_stream_requester.h" 21 #include "content/browser/renderer_host/media/media_stream_requester.h"
20 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 22 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
21 #include "content/browser/renderer_host/media/video_capture_manager.h" 23 #include "content/browser/renderer_host/media/video_capture_manager.h"
22 #include "content/browser/renderer_host/media/web_contents_capture_util.h" 24 #include "content/browser/renderer_host/media/web_contents_capture_util.h"
25 #include "content/browser/renderer_host/render_process_host_impl.h"
23 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/content_browser_client.h" 27 #include "content/public/browser/content_browser_client.h"
25 #include "content/public/browser/media_device_id.h" 28 #include "content/public/browser/media_device_id.h"
26 #include "content/public/browser/media_observer.h" 29 #include "content/public/browser/media_observer.h"
27 #include "content/public/browser/media_request_state.h" 30 #include "content/public/browser/media_request_state.h"
31 #include "content/public/browser/render_process_host.h"
28 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
29 #include "content/public/common/media_stream_request.h" 33 #include "content/public/common/media_stream_request.h"
30 #include "media/audio/audio_manager_base.h" 34 #include "media/audio/audio_manager_base.h"
31 #include "media/audio/audio_parameters.h" 35 #include "media/audio/audio_parameters.h"
32 #include "media/base/channel_layout.h" 36 #include "media/base/channel_layout.h"
33 #include "url/gurl.h" 37 #include "url/gurl.h"
34 38
35 #if defined(OS_WIN) 39 #if defined(OS_WIN)
36 #include "base/win/scoped_com_initializer.h" 40 #include "base/win/scoped_com_initializer.h"
37 #endif 41 #endif
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } else if (video_stream_source == kMediaStreamSourceDesktop) { 100 } else if (video_stream_source == kMediaStreamSourceDesktop) {
97 *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; 101 *video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE;
98 } 102 }
99 } else { 103 } else {
100 // This is normal video device capture. 104 // This is normal video device capture.
101 *video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE; 105 *video_type = content::MEDIA_DEVICE_VIDEO_CAPTURE;
102 } 106 }
103 } 107 }
104 } 108 }
105 109
110 // Private helper method for SendMessageToNativeLog() that obtains the global
111 // MediaStreamManager instance on the UI thread before sending |message| to the
112 // webrtcLoggingPrivate API.
113 void DoAddLogMessage(const std::string& message) {
114 // Must be on the UI thread to access BrowserMainLoop.
115 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
116 // May be null in tests.
117 // TODO(vrk): Handle this more elegantly by having native log messages become
118 // no-ops until MediaStreamManager is aware that a renderer process has
119 // started logging. crbug.com/333894
120 if (content::BrowserMainLoop::GetInstance()) {
121 content::BrowserMainLoop::GetInstance()->
122 media_stream_manager()->AddLogMessageOnUIThread(message);
123 }
124 }
125
126 // Private helper method to generate a string for the log message that lists the
127 // human readable names of |devices|.
128 std::string GetLogMessageString(MediaStreamType stream_type,
129 const StreamDeviceInfoArray& devices) {
130 std::string output_string =
131 base::StringPrintf("Getting devices for stream type %d:\n", stream_type);
132 if (devices.empty()) {
133 output_string += "No devices found.";
134 } else {
135 for (StreamDeviceInfoArray::const_iterator it = devices.begin();
136 it != devices.end(); ++it) {
137 output_string += " " + it->device.name + "\n";
138 }
139 }
140 return output_string;
141 }
142
106 } // namespace 143 } // namespace
107 144
108 145
109 // MediaStreamManager::DeviceRequest represents a request to either enumerate 146 // MediaStreamManager::DeviceRequest represents a request to either enumerate
110 // available devices or open one or more devices. 147 // available devices or open one or more devices.
111 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create 148 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create
112 // several subclasses of DeviceRequest and move some of the responsibility of 149 // several subclasses of DeviceRequest and move some of the responsibility of
113 // the MediaStreamManager to the subclasses to get rid of the way too many if 150 // the MediaStreamManager to the subclasses to get rid of the way too many if
114 // statements in MediaStreamManager. 151 // statements in MediaStreamManager.
115 class MediaStreamManager::DeviceRequest { 152 class MediaStreamManager::DeviceRequest {
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 FinalizeRequestFailed(label, request); 1044 FinalizeRequestFailed(label, request);
1008 return; 1045 return;
1009 } 1046 }
1010 1047
1011 if (!is_web_contents_capture && !is_screen_capture) { 1048 if (!is_web_contents_capture && !is_screen_capture) {
1012 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) || 1049 if (EnumerationRequired(&audio_enumeration_cache_, audio_type) ||
1013 EnumerationRequired(&video_enumeration_cache_, video_type)) { 1050 EnumerationRequired(&video_enumeration_cache_, video_type)) {
1014 // Enumerate the devices if there is no valid device lists to be used. 1051 // Enumerate the devices if there is no valid device lists to be used.
1015 StartEnumeration(request); 1052 StartEnumeration(request);
1016 return; 1053 return;
1054 } else {
1055 // Cache is valid, so log the cached devices for MediaStream requests.
1056 if (request->request_type == MEDIA_GENERATE_STREAM) {
1057 std::string log_message("Using cached devices for request.\n");
1058 if (audio_type != MEDIA_NO_SERVICE) {
1059 log_message +=
1060 GetLogMessageString(audio_type, audio_enumeration_cache_.devices);
1061 }
1062 if (video_type != MEDIA_NO_SERVICE) {
1063 log_message +=
1064 GetLogMessageString(video_type, video_enumeration_cache_.devices);
1065 }
1066 SendMessageToNativeLog(log_message);
1067 }
1017 } 1068 }
1018 1069
1019 if (!SetupDeviceCaptureRequest(request)) { 1070 if (!SetupDeviceCaptureRequest(request)) {
1020 FinalizeRequestFailed(label, request); 1071 FinalizeRequestFailed(label, request);
1021 return; 1072 return;
1022 } 1073 }
1023 } 1074 }
1024 PostRequestToUI(label, request); 1075 PostRequestToUI(label, request);
1025 } 1076 }
1026 1077
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 1447
1397 void MediaStreamManager::Closed(MediaStreamType stream_type, 1448 void MediaStreamManager::Closed(MediaStreamType stream_type,
1398 int capture_session_id) { 1449 int capture_session_id) {
1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1400 } 1451 }
1401 1452
1402 void MediaStreamManager::DevicesEnumerated( 1453 void MediaStreamManager::DevicesEnumerated(
1403 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { 1454 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) {
1404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1405 DVLOG(1) << "DevicesEnumerated(" 1456 DVLOG(1) << "DevicesEnumerated("
1406 << ", {stream_type = " << stream_type << "})"; 1457 << "{stream_type = " << stream_type << "})" << std::endl;
1458
1459 std::string log_message = "New device enumeration result:\n" +
1460 GetLogMessageString(stream_type, devices);
1461 SendMessageToNativeLog(log_message);
1407 1462
1408 // Only cache the device list when the device list has been changed. 1463 // Only cache the device list when the device list has been changed.
1409 bool need_update_clients = false; 1464 bool need_update_clients = false;
1410 EnumerationCache* cache = 1465 EnumerationCache* cache =
1411 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? 1466 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ?
1412 &audio_enumeration_cache_ : &video_enumeration_cache_; 1467 &audio_enumeration_cache_ : &video_enumeration_cache_;
1413 if (!cache->valid || 1468 if (!cache->valid ||
1414 devices.size() != cache->devices.size() || 1469 devices.size() != cache->devices.size() ||
1415 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), 1470 !std::equal(devices.begin(), devices.end(), cache->devices.begin(),
1416 StreamDeviceInfo::IsEqual)) { 1471 StreamDeviceInfo::IsEqual)) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 else 1524 else
1470 PostRequestToUI(*it, request); 1525 PostRequestToUI(*it, request);
1471 break; 1526 break;
1472 } 1527 }
1473 } 1528 }
1474 label_list.clear(); 1529 label_list.clear();
1475 --active_enumeration_ref_count_[stream_type]; 1530 --active_enumeration_ref_count_[stream_type];
1476 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); 1531 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0);
1477 } 1532 }
1478 1533
1534 // static
1535 void MediaStreamManager::SendMessageToNativeLog(const std::string& message) {
1536 BrowserThread::PostTask(
1537 BrowserThread::UI, FROM_HERE,
1538 base::Bind(DoAddLogMessage, message));
1539 }
1540
1541 void MediaStreamManager::AddLogMessageOnUIThread(const std::string& message) {
1542 #if defined(OS_ANDROID)
1543 // It appears android_aosp is being built with ENABLE_WEBRTC=0, since it does
1544 // not find RenderProcessHostImpl::WebRtcLogMessage. Logging is not enabled on
1545 // Android anyway, so make this function a no-op.
1546 // TODO(vrk): Figure out what's going on here and fix.
1547 return;
1548 #else
1549 // Must be on the UI thread to access RenderProcessHost from process ID.
1550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1551
1552 // Grab all unique process ids that request a MediaStream or have a
1553 // MediaStream running.
1554 std::set<int> requesting_process_ids;
1555 for (DeviceRequests::const_iterator it = requests_.begin();
perkj_chrome 2014/01/29 09:02:25 Sorry- I should probably have caught this.
1556 it != requests_.end(); ++it) {
1557 DeviceRequest* request = it->second;
1558 if (request->request_type == MEDIA_GENERATE_STREAM)
1559 requesting_process_ids.insert(request->requesting_process_id);
1560 }
1561
1562 for (std::set<int>::const_iterator it = requesting_process_ids.begin();
1563 it != requesting_process_ids.end(); ++it) {
1564 // Log the message to all renderers that are requesting a MediaStream or
1565 // have a MediaStream running.
1566 content::RenderProcessHostImpl* render_process_host_impl =
1567 static_cast<content::RenderProcessHostImpl*>(
1568 content::RenderProcessHost::FromID(*it));
1569 if (render_process_host_impl)
1570 render_process_host_impl->WebRtcLogMessage(message);
1571 }
1572 #endif
1573 }
1574
1479 void MediaStreamManager::HandleAccessRequestResponse( 1575 void MediaStreamManager::HandleAccessRequestResponse(
1480 const std::string& label, 1576 const std::string& label,
1481 const MediaStreamDevices& devices) { 1577 const MediaStreamDevices& devices) {
1482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1483 DVLOG(1) << "HandleAccessRequestResponse(" 1579 DVLOG(1) << "HandleAccessRequestResponse("
1484 << ", {label = " << label << "})"; 1580 << ", {label = " << label << "})";
1485 1581
1486 DeviceRequest* request = FindRequest(label); 1582 DeviceRequest* request = FindRequest(label);
1487 if (!request) { 1583 if (!request) {
1488 // The request has been canceled before the UI returned. 1584 // The request has been canceled before the UI returned.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 } 1800 }
1705 1801
1706 // Always do enumeration even though some enumeration is in progress, 1802 // Always do enumeration even though some enumeration is in progress,
1707 // because those enumeration commands could be sent before these devices 1803 // because those enumeration commands could be sent before these devices
1708 // change. 1804 // change.
1709 ++active_enumeration_ref_count_[stream_type]; 1805 ++active_enumeration_ref_count_[stream_type];
1710 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); 1806 GetDeviceManager(stream_type)->EnumerateDevices(stream_type);
1711 } 1807 }
1712 1808
1713 } // namespace content 1809 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698