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

Unified Diff: media/base/audio_fifo.cc

Issue 10915123: Adds media::AudioPullFifo class to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 8 years, 3 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/base/audio_fifo.h ('k') | media/base/audio_fifo_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_fifo.cc
diff --git a/media/base/audio_fifo.cc b/media/base/audio_fifo.cc
index eb9d65377f46e68ea7c3a79cd11c0e4ef2bb7988..8ee656e785963ee51b02ccc61f22e7540b088fdf 100644
--- a/media/base/audio_fifo.cc
+++ b/media/base/audio_fifo.cc
@@ -39,27 +39,24 @@ static int UpdatePos(int pos, int step, int max_size) {
AudioFifo::AudioFifo(int channels, int frames)
: audio_bus_(AudioBus::Create(channels, frames)),
- max_frames_in_fifo_(frames),
- frames_in_fifo_(0),
+ max_frames_(frames),
+ frames_(0),
read_pos_(0),
write_pos_(0) {}
AudioFifo::~AudioFifo() {}
-bool AudioFifo::Push(const AudioBus* source) {
+void AudioFifo::Push(const AudioBus* source) {
DCHECK(source);
DCHECK_EQ(source->channels(), audio_bus_->channels());
// Ensure that there is space for the new data in the FIFO.
const int source_size = source->frames();
- if (frames_in_fifo_ + source_size > max_frames()) {
- DLOG(ERROR) << "FIFO overflow.";
- return false;
- }
-
- // Figure out if wrapping is needed and if so what segment sizes we need
- // when adding the new audio bus content to the FIFO.
- int append_size = 0;
+ CHECK_LE(source_size + frames_, max_frames_);
+
+ // Figure out if wrapping is needed and if so what segment sizes we need
+ // when adding the new audio bus content to the FIFO.
+ int append_size = 0;
int wrap_size = 0;
GetSizes(write_pos_, max_frames(), source_size, &append_size, &wrap_size);
@@ -76,28 +73,24 @@ bool AudioFifo::Push(const AudioBus* source) {
}
}
- frames_in_fifo_ += source_size;
- DCHECK_LE(frames_in_fifo_, max_frames());
+ frames_ += source_size;
+ DCHECK_LE(frames_, max_frames());
write_pos_ = UpdatePos(write_pos_, source_size, max_frames());
- return true;
}
-bool AudioFifo::Consume(AudioBus* destination, int frames_to_consume) {
+
+void AudioFifo::Consume(AudioBus* destination,
+ int start_frame,
+ int frames_to_consume) {
DCHECK(destination);
DCHECK_EQ(destination->channels(), audio_bus_->channels());
// It is not possible to ask for more data than what is available in the FIFO.
- if (frames_to_consume > frames_in_fifo_) {
- DLOG(ERROR) << "FIFO underrun.";
- return false;
- }
+ CHECK_LE(frames_to_consume, frames_);
// A copy from the FIFO to |destination| will only be performed if the
// allocated memory in |destination| is sufficient.
- if (frames_to_consume > destination->frames()) {
- DLOG(ERROR) << "Insufficient space in destination.";
- return false;
- }
+ CHECK_LE(frames_to_consume + start_frame, destination->frames());
// Figure out if wrapping is needed and if so what segment sizes we need
// when removing audio bus content from the FIFO.
@@ -113,20 +106,20 @@ bool AudioFifo::Consume(AudioBus* destination, int frames_to_consume) {
const float* src = audio_bus_->channel(ch);
// Copy a selected part of the FIFO to the destination.
- memcpy(&dest[0], &src[read_pos_], consume_size * sizeof(src[0]));
+ memcpy(&dest[start_frame], &src[read_pos_], consume_size * sizeof(src[0]));
if (wrap_size > 0) {
// Wrapping is needed: copy remaining part to the destination.
- memcpy(&dest[consume_size], &src[0], wrap_size * sizeof(src[0]));
+ memcpy(&dest[consume_size + start_frame], &src[0],
+ wrap_size * sizeof(src[0]));
}
}
- frames_in_fifo_ -= frames_to_consume;
+ frames_ -= frames_to_consume;
read_pos_ = UpdatePos(read_pos_, frames_to_consume, max_frames());
- return true;
}
void AudioFifo::Clear() {
- frames_in_fifo_ = 0;
+ frames_ = 0;
read_pos_ = 0;
write_pos_ = 0;
}
« no previous file with comments | « media/base/audio_fifo.h ('k') | media/base/audio_fifo_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698