summaryrefslogtreecommitdiffstats
path: root/media/omx
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 21:03:36 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 21:03:36 +0000
commit7b1e54ab705914db175a849176d231be09ecfcf5 (patch)
tree84170fcc6298b671fcf184eba867ecd7e8e58fe6 /media/omx
parentf93ff3f54183a9268b536eba606f63060c67dd50 (diff)
downloadchromium_src-7b1e54ab705914db175a849176d231be09ecfcf5.zip
chromium_src-7b1e54ab705914db175a849176d231be09ecfcf5.tar.gz
chromium_src-7b1e54ab705914db175a849176d231be09ecfcf5.tar.bz2
Remove 2 memcpy() for omx video decode input
Some refactoring to remove 2 memcpy() for encoded video data for OpenMAX. Submitted for: wjia@google.com Reviewer: http://codereview.chromium.org/1574024/show Review URL: http://codereview.chromium.org/1572037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/omx')
-rw-r--r--media/omx/mock_omx.cc42
-rw-r--r--media/omx/mock_omx.h7
-rw-r--r--media/omx/omx_codec.cc63
-rw-r--r--media/omx/omx_codec.h24
-rw-r--r--media/omx/omx_codec_unittest.cc9
5 files changed, 102 insertions, 43 deletions
diff --git a/media/omx/mock_omx.cc b/media/omx/mock_omx.cc
index 010661f..79d8dc2 100644
--- a/media/omx/mock_omx.cc
+++ b/media/omx/mock_omx.cc
@@ -16,35 +16,40 @@ static OMX_ERRORTYPE MockSendCommand(OMX_HANDLETYPE component,
OMX_COMMANDTYPE command,
OMX_U32 param1,
OMX_PTR command_data) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->SendCommand(command, param1, command_data);
}
static OMX_ERRORTYPE MockGetParameter(OMX_HANDLETYPE component,
OMX_INDEXTYPE param_index,
OMX_PTR structure) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->GetParameter(param_index, structure);
}
static OMX_ERRORTYPE MockSetParameter(OMX_HANDLETYPE component,
OMX_INDEXTYPE param_index,
OMX_PTR structure) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->SetParameter(param_index, structure);
}
static OMX_ERRORTYPE MockGetConfig(OMX_HANDLETYPE component,
OMX_INDEXTYPE index,
OMX_PTR structure) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->GetConfig(index, structure);
}
static OMX_ERRORTYPE MockSetConfig(OMX_HANDLETYPE component,
OMX_INDEXTYPE index,
OMX_PTR structure) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->SetConfig(index, structure);
}
@@ -53,33 +58,48 @@ static OMX_ERRORTYPE MockAllocateBuffer(OMX_HANDLETYPE component,
OMX_U32 port_index,
OMX_PTR app_private,
OMX_U32 size_bytes) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->AllocateBuffer(buffer, port_index, app_private,
size_bytes);
}
+static OMX_ERRORTYPE MockUseBuffer(OMX_HANDLETYPE component,
+ OMX_BUFFERHEADERTYPE** buffer,
+ OMX_U32 port_index,
+ OMX_PTR app_private,
+ OMX_U32 size_bytes,
+ OMX_U8* pBuffer) {
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
+ return MockOmx::get()->UseBuffer(buffer, port_index, app_private,
+ size_bytes, pBuffer);
+}
+
static OMX_ERRORTYPE MockFreeBuffer(OMX_HANDLETYPE component,
OMX_U32 port_index,
OMX_BUFFERHEADERTYPE* buffer) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->FreeBuffer(port_index, buffer);
}
static OMX_ERRORTYPE MockEmptyThisBuffer(OMX_HANDLETYPE component,
OMX_BUFFERHEADERTYPE* buffer) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->EmptyThisBuffer(buffer);
}
static OMX_ERRORTYPE MockFillThisBuffer(OMX_HANDLETYPE component,
OMX_BUFFERHEADERTYPE* buffer) {
- CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component);
+ CHECK(MockOmx::get()->component() ==
+ reinterpret_cast<OMX_COMPONENTTYPE*>(component));
return MockOmx::get()->FillThisBuffer(buffer);
}
// Stub methods to export symbols used for OpenMAX.
extern "C" {
-
OMX_ERRORTYPE OMX_Init() {
return MockOmx::get()->Init();
}
@@ -102,7 +122,6 @@ OMX_ERRORTYPE OMX_GetComponentsOfRole(OMX_STRING name, OMX_U32* roles,
OMX_U8** component_names) {
return MockOmx::get()->GetComponentsOfRole(name, roles, component_names);
}
-
} // extern "C"
MockOmx::MockOmx() {
@@ -117,6 +136,7 @@ MockOmx::MockOmx() {
component_.GetConfig = &MockGetConfig;
component_.SetConfig = &MockSetConfig;
component_.AllocateBuffer = &MockAllocateBuffer;
+ component_.UseBuffer = &MockUseBuffer;
component_.FreeBuffer = &MockFreeBuffer;
component_.EmptyThisBuffer = &MockEmptyThisBuffer;
component_.FillThisBuffer = &MockFillThisBuffer;
diff --git a/media/omx/mock_omx.h b/media/omx/mock_omx.h
index 00ec378..9350e7e 100644
--- a/media/omx/mock_omx.h
+++ b/media/omx/mock_omx.h
@@ -46,6 +46,13 @@ class MockOmx {
OMX_PTR app_private,
OMX_U32 size_bytes));
+ MOCK_METHOD5(UseBuffer, OMX_ERRORTYPE(
+ OMX_BUFFERHEADERTYPE** buffer,
+ OMX_U32 port_index,
+ OMX_PTR app_private,
+ OMX_U32 size_bytes,
+ OMX_U8* pBuffer));
+
MOCK_METHOD2(FreeBuffer, OMX_ERRORTYPE(
OMX_U32 port_index,
OMX_BUFFERHEADERTYPE* buffer));
diff --git a/media/omx/omx_codec.cc b/media/omx/omx_codec.cc
index a86b263..b7d559f 100644
--- a/media/omx/omx_codec.cc
+++ b/media/omx/omx_codec.cc
@@ -11,7 +11,7 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "media/omx/omx_codec.h"
-#include "media/omx/omx_input_buffer.h"
+#include "media/base/buffers.h"
#include "media/omx/omx_output_sink.h"
namespace media {
@@ -48,8 +48,9 @@ OmxCodec::~OmxCodec() {
DCHECK_EQ(0u, output_buffers_.size());
DCHECK(available_input_buffers_.empty());
DCHECK(output_buffers_in_use_.empty());
- DCHECK(input_queue_.empty());
+ DCHECK(pending_input_queue_.empty());
DCHECK(output_queue_.empty());
+ DCHECK(processing_input_queue_.empty());
}
void OmxCodec::Setup(OmxConfigurator* configurator,
@@ -94,8 +95,8 @@ void OmxCodec::Read(ReadCallback* callback) {
NewRunnableMethod(this, &OmxCodec::ReadTask, callback));
}
-void OmxCodec::Feed(OmxInputBuffer* buffer, FeedCallback* callback) {
- scoped_refptr<OmxInputBuffer> buffer_ref = buffer;
+void OmxCodec::Feed(Buffer* buffer, FeedCallback* callback) {
+ scoped_refptr<Buffer> buffer_ref = buffer;
message_loop_->PostTask(
FROM_HERE,
NewRunnableMethod(this, &OmxCodec::FeedTask, buffer_ref,
@@ -183,7 +184,7 @@ void OmxCodec::ReadTask(ReadCallback* callback) {
FulfillOneRead();
}
-void OmxCodec::FeedTask(scoped_refptr<OmxInputBuffer> buffer,
+void OmxCodec::FeedTask(scoped_refptr<Buffer> buffer,
FeedCallback* callback) {
DCHECK_EQ(message_loop_, MessageLoop::current());
@@ -194,7 +195,7 @@ void OmxCodec::FeedTask(scoped_refptr<OmxInputBuffer> buffer,
}
// Queue this input buffer.
- input_queue_.push(std::make_pair(buffer, callback));
+ pending_input_queue_.push(std::make_pair(buffer, callback));
// Try to feed buffers into the decoder.
EmptyBufferTask();
@@ -207,11 +208,14 @@ void OmxCodec::FeedTask(scoped_refptr<OmxInputBuffer> buffer,
bool OmxCodec::AllocateInputBuffers() {
DCHECK_EQ(message_loop_, MessageLoop::current());
+ uint8* data = new uint8[input_buffer_size_];
+ scoped_ptr<uint8> data_deleter(data);
+
for (int i = 0; i < input_buffer_count_; ++i) {
OMX_BUFFERHEADERTYPE* buffer;
OMX_ERRORTYPE error =
- OMX_AllocateBuffer(component_handle_, &buffer, input_port_,
- NULL, input_buffer_size_);
+ OMX_UseBuffer(component_handle_, &buffer, input_port_,
+ NULL, input_buffer_size_, data);
if (error != OMX_ErrorNone)
return false;
input_buffers_.push_back(buffer);
@@ -297,12 +301,16 @@ void OmxCodec::FreeOutputBuffers() {
void OmxCodec::FreeInputQueue() {
DCHECK_EQ(message_loop_, MessageLoop::current());
- while (!input_queue_.empty()) {
- scoped_refptr<OmxInputBuffer> buffer = input_queue_.front().first;
- FeedCallback* callback = input_queue_.front().second;
+ while (!pending_input_queue_.empty()) {
+ scoped_refptr<Buffer> buffer = pending_input_queue_.front().first;
+ FeedCallback* callback = pending_input_queue_.front().second;
callback->Run(buffer);
delete callback;
- input_queue_.pop();
+ pending_input_queue_.pop();
+ }
+
+ while (!processing_input_queue_.empty()) {
+ processing_input_queue_.pop();
}
}
@@ -998,6 +1006,16 @@ void OmxCodec::EmptyBufferCompleteTask(OMX_BUFFERHEADERTYPE* buffer) {
if (!CanEmptyBuffer())
return;
+ scoped_refptr<Buffer> stored_buffer = processing_input_queue_.front().first;
+ FeedCallback* callback = processing_input_queue_.front().second;
+ processing_input_queue_.pop();
+
+ DCHECK_EQ(const_cast<OMX_U8*>(stored_buffer.get()->GetData()),
+ buffer->pBuffer);
+
+ callback->Run(stored_buffer);
+ delete callback;
+
// Enqueue the available buffer beacuse the decoder has consumed it.
available_input_buffers_.push(buffer);
@@ -1013,27 +1031,26 @@ void OmxCodec::EmptyBufferTask() {
// Loop for all available input data and input buffer for the
// decoder. When input has reached EOS we need to stop.
- while (!input_queue_.empty() &&
+ while (!pending_input_queue_.empty() &&
!available_input_buffers_.empty() &&
!input_eos_) {
- scoped_refptr<OmxInputBuffer> buffer = input_queue_.front().first;
- FeedCallback* callback = input_queue_.front().second;
+ InputUnit input_unit = pending_input_queue_.front();
+ pending_input_queue_.pop();
+ processing_input_queue_.push(input_unit);
+ scoped_refptr<Buffer> buffer = input_unit.first;
+
OMX_BUFFERHEADERTYPE* omx_buffer = available_input_buffers_.front();
available_input_buffers_.pop();
- // Read into |omx_buffer|.
input_eos_ = buffer->IsEndOfStream();
- int filled = buffer->Read(omx_buffer->pBuffer, input_buffer_size_);
- if (buffer->Used()) {
- input_queue_.pop();
- callback->Run(buffer);
- delete callback;
- }
+ // setup |omx_buffer|.
omx_buffer->nInputPortIndex = input_port_;
omx_buffer->nOffset = 0;
omx_buffer->nFlags = 0;
- omx_buffer->nFilledLen = filled;
+ omx_buffer->pBuffer = const_cast<OMX_U8*>(buffer.get()->GetData());
+ omx_buffer->nFilledLen = buffer.get()->GetDataSize();
+ omx_buffer->nAllocLen = omx_buffer->nFilledLen;
omx_buffer->pAppPrivate = this;
omx_buffer->nFlags |= input_eos_ ? OMX_BUFFERFLAG_EOS : 0;
omx_buffer->nTimeStamp = buffer->GetTimestamp().InMilliseconds();
diff --git a/media/omx/omx_codec.h b/media/omx/omx_codec.h
index d1c3e4b..f558827 100644
--- a/media/omx/omx_codec.h
+++ b/media/omx/omx_codec.h
@@ -151,7 +151,7 @@ class MessageLoop;
namespace media {
-class OmxInputBuffer;
+class Buffer;
class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
public:
@@ -159,7 +159,7 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
typedef Callback2<
const OmxConfigurator::MediaFormat&,
const OmxConfigurator::MediaFormat&>::Type FormatCallback;
- typedef Callback1<OmxInputBuffer*>::Type FeedCallback;
+ typedef Callback1<Buffer*>::Type FeedCallback;
typedef Callback2<int,
OmxOutputSink::BufferUsedCallback*>::Type ReadCallback;
typedef Callback0::Type Callback;
@@ -201,7 +201,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(OmxInputBuffer* buffer, FeedCallback* callback);
+ void Feed(Buffer* buffer, FeedCallback* callback);
// Flush the decoder and reset its end-of-stream state.
void Flush(Callback* callback);
@@ -233,7 +233,7 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
void StartTask();
void StopTask(Callback* callback);
void ReadTask(ReadCallback* callback);
- void FeedTask(scoped_refptr<OmxInputBuffer> buffer,
+ void FeedTask(scoped_refptr<Buffer> buffer,
FeedCallback* callback);
// Helper method to perform tasks when this object is stopped.
@@ -380,9 +380,19 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> {
scoped_ptr<Callback> stop_callback_;
scoped_ptr<Callback> error_callback_;
- // Input and output queue for encoded data and decoded frames.
- typedef std::pair<scoped_refptr<OmxInputBuffer>, FeedCallback*> InputUnit;
- std::queue<InputUnit> input_queue_;
+ typedef std::pair<scoped_refptr<Buffer>, FeedCallback*> InputUnit;
+
+ // Input queue for encoded data.
+ // The input buffers will be sent to OMX component via OMX_EmptyThisBuffer()
+ std::queue<InputUnit> pending_input_queue_;
+
+ // Input queue for encoded data.
+ // Those buffers have been sent to OMX component, but not returned
+ // by EmptyBufferDone callback. Once returned from OMX component, they
+ // will be returned to owner.
+ std::queue<InputUnit> processing_input_queue_;
+
+ // Output queue for decoded frames.
std::queue<ReadCallback*> output_queue_;
// Available input OpenMAX buffers that we can use to issue
diff --git a/media/omx/omx_codec_unittest.cc b/media/omx/omx_codec_unittest.cc
index 525bc69..eb4facc 100644
--- a/media/omx/omx_codec_unittest.cc
+++ b/media/omx/omx_codec_unittest.cc
@@ -67,6 +67,11 @@ ACTION(AllocateBuffer) {
(*arg0)->pBuffer = new uint8[kBufferSize];
}
+ACTION(UseBuffer) {
+ *arg0 = new OMX_BUFFERHEADERTYPE();
+ memset(*arg0, 0, sizeof(OMX_BUFFERHEADERTYPE));
+}
+
ACTION(FreeBuffer) {
delete [] arg1->pBuffer;
delete arg1;
@@ -197,9 +202,9 @@ class OmxCodecTest : public testing::Test {
// Expect allocation of buffers.
EXPECT_CALL(*MockOmx::get(),
- AllocateBuffer(NotNull(), 0, IsNull(), kBufferSize))
+ UseBuffer(NotNull(), 0, IsNull(), kBufferSize, _))
.Times(kBufferCount)
- .WillRepeatedly(DoAll(AllocateBuffer(), Return(OMX_ErrorNone)));
+ .WillRepeatedly(DoAll(UseBuffer(), Return(OMX_ErrorNone)));
// Don't support EGL images in this case.
EXPECT_CALL(mock_output_sink_, ProvidesEGLImages())