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

Side by Side Diff: content/renderer/media/webrtc_audio_renderer.cc

Issue 577953002: Adds time measurement of WebRtcAudioRenderer::Render (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed histogram Created 6 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
« no previous file with comments | « content/renderer/media/webrtc_audio_renderer.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/media/webrtc_audio_renderer.h" 5 #include "content/renderer/media/webrtc_audio_renderer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 11 matching lines...) Expand all
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 #include "base/win/windows_version.h" 24 #include "base/win/windows_version.h"
25 #include "media/audio/win/core_audio_util_win.h" 25 #include "media/audio/win/core_audio_util_win.h"
26 #endif 26 #endif
27 27
28 namespace content { 28 namespace content {
29 29
30 namespace { 30 namespace {
31 31
32 // We add a UMA histogram measuring the execution time of the Render() method
33 // every |kNumCallbacksBetweenRenderTimeHistograms| callback. Assuming 10ms
34 // between each callback leads to one UMA update each 100ms.
35 const int kNumCallbacksBetweenRenderTimeHistograms = 10;
36
32 // This is a simple wrapper class that's handed out to users of a shared 37 // This is a simple wrapper class that's handed out to users of a shared
33 // WebRtcAudioRenderer instance. This class maintains the per-user 'playing' 38 // WebRtcAudioRenderer instance. This class maintains the per-user 'playing'
34 // and 'started' states to avoid problems related to incorrect usage which 39 // and 'started' states to avoid problems related to incorrect usage which
35 // might violate the implementation assumptions inside WebRtcAudioRenderer 40 // might violate the implementation assumptions inside WebRtcAudioRenderer
36 // (see the play reference count). 41 // (see the play reference count).
37 class SharedAudioRenderer : public MediaStreamAudioRenderer { 42 class SharedAudioRenderer : public MediaStreamAudioRenderer {
38 public: 43 public:
39 // Callback definition for a callback that is called when when Play(), Pause() 44 // Callback definition for a callback that is called when when Play(), Pause()
40 // or SetVolume are called (whenever the internal |playing_state_| changes). 45 // or SetVolume are called (whenever the internal |playing_state_| changes).
41 typedef base::Callback< 46 typedef base::Callback<
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 session_id_(session_id), 188 session_id_(session_id),
184 media_stream_(media_stream), 189 media_stream_(media_stream),
185 source_(NULL), 190 source_(NULL),
186 play_ref_count_(0), 191 play_ref_count_(0),
187 start_ref_count_(0), 192 start_ref_count_(0),
188 audio_delay_milliseconds_(0), 193 audio_delay_milliseconds_(0),
189 fifo_delay_milliseconds_(0), 194 fifo_delay_milliseconds_(0),
190 sink_params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 195 sink_params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
191 media::CHANNEL_LAYOUT_STEREO, sample_rate, 16, 196 media::CHANNEL_LAYOUT_STEREO, sample_rate, 16,
192 frames_per_buffer, 197 frames_per_buffer,
193 GetCurrentDuckingFlag(source_render_frame_id)) { 198 GetCurrentDuckingFlag(source_render_frame_id)),
199 render_callback_count_(0) {
194 WebRtcLogMessage(base::StringPrintf( 200 WebRtcLogMessage(base::StringPrintf(
195 "WAR::WAR. source_render_view_id=%d" 201 "WAR::WAR. source_render_view_id=%d"
196 ", session_id=%d, sample_rate=%d, frames_per_buffer=%d, effects=%i", 202 ", session_id=%d, sample_rate=%d, frames_per_buffer=%d, effects=%i",
197 source_render_view_id, 203 source_render_view_id,
198 session_id, 204 session_id,
199 sample_rate, 205 sample_rate,
200 frames_per_buffer, 206 frames_per_buffer,
201 sink_params_.effects())); 207 sink_params_.effects()));
202 } 208 }
203 209
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 } 320 }
315 321
316 void WebRtcAudioRenderer::Play() { 322 void WebRtcAudioRenderer::Play() {
317 DVLOG(1) << "WebRtcAudioRenderer::Play()"; 323 DVLOG(1) << "WebRtcAudioRenderer::Play()";
318 DCHECK(thread_checker_.CalledOnValidThread()); 324 DCHECK(thread_checker_.CalledOnValidThread());
319 325
320 if (playing_state_.playing()) 326 if (playing_state_.playing())
321 return; 327 return;
322 328
323 playing_state_.set_playing(true); 329 playing_state_.set_playing(true);
330 render_callback_count_ = 0;
324 331
325 OnPlayStateChanged(media_stream_, &playing_state_); 332 OnPlayStateChanged(media_stream_, &playing_state_);
326 } 333 }
327 334
328 void WebRtcAudioRenderer::EnterPlayState() { 335 void WebRtcAudioRenderer::EnterPlayState() {
329 DVLOG(1) << "WebRtcAudioRenderer::EnterPlayState()"; 336 DVLOG(1) << "WebRtcAudioRenderer::EnterPlayState()";
330 DCHECK(thread_checker_.CalledOnValidThread()); 337 DCHECK(thread_checker_.CalledOnValidThread());
331 DCHECK_GT(start_ref_count_, 0) << "Did you forget to call Start()?"; 338 DCHECK_GT(start_ref_count_, 0) << "Did you forget to call Start()?";
332 base::AutoLock auto_lock(lock_); 339 base::AutoLock auto_lock(lock_);
333 if (state_ == UNINITIALIZED) 340 if (state_ == UNINITIALIZED)
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 bool WebRtcAudioRenderer::IsLocalRenderer() const { 419 bool WebRtcAudioRenderer::IsLocalRenderer() const {
413 return false; 420 return false;
414 } 421 }
415 422
416 int WebRtcAudioRenderer::Render(media::AudioBus* audio_bus, 423 int WebRtcAudioRenderer::Render(media::AudioBus* audio_bus,
417 int audio_delay_milliseconds) { 424 int audio_delay_milliseconds) {
418 base::AutoLock auto_lock(lock_); 425 base::AutoLock auto_lock(lock_);
419 if (!source_) 426 if (!source_)
420 return 0; 427 return 0;
421 428
429 base::TimeTicks start_time = base::TimeTicks::Now() ;
no longer working on chromium 2014/09/18 17:35:42 Render() is triggered by callbacks from the device
henrika (OOO until Aug 14) 2014/09/19 13:13:53 Will move it to SourceCallback. Thanks.
430
422 DVLOG(2) << "WebRtcAudioRenderer::Render()"; 431 DVLOG(2) << "WebRtcAudioRenderer::Render()";
423 DVLOG(2) << "audio_delay_milliseconds: " << audio_delay_milliseconds; 432 DVLOG(2) << "audio_delay_milliseconds: " << audio_delay_milliseconds;
424 433
425 audio_delay_milliseconds_ = audio_delay_milliseconds; 434 audio_delay_milliseconds_ = audio_delay_milliseconds;
426 435
427 if (audio_fifo_) 436 if (audio_fifo_)
428 audio_fifo_->Consume(audio_bus, audio_bus->frames()); 437 audio_fifo_->Consume(audio_bus, audio_bus->frames());
429 else 438 else
430 SourceCallback(0, audio_bus); 439 SourceCallback(0, audio_bus);
431 440
441 if (++render_callback_count_ == kNumCallbacksBetweenRenderTimeHistograms) {
442 base::TimeDelta elapsed = base::TimeTicks::Now() - start_time;
443 render_callback_count_ = 0;
444 UMA_HISTOGRAM_TIMES("WebRTC.AudioRenderTimes", elapsed);
445 }
446
432 return (state_ == PLAYING) ? audio_bus->frames() : 0; 447 return (state_ == PLAYING) ? audio_bus->frames() : 0;
433 } 448 }
434 449
435 void WebRtcAudioRenderer::OnRenderError() { 450 void WebRtcAudioRenderer::OnRenderError() {
436 NOTIMPLEMENTED(); 451 NOTIMPLEMENTED();
437 LOG(ERROR) << "OnRenderError()"; 452 LOG(ERROR) << "OnRenderError()";
438 } 453 }
439 454
440 // Called by AudioPullFifo when more data is necessary. 455 // Called by AudioPullFifo when more data is necessary.
441 void WebRtcAudioRenderer::SourceCallback( 456 void WebRtcAudioRenderer::SourceCallback(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 if (RemovePlayingState(source, state)) 553 if (RemovePlayingState(source, state))
539 EnterPauseState(); 554 EnterPauseState();
540 } else if (AddPlayingState(source, state)) { 555 } else if (AddPlayingState(source, state)) {
541 EnterPlayState(); 556 EnterPlayState();
542 } 557 }
543 UpdateSourceVolume(source); 558 UpdateSourceVolume(source);
544 } 559 }
545 } 560 }
546 561
547 } // namespace content 562 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_renderer.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698