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) { | |
| 43 // Must be on the UI thread to access BrowserMainLoop. | |
| 44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 45 content::BrowserMainLoop::GetInstance()->media_stream_manager()-> | |
| 46 AddLogMessageOnUIThread(message); | |
| 47 } | |
| 48 | |
| 39 namespace content { | 49 namespace content { |
| 40 | 50 |
| 41 namespace { | 51 namespace { |
| 42 // Creates a random label used to identify requests. | 52 // Creates a random label used to identify requests. |
| 43 std::string RandomLabel() { | 53 std::string RandomLabel() { |
| 44 // An earlier PeerConnection spec, | 54 // An earlier PeerConnection spec, |
| 45 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the | 55 // http://dev.w3.org/2011/webrtc/editor/webrtc.html, specified the |
| 46 // MediaStream::label alphabet as containing 36 characters from | 56 // 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, | 57 // 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. | 58 // U+0030 to U+0039, U+0041 to U+005A, U+005E to U+007E. |
| (...skipping 1336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1385 } | 1395 } |
| 1386 | 1396 |
| 1387 void MediaStreamManager::Closed(MediaStreamType stream_type, | 1397 void MediaStreamManager::Closed(MediaStreamType stream_type, |
| 1388 int capture_session_id) { | 1398 int capture_session_id) { |
| 1389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1390 } | 1400 } |
| 1391 | 1401 |
| 1392 void MediaStreamManager::DevicesEnumerated( | 1402 void MediaStreamManager::DevicesEnumerated( |
| 1393 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { | 1403 MediaStreamType stream_type, const StreamDeviceInfoArray& devices) { |
| 1394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1395 DVLOG(1) << "DevicesEnumerated(" | 1405 std::stringstream devices_msg; |
|
Henrik Grunell
2014/01/22 07:05:24
I think someone told me in a CL not to use strings
perkj_chrome
2014/01/22 10:03:29
Streams are only allowed for logging:
http://googl
vrk (LEFT CHROMIUM)
2014/01/23 21:46:32
Going to keep as-is. Let's fix this in a follow-up
| |
| 1396 << ", {stream_type = " << stream_type << "})"; | 1406 devices_msg << "DevicesEnumerated(" |
| 1407 << "{stream_type = " << stream_type << "})" << std::endl; | |
| 1408 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); | |
| 1409 it != devices.end(); ++it) { | |
| 1410 devices_msg << " " << it->device.name << " (" | |
| 1411 << it->device.id << ")" << std::endl; | |
| 1412 } | |
| 1413 if (devices.empty()) | |
| 1414 devices_msg << "No devices found."; | |
| 1415 | |
| 1416 DVLOG(1) << devices_msg; | |
| 1417 AddLogMessage(devices_msg.str()); | |
| 1397 | 1418 |
| 1398 // Only cache the device list when the device list has been changed. | 1419 // Only cache the device list when the device list has been changed. |
| 1399 bool need_update_clients = false; | 1420 bool need_update_clients = false; |
| 1400 EnumerationCache* cache = | 1421 EnumerationCache* cache = |
| 1401 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? | 1422 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
| 1402 &audio_enumeration_cache_ : &video_enumeration_cache_; | 1423 &audio_enumeration_cache_ : &video_enumeration_cache_; |
| 1403 if (!cache->valid || | 1424 if (!cache->valid || |
| 1404 devices.size() != cache->devices.size() || | 1425 devices.size() != cache->devices.size() || |
| 1405 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), | 1426 !std::equal(devices.begin(), devices.end(), cache->devices.begin(), |
| 1406 StreamDeviceInfo::IsEqual)) { | 1427 StreamDeviceInfo::IsEqual)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1459 else | 1480 else |
| 1460 PostRequestToUI(*it, request); | 1481 PostRequestToUI(*it, request); |
| 1461 break; | 1482 break; |
| 1462 } | 1483 } |
| 1463 } | 1484 } |
| 1464 label_list.clear(); | 1485 label_list.clear(); |
| 1465 --active_enumeration_ref_count_[stream_type]; | 1486 --active_enumeration_ref_count_[stream_type]; |
| 1466 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); | 1487 DCHECK_GE(active_enumeration_ref_count_[stream_type], 0); |
| 1467 } | 1488 } |
| 1468 | 1489 |
| 1490 // static | |
| 1491 void MediaStreamManager::AddLogMessage(const std::string& message) { | |
| 1492 BrowserThread::PostTask( | |
| 1493 BrowserThread::UI, FROM_HERE, | |
| 1494 base::Bind(::DoAddLogMessage, message)); | |
| 1495 } | |
| 1496 | |
| 1497 void MediaStreamManager::AddLogMessageOnUIThread(const std::string& message) { | |
| 1498 // Must be on the UI thread to access RenderProcessHost from process ID. | |
| 1499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1500 | |
| 1501 // Add logs for each pending request. | |
| 1502 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | |
|
perkj_chrome
2014/01/22 10:03:29
Are you aware that a request is "Pending" as long
vrk (LEFT CHROMIUM)
2014/01/22 18:30:30
I think this behavior is acceptable in practice. W
vrk (LEFT CHROMIUM)
2014/01/23 21:46:32
Talked offline. This is hard to fix and I think th
| |
| 1503 ++it) { | |
| 1504 DeviceRequest* request = it->second; | |
| 1505 // Log the message to all renderers that are requesting a MediaStream or | |
| 1506 // device enumeration. | |
|
perkj_chrome
2014/01/22 10:03:29
Can you add this comment to the header file as wel
vrk (LEFT CHROMIUM)
2014/01/23 21:46:32
Done, though reworded.
| |
| 1507 if (request->request_type == MEDIA_GENERATE_STREAM || | |
| 1508 request->request_type == MEDIA_ENUMERATE_DEVICES) { | |
| 1509 content::RenderProcessHostImpl* render_process_host_impl = | |
| 1510 static_cast<content::RenderProcessHostImpl*>( | |
| 1511 content::RenderProcessHost::FromID( | |
| 1512 request->requesting_process_id)); | |
| 1513 render_process_host_impl->WebRtcLogMessage(message); | |
| 1514 } | |
| 1515 } | |
| 1516 } | |
| 1517 | |
| 1469 void MediaStreamManager::HandleAccessRequestResponse( | 1518 void MediaStreamManager::HandleAccessRequestResponse( |
| 1470 const std::string& label, | 1519 const std::string& label, |
| 1471 const MediaStreamDevices& devices) { | 1520 const MediaStreamDevices& devices) { |
| 1472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1473 DVLOG(1) << "HandleAccessRequestResponse(" | 1522 DVLOG(1) << "HandleAccessRequestResponse(" |
| 1474 << ", {label = " << label << "})"; | 1523 << ", {label = " << label << "})"; |
| 1475 | 1524 |
| 1476 DeviceRequest* request = FindRequest(label); | 1525 DeviceRequest* request = FindRequest(label); |
| 1477 if (!request) { | 1526 if (!request) { |
| 1478 // The request has been canceled before the UI returned. | 1527 // The request has been canceled before the UI returned. |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1694 } | 1743 } |
| 1695 | 1744 |
| 1696 // Always do enumeration even though some enumeration is in progress, | 1745 // Always do enumeration even though some enumeration is in progress, |
| 1697 // because those enumeration commands could be sent before these devices | 1746 // because those enumeration commands could be sent before these devices |
| 1698 // change. | 1747 // change. |
| 1699 ++active_enumeration_ref_count_[stream_type]; | 1748 ++active_enumeration_ref_count_[stream_type]; |
| 1700 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1749 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
| 1701 } | 1750 } |
| 1702 | 1751 |
| 1703 } // namespace content | 1752 } // namespace content |
| OLD | NEW |