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

Unified Diff: media/filters/audio_renderer_algorithm_ola.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_ola.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/audio_renderer_algorithm_ola.cc
===================================================================
--- media/filters/audio_renderer_algorithm_ola.cc (revision 20165)
+++ media/filters/audio_renderer_algorithm_ola.cc (working copy)
@@ -16,8 +16,7 @@
const size_t kDefaultWindowSize = 4096;
AudioRendererAlgorithmOLA::AudioRendererAlgorithmOLA()
- : data_offset_(0),
- input_step_(0),
+ : input_step_(0),
output_step_(0) {
}
@@ -25,7 +24,7 @@
}
size_t AudioRendererAlgorithmOLA::FillBuffer(DataBuffer* buffer_out) {
- if (IsInputFinished())
+ if (IsQueueEmpty())
return 0;
if (playback_rate() == 0.0f)
return 0;
@@ -35,8 +34,11 @@
uint8* dest = buffer_out->GetWritableData(dest_remaining);
size_t dest_written = 0;
if (playback_rate() == 1.0f) {
- dest_written = CopyInput(dest, dest_remaining);
- AdvanceInput(dest_written);
+ if (QueueSize() < dest_remaining)
+ dest_written = CopyFromInput(dest, QueueSize());
+ else
+ dest_written = CopyFromInput(dest, dest_remaining);
+ AdvanceInputPosition(dest_written);
return dest_written;
}
@@ -44,21 +46,25 @@
// TODO(kylep): Limit the rates to reasonable values. We may want to do this
// on the UI side or in set_playback_rate().
while (dest_remaining >= output_step_ + crossfade_size_) {
+ // If we don't have enough data to completely finish this loop, quit.
+ if (QueueSize() < kDefaultWindowSize)
+ break;
+
// Copy bulk of data to output (including some to crossfade to the next
// copy), then add to our running sum of written data and subtract from
// our tally of remaing requested.
- size_t copied = CopyInput(dest, output_step_ + crossfade_size_);
+ size_t copied = CopyFromInput(dest, output_step_ + crossfade_size_);
dest_written += copied;
dest_remaining -= copied;
// Advance pointers for crossfade.
dest += output_step_;
- AdvanceInput(input_step_);
+ AdvanceInputPosition(input_step_);
// Prepare intermediate buffer.
size_t crossfade_size;
scoped_array<uint8> src(new uint8[crossfade_size_]);
- crossfade_size = CopyInput(src.get(), crossfade_size_);
+ crossfade_size = CopyFromInput(src.get(), crossfade_size_);
// Calculate number of samples to crossfade, then do so.
int samples = static_cast<int>(crossfade_size / sample_bytes()
@@ -82,17 +88,12 @@
}
// Advance pointers again.
- AdvanceInput(crossfade_size_);
- dest += crossfade_size_;
+ AdvanceInputPosition(crossfade_size);
+ dest += crossfade_size;
}
return dest_written;
}
-void AudioRendererAlgorithmOLA::FlushBuffers() {
- AudioRendererAlgorithmBase::FlushBuffers();
- saved_buf_ = NULL;
-}
-
void AudioRendererAlgorithmOLA::set_playback_rate(float new_rate) {
AudioRendererAlgorithmBase::set_playback_rate(new_rate);
@@ -118,74 +119,10 @@
output_step_ -= crossfade_size_;
}
-void AudioRendererAlgorithmOLA::AdvanceInput(size_t bytes) {
- if (IsInputFinished())
- return;
-
- DCHECK(saved_buf_) << "Did you forget to call CopyInput()?";
-
- // Calculate number of usable bytes in |saved_buf_|.
- size_t saved_buf_remaining = saved_buf_->GetDataSize() - data_offset_;
-
- // If there is enough data in |saved_buf_| to advance into it, do so.
- // Otherwise, advance into the queue.
- if (saved_buf_remaining > bytes) {
- data_offset_ += bytes;
- } else {
- if (!IsQueueEmpty()) {
- saved_buf_ = FrontQueue();
- PopFrontQueue();
- } else {
- saved_buf_ = NULL;
- }
- // TODO(kylep): Make this function loop to eliminate the DCHECK.
- DCHECK_GE(bytes, saved_buf_remaining);
-
- data_offset_ = bytes - saved_buf_remaining;
- }
-}
-
void AudioRendererAlgorithmOLA::AlignToSampleBoundary(size_t* value) {
(*value) -= ((*value) % (channels() * sample_bytes()));
}
-// TODO(kylep): Make this function loop to satisfy requests better.
-size_t AudioRendererAlgorithmOLA::CopyInput(uint8* dest, size_t length) {
- if (IsInputFinished())
- return 0;
-
- // Lazy initialization.
- if (!saved_buf_) {
- saved_buf_ = FrontQueue();
- PopFrontQueue();
- }
-
- size_t dest_written = 0;
- size_t data_length = saved_buf_->GetDataSize() - data_offset_;
-
- // Prevent writing past end of the buffer.
- if (data_length > length)
- data_length = length;
- memcpy(dest, saved_buf_->GetData() + data_offset_, data_length);
-
- dest += data_length;
- length -= data_length;
- dest_written += data_length;
-
- if (length > 0) {
- // We should have enough data in the next buffer so long as the
- // queue is not empty.
- if (IsQueueEmpty())
- return dest_written;
- DCHECK_LE(length, FrontQueue()->GetDataSize());
-
- memcpy(dest, FrontQueue()->GetData(), length);
- dest_written += length;
- }
-
- return dest_written;
-}
-
template <class Type>
void AudioRendererAlgorithmOLA::Crossfade(int samples,
const Type* src,
@@ -205,8 +142,4 @@
}
}
-bool AudioRendererAlgorithmOLA::IsInputFinished() {
- return !saved_buf_ && IsQueueEmpty();
-}
-
} // namespace media
« no previous file with comments | « media/filters/audio_renderer_algorithm_ola.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698