diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 22:38:45 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-14 22:38:45 +0000 |
commit | ffe0b6416f9c25ebd0c8a22db8c8495c774aceaa (patch) | |
tree | fc8f922840707736d01259b6109d71038f228b7c /media/omx | |
parent | 37a3a4bf36aa3a07ed4982c815d427141b2aa9f8 (diff) | |
download | chromium_src-ffe0b6416f9c25ebd0c8a22db8c8495c774aceaa.zip chromium_src-ffe0b6416f9c25ebd0c8a22db8c8495c774aceaa.tar.gz chromium_src-ffe0b6416f9c25ebd0c8a22db8c8495c774aceaa.tar.bz2 |
Revert "Remove 2 memcpy() for omx video decode input"
Reverr r44537 as it introduces memory leaks.
TBR=wjia@google.com, rsesek@chromium.org
Review URL: http://codereview.chromium.org/1585038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44568 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/omx')
-rw-r--r-- | media/omx/mock_omx.cc | 42 | ||||
-rw-r--r-- | media/omx/mock_omx.h | 7 | ||||
-rw-r--r-- | media/omx/omx_codec.cc | 63 | ||||
-rw-r--r-- | media/omx/omx_codec.h | 24 | ||||
-rw-r--r-- | media/omx/omx_codec_unittest.cc | 9 |
5 files changed, 43 insertions, 102 deletions
diff --git a/media/omx/mock_omx.cc b/media/omx/mock_omx.cc index 79d8dc2..010661f 100644 --- a/media/omx/mock_omx.cc +++ b/media/omx/mock_omx.cc @@ -16,40 +16,35 @@ static OMX_ERRORTYPE MockSendCommand(OMX_HANDLETYPE component, OMX_COMMANDTYPE command, OMX_U32 param1, OMX_PTR command_data) { - CHECK(MockOmx::get()->component() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (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() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (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() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (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() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (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() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component); return MockOmx::get()->SetConfig(index, structure); } @@ -58,48 +53,33 @@ static OMX_ERRORTYPE MockAllocateBuffer(OMX_HANDLETYPE component, OMX_U32 port_index, OMX_PTR app_private, OMX_U32 size_bytes) { - CHECK(MockOmx::get()->component() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (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() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component); return MockOmx::get()->FreeBuffer(port_index, buffer); } static OMX_ERRORTYPE MockEmptyThisBuffer(OMX_HANDLETYPE component, OMX_BUFFERHEADERTYPE* buffer) { - CHECK(MockOmx::get()->component() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (OMX_COMPONENTTYPE*)component); return MockOmx::get()->EmptyThisBuffer(buffer); } static OMX_ERRORTYPE MockFillThisBuffer(OMX_HANDLETYPE component, OMX_BUFFERHEADERTYPE* buffer) { - CHECK(MockOmx::get()->component() == - reinterpret_cast<OMX_COMPONENTTYPE*>(component)); + CHECK(MockOmx::get()->component() == (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(); } @@ -122,6 +102,7 @@ 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() { @@ -136,7 +117,6 @@ 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 9350e7e..00ec378 100644 --- a/media/omx/mock_omx.h +++ b/media/omx/mock_omx.h @@ -46,13 +46,6 @@ 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 b7d559f..a86b263 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/base/buffers.h" +#include "media/omx/omx_input_buffer.h" #include "media/omx/omx_output_sink.h" namespace media { @@ -48,9 +48,8 @@ OmxCodec::~OmxCodec() { DCHECK_EQ(0u, output_buffers_.size()); DCHECK(available_input_buffers_.empty()); DCHECK(output_buffers_in_use_.empty()); - DCHECK(pending_input_queue_.empty()); + DCHECK(input_queue_.empty()); DCHECK(output_queue_.empty()); - DCHECK(processing_input_queue_.empty()); } void OmxCodec::Setup(OmxConfigurator* configurator, @@ -95,8 +94,8 @@ void OmxCodec::Read(ReadCallback* callback) { NewRunnableMethod(this, &OmxCodec::ReadTask, callback)); } -void OmxCodec::Feed(Buffer* buffer, FeedCallback* callback) { - scoped_refptr<Buffer> buffer_ref = buffer; +void OmxCodec::Feed(OmxInputBuffer* buffer, FeedCallback* callback) { + scoped_refptr<OmxInputBuffer> buffer_ref = buffer; message_loop_->PostTask( FROM_HERE, NewRunnableMethod(this, &OmxCodec::FeedTask, buffer_ref, @@ -184,7 +183,7 @@ void OmxCodec::ReadTask(ReadCallback* callback) { FulfillOneRead(); } -void OmxCodec::FeedTask(scoped_refptr<Buffer> buffer, +void OmxCodec::FeedTask(scoped_refptr<OmxInputBuffer> buffer, FeedCallback* callback) { DCHECK_EQ(message_loop_, MessageLoop::current()); @@ -195,7 +194,7 @@ void OmxCodec::FeedTask(scoped_refptr<Buffer> buffer, } // Queue this input buffer. - pending_input_queue_.push(std::make_pair(buffer, callback)); + input_queue_.push(std::make_pair(buffer, callback)); // Try to feed buffers into the decoder. EmptyBufferTask(); @@ -208,14 +207,11 @@ void OmxCodec::FeedTask(scoped_refptr<Buffer> 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_UseBuffer(component_handle_, &buffer, input_port_, - NULL, input_buffer_size_, data); + OMX_AllocateBuffer(component_handle_, &buffer, input_port_, + NULL, input_buffer_size_); if (error != OMX_ErrorNone) return false; input_buffers_.push_back(buffer); @@ -301,16 +297,12 @@ void OmxCodec::FreeOutputBuffers() { void OmxCodec::FreeInputQueue() { DCHECK_EQ(message_loop_, MessageLoop::current()); - while (!pending_input_queue_.empty()) { - scoped_refptr<Buffer> buffer = pending_input_queue_.front().first; - FeedCallback* callback = pending_input_queue_.front().second; + while (!input_queue_.empty()) { + scoped_refptr<OmxInputBuffer> buffer = input_queue_.front().first; + FeedCallback* callback = input_queue_.front().second; callback->Run(buffer); delete callback; - pending_input_queue_.pop(); - } - - while (!processing_input_queue_.empty()) { - processing_input_queue_.pop(); + input_queue_.pop(); } } @@ -1006,16 +998,6 @@ 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); @@ -1031,26 +1013,27 @@ 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 (!pending_input_queue_.empty() && + while (!input_queue_.empty() && !available_input_buffers_.empty() && !input_eos_) { - InputUnit input_unit = pending_input_queue_.front(); - pending_input_queue_.pop(); - processing_input_queue_.push(input_unit); - scoped_refptr<Buffer> buffer = input_unit.first; - + scoped_refptr<OmxInputBuffer> buffer = input_queue_.front().first; + FeedCallback* callback = input_queue_.front().second; 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->pBuffer = const_cast<OMX_U8*>(buffer.get()->GetData()); - omx_buffer->nFilledLen = buffer.get()->GetDataSize(); - omx_buffer->nAllocLen = omx_buffer->nFilledLen; + omx_buffer->nFilledLen = filled; 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 f558827..d1c3e4b 100644 --- a/media/omx/omx_codec.h +++ b/media/omx/omx_codec.h @@ -151,7 +151,7 @@ class MessageLoop; namespace media { -class Buffer; +class OmxInputBuffer; 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<Buffer*>::Type FeedCallback; + typedef Callback1<OmxInputBuffer*>::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(Buffer* buffer, FeedCallback* callback); + void Feed(OmxInputBuffer* 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<Buffer> buffer, + void FeedTask(scoped_refptr<OmxInputBuffer> buffer, FeedCallback* callback); // Helper method to perform tasks when this object is stopped. @@ -380,19 +380,9 @@ class OmxCodec : public base::RefCountedThreadSafe<OmxCodec> { scoped_ptr<Callback> stop_callback_; scoped_ptr<Callback> error_callback_; - 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. + // Input and output queue for encoded data and decoded frames. + typedef std::pair<scoped_refptr<OmxInputBuffer>, FeedCallback*> InputUnit; + std::queue<InputUnit> input_queue_; 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 eb4facc..525bc69 100644 --- a/media/omx/omx_codec_unittest.cc +++ b/media/omx/omx_codec_unittest.cc @@ -67,11 +67,6 @@ 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; @@ -202,9 +197,9 @@ class OmxCodecTest : public testing::Test { // Expect allocation of buffers. EXPECT_CALL(*MockOmx::get(), - UseBuffer(NotNull(), 0, IsNull(), kBufferSize, _)) + AllocateBuffer(NotNull(), 0, IsNull(), kBufferSize)) .Times(kBufferCount) - .WillRepeatedly(DoAll(UseBuffer(), Return(OMX_ErrorNone))); + .WillRepeatedly(DoAll(AllocateBuffer(), Return(OMX_ErrorNone))); // Don't support EGL images in this case. EXPECT_CALL(mock_output_sink_, ProvidesEGLImages()) |