summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorkylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 20:39:05 +0000
committerkylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-13 20:39:05 +0000
commit3cead8b0c7980c23171a569ee10b2b9835e4b941 (patch)
treea48ff765f755bc9cd00514bbcdcde4f63079f6c3 /media
parent2933580fcac85dbd0ad6eb5ccb5fe88fef40a128 (diff)
downloadchromium_src-3cead8b0c7980c23171a569ee10b2b9835e4b941.zip
chromium_src-3cead8b0c7980c23171a569ee10b2b9835e4b941.tar.gz
chromium_src-3cead8b0c7980c23171a569ee10b2b9835e4b941.tar.bz2
Add methods to ARAB and BufferQueue to allow owners to query it for the timestamp of our next byte.
BUG=16011 TEST=src/media/base/buffer_queue_unittest.cc Review URL: http://codereview.chromium.org/149494 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/buffer_queue.cc8
-rw-r--r--media/base/buffer_queue.h5
-rw-r--r--media/base/buffer_queue_unittest.cc41
-rw-r--r--media/filters/audio_renderer_algorithm_base.cc4
-rw-r--r--media/filters/audio_renderer_algorithm_base.h3
5 files changed, 61 insertions, 0 deletions
diff --git a/media/base/buffer_queue.cc b/media/base/buffer_queue.cc
index 18b30d50..f78fb1d 100644
--- a/media/base/buffer_queue.cc
+++ b/media/base/buffer_queue.cc
@@ -80,6 +80,14 @@ void BufferQueue::Enqueue(Buffer* buffer_in) {
size_in_bytes_ += buffer_in->GetDataSize();
}
+base::TimeDelta BufferQueue::GetTime(double bytes_to_sec) {
+ double bytes_to_usec = bytes_to_sec * base::Time::kMicrosecondsPerSecond;
+
+ return queue_.front()->GetTimestamp() +
+ base::TimeDelta::FromMicroseconds(static_cast<int64>(
+ data_offset_ * bytes_to_usec));
+}
+
void BufferQueue::Clear() {
queue_.clear();
size_in_bytes_ = 0;
diff --git a/media/base/buffer_queue.h b/media/base/buffer_queue.h
index 363b136..39e1976 100644
--- a/media/base/buffer_queue.h
+++ b/media/base/buffer_queue.h
@@ -14,6 +14,7 @@
#include <deque>
#include "base/ref_counted.h"
+#include "base/time.h"
namespace media {
@@ -38,6 +39,10 @@ class BufferQueue {
// Enqueues |buffer_in| and adds a reference.
void Enqueue(Buffer* buffer_in);
+ // Returns the timestamp of the first buffer plus |data_offset_| in
+ // microseconds, calculated using the conversion |bytes_to_sec|.
+ base::TimeDelta GetTime(double bytes_to_sec);
+
// Returns true if the |queue_| is empty.
bool IsEmpty();
diff --git a/media/base/buffer_queue_unittest.cc b/media/base/buffer_queue_unittest.cc
index 7f64b43..91e10e0 100644
--- a/media/base/buffer_queue_unittest.cc
+++ b/media/base/buffer_queue_unittest.cc
@@ -4,6 +4,7 @@
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/time.h"
#include "media/base/buffer_queue.h"
#include "media/base/data_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -123,4 +124,44 @@ TEST_F(BufferQueueTest, CopyFromMiddleOfBuffer) {
EXPECT_EQ(0, memcmp(dataBig, kData, kDataSize));
}
+TEST_F(BufferQueueTest, GetTime) {
+ const struct {
+ int64 first_time_seconds;
+ size_t consume_bytes;
+ double bytes_to_seconds;
+ } tests[] = {
+ { 0, 0, 0.5 },
+ { 0, 0, 1 },
+ { 0, 0, 1.75 },
+ { 0, 4, 0.5 },
+ { 0, 4, 1 },
+ { 0, 4, 1.75 },
+ { 5, 0, 0.5 },
+ { 5, 0, 1 },
+ { 5, 0, 1.75 },
+ { 5, 4, 0.5 },
+ { 5, 4, 1 },
+ { 5, 4, 1.75 },
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
+ buffer2->SetTimestamp(base::TimeDelta::FromSeconds(
+ tests[i].first_time_seconds));
+ queue_.Enqueue(buffer2.get());
+ queue_.Consume(tests[i].consume_bytes);
+
+ int64 expected = base::TimeDelta::FromSeconds(static_cast<int64>(
+ tests[i].first_time_seconds + (tests[i].consume_bytes *
+ tests[i].bytes_to_seconds))).ToInternalValue();
+
+ int64 actual = queue_.GetTime(tests[i].bytes_to_seconds).ToInternalValue();
+
+ EXPECT_EQ(expected, actual) << "With test = {"
+ << tests[i].first_time_seconds << ", " << tests[i].consume_bytes
+ << ", " << tests[i].bytes_to_seconds << "}\n";
+
+ queue_.Clear();
+ }
+}
+
} // namespace media
diff --git a/media/filters/audio_renderer_algorithm_base.cc b/media/filters/audio_renderer_algorithm_base.cc
index ef6c0ec..8e64656 100644
--- a/media/filters/audio_renderer_algorithm_base.cc
+++ b/media/filters/audio_renderer_algorithm_base.cc
@@ -54,6 +54,10 @@ void AudioRendererAlgorithmBase::FlushBuffers() {
request_read_callback_->Run();
}
+base::TimeDelta AudioRendererAlgorithmBase::GetTime() {
+ return queue_.GetTime(1.0 / (channels() * sample_rate() * sample_bytes()));
+}
+
void AudioRendererAlgorithmBase::EnqueueBuffer(Buffer* buffer_in) {
// If we're at end of stream, |buffer_in| contains no data.
if (!buffer_in->IsEndOfStream())
diff --git a/media/filters/audio_renderer_algorithm_base.h b/media/filters/audio_renderer_algorithm_base.h
index 3fc8fde..9449c25 100644
--- a/media/filters/audio_renderer_algorithm_base.h
+++ b/media/filters/audio_renderer_algorithm_base.h
@@ -58,6 +58,9 @@ class AudioRendererAlgorithmBase {
// Clears |queue_|.
virtual void FlushBuffers();
+ // Returns the time of the next byte in our data.
+ virtual base::TimeDelta GetTime();
+
// Enqueues a buffer. It is called from the owner of the algorithm after a
// read completes.
virtual void EnqueueBuffer(Buffer* buffer_in);