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

Unified Diff: media/filters/null_audio_renderer.cc

Issue 9395057: Fix muted audio when playback rate != 1.0 or 0.0 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase ToT Created 8 years, 10 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 | « media/filters/null_audio_renderer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/null_audio_renderer.cc
diff --git a/media/filters/null_audio_renderer.cc b/media/filters/null_audio_renderer.cc
index 6168bd9212198143991d4b264cd7d347c145c14e..f7ee27ce4b29aa3872af080418be18c2467ea080 100644
--- a/media/filters/null_audio_renderer.cc
+++ b/media/filters/null_audio_renderer.cc
@@ -22,6 +22,7 @@ NullAudioRenderer::NullAudioRenderer()
: AudioRendererBase(),
bytes_per_millisecond_(0),
buffer_size_(0),
+ bytes_per_frame_(0),
thread_("AudioThread") {
}
@@ -37,10 +38,16 @@ bool NullAudioRenderer::OnInitialize(int bits_per_channel,
ChannelLayout channel_layout,
int sample_rate) {
// Calculate our bytes per millisecond value and allocate our buffer.
- bytes_per_millisecond_ =
- (ChannelLayoutToChannelCount(channel_layout) * sample_rate *
- bits_per_channel / 8) / base::Time::kMillisecondsPerSecond;
- buffer_size_ = bytes_per_millisecond_ * kBufferSizeInMilliseconds;
+ int channels = ChannelLayoutToChannelCount(channel_layout);
+ int bytes_per_channel = bits_per_channel / 8;
+ bytes_per_frame_ = channels * bytes_per_channel;
+
+ bytes_per_millisecond_ = (bytes_per_frame_ * sample_rate) /
+ base::Time::kMillisecondsPerSecond;
+
+ buffer_size_ =
+ bytes_per_millisecond_ * kBufferSizeInMilliseconds;
+
buffer_.reset(new uint8[buffer_size_]);
DCHECK(buffer_.get());
@@ -61,7 +68,10 @@ void NullAudioRenderer::FillBufferTask() {
// Only consume buffers when actually playing.
if (GetPlaybackRate() > 0.0f) {
- size_t bytes = FillBuffer(buffer_.get(), buffer_size_, base::TimeDelta());
+ size_t requested_frames = buffer_size_ / bytes_per_frame_;
+ size_t frames = FillBuffer(
+ buffer_.get(), requested_frames, base::TimeDelta());
+ size_t bytes = frames * bytes_per_frame_;
// Calculate our sleep duration, taking playback rate into consideration.
delay = base::TimeDelta::FromMilliseconds(
« no previous file with comments | « media/filters/null_audio_renderer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698