summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 21:15:00 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-05 21:15:00 +0000
commit0d7cef4d19826157be5d8ee93a5a85a8a3d2fe5c (patch)
tree768113ab7d376c80ebf1a8e36e654ebccf2f1cf3 /media
parentd7313ce9aecaed59829e57bf12521eaf135e5f74 (diff)
downloadchromium_src-0d7cef4d19826157be5d8ee93a5a85a8a3d2fe5c.zip
chromium_src-0d7cef4d19826157be5d8ee93a5a85a8a3d2fe5c.tar.gz
chromium_src-0d7cef4d19826157be5d8ee93a5a85a8a3d2fe5c.tar.bz2
Refactor media::InputBuffer to consolidate it with media::Buffer
Rename media::InputBuffer to media::OmxInputBuffer and inherit from media::Buffer. Also provide the timestamp to media::OmxCodec. TEST=omx_test BUG=32753 Review URL: http://codereview.chromium.org/577012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/omx_video_decode_engine.cc5
-rw-r--r--media/filters/omx_video_decode_engine.h4
-rw-r--r--media/media.gyp4
-rw-r--r--media/omx/omx_codec.cc13
-rw-r--r--media/omx/omx_codec.h19
-rw-r--r--media/omx/omx_input_buffer.cc (renamed from media/omx/input_buffer.cc)16
-rw-r--r--media/omx/omx_input_buffer.h (renamed from media/omx/input_buffer.h)27
-rw-r--r--media/tools/omx_test/omx_test.cc7
8 files changed, 49 insertions, 46 deletions
diff --git a/media/filters/omx_video_decode_engine.cc b/media/filters/omx_video_decode_engine.cc
index 85d3936..1297af1 100644
--- a/media/filters/omx_video_decode_engine.cc
+++ b/media/filters/omx_video_decode_engine.cc
@@ -101,7 +101,8 @@ void OmxVideoDecodeEngine::DecodeFrame(const Buffer& buffer,
uint8* data = new uint8[buffer.GetDataSize()];
memcpy(data, buffer.GetData(), buffer.GetDataSize());
- InputBuffer* input_buffer = new InputBuffer(data, buffer.GetDataSize());
+ OmxInputBuffer* input_buffer =
+ new OmxInputBuffer(data, buffer.GetDataSize());
// Feed in the new buffer regardless.
//
@@ -125,7 +126,7 @@ void OmxVideoDecodeEngine::DecodeFrame(const Buffer& buffer,
omx_codec_->Read(NewCallback(this, &OmxVideoDecodeEngine::OnReadComplete));
}
-void OmxVideoDecodeEngine::OnFeedDone(InputBuffer* buffer) {
+void OmxVideoDecodeEngine::OnFeedDone(OmxInputBuffer* buffer) {
DCHECK_EQ(message_loop_, MessageLoop::current());
// TODO(ajwong): Add a DoNothingCallback or similar.
}
diff --git a/media/filters/omx_video_decode_engine.h b/media/filters/omx_video_decode_engine.h
index bb3015a..71a006f 100644
--- a/media/filters/omx_video_decode_engine.h
+++ b/media/filters/omx_video_decode_engine.h
@@ -10,8 +10,8 @@
#include "base/lock.h"
#include "base/task.h"
#include "media/filters/video_decode_engine.h"
-#include "media/omx/input_buffer.h"
#include "media/omx/omx_codec.h"
+#include "media/omx/omx_input_buffer.h"
class MessageLoop;
@@ -77,7 +77,7 @@ class OmxVideoDecodeEngine : public VideoDecodeEngine {
Task* done_cb;
};
- virtual void OnFeedDone(InputBuffer* buffer);
+ virtual void OnFeedDone(OmxInputBuffer* buffer);
virtual void OnHardwareError();
virtual void OnReadComplete(uint8* buffer, int size);
virtual void OnFormatChange(
diff --git a/media/media.gyp b/media/media.gyp
index 06acff2..935a0f4 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -312,12 +312,12 @@
'../third_party/openmax/openmax.gyp:il',
],
'sources': [
- 'omx/input_buffer.cc',
- 'omx/input_buffer.h',
'omx/omx_codec.cc',
'omx/omx_codec.h',
'omx/omx_configurator.cc',
'omx/omx_configurator.h',
+ 'omx/omx_input_buffer.cc',
+ 'omx/omx_input_buffer.h',
],
'export_dependent_settings': [
'../third_party/openmax/openmax.gyp:il',
diff --git a/media/omx/omx_codec.cc b/media/omx/omx_codec.cc
index 71387d1..6b8d95e 100644
--- a/media/omx/omx_codec.cc
+++ b/media/omx/omx_codec.cc
@@ -8,8 +8,8 @@
#include "base/message_loop.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
-#include "media/omx/input_buffer.h"
#include "media/omx/omx_codec.h"
+#include "media/omx/omx_input_buffer.h"
namespace media {
@@ -82,7 +82,7 @@ void OmxCodec::Read(ReadCallback* callback) {
NewRunnableMethod(this, &OmxCodec::ReadTask, callback));
}
-void OmxCodec::Feed(InputBuffer* buffer, FeedCallback* callback) {
+void OmxCodec::Feed(OmxInputBuffer* buffer, FeedCallback* callback) {
message_loop_->PostTask(
FROM_HERE,
NewRunnableMethod(this, &OmxCodec::FeedTask, buffer, callback));
@@ -159,7 +159,8 @@ void OmxCodec::ReadTask(ReadCallback* callback) {
FillBufferTask();
}
-void OmxCodec::FeedTask(InputBuffer* buffer, FeedCallback* callback) {
+void OmxCodec::FeedTask(OmxInputBuffer* buffer,
+ FeedCallback* callback) {
DCHECK_EQ(message_loop_, MessageLoop::current());
if (!CanAcceptInput()) {
@@ -246,7 +247,7 @@ void OmxCodec::FreeInputQueue() {
DCHECK_EQ(message_loop_, MessageLoop::current());
while (!input_queue_.empty()) {
- InputBuffer* buffer = input_queue_.front().first;
+ OmxInputBuffer* buffer = input_queue_.front().first;
FeedCallback* callback = input_queue_.front().second;
callback->Run(buffer);
delete callback;
@@ -964,7 +965,7 @@ void OmxCodec::EmptyBufferTask() {
while (!input_queue_.empty() &&
!available_input_buffers_.empty() &&
!input_eos_) {
- InputBuffer* buffer = input_queue_.front().first;
+ OmxInputBuffer* buffer = input_queue_.front().first;
FeedCallback* callback = input_queue_.front().second;
OMX_BUFFERHEADERTYPE* omx_buffer = available_input_buffers_.front();
available_input_buffers_.pop();
@@ -984,7 +985,7 @@ void OmxCodec::EmptyBufferTask() {
omx_buffer->nFilledLen = filled;
omx_buffer->pAppPrivate = this;
omx_buffer->nFlags |= input_eos_ ? OMX_BUFFERFLAG_EOS : 0;
- // TODO(hclam): Get timestamp from the input buffer and fill in here.
+ omx_buffer->nTimeStamp = buffer->GetTimestamp().InMilliseconds();
// Give this buffer to OMX.
OMX_ERRORTYPE ret = OMX_EmptyThisBuffer(component_handle_, omx_buffer);
diff --git a/media/omx/omx_codec.h b/media/omx/omx_codec.h
index fac10c6..0eb94b8 100644
--- a/media/omx/omx_codec.h
+++ b/media/omx/omx_codec.h
@@ -15,10 +15,10 @@
// // Initialization.
// MessageLoop message_loop;
// OmxCodec* decoder = new OmxCodec(&message_loop);
-// OmxCodec::OmxMediaFormat input_format, output_format;
+// OmxConfigurator::MediaFormat input_format, output_format;
// input_format.codec = OmxCodec::kCodecH264;
// output_format.codec = OmxCodec::kCodecRaw;
-// decoder->Setup(input_format, output_format);
+// decoder->Setup(new OmxDecoderConfigurator(input_format, output_format));
// decoder->SetErrorCallback(NewCallback(this, &Client::ErrorCallback));
// decoder->SetFormatCallback(NewCallback(this, &Client::FormatCallback));
//
@@ -29,7 +29,7 @@
// // queue the input buffers and output requests and process them until
// // the decoder can actually process them.
// for (int i = 0; i < kInitialBuffers; ++i) {
-// InputBuffer* buffer = PrepareInitialInputBuffer();
+// OmxInputBuffer* buffer = PrepareInitialInputBuffer();
// decoder->Feed(buffer, NewCallback(this, &Client::FeedCallback));
// }
//
@@ -40,7 +40,7 @@
// decoder->Stop(NewCallback(this, &Client::StopCallback));
//
// A typical FeedCallback will look like:
-// void Client::FeedCallback(InputBuffer* buffer) {
+// void Client::FeedCallback(OmxInputBuffer* buffer) {
// // We have read to the end so stop feeding.
// if (buffer->Eos())
// return;
@@ -95,18 +95,19 @@
#include "third_party/openmax/il/OMX_Core.h"
#include "third_party/openmax/il/OMX_Video.h"
-class InputBuffer;
class MessageLoop;
namespace media {
+class OmxInputBuffer;
+
class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
public:
// TODO(jiesun): remove callback parameters.
typedef Callback2<
const OmxConfigurator::MediaFormat&,
const OmxConfigurator::MediaFormat&>::Type FormatCallback;
- typedef Callback1<InputBuffer*>::Type FeedCallback;
+ typedef Callback1<OmxInputBuffer*>::Type FeedCallback;
typedef Callback2<uint8*, int>::Type ReadCallback;
typedef Callback0::Type Callback;
@@ -139,7 +140,7 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
// Feed the decoder with |buffer|. When the decoder has consumed the
// buffer |callback| is called with |buffer| being the parameter.
- void Feed(InputBuffer* buffer, FeedCallback* callback);
+ void Feed(OmxInputBuffer* buffer, FeedCallback* callback);
// Flush the decoder and reset its end-of-stream state.
void Flush(Callback* callback);
@@ -169,7 +170,7 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
void StartTask();
void StopTask(Callback* callback);
void ReadTask(ReadCallback* callback);
- void FeedTask(InputBuffer* buffer, FeedCallback* callback);
+ void FeedTask(OmxInputBuffer* buffer, FeedCallback* callback);
// Helper method to perform tasks when this object is stopped.
void DoneStop();
@@ -309,7 +310,7 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
scoped_ptr<Callback> error_callback_;
// Input and output queue for encoded data and decoded frames.
- typedef std::pair<InputBuffer*, FeedCallback*> InputUnit;
+ typedef std::pair<OmxInputBuffer*, FeedCallback*> InputUnit;
std::queue<InputUnit> input_queue_;
std::queue<ReadCallback*> output_queue_;
diff --git a/media/omx/input_buffer.cc b/media/omx/omx_input_buffer.cc
index c26b9f7..b4864fe 100644
--- a/media/omx/input_buffer.cc
+++ b/media/omx/omx_input_buffer.cc
@@ -2,7 +2,7 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
-#include "media/omx/input_buffer.h"
+#include "media/omx/omx_input_buffer.h"
#include <algorithm>
@@ -10,34 +10,30 @@
namespace media {
-InputBuffer::InputBuffer()
+OmxInputBuffer::OmxInputBuffer()
: size_(0),
used_(0) {
}
-InputBuffer::InputBuffer(uint8* data, int size)
+OmxInputBuffer::OmxInputBuffer(uint8* data, int size)
: data_(data),
size_(size),
used_(0) {
DCHECK_GE(size, 0);
}
-InputBuffer::~InputBuffer() {
+OmxInputBuffer::~OmxInputBuffer() {
}
-int InputBuffer::Read(uint8* output_data, int output_size) {
+int OmxInputBuffer::Read(uint8* output_data, int output_size) {
int copy = std::min(output_size, size_ - used_);
memcpy(output_data, data_.get() + used_, copy);
used_ += copy;
return copy;
}
-bool InputBuffer::Used() {
+bool OmxInputBuffer::Used() {
return used_ == size_;
}
-bool InputBuffer::IsEndOfStream() {
- return data_.get() == NULL || size_ == 0;
-}
-
} // namespace media
diff --git a/media/omx/input_buffer.h b/media/omx/omx_input_buffer.h
index 9c6f442..10a9049 100644
--- a/media/omx/input_buffer.h
+++ b/media/omx/omx_input_buffer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// Copyright (c) 2010 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.
@@ -7,25 +7,25 @@
//
// This object is implemened using system memory.
-#ifndef MEDIA_OMX_INPUT_BUFFER_H_
-#define MEDIA_OMX_INPUT_BUFFER_H_
+#ifndef MEDIA_OMX_OMX_INPUT_BUFFER_H_
+#define MEDIA_OMX_OMX_INPUT_BUFFER_H_
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "media/base/buffers.h"
namespace media {
-// TODO(hclam): consolidate our buffer implementations http://crbug.com/28654
-class InputBuffer {
+class OmxInputBuffer : public Buffer {
public:
// Creates an empty input buffer.
- InputBuffer();
+ OmxInputBuffer();
// Creates an input buffer given |data| and |size|.
// After construction, this object will be given the ownership of
// |data| and is responsible for deleting it.
- InputBuffer(uint8* data, int size);
- ~InputBuffer();
+ OmxInputBuffer(uint8* data, int size);
+ virtual ~OmxInputBuffer();
// Read from the this buffer into |data| with the maximum |size| bytes.
// Returns number of bytes read. If a read is successful, the number
@@ -36,15 +36,18 @@ class InputBuffer {
// Returns true if this buffer is used.
bool Used();
- // Returns true if this is an end-of-stream buffer.
- bool IsEndOfStream();
-
private:
+ virtual const uint8* GetData() const { return data_.get(); }
+
+ virtual size_t GetDataSize() const { return size_; }
+
scoped_array<uint8> data_;
int size_;
int used_;
+
+ DISALLOW_COPY_AND_ASSIGN(OmxInputBuffer);
};
} // namespace media
-#endif // MEDIA_OMX_INPUT_BUFFER_H_
+#endif // MEDIA_OMX_OMX_INPUT_BUFFER_H_
diff --git a/media/tools/omx_test/omx_test.cc b/media/tools/omx_test/omx_test.cc
index 823480b..ae13aa4 100644
--- a/media/tools/omx_test/omx_test.cc
+++ b/media/tools/omx_test/omx_test.cc
@@ -17,8 +17,8 @@
#include "media/ffmpeg/ffmpeg_common.h"
#include "media/ffmpeg/file_protocol.h"
#include "media/filters/bitstream_converter.h"
-#include "media/omx/input_buffer.h"
#include "media/omx/omx_codec.h"
+#include "media/omx/omx_input_buffer.h"
#include "media/tools/omx_test/color_space_util.h"
#include "media/tools/omx_test/file_reader_util.h"
#include "media/tools/omx_test/file_writer_util.h"
@@ -32,6 +32,7 @@ using media::OmxCodec;
using media::OmxConfigurator;
using media::OmxDecoderConfigurator;
using media::OmxEncoderConfigurator;
+using media::OmxInputBuffer;
using media::YuvFileReader;
// This is the driver object to feed the decoder with data from a file.
@@ -95,7 +96,7 @@ class TestApp {
input_format.video_header.height);
}
- void FeedCallback(media::InputBuffer* buffer) {
+ void FeedCallback(OmxInputBuffer* buffer) {
// We receive this callback when the decoder has consumed an input buffer.
// In this case, delete the previous buffer and enqueue a new one.
// There are some conditions we don't want to enqueue, for example when
@@ -137,7 +138,7 @@ class TestApp {
uint8* data;
int read;
file_reader_->Read(&data, &read);
- codec_->Feed(new media::InputBuffer(data, read),
+ codec_->Feed(new OmxInputBuffer(data, read),
NewCallback(this, &TestApp::FeedCallback));
}