Commit 50687650 authored by scherkus's avatar scherkus Committed by Commit bot

Remove time getters from AudioBufferQueue and AudioRendererAlgorithm.

With the switch to pure frame-based calculation of time in 5b6ce11b,
these methods are no longer used.

BUG=370634

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

Cr-Commit-Position: refs/heads/master@{#292560}
parent 51d48522
...@@ -20,16 +20,9 @@ void AudioBufferQueue::Clear() { ...@@ -20,16 +20,9 @@ void AudioBufferQueue::Clear() {
current_buffer_ = buffers_.begin(); current_buffer_ = buffers_.begin();
current_buffer_offset_ = 0; current_buffer_offset_ = 0;
frames_ = 0; frames_ = 0;
current_time_ = kNoTimestamp();
} }
void AudioBufferQueue::Append(const scoped_refptr<AudioBuffer>& buffer_in) { 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 // Add the buffer to the queue. Inserting into deque invalidates all
// iterators, so point to the first buffer. // iterators, so point to the first buffer.
buffers_.push_back(buffer_in); buffers_.push_back(buffer_in);
...@@ -114,12 +107,6 @@ int AudioBufferQueue::InternalRead(int frames, ...@@ -114,12 +107,6 @@ int AudioBufferQueue::InternalRead(int frames,
// Has the buffer has been consumed? // Has the buffer has been consumed?
if (current_buffer_offset == buffer->frame_count()) { 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. // If we are at the last buffer, no more data to be copied, so stop.
BufferQueue::iterator next = current_buffer + 1; BufferQueue::iterator next = current_buffer + 1;
if (next == buffers_.end()) if (next == buffers_.end())
...@@ -137,8 +124,6 @@ int AudioBufferQueue::InternalRead(int frames, ...@@ -137,8 +124,6 @@ int AudioBufferQueue::InternalRead(int frames,
DCHECK_GE(frames_, 0); DCHECK_GE(frames_, 0);
DCHECK(current_buffer_ != buffers_.end() || 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 // Remove any buffers before the current buffer as there is no going
// backwards. // backwards.
buffers_.erase(buffers_.begin(), current_buffer); buffers_.erase(buffers_.begin(), current_buffer);
...@@ -149,15 +134,4 @@ int AudioBufferQueue::InternalRead(int frames, ...@@ -149,15 +134,4 @@ int AudioBufferQueue::InternalRead(int frames,
return taken; 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 } // namespace media
...@@ -57,13 +57,6 @@ class MEDIA_EXPORT AudioBufferQueue { ...@@ -57,13 +57,6 @@ class MEDIA_EXPORT AudioBufferQueue {
// Returns the number of frames buffered beyond the current position. // Returns the number of frames buffered beyond the current position.
int frames() const { return frames_; } 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: private:
// Definition of the buffer queue. // Definition of the buffer queue.
typedef std::deque<scoped_refptr<AudioBuffer> > BufferQueue; typedef std::deque<scoped_refptr<AudioBuffer> > BufferQueue;
...@@ -81,10 +74,6 @@ class MEDIA_EXPORT AudioBufferQueue { ...@@ -81,10 +74,6 @@ class MEDIA_EXPORT AudioBufferQueue {
int dest_frame_offset, int dest_frame_offset,
AudioBus* dest); 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::iterator current_buffer_;
BufferQueue buffers_; BufferQueue buffers_;
int current_buffer_offset_; int current_buffer_offset_;
...@@ -92,10 +81,6 @@ class MEDIA_EXPORT AudioBufferQueue { ...@@ -92,10 +81,6 @@ class MEDIA_EXPORT AudioBufferQueue {
// Number of frames available to be read in the buffer. // Number of frames available to be read in the buffer.
int frames_; 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); DISALLOW_COPY_AND_ASSIGN(AudioBufferQueue);
}; };
......
...@@ -344,125 +344,4 @@ TEST(AudioBufferQueueTest, Peek) { ...@@ -344,125 +344,4 @@ TEST(AudioBufferQueueTest, Peek) {
EXPECT_EQ(30, buffer.PeekFrames(30, 0, 0, bus1.get())); 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 } // namespace media
...@@ -210,10 +210,6 @@ void AudioRendererAlgorithm::FlushBuffers() { ...@@ -210,10 +210,6 @@ void AudioRendererAlgorithm::FlushBuffers() {
capacity_ = kStartingBufferSizeInFrames; capacity_ = kStartingBufferSizeInFrames;
} }
base::TimeDelta AudioRendererAlgorithm::GetTime() {
return audio_buffer_.current_time();
}
void AudioRendererAlgorithm::EnqueueBuffer( void AudioRendererAlgorithm::EnqueueBuffer(
const scoped_refptr<AudioBuffer>& buffer_in) { const scoped_refptr<AudioBuffer>& buffer_in) {
DCHECK(!buffer_in->end_of_stream()); DCHECK(!buffer_in->end_of_stream());
......
...@@ -51,10 +51,6 @@ class MEDIA_EXPORT AudioRendererAlgorithm { ...@@ -51,10 +51,6 @@ class MEDIA_EXPORT AudioRendererAlgorithm {
// Clears |audio_buffer_|. // Clears |audio_buffer_|.
void FlushBuffers(); 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 // Enqueues a buffer. It is called from the owner of the algorithm after a
// read completes. // read completes.
void EnqueueBuffer(const scoped_refptr<AudioBuffer>& buffer_in); void EnqueueBuffer(const scoped_refptr<AudioBuffer>& buffer_in);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment