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

Unified Diff: content/renderer/media/webrtc_audio_renderer.cc

Issue 2452183003: Revert of Make more media APIs aware of |delay| and |delay_timestamp| (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/webrtc_audio_renderer.h ('k') | media/audio/audio_device_thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webrtc_audio_renderer.cc
diff --git a/content/renderer/media/webrtc_audio_renderer.cc b/content/renderer/media/webrtc_audio_renderer.cc
index 32c27bf8be65487b9e021bf5e6a3e95d8345ab66..3e39fe4419289ef807430ed6bcba3344583bfe6d 100644
--- a/content/renderer/media/webrtc_audio_renderer.cc
+++ b/content/renderer/media/webrtc_audio_renderer.cc
@@ -167,6 +167,7 @@
source_(NULL),
play_ref_count_(0),
start_ref_count_(0),
+ audio_delay_milliseconds_(0),
sink_params_(kFormat, kChannelLayout, 0, kBitsPerSample, 0),
output_device_id_(device_id),
security_origin_(security_origin) {
@@ -267,7 +268,7 @@
state_ = PLAYING;
if (audio_fifo_) {
- audio_delay_ = base::TimeDelta();
+ audio_delay_milliseconds_ = 0;
audio_fifo_->Clear();
}
}
@@ -400,26 +401,35 @@
callback.Run(media::OUTPUT_DEVICE_STATUS_OK);
}
-int WebRtcAudioRenderer::Render(base::TimeDelta delay,
- base::TimeTicks delay_timestamp,
- int prior_frames_skipped,
- media::AudioBus* audio_bus) {
+int WebRtcAudioRenderer::Render(media::AudioBus* audio_bus,
+ uint32_t frames_delayed,
+ uint32_t frames_skipped) {
DCHECK(sink_->CurrentThreadIsRenderingThread());
base::AutoLock auto_lock(lock_);
if (!source_)
return 0;
+ // TODO(grunell): Converting from frames to milliseconds will potentially lose
+ // hundreds of microseconds which may cause audio video drift. Update
+ // this class and all usage of render delay msec -> frames (possibly even
+ // using a double type for frames). See http://crbug.com/586540
+ uint32_t audio_delay_milliseconds = static_cast<double>(frames_delayed) *
+ base::Time::kMillisecondsPerSecond /
+ sink_params_.sample_rate();
+
DVLOG(2) << "WebRtcAudioRenderer::Render()";
- DVLOG(2) << "audio_delay: " << delay;
-
- audio_delay_ = delay;
+ DVLOG(2) << "audio_delay_milliseconds: " << audio_delay_milliseconds;
+
+ DCHECK_LE(audio_delay_milliseconds, static_cast<uint32_t>(INT_MAX));
+ audio_delay_milliseconds_ = static_cast<int>(audio_delay_milliseconds);
// If there are skipped frames, pull and throw away the same amount. We always
// pull 10 ms of data from the source (see PrepareSink()), so the fifo is only
// required if the number of frames to drop doesn't correspond to 10 ms.
- if (prior_frames_skipped > 0) {
- const int source_frames_per_buffer = sink_params_.sample_rate() / 100;
- if (!audio_fifo_ && prior_frames_skipped != source_frames_per_buffer) {
+ if (frames_skipped > 0) {
+ const uint32_t source_frames_per_buffer =
+ static_cast<uint32_t>(sink_params_.sample_rate() / 100);
+ if (!audio_fifo_ && frames_skipped != source_frames_per_buffer) {
audio_fifo_.reset(new media::AudioPullFifo(
kChannels, source_frames_per_buffer,
base::Bind(&WebRtcAudioRenderer::SourceCallback,
@@ -427,7 +437,7 @@
}
std::unique_ptr<media::AudioBus> drop_bus =
- media::AudioBus::Create(audio_bus->channels(), prior_frames_skipped);
+ media::AudioBus::Create(audio_bus->channels(), frames_skipped);
if (audio_fifo_)
audio_fifo_->Consume(drop_bus.get(), drop_bus->frames());
else
@@ -457,7 +467,7 @@
<< fifo_frame_delay << ", "
<< audio_bus->frames() << ")";
- int output_delay_milliseconds = audio_delay_.InMilliseconds();
+ int output_delay_milliseconds = audio_delay_milliseconds_;
// TODO(grunell): This integer division by sample_rate will cause loss of
// partial milliseconds, and may cause avsync drift. http://crbug.com/586540
output_delay_milliseconds += fifo_frame_delay *
« no previous file with comments | « content/renderer/media/webrtc_audio_renderer.h ('k') | media/audio/audio_device_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698