From 0d7cef4d19826157be5d8ee93a5a85a8a3d2fe5c Mon Sep 17 00:00:00 2001 From: "hclam@chromium.org" Date: Fri, 5 Feb 2010 21:15:00 +0000 Subject: 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 --- media/filters/omx_video_decode_engine.cc | 5 +-- media/filters/omx_video_decode_engine.h | 4 +-- media/media.gyp | 4 +-- media/omx/input_buffer.cc | 43 -------------------------- media/omx/input_buffer.h | 50 ------------------------------ media/omx/omx_codec.cc | 13 ++++---- media/omx/omx_codec.h | 19 ++++++------ media/omx/omx_input_buffer.cc | 39 +++++++++++++++++++++++ media/omx/omx_input_buffer.h | 53 ++++++++++++++++++++++++++++++++ media/tools/omx_test/omx_test.cc | 7 +++-- 10 files changed, 120 insertions(+), 117 deletions(-) delete mode 100644 media/omx/input_buffer.cc delete mode 100644 media/omx/input_buffer.h create mode 100644 media/omx/omx_input_buffer.cc create mode 100644 media/omx/omx_input_buffer.h (limited to 'media') 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/input_buffer.cc b/media/omx/input_buffer.cc deleted file mode 100644 index c26b9f7..0000000 --- a/media/omx/input_buffer.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2009 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/omx/input_buffer.h" - -#include - -#include "base/logging.h" - -namespace media { - -InputBuffer::InputBuffer() - : size_(0), - used_(0) { -} - -InputBuffer::InputBuffer(uint8* data, int size) - : data_(data), - size_(size), - used_(0) { - DCHECK_GE(size, 0); -} - -InputBuffer::~InputBuffer() { -} - -int InputBuffer::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() { - 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/input_buffer.h deleted file mode 100644 index 9c6f442..0000000 --- a/media/omx/input_buffer.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2009 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. - -// Defines the input buffer object for the video decoder. This provides -// the interface needed by the video decoder to read input data. -// -// This object is implemened using system memory. - -#ifndef MEDIA_OMX_INPUT_BUFFER_H_ -#define MEDIA_OMX_INPUT_BUFFER_H_ - -#include "base/basictypes.h" -#include "base/scoped_ptr.h" - -namespace media { - -// TODO(hclam): consolidate our buffer implementations http://crbug.com/28654 -class InputBuffer { - public: - // Creates an empty input buffer. - InputBuffer(); - - // 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(); - - // Read from the this buffer into |data| with the maximum |size| bytes. - // Returns number of bytes read. If a read is successful, the number - // of used bytes will advances accordingly. - // Returns a negative number on error. - int Read(uint8* data, int size); - - // Returns true if this buffer is used. - bool Used(); - - // Returns true if this is an end-of-stream buffer. - bool IsEndOfStream(); - - private: - scoped_array data_; - int size_; - int used_; -}; - -} // namespace media - -#endif // MEDIA_OMX_INPUT_BUFFER_H_ 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 { public: // TODO(jiesun): remove callback parameters. typedef Callback2< const OmxConfigurator::MediaFormat&, const OmxConfigurator::MediaFormat&>::Type FormatCallback; - typedef Callback1::Type FeedCallback; + typedef Callback1::Type FeedCallback; typedef Callback2::Type ReadCallback; typedef Callback0::Type Callback; @@ -139,7 +140,7 @@ class OmxCodec : public base::RefCountedThreadSafe { // 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 { 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 { scoped_ptr error_callback_; // Input and output queue for encoded data and decoded frames. - typedef std::pair InputUnit; + typedef std::pair InputUnit; std::queue input_queue_; std::queue output_queue_; diff --git a/media/omx/omx_input_buffer.cc b/media/omx/omx_input_buffer.cc new file mode 100644 index 0000000..b4864fe --- /dev/null +++ b/media/omx/omx_input_buffer.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2009 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/omx/omx_input_buffer.h" + +#include + +#include "base/logging.h" + +namespace media { + +OmxInputBuffer::OmxInputBuffer() + : size_(0), + used_(0) { +} + +OmxInputBuffer::OmxInputBuffer(uint8* data, int size) + : data_(data), + size_(size), + used_(0) { + DCHECK_GE(size, 0); +} + +OmxInputBuffer::~OmxInputBuffer() { +} + +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 OmxInputBuffer::Used() { + return used_ == size_; +} + +} // namespace media diff --git a/media/omx/omx_input_buffer.h b/media/omx/omx_input_buffer.h new file mode 100644 index 0000000..10a9049 --- /dev/null +++ b/media/omx/omx_input_buffer.h @@ -0,0 +1,53 @@ +// 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. + +// Defines the input buffer object for the video decoder. This provides +// the interface needed by the video decoder to read input data. +// +// This object is implemened using system memory. + +#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 { + +class OmxInputBuffer : public Buffer { + public: + // Creates an empty input buffer. + 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. + 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 + // of used bytes will advances accordingly. + // Returns a negative number on error. + int Read(uint8* data, int size); + + // Returns true if this buffer is used. + bool Used(); + + private: + virtual const uint8* GetData() const { return data_.get(); } + + virtual size_t GetDataSize() const { return size_; } + + scoped_array data_; + int size_; + int used_; + + DISALLOW_COPY_AND_ASSIGN(OmxInputBuffer); +}; + +} // namespace media + +#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)); } -- cgit v1.1