diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 18:35:45 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-15 18:35:45 +0000 |
commit | 15d511800510aeac104d1123d2a68bf4b5ba7331 (patch) | |
tree | 45d432467cd852f666fc7e1bd07a99684a1eea3b | |
parent | 79c2b56bcad7b23ccc25d2bc934887ea080b7a9d (diff) | |
download | chromium_src-15d511800510aeac104d1123d2a68bf4b5ba7331.zip chromium_src-15d511800510aeac104d1123d2a68bf4b5ba7331.tar.gz chromium_src-15d511800510aeac104d1123d2a68bf4b5ba7331.tar.bz2 |
Remove 2 memcpy() in the OpenMAX code path
Reviewed: http://codereview.chromium.org/1620012
Submitted for: wjia@chromium.org
This also fixes new/delete mismatch in the last commit by
using scoped_array for data.
Review URL: http://codereview.chromium.org/1630026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44677 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/filters/ffmpeg_video_decode_engine.cc | 12 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decode_engine.h | 2 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decode_engine_unittest.cc | 6 | ||||
-rw-r--r-- | media/filters/omx_video_decode_engine.cc | 18 | ||||
-rw-r--r-- | media/filters/omx_video_decode_engine.h | 5 | ||||
-rw-r--r-- | media/filters/video_decode_engine.h | 3 | ||||
-rw-r--r-- | media/filters/video_decoder_impl.cc | 2 | ||||
-rw-r--r-- | media/filters/video_decoder_impl_unittest.cc | 2 | ||||
-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 | ||||
-rw-r--r-- | media/tools/omx_test/omx_test.cc | 9 |
14 files changed, 126 insertions, 78 deletions
diff --git a/media/filters/ffmpeg_video_decode_engine.cc b/media/filters/ffmpeg_video_decode_engine.cc index 3fffbab..8685fbf 100644 --- a/media/filters/ffmpeg_video_decode_engine.cc +++ b/media/filters/ffmpeg_video_decode_engine.cc @@ -60,7 +60,7 @@ void FFmpegVideoDecodeEngine::Initialize(AVStream* stream, Task* done_cb) { } // Decodes one frame of video with the given buffer. -void FFmpegVideoDecodeEngine::DecodeFrame(const Buffer& buffer, +void FFmpegVideoDecodeEngine::DecodeFrame(Buffer* buffer, AVFrame* yuv_frame, bool* got_frame, Task* done_cb) { @@ -70,8 +70,8 @@ void FFmpegVideoDecodeEngine::DecodeFrame(const Buffer& buffer, // Due to FFmpeg API changes we no longer have const read-only pointers. AVPacket packet; av_init_packet(&packet); - packet.data = const_cast<uint8*>(buffer.GetData()); - packet.size = buffer.GetDataSize(); + packet.data = const_cast<uint8*>(buffer->GetData()); + packet.size = buffer->GetDataSize(); // We don't allocate AVFrame on the stack since different versions of FFmpeg // may change the size of AVFrame, causing stack corruption. The solution is @@ -83,11 +83,11 @@ void FFmpegVideoDecodeEngine::DecodeFrame(const Buffer& buffer, // Log the problem if we can't decode a video frame and exit early. if (result < 0) { LOG(INFO) << "Error decoding a video frame with timestamp: " - << buffer.GetTimestamp().InMicroseconds() << " us" + << buffer->GetTimestamp().InMicroseconds() << " us" << " , duration: " - << buffer.GetDuration().InMicroseconds() << " us" + << buffer->GetDuration().InMicroseconds() << " us" << " , packet size: " - << buffer.GetDataSize() << " bytes"; + << buffer->GetDataSize() << " bytes"; *got_frame = false; } else { // If frame_decoded == 0, then no frame was produced. diff --git a/media/filters/ffmpeg_video_decode_engine.h b/media/filters/ffmpeg_video_decode_engine.h index b4fe69d..8e5b2e3 100644 --- a/media/filters/ffmpeg_video_decode_engine.h +++ b/media/filters/ffmpeg_video_decode_engine.h @@ -24,7 +24,7 @@ class FFmpegVideoDecodeEngine : public VideoDecodeEngine { // Implementation of the VideoDecodeEngine Interface. virtual void Initialize(AVStream* stream, Task* done_cb); - virtual void DecodeFrame(const Buffer& buffer, AVFrame* yuv_frame, + virtual void DecodeFrame(Buffer* buffer, AVFrame* yuv_frame, bool* got_result, Task* done_cb); virtual void Flush(Task* done_cb); virtual VideoFrame::Format GetSurfaceFormat() const; diff --git a/media/filters/ffmpeg_video_decode_engine_unittest.cc b/media/filters/ffmpeg_video_decode_engine_unittest.cc index 6ce2853..75e0c29 100644 --- a/media/filters/ffmpeg_video_decode_engine_unittest.cc +++ b/media/filters/ffmpeg_video_decode_engine_unittest.cc @@ -130,7 +130,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_Normal) { EXPECT_CALL(done_cb, Run()); bool got_result; - test_engine_->DecodeFrame(*buffer_, &yuv_frame_, &got_result, + test_engine_->DecodeFrame(buffer_, &yuv_frame_, &got_result, done_cb.CreateTask()); EXPECT_TRUE(got_result); } @@ -147,7 +147,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_0ByteFrame) { EXPECT_CALL(done_cb, Run()); bool got_result; - test_engine_->DecodeFrame(*buffer_, &yuv_frame_, &got_result, + test_engine_->DecodeFrame(buffer_, &yuv_frame_, &got_result, done_cb.CreateTask()); EXPECT_FALSE(got_result); } @@ -163,7 +163,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, DecodeFrame_DecodeError) { EXPECT_CALL(done_cb, Run()); bool got_result; - test_engine_->DecodeFrame(*buffer_, &yuv_frame_, &got_result, + test_engine_->DecodeFrame(buffer_, &yuv_frame_, &got_result, done_cb.CreateTask()); EXPECT_FALSE(got_result); } diff --git a/media/filters/omx_video_decode_engine.cc b/media/filters/omx_video_decode_engine.cc index be4bd8d..6b456b2 100644 --- a/media/filters/omx_video_decode_engine.cc +++ b/media/filters/omx_video_decode_engine.cc @@ -90,7 +90,7 @@ void OmxVideoDecodeEngine::OnHardwareError() { // For every input buffer received here, we submit one read request to the // decoder. So when a read complete callback is received, a corresponding // decode request must exist. -void OmxVideoDecodeEngine::DecodeFrame(const Buffer& buffer, +void OmxVideoDecodeEngine::DecodeFrame(Buffer* buffer, AVFrame* yuv_frame, bool* got_result, Task* done_cb) { @@ -100,20 +100,10 @@ void OmxVideoDecodeEngine::DecodeFrame(const Buffer& buffer, } if (!has_fed_on_eos_) { - OmxInputBuffer* input_buffer; - if (buffer.IsEndOfStream()) { - input_buffer = new OmxInputBuffer(NULL, 0); - } else { - // TODO(ajwong): This is a memcpy() of the compressed frame. Avoid? - uint8* data = new uint8[buffer.GetDataSize()]; - memcpy(data, buffer.GetData(), buffer.GetDataSize()); - input_buffer = new OmxInputBuffer(data, buffer.GetDataSize()); - } - - omx_codec_->Feed(input_buffer, + omx_codec_->Feed(buffer, NewCallback(this, &OmxVideoDecodeEngine::OnFeedDone)); - if (buffer.IsEndOfStream()) { + if (buffer->IsEndOfStream()) { has_fed_on_eos_ = true; } } @@ -126,7 +116,7 @@ void OmxVideoDecodeEngine::DecodeFrame(const Buffer& buffer, omx_codec_->Read(NewCallback(this, &OmxVideoDecodeEngine::OnReadComplete)); } -void OmxVideoDecodeEngine::OnFeedDone(OmxInputBuffer* buffer) { +void OmxVideoDecodeEngine::OnFeedDone(Buffer* 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 3ddc244..e5f7946 100644 --- a/media/filters/omx_video_decode_engine.h +++ b/media/filters/omx_video_decode_engine.h @@ -14,7 +14,6 @@ #include "base/task.h" #include "media/filters/video_decode_engine.h" #include "media/omx/omx_codec.h" -#include "media/omx/omx_input_buffer.h" class MessageLoop; @@ -35,7 +34,7 @@ class OmxVideoDecodeEngine : public VideoDecodeEngine, // Implementation of the VideoDecodeEngine Interface. virtual void Initialize(AVStream* stream, Task* done_cb); - virtual void DecodeFrame(const Buffer& buffer, AVFrame* yuv_frame, + virtual void DecodeFrame(Buffer* buffer, AVFrame* yuv_frame, bool* got_result, Task* done_cb); virtual void Flush(Task* done_cb); virtual VideoFrame::Format GetSurfaceFormat() const; @@ -95,7 +94,7 @@ class OmxVideoDecodeEngine : public VideoDecodeEngine, Task* done_cb; }; - virtual void OnFeedDone(OmxInputBuffer* buffer); + virtual void OnFeedDone(Buffer* buffer); virtual void OnHardwareError(); virtual void OnReadComplete( int buffer_id, OmxOutputSink::BufferUsedCallback* callback); diff --git a/media/filters/video_decode_engine.h b/media/filters/video_decode_engine.h index bfdc13c..9f05ab5 100644 --- a/media/filters/video_decode_engine.h +++ b/media/filters/video_decode_engine.h @@ -40,7 +40,7 @@ class VideoDecodeEngine { // // TODO(ajwong): Should this function just allocate a new yuv_frame and return // it via a "GetNextFrame()" method or similar? - virtual void DecodeFrame(const Buffer& buffer, AVFrame* yuv_frame, + virtual void DecodeFrame(Buffer* buffer, AVFrame* yuv_frame, bool* got_result, Task* done_cb) = 0; // Flushes the decode engine of any buffered input packets. @@ -52,7 +52,6 @@ class VideoDecodeEngine { // Returns the current state of the decode engine. virtual State state() const = 0; - }; } // namespace media diff --git a/media/filters/video_decoder_impl.cc b/media/filters/video_decoder_impl.cc index 4bd7abc..9592dbb 100644 --- a/media/filters/video_decoder_impl.cc +++ b/media/filters/video_decoder_impl.cc @@ -142,7 +142,7 @@ void VideoDecoderImpl::DoDecode(Buffer* buffer, Task* done_cb) { AVFrame* yuv_frame = avcodec_alloc_frame(); bool* got_frame = new bool; decode_engine_->DecodeFrame( - *buffer, + buffer, yuv_frame, got_frame, NewRunnableMethod(this, diff --git a/media/filters/video_decoder_impl_unittest.cc b/media/filters/video_decoder_impl_unittest.cc index 4742951..4ab6d65 100644 --- a/media/filters/video_decoder_impl_unittest.cc +++ b/media/filters/video_decoder_impl_unittest.cc @@ -49,7 +49,7 @@ class MockFFmpegDemuxerStream : public MockDemuxerStream, class MockVideoDecodeEngine : public VideoDecodeEngine { public: MOCK_METHOD2(Initialize, void(AVStream* stream, Task* done_cb)); - MOCK_METHOD4(DecodeFrame, void(const Buffer& buffer, AVFrame* yuv_frame, + MOCK_METHOD4(DecodeFrame, void(Buffer* buffer, AVFrame* yuv_frame, bool* got_result, Task* done_cb)); MOCK_METHOD1(Flush, void(Task* done_cb)); MOCK_CONST_METHOD0(state, State()); 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..70a5fe8 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_array<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()) diff --git a/media/tools/omx_test/omx_test.cc b/media/tools/omx_test/omx_test.cc index e90f150..947147e 100644 --- a/media/tools/omx_test/omx_test.cc +++ b/media/tools/omx_test/omx_test.cc @@ -19,7 +19,7 @@ #include "media/ffmpeg/file_protocol.h" #include "media/filters/bitstream_converter.h" #include "media/omx/omx_codec.h" -#include "media/omx/omx_input_buffer.h" +#include "media/base/data_buffer.h" #include "media/omx/omx_output_sink.h" #include "media/tools/omx_test/color_space_util.h" #include "media/tools/omx_test/file_reader_util.h" @@ -34,9 +34,10 @@ using media::OmxCodec; using media::OmxConfigurator; using media::OmxDecoderConfigurator; using media::OmxEncoderConfigurator; -using media::OmxInputBuffer; using media::OmxOutputSink; using media::YuvFileReader; +using media::Buffer; +using media::DataBuffer; // This is the driver object to feed the decoder with data from a file. // It also provides callbacks for the decoder to receive events from the @@ -99,7 +100,7 @@ class TestApp { input_format.video_header.height); } - void FeedCallback(OmxInputBuffer* buffer) { + void FeedCallback(Buffer* 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 @@ -140,7 +141,7 @@ class TestApp { uint8* data; int read; file_reader_->Read(&data, &read); - codec_->Feed(new OmxInputBuffer(data, read), + codec_->Feed(new DataBuffer(data, read), NewCallback(this, &TestApp::FeedCallback)); } |