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

Unified Diff: media/filters/audio_renderer_algorithm_base.cc

Issue 155255: Refactor audio renderer algorithms to use BufferQueue. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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/audio_renderer_algorithm_base.h ('k') | media/filters/audio_renderer_algorithm_default.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_renderer_algorithm_base.cc
===================================================================
--- media/filters/audio_renderer_algorithm_base.cc (revision 20165)
+++ media/filters/audio_renderer_algorithm_base.cc (working copy)
@@ -8,14 +8,10 @@
namespace media {
-// The maximum size of the queue, which also acts as the number of initial reads
-// to perform for buffering. The size of the queue should never exceed this
-// number since we read only after we've dequeued and released a buffer in
-// callback thread.
-//
-// This is sort of a magic number, but for 44.1kHz stereo audio this will give
-// us enough data to fill approximately 4 complete callback buffers.
-const size_t kDefaultMaxQueueSize = 16;
+// The size in bytes we try to maintain for the |queue_|. Previous usage
+// maintained a deque of 16 Buffers, each of size 4Kb. This worked well, so we
+// maintain this number of bytes (16 * 4096).
+const size_t kDefaultMaxQueueSizeInBytes = 65536;
AudioRendererAlgorithmBase::AudioRendererAlgorithmBase()
: channels_(0),
@@ -40,21 +36,24 @@
set_playback_rate(initial_playback_rate);
- for (size_t i = 0; i < kDefaultMaxQueueSize; ++i)
- request_read_callback_->Run();
+ // Do the initial read.
+ request_read_callback_->Run();
}
void AudioRendererAlgorithmBase::FlushBuffers() {
// Clear the queue of decoded packets (releasing the buffers).
- queue_.clear();
+ queue_.Clear();
+ request_read_callback_->Run();
}
void AudioRendererAlgorithmBase::EnqueueBuffer(Buffer* buffer_in) {
// If we're at end of stream, |buffer_in| contains no data.
- if (!buffer_in->IsEndOfStream()) {
- queue_.push_back(buffer_in);
- DCHECK_LE(queue_.size(), kDefaultMaxQueueSize);
- }
+ if (!buffer_in->IsEndOfStream())
+ queue_.Enqueue(buffer_in);
+
+ // If we still don't have enough data, request more.
+ if (queue_.SizeInBytes() < kDefaultMaxQueueSizeInBytes)
+ request_read_callback_->Run();
}
float AudioRendererAlgorithmBase::playback_rate() {
@@ -66,19 +65,25 @@
playback_rate_ = new_rate;
}
-bool AudioRendererAlgorithmBase::IsQueueEmpty() {
- return queue_.empty();
+void AudioRendererAlgorithmBase::AdvanceInputPosition(size_t bytes) {
+ queue_.Consume(bytes);
+
+ if (queue_.SizeInBytes() < kDefaultMaxQueueSizeInBytes)
+ request_read_callback_->Run();
}
-scoped_refptr<Buffer> AudioRendererAlgorithmBase::FrontQueue() {
- return queue_.front();
+size_t AudioRendererAlgorithmBase::CopyFromInput(uint8* dest, size_t bytes) {
+ return queue_.Copy(dest, bytes);
}
-void AudioRendererAlgorithmBase::PopFrontQueue() {
- queue_.pop_front();
- request_read_callback_->Run();
+bool AudioRendererAlgorithmBase::IsQueueEmpty() {
+ return queue_.IsEmpty();
}
+size_t AudioRendererAlgorithmBase::QueueSize() {
+ return queue_.SizeInBytes();
+}
+
int AudioRendererAlgorithmBase::channels() {
return channels_;
}
« no previous file with comments | « media/filters/audio_renderer_algorithm_base.h ('k') | media/filters/audio_renderer_algorithm_default.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698