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

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

Issue 9479012: Merge 123292 - Increase the buffer size in AudioRendererImpl to fix muted playback rate (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1025/src/
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/content_browser.gypi ('k') | media/audio/audio_util.h » ('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/audio_renderer_impl.h" 5 #include "content/renderer/media/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "content/common/child_process.h" 12 #include "content/common/child_process.h"
13 #include "content/common/media/audio_messages.h" 13 #include "content/common/media/audio_messages.h"
14 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
15 #include "media/audio/audio_buffers_state.h" 15 #include "media/audio/audio_buffers_state.h"
16 #include "media/audio/audio_util.h" 16 #include "media/audio/audio_util.h"
17 #include "media/base/filter_host.h" 17 #include "media/base/filter_host.h"
18 18
19 // We define GetBufferSizeForSampleRate() instead of using
20 // GetAudioHardwareBufferSize() in audio_util because we're using
21 // the AUDIO_PCM_LINEAR flag, instead of AUDIO_PCM_LOW_LATENCY,
22 // which the audio_util functions assume.
23 //
24 // See: http://code.google.com/p/chromium/issues/detail?id=103627
25 // for a more detailed description of the subtleties.
26 static size_t GetBufferSizeForSampleRate(int sample_rate) {
27 // kNominalBufferSize has been tested on Windows, Mac OS X, and Linux
28 // using the low-latency audio codepath (SyncSocket implementation)
29 // with the AUDIO_PCM_LINEAR flag.
30 const size_t kNominalBufferSize = 2048;
31
32 if (sample_rate <= 48000)
33 return kNominalBufferSize;
34 else if (sample_rate <= 96000)
35 return kNominalBufferSize * 2;
36 return kNominalBufferSize * 4;
37 }
38
39 AudioRendererImpl::AudioRendererImpl(media::AudioRendererSink* sink) 19 AudioRendererImpl::AudioRendererImpl(media::AudioRendererSink* sink)
40 : AudioRendererBase(), 20 : AudioRendererBase(),
41 bytes_per_second_(0), 21 bytes_per_second_(0),
42 stopped_(false), 22 stopped_(false),
43 sink_(sink), 23 sink_(sink),
44 is_initialized_(false) { 24 is_initialized_(false) {
45 } 25 }
46 26
47 AudioRendererImpl::~AudioRendererImpl() { 27 AudioRendererImpl::~AudioRendererImpl() {
48 } 28 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 sample_rate, 64 sample_rate,
85 bits_per_channel, 65 bits_per_channel,
86 0); 66 0);
87 67
88 bytes_per_second_ = audio_parameters_.GetBytesPerSecond(); 68 bytes_per_second_ = audio_parameters_.GetBytesPerSecond();
89 69
90 DCHECK(sink_.get()); 70 DCHECK(sink_.get());
91 71
92 if (!is_initialized_) { 72 if (!is_initialized_) {
93 sink_->Initialize( 73 sink_->Initialize(
94 GetBufferSizeForSampleRate(sample_rate), 74 media::SelectSamplesPerPacket(sample_rate),
95 audio_parameters_.channels, 75 audio_parameters_.channels,
96 audio_parameters_.sample_rate, 76 audio_parameters_.sample_rate,
97 audio_parameters_.format, 77 audio_parameters_.format,
98 this); 78 this);
99 79
100 sink_->Start(); 80 sink_->Start();
101 is_initialized_ = true; 81 is_initialized_ = true;
102 return true; 82 return true;
103 } 83 }
104 84
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 227
248 void AudioRendererImpl::OnError() { 228 void AudioRendererImpl::OnError() {
249 host()->DisableAudioRenderer(); 229 host()->DisableAudioRenderer();
250 } 230 }
251 231
252 void AudioRendererImpl::OnRenderEndOfStream() { 232 void AudioRendererImpl::OnRenderEndOfStream() {
253 // TODO(enal): schedule callback instead of polling. 233 // TODO(enal): schedule callback instead of polling.
254 if (base::Time::Now() >= earliest_end_time_) 234 if (base::Time::Now() >= earliest_end_time_)
255 SignalEndOfStream(); 235 SignalEndOfStream();
256 } 236 }
OLDNEW
« no previous file with comments | « content/content_browser.gypi ('k') | media/audio/audio_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698