Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media/audio_stream_monitor.h" | 5 #include "content/browser/media/audio_stream_monitor.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 return is_audible_; | 48 return is_audible_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 void AudioStreamMonitor::StartMonitoringStream( | 52 void AudioStreamMonitor::StartMonitoringStream( |
| 53 int render_process_id, | 53 int render_process_id, |
| 54 int render_frame_id, | 54 int render_frame_id, |
| 55 int stream_id, | 55 int stream_id, |
| 56 const ReadPowerAndClipCallback& read_power_callback) { | 56 const ReadPowerAndClipCallback& read_power_callback) { |
| 57 if (!monitoring_available()) | |
|
DaleCurtis
2016/11/14 18:51:07
Can we change this to power_level_monitoring() or
altimin
2016/11/15 12:06:17
Done. There is some logic that uses this function
| |
| 58 return; | |
| 59 BrowserThread::PostTask(BrowserThread::UI, | 57 BrowserThread::PostTask(BrowserThread::UI, |
| 60 FROM_HERE, | 58 FROM_HERE, |
| 61 base::Bind(&StartMonitoringHelper, | 59 base::Bind(&StartMonitoringHelper, |
| 62 render_process_id, | 60 render_process_id, |
| 63 render_frame_id, | 61 render_frame_id, |
| 64 stream_id, | 62 stream_id, |
| 65 read_power_callback)); | 63 read_power_callback)); |
| 66 } | 64 } |
| 67 | 65 |
| 68 // static | 66 // static |
| 69 void AudioStreamMonitor::StopMonitoringStream(int render_process_id, | 67 void AudioStreamMonitor::StopMonitoringStream(int render_process_id, |
| 70 int render_frame_id, | 68 int render_frame_id, |
| 71 int stream_id) { | 69 int stream_id) { |
| 72 if (!media::AudioOutputController::will_monitor_audio_levels()) | |
| 73 return; | |
| 74 BrowserThread::PostTask(BrowserThread::UI, | 70 BrowserThread::PostTask(BrowserThread::UI, |
| 75 FROM_HERE, | 71 FROM_HERE, |
| 76 base::Bind(&StopMonitoringHelper, | 72 base::Bind(&StopMonitoringHelper, |
| 77 render_process_id, | 73 render_process_id, |
| 78 render_frame_id, | 74 render_frame_id, |
| 79 stream_id)); | 75 stream_id)); |
| 80 } | 76 } |
| 81 | 77 |
| 82 // static | 78 // static |
| 83 void AudioStreamMonitor::StartMonitoringHelper( | 79 void AudioStreamMonitor::StartMonitoringHelper( |
| 84 int render_process_id, | 80 int render_process_id, |
| 85 int render_frame_id, | 81 int render_frame_id, |
| 86 int stream_id, | 82 int stream_id, |
| 87 const ReadPowerAndClipCallback& read_power_callback) { | 83 const ReadPowerAndClipCallback& read_power_callback) { |
| 88 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 84 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 89 AudioStreamMonitor* const monitor = | 85 AudioStreamMonitor* const monitor = |
| 90 AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); | 86 AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); |
| 91 if (monitor) { | 87 if (monitor) { |
|
DaleCurtis
2016/11/14 18:51:07
Invert to if (!monitor) return to avoid extra nest
altimin
2016/11/15 12:06:17
Done.
| |
| 88 if (!monitoring_available()) { | |
| 89 // If audio level monitoring is not available, assume that an active | |
|
DaleCurtis
2016/11/14 18:51:07
Reflow comment.
altimin
2016/11/15 12:06:17
Done.
| |
| 90 // stream | |
| 91 // means audio signal. | |
| 92 monitor->web_contents_->OnAudioStateChanged(true); | |
| 93 return; | |
| 94 } | |
| 95 | |
| 92 monitor->StartMonitoringStreamOnUIThread( | 96 monitor->StartMonitoringStreamOnUIThread( |
| 93 render_process_id, stream_id, read_power_callback); | 97 render_process_id, stream_id, read_power_callback); |
| 94 } | 98 } |
| 95 } | 99 } |
| 96 | 100 |
| 97 // static | 101 // static |
| 98 void AudioStreamMonitor::StopMonitoringHelper(int render_process_id, | 102 void AudioStreamMonitor::StopMonitoringHelper(int render_process_id, |
| 99 int render_frame_id, | 103 int render_frame_id, |
| 100 int stream_id) { | 104 int stream_id) { |
| 101 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 102 AudioStreamMonitor* const monitor = | 106 AudioStreamMonitor* const monitor = |
| 103 AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); | 107 AudioStreamMonitorFromRenderFrame(render_process_id, render_frame_id); |
| 104 if (monitor) | 108 if (monitor) { |
|
DaleCurtis
2016/11/14 18:51:07
Invert to if (!monitor) return to avoid extra nest
altimin
2016/11/15 12:06:17
Done.
| |
| 109 if (!monitoring_available()) { | |
| 110 monitor->web_contents_->OnAudioStateChanged(false); | |
| 111 return; | |
| 112 } | |
| 105 monitor->StopMonitoringStreamOnUIThread(render_process_id, stream_id); | 113 monitor->StopMonitoringStreamOnUIThread(render_process_id, stream_id); |
| 114 } | |
| 106 } | 115 } |
| 107 | 116 |
| 108 void AudioStreamMonitor::StartMonitoringStreamOnUIThread( | 117 void AudioStreamMonitor::StartMonitoringStreamOnUIThread( |
| 109 int render_process_id, | 118 int render_process_id, |
| 110 int stream_id, | 119 int stream_id, |
| 111 const ReadPowerAndClipCallback& read_power_callback) { | 120 const ReadPowerAndClipCallback& read_power_callback) { |
| 112 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
| 113 DCHECK(!read_power_callback.is_null()); | 122 DCHECK(!read_power_callback.is_null()); |
| 114 poll_callbacks_[StreamID(render_process_id, stream_id)] = read_power_callback; | 123 poll_callbacks_[StreamID(render_process_id, stream_id)] = read_power_callback; |
| 115 if (!poll_timer_.IsRunning()) { | 124 if (!poll_timer_.IsRunning()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 off_timer_.Stop(); | 179 off_timer_.Stop(); |
| 171 } else if (!off_timer_.IsRunning()) { | 180 } else if (!off_timer_.IsRunning()) { |
| 172 off_timer_.Start( | 181 off_timer_.Start( |
| 173 FROM_HERE, | 182 FROM_HERE, |
| 174 off_time - now, | 183 off_time - now, |
| 175 base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); | 184 base::Bind(&AudioStreamMonitor::MaybeToggle, base::Unretained(this))); |
| 176 } | 185 } |
| 177 } | 186 } |
| 178 | 187 |
| 179 } // namespace content | 188 } // namespace content |
| OLD | NEW |