summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-16 21:46:10 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-16 21:46:10 +0000
commitd8a447c5f7eef2dfe00a2a80466288be0d7329f7 (patch)
tree81378251205188e2718b4fc73282e62beca1c624 /media
parentf7842f9049b7c2a16e29f01d713685ab32cd4c47 (diff)
downloadchromium_src-d8a447c5f7eef2dfe00a2a80466288be0d7329f7.zip
chromium_src-d8a447c5f7eef2dfe00a2a80466288be0d7329f7.tar.gz
chromium_src-d8a447c5f7eef2dfe00a2a80466288be0d7329f7.tar.bz2
Checking in media::DataBuffer, a simple implementation of WritableBufferInterface.
Removed media/base/media.cc, since it's no longer needed to generate media.lib. Also added media/using_media.scons and updated scons files for Linux build. Review URL: http://codereview.chromium.org/13682 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7099 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/buffers.h10
-rwxr-xr-xmedia/base/data_buffer.cc62
-rwxr-xr-xmedia/base/data_buffer.h50
-rw-r--r--media/base/data_buffer_unittest.cc49
-rw-r--r--media/base/media.cc15
-rw-r--r--media/build/media.vcproj8
-rw-r--r--media/build/media_unittests.vcproj12
-rw-r--r--media/media_lib.scons2
-rw-r--r--media/media_unittests.scons2
-rw-r--r--media/using_media.scons15
10 files changed, 202 insertions, 23 deletions
diff --git a/media/base/buffers.h b/media/base/buffers.h
index bf06a9a..13d35f5 100644
--- a/media/base/buffers.h
+++ b/media/base/buffers.h
@@ -35,10 +35,10 @@ class StreamSampleInterface :
public base::RefCountedThreadSafe<StreamSampleInterface> {
public:
// Returns the timestamp of this buffer in microseconds.
- virtual int64 GetTimestamp() = 0;
+ virtual int64 GetTimestamp() const = 0;
// Returns the duration of this buffer in microseconds.
- virtual int64 GetDuration() = 0;
+ virtual int64 GetDuration() const = 0;
// Sets the timestamp of this buffer in microseconds.
virtual void SetTimestamp(int64 timestamp) = 0;
@@ -55,10 +55,10 @@ class StreamSampleInterface :
class BufferInterface : public StreamSampleInterface {
public:
// Returns a read only pointer to the buffer data.
- virtual const char* GetData() = 0;
+ virtual const char* GetData() const = 0;
// Returns the size of valid data in bytes.
- virtual size_t GetDataSize() = 0;
+ virtual size_t GetDataSize() const = 0;
};
@@ -72,7 +72,7 @@ class WritableBufferInterface : public BufferInterface {
virtual void SetDataSize(size_t data_size) = 0;
// Returns the maximum allocated size for this buffer.
- virtual size_t GetBufferSize() = 0;
+ virtual size_t GetBufferSize() const = 0;
};
diff --git a/media/base/data_buffer.cc b/media/base/data_buffer.cc
new file mode 100755
index 0000000..c5c290d
--- /dev/null
+++ b/media/base/data_buffer.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "media/base/data_buffer.h"
+
+namespace media {
+
+DataBuffer::DataBuffer(char* data, size_t buffer_size, size_t data_size,
+ int64 timestamp, int64 duration)
+ : data_(data),
+ buffer_size_(buffer_size),
+ data_size_(data_size),
+ timestamp_(timestamp),
+ duration_(duration) {
+ DCHECK(data);
+ DCHECK(buffer_size >= 0);
+ DCHECK(data_size <= buffer_size);
+}
+
+DataBuffer::~DataBuffer() {
+ delete [] data_;
+}
+
+int64 DataBuffer::GetTimestamp() const {
+ return timestamp_;
+}
+
+void DataBuffer::SetTimestamp(int64 timestamp) {
+ timestamp_ = timestamp;
+}
+
+int64 DataBuffer::GetDuration() const {
+ return duration_;
+}
+
+void DataBuffer::SetDuration(int64 duration) {
+ duration_ = duration;
+}
+
+const char* DataBuffer::GetData() const {
+ return data_;
+}
+
+size_t DataBuffer::GetDataSize() const {
+ return data_size_;
+}
+
+char* DataBuffer::GetWritableData() {
+ return data_;
+}
+
+size_t DataBuffer::GetBufferSize() const {
+ return buffer_size_;
+}
+
+void DataBuffer::SetDataSize(size_t data_size) {
+ data_size_ = data_size;
+}
+
+} // namespace media
diff --git a/media/base/data_buffer.h b/media/base/data_buffer.h
new file mode 100755
index 0000000..6e1a004
--- /dev/null
+++ b/media/base/data_buffer.h
@@ -0,0 +1,50 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// A simple implementation of WritableBufferInterface that takes ownership of
+// the given data pointer.
+//
+// DataBuffer assumes that memory was allocated with new char[].
+
+#ifndef MEDIA_BASE_DATA_BUFFER_H_
+#define MEDIA_BASE_DATA_BUFFER_H_
+
+#include "media/base/buffers.h"
+
+namespace media {
+
+class DataBuffer : public WritableBufferInterface {
+ public:
+ DataBuffer(char* data, size_t buffer_size, size_t data_size,
+ int64 timestamp, int64 duration);
+
+ // StreamSampleInterface
+ virtual int64 GetTimestamp() const;
+ virtual void SetTimestamp(int64 timestamp);
+ virtual int64 GetDuration() const;
+ virtual void SetDuration(int64 duration);
+
+ // BufferInterface
+ virtual const char* GetData() const;
+ virtual size_t GetDataSize() const;
+
+ // WritableBufferInterface
+ virtual char* GetWritableData();
+ virtual size_t GetBufferSize() const;
+ virtual void SetDataSize(size_t data_size);
+
+ protected:
+ virtual ~DataBuffer();
+
+ private:
+ char* data_;
+ size_t buffer_size_;
+ size_t data_size_;
+ int64 timestamp_;
+ int64 duration_;
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_DATA_BUFFER_H_
diff --git a/media/base/data_buffer_unittest.cc b/media/base/data_buffer_unittest.cc
new file mode 100644
index 0000000..e9bb690
--- /dev/null
+++ b/media/base/data_buffer_unittest.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/string_util.h"
+#include "media/base/data_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using media::DataBuffer;
+
+TEST(DataBufferTest, Basic) {
+ const size_t kBufferSize = 32;
+ const char kData[] = "hello";
+ const size_t kDataSize = arraysize(kData);
+ const char kNewData[] = "chromium";
+ const size_t kNewDataSize = arraysize(kNewData);
+
+ // Create our buffer and copy some data into it.
+ char* data = new char[kBufferSize];
+ ASSERT_TRUE(data);
+ size_t copied = base::strlcpy(data, kData, kBufferSize);
+ EXPECT_EQ(kDataSize, copied + 1);
+
+ // Create a DataBuffer.
+ scoped_refptr<DataBuffer> buffer;
+ buffer = new DataBuffer(data, kBufferSize, kDataSize, 1337, 1667);
+ ASSERT_TRUE(buffer.get());
+
+ // Test StreamSampleInterface.
+ EXPECT_EQ(1337, buffer->GetTimestamp());
+ EXPECT_EQ(1667, buffer->GetDuration());
+ buffer->SetTimestamp(1234);
+ buffer->SetDuration(5678);
+ EXPECT_EQ(1234, buffer->GetTimestamp());
+ EXPECT_EQ(5678, buffer->GetDuration());
+
+ // Test BufferInterface.
+ ASSERT_EQ(data, buffer->GetData());
+ EXPECT_EQ(kDataSize, buffer->GetDataSize());
+ EXPECT_STREQ(kData, buffer->GetData());
+
+ // Test WritableBufferInterface.
+ ASSERT_EQ(data, buffer->GetWritableData());
+ EXPECT_EQ(kBufferSize, buffer->GetBufferSize());
+ copied = base::strlcpy(data, kNewData, kBufferSize);
+ EXPECT_EQ(kNewDataSize, copied + 1);
+ buffer->SetDataSize(kNewDataSize);
+ EXPECT_EQ(kNewDataSize, buffer->GetDataSize());
+}
diff --git a/media/base/media.cc b/media/base/media.cc
deleted file mode 100644
index 91486ee..0000000
--- a/media/base/media.cc
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/base/buffers.h"
-#include "media/base/filters.h"
-#include "media/base/media_format.h"
-
-namespace media {
-
-// Dummy function to generate media.lib.
-void DoNothing() {
-}
-
-} // namespace media
diff --git a/media/build/media.vcproj b/media/build/media.vcproj
index 53f38ea..55a4556 100644
--- a/media/build/media.vcproj
+++ b/media/build/media.vcproj
@@ -129,11 +129,15 @@
>
</File>
<File
- RelativePath="..\base\filters.h"
+ RelativePath="..\base\data_buffer.cc"
>
</File>
<File
- RelativePath="..\base\media.cc"
+ RelativePath="..\base\data_buffer.h"
+ >
+ </File>
+ <File
+ RelativePath="..\base\filters.h"
>
</File>
<File
diff --git a/media/build/media_unittests.vcproj b/media/build/media_unittests.vcproj
index f814142..82347fc 100644
--- a/media/build/media_unittests.vcproj
+++ b/media/build/media_unittests.vcproj
@@ -149,6 +149,18 @@
>
</File>
</Filter>
+ <Filter
+ Name="tests"
+ >
+ <Filter
+ Name="base"
+ >
+ <File
+ RelativePath="..\base\data_buffer_unittest.cc"
+ >
+ </File>
+ </Filter>
+ </Filter>
</Files>
<Globals>
</Globals>
diff --git a/media/media_lib.scons b/media/media_lib.scons
index 9f016c4..cfb108c 100644
--- a/media/media_lib.scons
+++ b/media/media_lib.scons
@@ -25,7 +25,7 @@ env.Prepend(
# These net files work on *all* platforms; files that don't work
# cross-platform live below.
input_files = [
- 'base/media.cc',
+ 'base/data_buffer.cc',
'base/media_format.cc',
]
diff --git a/media/media_unittests.scons b/media/media_unittests.scons
index b6116f7..f7c1ba4 100644
--- a/media/media_unittests.scons
+++ b/media/media_unittests.scons
@@ -14,6 +14,7 @@ env.SConscript([
'$BASE_DIR/using_base.scons',
'$GTEST_DIR/../using_gtest.scons',
'$ICU38_DIR/using_icu38.scons',
+ '$MEDIA_DIR/using_media.scons',
], {'env':env})
env.Prepend(
@@ -46,6 +47,7 @@ if env['PLATFORM'] == 'win32':
)
input_files = [
+ 'base/data_buffer_unittest.cc',
'base/run_all_unittests.cc',
]
diff --git a/media/using_media.scons b/media/using_media.scons
new file mode 100644
index 0000000..545325a2
--- /dev/null
+++ b/media/using_media.scons
@@ -0,0 +1,15 @@
+# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+__doc__ = """
+Settings for other components using the media library.
+"""
+
+Import("env")
+
+env.Append(
+ LIBS = [
+ 'media',
+ ],
+)