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

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 1272223003: Implement writing mic audio input data to file for debugging purposes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 206
207 #if defined(ENABLE_WEBRTC) 207 #if defined(ENABLE_WEBRTC)
208 #include "content/browser/media/webrtc_internals.h" 208 #include "content/browser/media/webrtc_internals.h"
209 #include "content/browser/renderer_host/media/media_stream_track_metrics_host.h" 209 #include "content/browser/renderer_host/media/media_stream_track_metrics_host.h"
210 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h" 210 #include "content/browser/renderer_host/media/webrtc_identity_service_host.h"
211 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h" 211 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
212 #include "content/common/media/aec_dump_messages.h" 212 #include "content/common/media/aec_dump_messages.h"
213 #include "content/common/media/media_stream_messages.h" 213 #include "content/common/media/media_stream_messages.h"
214 #endif 214 #endif
215 215
216 #if defined(OS_WIN)
217 #define IntToStringType base::IntToString16
218 #else
219 #define IntToStringType base::IntToString
220 #endif
221
216 namespace content { 222 namespace content {
217 namespace { 223 namespace {
218 224
219 const char kSiteProcessMapKeyName[] = "content_site_process_map"; 225 const char kSiteProcessMapKeyName[] = "content_site_process_map";
220 226
227 #ifdef ENABLE_WEBRTC
228 const base::FilePath::CharType kAecDumpFileNameAddition[] =
229 FILE_PATH_LITERAL("aec_dump");
230 #endif
231
221 void CacheShaderInfo(int32 id, base::FilePath path) { 232 void CacheShaderInfo(int32 id, base::FilePath path) {
222 ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path); 233 ShaderCacheFactory::GetInstance()->SetCacheInfo(id, path);
223 } 234 }
224 235
225 void RemoveShaderInfo(int32 id) { 236 void RemoveShaderInfo(int32 id) {
226 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(id); 237 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(id);
227 } 238 }
228 239
229 net::URLRequestContext* GetRequestContext( 240 net::URLRequestContext* GetRequestContext(
230 scoped_refptr<net::URLRequestContextGetter> request_context, 241 scoped_refptr<net::URLRequestContextGetter> request_context,
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 storage_partition_impl_->GetAppCacheService(), 798 storage_partition_impl_->GetAppCacheService(),
788 ChromeBlobStorageContext::GetFor(browser_context), 799 ChromeBlobStorageContext::GetFor(browser_context),
789 storage_partition_impl_->GetFileSystemContext(), 800 storage_partition_impl_->GetFileSystemContext(),
790 storage_partition_impl_->GetServiceWorkerContext(), 801 storage_partition_impl_->GetServiceWorkerContext(),
791 storage_partition_impl_->GetHostZoomLevelContext(), 802 storage_partition_impl_->GetHostZoomLevelContext(),
792 get_contexts_callback); 803 get_contexts_callback);
793 804
794 AddFilter(resource_message_filter); 805 AddFilter(resource_message_filter);
795 MediaStreamManager* media_stream_manager = 806 MediaStreamManager* media_stream_manager =
796 BrowserMainLoop::GetInstance()->media_stream_manager(); 807 BrowserMainLoop::GetInstance()->media_stream_manager();
797 AddFilter(new AudioInputRendererHost( 808 // The AudioInputRendererHost and AudioRendererHost needs to be available for
809 // lookup, so it's stashed in a member variable.
810 audio_input_renderer_host_ = new AudioInputRendererHost(
798 GetID(), 811 GetID(),
812 base::GetProcId(GetHandle()),
799 audio_manager, 813 audio_manager,
800 media_stream_manager, 814 media_stream_manager,
801 AudioMirroringManager::GetInstance(), 815 AudioMirroringManager::GetInstance(),
802 BrowserMainLoop::GetInstance()->user_input_monitor())); 816 BrowserMainLoop::GetInstance()->user_input_monitor());
803 // The AudioRendererHost needs to be available for lookup, so it's 817 AddFilter(audio_input_renderer_host_.get());
804 // stashed in a member variable.
805 audio_renderer_host_ = new AudioRendererHost( 818 audio_renderer_host_ = new AudioRendererHost(
806 GetID(), 819 GetID(),
807 audio_manager, 820 audio_manager,
808 AudioMirroringManager::GetInstance(), 821 AudioMirroringManager::GetInstance(),
809 media_internals, 822 media_internals,
810 media_stream_manager, 823 media_stream_manager,
811 browser_context->GetResourceContext()->GetMediaDeviceIDSalt()); 824 browser_context->GetResourceContext()->GetMediaDeviceIDSalt());
812 AddFilter(audio_renderer_host_.get()); 825 AddFilter(audio_renderer_host_.get());
813 AddFilter( 826 AddFilter(
814 new MidiHost(GetID(), BrowserMainLoop::GetInstance()->midi_manager())); 827 new MidiHost(GetID(), BrowserMainLoop::GetInstance()->midi_manager()));
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 tracked_objects::ThreadData::Status status = 1609 tracked_objects::ThreadData::Status status =
1597 tracked_objects::ThreadData::status(); 1610 tracked_objects::ThreadData::status();
1598 Send(new ChildProcessMsg_SetProfilerStatus(status)); 1611 Send(new ChildProcessMsg_SetProfilerStatus(status));
1599 1612
1600 #if defined(OS_MACOSX) && !defined(OS_IOS) 1613 #if defined(OS_MACOSX) && !defined(OS_IOS)
1601 io_surface_manager_token_ = 1614 io_surface_manager_token_ =
1602 BrowserIOSurfaceManager::GetInstance()->GenerateChildProcessToken( 1615 BrowserIOSurfaceManager::GetInstance()->GenerateChildProcessToken(
1603 GetID()); 1616 GetID());
1604 Send(new ChildProcessMsg_SetIOSurfaceManagerToken(io_surface_manager_token_)); 1617 Send(new ChildProcessMsg_SetIOSurfaceManagerToken(io_surface_manager_token_));
1605 #endif 1618 #endif
1619
1606 #if defined(USE_OZONE) 1620 #if defined(USE_OZONE)
1607 Send(new ChildProcessMsg_InitializeClientNativePixmapFactory( 1621 Send(new ChildProcessMsg_InitializeClientNativePixmapFactory(
1608 base::FileDescriptor( 1622 base::FileDescriptor(
1609 ui::OzonePlatform::GetInstance()->OpenClientNativePixmapDevice()))); 1623 ui::OzonePlatform::GetInstance()->OpenClientNativePixmapDevice())));
1610 #endif 1624 #endif
1625
1626 // Inform AudioInputRendererHost about the new render process PID.
1627 // AudioInputRendererHost is reference counted, so it's lifetime is
1628 // guarantueed during the lifetime of the closure.
1629 BrowserThread::PostTask(
1630 BrowserThread::IO, FROM_HERE,
1631 base::Bind(&AudioInputRendererHost::set_renderer_pid,
1632 audio_input_renderer_host_,
1633 peer_pid));
1611 } 1634 }
1612 1635
1613 void RenderProcessHostImpl::OnChannelError() { 1636 void RenderProcessHostImpl::OnChannelError() {
1614 ProcessDied(true /* already_dead */, nullptr); 1637 ProcessDied(true /* already_dead */, nullptr);
1615 } 1638 }
1616 1639
1617 void RenderProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { 1640 void RenderProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) {
1618 // Message de-serialization failed. We consider this a capital crime. Kill the 1641 // Message de-serialization failed. We consider this a capital crime. Kill the
1619 // renderer if we have one. 1642 // renderer if we have one.
1620 LOG(ERROR) << "bad message " << message.type() << " terminating renderer."; 1643 LOG(ERROR) << "bad message " << message.type() << " terminating renderer.";
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 1778
1756 void RenderProcessHostImpl::ResumeRequestsForView(int route_id) { 1779 void RenderProcessHostImpl::ResumeRequestsForView(int route_id) {
1757 widget_helper_->ResumeRequestsForView(route_id); 1780 widget_helper_->ResumeRequestsForView(route_id);
1758 } 1781 }
1759 1782
1760 void RenderProcessHostImpl::FilterURL(bool empty_allowed, GURL* url) { 1783 void RenderProcessHostImpl::FilterURL(bool empty_allowed, GURL* url) {
1761 FilterURL(this, empty_allowed, url); 1784 FilterURL(this, empty_allowed, url);
1762 } 1785 }
1763 1786
1764 #if defined(ENABLE_WEBRTC) 1787 #if defined(ENABLE_WEBRTC)
1765 void RenderProcessHostImpl::EnableAecDump(const base::FilePath& file) { 1788 void RenderProcessHostImpl::EnableAudioDebugRecordings(
1789 const base::FilePath& file) {
1766 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1790 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1791
1767 // Enable AEC dump for each registered consumer. 1792 // Enable AEC dump for each registered consumer.
1793 base::FilePath file_with_extensions =
1794 GetAecDumpFilePathWithExtensions(file);
1768 for (std::vector<int>::iterator it = aec_dump_consumers_.begin(); 1795 for (std::vector<int>::iterator it = aec_dump_consumers_.begin();
1769 it != aec_dump_consumers_.end(); ++it) { 1796 it != aec_dump_consumers_.end(); ++it) {
1770 EnableAecDumpForId(file, *it); 1797 EnableAecDumpForId(file_with_extensions, *it);
1771 } 1798 }
1799
1800 // Enable mic input recording. AudioInputRendererHost is reference counted, so
1801 // it's lifetime is guarantueed during the lifetime of the closure.
1802 BrowserThread::PostTask(
1803 BrowserThread::IO, FROM_HERE,
1804 base::Bind(&AudioInputRendererHost::EnableDebugRecording,
1805 audio_input_renderer_host_,
1806 file));
1772 } 1807 }
1773 1808
1774 void RenderProcessHostImpl::DisableAecDump() { 1809 void RenderProcessHostImpl::DisableAudioDebugRecordings() {
1775 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1810 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1811
1776 // Posting on the FILE thread and then replying back on the UI thread is only 1812 // Posting on the FILE thread and then replying back on the UI thread is only
1777 // for avoiding races between enable and disable. Nothing is done on the FILE 1813 // for avoiding races between enable and disable. Nothing is done on the FILE
1778 // thread. 1814 // thread.
1779 BrowserThread::PostTaskAndReply( 1815 BrowserThread::PostTaskAndReply(
1780 BrowserThread::FILE, FROM_HERE, 1816 BrowserThread::FILE, FROM_HERE,
1781 base::Bind(&DisableAecDumpOnFileThread), 1817 base::Bind(&DisableAecDumpOnFileThread),
1782 base::Bind(&RenderProcessHostImpl::SendDisableAecDumpToRenderer, 1818 base::Bind(&RenderProcessHostImpl::SendDisableAecDumpToRenderer,
1783 weak_factory_.GetWeakPtr())); 1819 weak_factory_.GetWeakPtr()));
1820
1821 // AudioInputRendererHost is reference counted, so it's lifetime is
1822 // guaranteed during the lifetime of the closure.
1823 BrowserThread::PostTask(
1824 BrowserThread::IO, FROM_HERE,
1825 base::Bind(
1826 &AudioInputRendererHost::DisableDebugRecording,
1827 audio_input_renderer_host_));
1784 } 1828 }
1785 1829
1786 void RenderProcessHostImpl::SetWebRtcLogMessageCallback( 1830 void RenderProcessHostImpl::SetWebRtcLogMessageCallback(
1787 base::Callback<void(const std::string&)> callback) { 1831 base::Callback<void(const std::string&)> callback) {
1788 webrtc_log_message_callback_ = callback; 1832 webrtc_log_message_callback_ = callback;
1789 } 1833 }
1790 1834
1791 RenderProcessHostImpl::WebRtcStopRtpDumpCallback 1835 RenderProcessHostImpl::WebRtcStopRtpDumpCallback
1792 RenderProcessHostImpl::StartRtpDump( 1836 RenderProcessHostImpl::StartRtpDump(
1793 bool incoming, 1837 bool incoming,
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 Send(queued_messages_.front()); 2420 Send(queued_messages_.front());
2377 queued_messages_.pop(); 2421 queued_messages_.pop();
2378 } 2422 }
2379 2423
2380 #if defined(ENABLE_WEBRTC) 2424 #if defined(ENABLE_WEBRTC)
2381 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841 2425 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/465841
2382 // is fixed. 2426 // is fixed.
2383 tracked_objects::ScopedTracker tracking_profile7( 2427 tracked_objects::ScopedTracker tracking_profile7(
2384 FROM_HERE_WITH_EXPLICIT_FUNCTION( 2428 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2385 "465841 RenderProcessHostImpl::OnProcessLaunched::EnableAec")); 2429 "465841 RenderProcessHostImpl::OnProcessLaunched::EnableAec"));
2386 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) 2430 if (WebRTCInternals::GetInstance()->IsAudioDebugRecordingsEnabled()) {
2387 EnableAecDump(WebRTCInternals::GetInstance()->aec_dump_file_path()); 2431 EnableAudioDebugRecordings(
2432 WebRTCInternals::GetInstance()->GetAudioDebugRecordingsFilePath());
2433 }
2388 #endif 2434 #endif
2389 } 2435 }
2390 2436
2391 void RenderProcessHostImpl::OnProcessLaunchFailed() { 2437 void RenderProcessHostImpl::OnProcessLaunchFailed() {
2392 // If this object will be destructed soon, then observers have already been 2438 // If this object will be destructed soon, then observers have already been
2393 // sent a RenderProcessHostDestroyed notification, and we must observe our 2439 // sent a RenderProcessHostDestroyed notification, and we must observe our
2394 // contract that says that will be the last call. 2440 // contract that says that will be the last call.
2395 if (deleting_soon_) 2441 if (deleting_soon_)
2396 return; 2442 return;
2397 2443
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2457 FROM_HERE, 2503 FROM_HERE,
2458 base::Bind( 2504 base::Bind(
2459 &RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread, 2505 &RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread,
2460 weak_factory_.GetWeakPtr(), 2506 weak_factory_.GetWeakPtr(),
2461 id)); 2507 id));
2462 } 2508 }
2463 2509
2464 void RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread(int id) { 2510 void RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread(int id) {
2465 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2511 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2466 aec_dump_consumers_.push_back(id); 2512 aec_dump_consumers_.push_back(id);
2467 if (WebRTCInternals::GetInstance()->aec_dump_enabled()) { 2513
2468 EnableAecDumpForId(WebRTCInternals::GetInstance()->aec_dump_file_path(), 2514 if (WebRTCInternals::GetInstance()->IsAudioDebugRecordingsEnabled()) {
2469 id); 2515 base::FilePath file_with_extensions = GetAecDumpFilePathWithExtensions(
2516 WebRTCInternals::GetInstance()->GetAudioDebugRecordingsFilePath());
2517 EnableAecDumpForId(file_with_extensions, id);
2470 } 2518 }
2471 } 2519 }
2472 2520
2473 void RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread(int id) { 2521 void RenderProcessHostImpl::UnregisterAecDumpConsumerOnUIThread(int id) {
2474 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2522 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2475 for (std::vector<int>::iterator it = aec_dump_consumers_.begin(); 2523 for (std::vector<int>::iterator it = aec_dump_consumers_.begin();
2476 it != aec_dump_consumers_.end(); ++it) { 2524 it != aec_dump_consumers_.end(); ++it) {
2477 if (*it == id) { 2525 if (*it == id) {
2478 aec_dump_consumers_.erase(it); 2526 aec_dump_consumers_.erase(it);
2479 break; 2527 break;
2480 } 2528 }
2481 } 2529 }
2482 } 2530 }
2483 2531
2484 #if defined(OS_WIN)
2485 #define IntToStringType base::IntToString16
2486 #else
2487 #define IntToStringType base::IntToString
2488 #endif
2489
2490 void RenderProcessHostImpl::EnableAecDumpForId(const base::FilePath& file, 2532 void RenderProcessHostImpl::EnableAecDumpForId(const base::FilePath& file,
2491 int id) { 2533 int id) {
2492 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2534 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2493 base::FilePath unique_file =
2494 file.AddExtension(IntToStringType(base::GetProcId(GetHandle())))
2495 .AddExtension(IntToStringType(id));
2496 BrowserThread::PostTaskAndReplyWithResult( 2535 BrowserThread::PostTaskAndReplyWithResult(
2497 BrowserThread::FILE, FROM_HERE, 2536 BrowserThread::FILE, FROM_HERE,
2498 base::Bind(&CreateAecDumpFileForProcess, unique_file, GetHandle()), 2537 base::Bind(&CreateAecDumpFileForProcess,
2538 file.AddExtension(IntToStringType(id)),
2539 GetHandle()),
2499 base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer, 2540 base::Bind(&RenderProcessHostImpl::SendAecDumpFileToRenderer,
2500 weak_factory_.GetWeakPtr(), 2541 weak_factory_.GetWeakPtr(),
2501 id)); 2542 id));
2502 } 2543 }
2503 2544
2504 #undef IntToStringType
2505
2506 void RenderProcessHostImpl::SendAecDumpFileToRenderer( 2545 void RenderProcessHostImpl::SendAecDumpFileToRenderer(
2507 int id, 2546 int id,
2508 IPC::PlatformFileForTransit file_for_transit) { 2547 IPC::PlatformFileForTransit file_for_transit) {
2509 if (file_for_transit == IPC::InvalidPlatformFileForTransit()) 2548 if (file_for_transit == IPC::InvalidPlatformFileForTransit())
2510 return; 2549 return;
2511 Send(new AecDumpMsg_EnableAecDump(id, file_for_transit)); 2550 Send(new AecDumpMsg_EnableAecDump(id, file_for_transit));
2512 } 2551 }
2513 2552
2514 void RenderProcessHostImpl::SendDisableAecDumpToRenderer() { 2553 void RenderProcessHostImpl::SendDisableAecDumpToRenderer() {
2515 Send(new AecDumpMsg_DisableAecDump()); 2554 Send(new AecDumpMsg_DisableAecDump());
2516 } 2555 }
2517 #endif 2556
2557 base::FilePath RenderProcessHostImpl::GetAecDumpFilePathWithExtensions(
2558 const base::FilePath& file) {
2559 return file.AddExtension(IntToStringType(base::GetProcId(GetHandle())))
2560 .AddExtension(kAecDumpFileNameAddition);
2561 }
2562 #endif // defined(ENABLE_WEBRTC)
2518 2563
2519 void RenderProcessHostImpl::IncrementWorkerRefCount() { 2564 void RenderProcessHostImpl::IncrementWorkerRefCount() {
2520 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2565 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2521 ++worker_ref_count_; 2566 ++worker_ref_count_;
2522 if (worker_ref_count_ > max_worker_count_) 2567 if (worker_ref_count_ > max_worker_count_)
2523 max_worker_count_ = worker_ref_count_; 2568 max_worker_count_ = worker_ref_count_;
2524 } 2569 }
2525 2570
2526 void RenderProcessHostImpl::DecrementWorkerRefCount() { 2571 void RenderProcessHostImpl::DecrementWorkerRefCount() {
2527 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2572 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2528 DCHECK_GT(worker_ref_count_, 0); 2573 DCHECK_GT(worker_ref_count_, 0);
2529 --worker_ref_count_; 2574 --worker_ref_count_;
2530 if (worker_ref_count_ == 0) 2575 if (worker_ref_count_ == 0)
2531 Cleanup(); 2576 Cleanup();
2532 } 2577 }
2533 2578
2534 void RenderProcessHostImpl::GetAudioOutputControllers( 2579 void RenderProcessHostImpl::GetAudioOutputControllers(
2535 const GetAudioOutputControllersCallback& callback) const { 2580 const GetAudioOutputControllersCallback& callback) const {
2536 audio_renderer_host()->GetOutputControllers(callback); 2581 audio_renderer_host()->GetOutputControllers(callback);
2537 } 2582 }
2538 2583
2539 BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() { 2584 BluetoothDispatcherHost* RenderProcessHostImpl::GetBluetoothDispatcherHost() {
2540 return bluetooth_dispatcher_host_.get(); 2585 return bluetooth_dispatcher_host_.get();
2541 } 2586 }
2542 2587
2543 } // namespace content 2588 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/browser/resources/media/dump_creator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698