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

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

Issue 1528473003: Feed the WebRTC APM with empty far-end frames for the number of frames skipped by OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review. Rebase. Created 5 years 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 (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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 : state_(UNINITIALIZED), 178 : state_(UNINITIALIZED),
179 source_render_frame_id_(source_render_frame_id), 179 source_render_frame_id_(source_render_frame_id),
180 session_id_(session_id), 180 session_id_(session_id),
181 signaling_thread_(signaling_thread), 181 signaling_thread_(signaling_thread),
182 media_stream_(media_stream), 182 media_stream_(media_stream),
183 source_(NULL), 183 source_(NULL),
184 play_ref_count_(0), 184 play_ref_count_(0),
185 start_ref_count_(0), 185 start_ref_count_(0),
186 audio_delay_milliseconds_(0), 186 audio_delay_milliseconds_(0),
187 fifo_delay_milliseconds_(0), 187 fifo_delay_milliseconds_(0),
188 skipped_frames_(0),
188 sink_params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 189 sink_params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
189 media::CHANNEL_LAYOUT_STEREO, 190 media::CHANNEL_LAYOUT_STEREO,
190 0, 191 0,
191 16, 192 16,
192 0), 193 0),
193 output_device_id_(device_id), 194 output_device_id_(device_id),
194 security_origin_(security_origin), 195 security_origin_(security_origin),
195 render_callback_count_(0) { 196 render_callback_count_(0) {
196 WebRtcLogMessage(base::StringPrintf( 197 WebRtcLogMessage(base::StringPrintf(
197 "WAR::WAR. source_render_frame_id=%d, session_id=%d, effects=%i", 198 "WAR::WAR. source_render_frame_id=%d, session_id=%d, effects=%i",
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 DCHECK(audio_renderer_thread_checker_.CalledOnValidThread()); 424 DCHECK(audio_renderer_thread_checker_.CalledOnValidThread());
424 base::AutoLock auto_lock(lock_); 425 base::AutoLock auto_lock(lock_);
425 if (!source_) 426 if (!source_)
426 return 0; 427 return 0;
427 428
428 DVLOG(2) << "WebRtcAudioRenderer::Render()"; 429 DVLOG(2) << "WebRtcAudioRenderer::Render()";
429 DVLOG(2) << "audio_delay_milliseconds: " << audio_delay_milliseconds; 430 DVLOG(2) << "audio_delay_milliseconds: " << audio_delay_milliseconds;
430 431
431 DCHECK_LE(audio_delay_milliseconds, static_cast<uint32_t>(INT_MAX)); 432 DCHECK_LE(audio_delay_milliseconds, static_cast<uint32_t>(INT_MAX));
432 audio_delay_milliseconds_ = static_cast<int>(audio_delay_milliseconds); 433 audio_delay_milliseconds_ = static_cast<int>(audio_delay_milliseconds);
434 skipped_frames_ += frames_skipped;
433 435
434 if (audio_fifo_) 436 if (audio_fifo_)
435 audio_fifo_->Consume(audio_bus, audio_bus->frames()); 437 audio_fifo_->Consume(audio_bus, audio_bus->frames());
436 else 438 else
437 SourceCallback(0, audio_bus); 439 SourceCallback(0, audio_bus);
438 440
439 return (state_ == PLAYING) ? audio_bus->frames() : 0; 441 return (state_ == PLAYING) ? audio_bus->frames() : 0;
440 } 442 }
441 443
442 void WebRtcAudioRenderer::OnRenderError() { 444 void WebRtcAudioRenderer::OnRenderError() {
(...skipping 11 matching lines...) Expand all
454 << audio_bus->frames() << ")"; 456 << audio_bus->frames() << ")";
455 457
456 int output_delay_milliseconds = audio_delay_milliseconds_; 458 int output_delay_milliseconds = audio_delay_milliseconds_;
457 output_delay_milliseconds += fifo_delay_milliseconds_; 459 output_delay_milliseconds += fifo_delay_milliseconds_;
458 DVLOG(2) << "output_delay_milliseconds: " << output_delay_milliseconds; 460 DVLOG(2) << "output_delay_milliseconds: " << output_delay_milliseconds;
459 461
460 // We need to keep render data for the |source_| regardless of |state_|, 462 // We need to keep render data for the |source_| regardless of |state_|,
461 // otherwise the data will be buffered up inside |source_|. 463 // otherwise the data will be buffered up inside |source_|.
462 source_->RenderData(audio_bus, sink_params_.sample_rate(), 464 source_->RenderData(audio_bus, sink_params_.sample_rate(),
463 output_delay_milliseconds, 465 output_delay_milliseconds,
466 skipped_frames_,
464 &current_time_); 467 &current_time_);
468 skipped_frames_ = 0;
465 469
466 // Avoid filling up the audio bus if we are not playing; instead 470 // Avoid filling up the audio bus if we are not playing; instead
467 // return here and ensure that the returned value in Render() is 0. 471 // return here and ensure that the returned value in Render() is 0.
468 if (state_ != PLAYING) 472 if (state_ != PLAYING)
469 audio_bus->Zero(); 473 audio_bus->Zero();
470 474
471 if (++render_callback_count_ == kNumCallbacksBetweenRenderTimeHistograms) { 475 if (++render_callback_count_ == kNumCallbacksBetweenRenderTimeHistograms) {
472 base::TimeDelta elapsed = base::TimeTicks::Now() - start_time; 476 base::TimeDelta elapsed = base::TimeTicks::Now() - start_time;
473 render_callback_count_ = 0; 477 render_callback_count_ = 0;
474 UMA_HISTOGRAM_TIMES("WebRTC.AudioRenderTimes", elapsed); 478 UMA_HISTOGRAM_TIMES("WebRTC.AudioRenderTimes", elapsed);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 sink_params_ = new_sink_params; 655 sink_params_ = new_sink_params;
652 fifo_delay_milliseconds_ = new_fifo_delay_milliseconds; 656 fifo_delay_milliseconds_ = new_fifo_delay_milliseconds;
653 if (new_audio_fifo.get()) 657 if (new_audio_fifo.get())
654 audio_fifo_ = new_audio_fifo.Pass(); 658 audio_fifo_ = new_audio_fifo.Pass();
655 } 659 }
656 660
657 sink_->Initialize(new_sink_params, this); 661 sink_->Initialize(new_sink_params, this);
658 } 662 }
659 663
660 } // namespace content 664 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_renderer.h ('k') | content/renderer/media/webrtc_audio_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698