summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-26 21:39:32 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-26 21:39:32 +0000
commit5e0d4de52fcf0ddbcd94a56e6890af4aabf6f705 (patch)
treee485677b0f64cb5268eef6a6a0f5618bcc03b6cc /media
parent5c84b7e13f3525b84f7928e946727b5b8b77899b (diff)
downloadchromium_src-5e0d4de52fcf0ddbcd94a56e6890af4aabf6f705.zip
chromium_src-5e0d4de52fcf0ddbcd94a56e6890af4aabf6f705.tar.gz
chromium_src-5e0d4de52fcf0ddbcd94a56e6890af4aabf6f705.tar.bz2
Removed PushSource::Packet. SeekableBuffer.current_time() fixed to return
kInvalidTimestamp when the time is unknown. TEST=media_unittests BUG=28654 Review URL: http://codereview.chromium.org/2140001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/simple_sources.cc56
-rw-r--r--media/audio/simple_sources.h16
-rw-r--r--media/base/seekable_buffer.cc5
-rw-r--r--media/base/seekable_buffer.h6
-rw-r--r--media/base/seekable_buffer_unittest.cc25
-rw-r--r--media/filters/audio_renderer_algorithm_base.h3
6 files changed, 40 insertions, 71 deletions
diff --git a/media/audio/simple_sources.cc b/media/audio/simple_sources.cc
index 1edd2b2..4b2ce29 100644
--- a/media/audio/simple_sources.cc
+++ b/media/audio/simple_sources.cc
@@ -9,7 +9,9 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/ref_counted.h"
#include "media/audio/audio_output.h"
+#include "media/base/data_buffer.h"
//////////////////////////////////////////////////////////////////////////////
// SineWaveAudioSource implementation.
@@ -51,39 +53,15 @@ void SineWaveAudioSource::OnError(AudioOutputStream* stream, int code) {
// PushSource implementation.
PushSource::PushSource()
- : buffered_bytes_(0),
- front_buffer_consumed_(0) {
+ : buffer_(0, 0) {
}
-PushSource::~PushSource() {
- CleanUp();
-}
+PushSource::~PushSource() { }
uint32 PushSource::OnMoreData(AudioOutputStream* stream, void* dest,
uint32 max_size, uint32 pending_bytes) {
- uint32 copied = 0;
- while (copied < max_size) {
- AutoLock auto_lock(lock_);
-
- // Under lock processing in this scope.
- if (!packets_.size())
- break;
- Packet packet = packets_.front();
- uint32 size = std::min(max_size - copied,
- packet.size - front_buffer_consumed_);
- memcpy(static_cast<char*>(dest) + copied,
- packet.buffer + front_buffer_consumed_,
- size);
- front_buffer_consumed_ += size;
- buffered_bytes_ -= size;
- copied += size;
- if (front_buffer_consumed_ == packet.size) {
- delete [] packet.buffer;
- packets_.pop_front();
- front_buffer_consumed_ = 0;
- }
- }
- return copied;
+ AutoLock auto_lock(buffer_lock_);
+ return buffer_.Read(static_cast<uint8*>(dest), max_size);
}
void PushSource::OnClose(AudioOutputStream* stream) {
@@ -100,18 +78,14 @@ bool PushSource::Write(const void *data, uint32 len) {
NOTREACHED();
return false;
}
- Packet packet = { new char[len], len };
- memcpy(packet.buffer, data, packet.size);
- // Under lock processing here.
- AutoLock auto_lock(lock_);
- packets_.push_back(packet);
- buffered_bytes_ += len;
+ AutoLock auto_lock(buffer_lock_);
+ buffer_.Append(static_cast<const uint8*>(data), len);
return true;
}
uint32 PushSource::UnProcessedBytes() {
- AutoLock auto_lock(lock_);
- return buffered_bytes_;
+ AutoLock auto_lock(buffer_lock_);
+ return buffer_.forward_bytes();
}
void PushSource::ClearAll() {
@@ -120,12 +94,6 @@ void PushSource::ClearAll() {
}
void PushSource::CleanUp() {
- AutoLock auto_lock(lock_);
- PacketList::const_iterator it;
- for (it = packets_.begin(); it != packets_.end(); ++it) {
- delete [] it->buffer;
- }
- packets_.clear();
- buffered_bytes_ = 0;
- front_buffer_consumed_ = 0;
+ AutoLock auto_lock(buffer_lock_);
+ buffer_.Clear();
}
diff --git a/media/audio/simple_sources.h b/media/audio/simple_sources.h
index 9d8c5fa..0ab457b 100644
--- a/media/audio/simple_sources.h
+++ b/media/audio/simple_sources.h
@@ -9,6 +9,7 @@
#include "base/lock.h"
#include "media/audio/audio_output.h"
+#include "media/base/seekable_buffer.h"
// An audio source that produces a pure sinusoidal tone.
class SineWaveAudioSource : public AudioOutputStream::AudioSourceCallback {
@@ -77,21 +78,12 @@ class PushSource : public AudioOutputStream::AudioSourceCallback,
void ClearAll();
private:
- // Defines the unit of playback. We own the memory pointed by |buffer|.
- struct Packet {
- char* buffer;
- uint32 size;
- };
-
// Free acquired resources.
void CleanUp();
- typedef std::list<Packet> PacketList;
- PacketList packets_;
- uint32 buffered_bytes_;
- uint32 front_buffer_consumed_;
- // Serialize access to packets_ and buffered_bytes_ using this lock.
- Lock lock_;
+ media::SeekableBuffer buffer_;
+ // Serialize access to |buffer_| using this lock.
+ Lock buffer_lock_;
};
#endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_
diff --git a/media/base/seekable_buffer.cc b/media/base/seekable_buffer.cc
index 15819c1..f076ee8 100644
--- a/media/base/seekable_buffer.cc
+++ b/media/base/seekable_buffer.cc
@@ -17,7 +17,8 @@ SeekableBuffer::SeekableBuffer(size_t backward_capacity,
backward_capacity_(backward_capacity),
backward_bytes_(0),
forward_capacity_(forward_capacity),
- forward_bytes_(0) {
+ forward_bytes_(0),
+ current_time_(StreamSample::kInvalidTimestamp) {
current_buffer_ = buffers_.begin();
}
@@ -30,7 +31,7 @@ void SeekableBuffer::Clear() {
current_buffer_offset_ = 0;
backward_bytes_ = 0;
forward_bytes_ = 0;
- current_time_ = base::TimeDelta();
+ current_time_ = StreamSample::kInvalidTimestamp;
}
diff --git a/media/base/seekable_buffer.h b/media/base/seekable_buffer.h
index 1a423e0..eff34e6 100644
--- a/media/base/seekable_buffer.h
+++ b/media/base/seekable_buffer.h
@@ -111,9 +111,9 @@ class SeekableBuffer {
// value calculated based on the timestamp of the current buffer. If
// timestamp for the current buffer is set to 0 or the data was added with
// Append(const uint*, size_t), then returns value that corresponds to the
- // last position in a buffer that had timestamp set. 0 is returned if no
- // buffers we read from had timestamp set.
- // TODO(sergeyu): Use StreamSample::kInvalidTimestamp here.
+ // last position in a buffer that had timestamp set.
+ // StreamSample::kInvalidTimestamp is returned if no buffers we read
+ // from had timestamp set.
base::TimeDelta current_time() const { return current_time_; }
private:
diff --git a/media/base/seekable_buffer_unittest.cc b/media/base/seekable_buffer_unittest.cc
index 72e1933..286580b 100644
--- a/media/base/seekable_buffer_unittest.cc
+++ b/media/base/seekable_buffer_unittest.cc
@@ -291,6 +291,9 @@ TEST_F(SeekableBufferTest, AllMethods) {
TEST_F(SeekableBufferTest, GetTime) {
+ const base::TimeDelta kInvalidTimestamp =
+ media::StreamSample::kInvalidTimestamp;
+
const struct {
int64 first_time_useconds;
int64 duration_useconds;
@@ -298,15 +301,15 @@ TEST_F(SeekableBufferTest, GetTime) {
int64 expected_time;
} tests[] = {
// Timestamps of 0 are treated as garbage.
- { 0, 1000000, 0, 0 },
- { 0, 4000000, 0, 0 },
- { 0, 8000000, 0, 0 },
- { 0, 1000000, 4, 0 },
- { 0, 4000000, 4, 0 },
- { 0, 8000000, 4, 0 },
- { 0, 1000000, kWriteSize, 0 },
- { 0, 4000000, kWriteSize, 0 },
- { 0, 8000000, kWriteSize, 0 },
+ { 0, 1000000, 0, kInvalidTimestamp.ToInternalValue() },
+ { 0, 4000000, 0, kInvalidTimestamp.ToInternalValue() },
+ { 0, 8000000, 0, kInvalidTimestamp.ToInternalValue() },
+ { 0, 1000000, 4, kInvalidTimestamp.ToInternalValue() },
+ { 0, 4000000, 4, kInvalidTimestamp.ToInternalValue() },
+ { 0, 8000000, 4, kInvalidTimestamp.ToInternalValue() },
+ { 0, 1000000, kWriteSize, kInvalidTimestamp.ToInternalValue() },
+ { 0, 4000000, kWriteSize, kInvalidTimestamp.ToInternalValue() },
+ { 0, 8000000, kWriteSize, kInvalidTimestamp.ToInternalValue() },
{ 5, 1000000, 0, 5 },
{ 5, 4000000, 0, 5 },
{ 5, 8000000, 0, 5 },
@@ -318,6 +321,10 @@ TEST_F(SeekableBufferTest, GetTime) {
{ 5, 8000000, kWriteSize, 8000005 },
};
+ // current_time() must initially return kInvalidTimestamp.
+ EXPECT_EQ(kInvalidTimestamp.ToInternalValue(),
+ buffer_.current_time().ToInternalValue());
+
scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(kWriteSize);
memcpy(buffer->GetWritableData(), data_, kWriteSize);
buffer->SetDataSize(kWriteSize);
diff --git a/media/filters/audio_renderer_algorithm_base.h b/media/filters/audio_renderer_algorithm_base.h
index 042f856..c90822c 100644
--- a/media/filters/audio_renderer_algorithm_base.h
+++ b/media/filters/audio_renderer_algorithm_base.h
@@ -57,7 +57,8 @@ class AudioRendererAlgorithmBase {
// Clears |queue_|.
virtual void FlushBuffers();
- // Returns the time of the next byte in our data.
+ // Returns the time of the next byte in our data or
+ // StreamSample::kInvalidTimestamp if current time is unknown.
virtual base::TimeDelta GetTime();
// Enqueues a buffer. It is called from the owner of the algorithm after a