Skip to content

Commit

Permalink
Remove time getters from AudioBufferQueue and AudioRendererAlgorithm.
Browse files Browse the repository at this point in the history
With the switch to pure frame-based calculation of time in 5b6ce11,
these methods are no longer used.

BUG=370634

Review URL: https://codereview.chromium.org/516113002

Cr-Commit-Position: refs/heads/master@{#292560}
  • Loading branch information
scherkus authored and Commit bot committed Aug 29, 2014
1 parent 51d4852 commit 5068765
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 170 deletions.
26 changes: 0 additions & 26 deletions media/base/audio_buffer_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ void AudioBufferQueue::Clear() {
current_buffer_ = buffers_.begin();
current_buffer_offset_ = 0;
frames_ = 0;
current_time_ = kNoTimestamp();
}

void AudioBufferQueue::Append(const scoped_refptr<AudioBuffer>& buffer_in) {
// If we have just written the first buffer, update |current_time_| to be the
// start time.
if (buffers_.empty() && buffer_in->timestamp() != kNoTimestamp()) {
current_time_ = buffer_in->timestamp();
}

// Add the buffer to the queue. Inserting into deque invalidates all
// iterators, so point to the first buffer.
buffers_.push_back(buffer_in);
Expand Down Expand Up @@ -114,12 +107,6 @@ int AudioBufferQueue::InternalRead(int frames,

// Has the buffer has been consumed?
if (current_buffer_offset == buffer->frame_count()) {
if (advance_position) {
// Next buffer may not have timestamp, so we need to update current
// timestamp before switching to the next buffer.
UpdateCurrentTime(current_buffer, current_buffer_offset);
}

// If we are at the last buffer, no more data to be copied, so stop.
BufferQueue::iterator next = current_buffer + 1;
if (next == buffers_.end())
Expand All @@ -137,8 +124,6 @@ int AudioBufferQueue::InternalRead(int frames,
DCHECK_GE(frames_, 0);
DCHECK(current_buffer_ != buffers_.end() || frames_ == 0);

UpdateCurrentTime(current_buffer, current_buffer_offset);

// Remove any buffers before the current buffer as there is no going
// backwards.
buffers_.erase(buffers_.begin(), current_buffer);
Expand All @@ -149,15 +134,4 @@ int AudioBufferQueue::InternalRead(int frames,
return taken;
}

void AudioBufferQueue::UpdateCurrentTime(BufferQueue::iterator buffer,
int offset) {
if (buffer != buffers_.end() && (*buffer)->timestamp() != kNoTimestamp()) {
double time_offset = ((*buffer)->duration().InMicroseconds() * offset) /
static_cast<double>((*buffer)->frame_count());
current_time_ =
(*buffer)->timestamp() + base::TimeDelta::FromMicroseconds(
static_cast<int64>(time_offset + 0.5));
}
}

} // namespace media
15 changes: 0 additions & 15 deletions media/base/audio_buffer_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ class MEDIA_EXPORT AudioBufferQueue {
// Returns the number of frames buffered beyond the current position.
int frames() const { return frames_; }

// Returns the current timestamp, taking into account current offset. The
// value calculated based on the timestamp of the current buffer. If timestamp
// for the current buffer is set to 0, then returns value that corresponds to
// the last position in a buffer that had timestamp set. kNoTimestamp() is
// returned if no buffers we read from had timestamp set.
base::TimeDelta current_time() const { return current_time_; }

private:
// Definition of the buffer queue.
typedef std::deque<scoped_refptr<AudioBuffer> > BufferQueue;
Expand All @@ -81,21 +74,13 @@ class MEDIA_EXPORT AudioBufferQueue {
int dest_frame_offset,
AudioBus* dest);

// Updates |current_time_| with the time that corresponds to the specified
// position in the buffer.
void UpdateCurrentTime(BufferQueue::iterator buffer, int offset);

BufferQueue::iterator current_buffer_;
BufferQueue buffers_;
int current_buffer_offset_;

// Number of frames available to be read in the buffer.
int frames_;

// Keeps track of the most recent time we've seen in case the |buffers_| is
// empty when our owner asks what time it is.
base::TimeDelta current_time_;

DISALLOW_COPY_AND_ASSIGN(AudioBufferQueue);
};

Expand Down
121 changes: 0 additions & 121 deletions media/base/audio_buffer_queue_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,125 +344,4 @@ TEST(AudioBufferQueueTest, Peek) {
EXPECT_EQ(30, buffer.PeekFrames(30, 0, 0, bus1.get()));
}

TEST(AudioBufferQueueTest, Time) {
const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
const int channels = ChannelLayoutToChannelCount(channel_layout);
const base::TimeDelta start_time1;
const base::TimeDelta start_time2 = base::TimeDelta::FromSeconds(30);
AudioBufferQueue buffer;
scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);

scoped_refptr<AudioBuffer> audio_buffer =
MakeAudioBuffer<int16>(kSampleFormatS16,
channel_layout,
channels,
kSampleRate,
1,
1,
10,
start_time1);

// Add two buffers (second one added later):
// first: start=0s, duration=10s
// second: start=30s, duration=10s
buffer.Append(audio_buffer);
EXPECT_EQ(10, buffer.frames());

// Check starting time.
EXPECT_EQ(start_time1, buffer.current_time());

// Read 2 frames, should be 2s in (since duration is 1s per sample).
int frames_read = 2;
EXPECT_EQ(frames_read, buffer.ReadFrames(frames_read, 0, bus.get()));
EXPECT_EQ(
start_time1 +
frames_read * audio_buffer->duration() / audio_buffer->frame_count(),
buffer.current_time());

// Skip 2 frames.
buffer.SeekFrames(2);
frames_read += 2;
EXPECT_EQ(
start_time1 +
frames_read * audio_buffer->duration() / audio_buffer->frame_count(),
buffer.current_time());

// Add second buffer for more data.
buffer.Append(MakeAudioBuffer<int16>(kSampleFormatS16,
channel_layout,
channels,
kSampleRate,
1,
1,
10,
start_time2));
EXPECT_EQ(16, buffer.frames());

// Read until almost the end of buffer1.
frames_read += 5;
EXPECT_EQ(5, buffer.ReadFrames(5, 0, bus.get()));
EXPECT_EQ(
start_time1 +
frames_read * audio_buffer->duration() / audio_buffer->frame_count(),
buffer.current_time());

// Read 1 value, so time moved to buffer2.
EXPECT_EQ(1, buffer.ReadFrames(1, 0, bus.get()));
EXPECT_EQ(start_time2, buffer.current_time());

// Read all 10 frames in buffer2, timestamp should be last time from buffer2.
frames_read = 10;
EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get()));
const base::TimeDelta expected_current_time =
start_time2 +
frames_read * audio_buffer->duration() / audio_buffer->frame_count();
EXPECT_EQ(expected_current_time, buffer.current_time());

// Try to read more frames (which don't exist), timestamp should remain.
EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get()));
EXPECT_EQ(expected_current_time, buffer.current_time());
}

TEST(AudioBufferQueueTest, NoTime) {
const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
const int channels = ChannelLayoutToChannelCount(channel_layout);
const base::TimeDelta kNoTime = kNoTimestamp();
AudioBufferQueue buffer;
scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);

// Add two buffers with no timestamps. Time should always be unknown.
buffer.Append(
MakeTestBuffer<int16>(kSampleFormatS16, channel_layout, 1, 1, 10));
buffer.Append(
MakeTestBuffer<int16>(kSampleFormatS16, channel_layout, 1, 1, 10));
EXPECT_EQ(20, buffer.frames());

// Check starting time.
EXPECT_EQ(kNoTime, buffer.current_time());

// Read 2 frames.
EXPECT_EQ(2, buffer.ReadFrames(2, 0, bus.get()));
EXPECT_EQ(kNoTime, buffer.current_time());

// Skip 2 frames.
buffer.SeekFrames(2);
EXPECT_EQ(kNoTime, buffer.current_time());

// Read until almost the end of buffer1.
EXPECT_EQ(5, buffer.ReadFrames(5, 0, bus.get()));
EXPECT_EQ(kNoTime, buffer.current_time());

// Read 1 value, so time moved to buffer2.
EXPECT_EQ(1, buffer.ReadFrames(1, 0, bus.get()));
EXPECT_EQ(kNoTime, buffer.current_time());

// Read all 10 frames in buffer2.
EXPECT_EQ(10, buffer.ReadFrames(10, 0, bus.get()));
EXPECT_EQ(kNoTime, buffer.current_time());

// Try to read more frames (which don't exist), timestamp should remain.
EXPECT_EQ(0, buffer.ReadFrames(5, 0, bus.get()));
EXPECT_EQ(kNoTime, buffer.current_time());
}

} // namespace media
4 changes: 0 additions & 4 deletions media/filters/audio_renderer_algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ void AudioRendererAlgorithm::FlushBuffers() {
capacity_ = kStartingBufferSizeInFrames;
}

base::TimeDelta AudioRendererAlgorithm::GetTime() {
return audio_buffer_.current_time();
}

void AudioRendererAlgorithm::EnqueueBuffer(
const scoped_refptr<AudioBuffer>& buffer_in) {
DCHECK(!buffer_in->end_of_stream());
Expand Down
4 changes: 0 additions & 4 deletions media/filters/audio_renderer_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ class MEDIA_EXPORT AudioRendererAlgorithm {
// Clears |audio_buffer_|.
void FlushBuffers();

// Returns the time of the next byte in our data or kNoTimestamp() if current
// time is unknown.
base::TimeDelta GetTime();

// Enqueues a buffer. It is called from the owner of the algorithm after a
// read completes.
void EnqueueBuffer(const scoped_refptr<AudioBuffer>& buffer_in);
Expand Down

0 comments on commit 5068765

Please sign in to comment.