summaryrefslogtreecommitdiffstats
path: root/media/tools
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 19:03:59 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-17 19:03:59 +0000
commit19ffd67a4c32136d1d2abc07c97dcbb7ec5af216 (patch)
tree15ed2566ef839af4e218fc1d96880a9d1dc5ac44 /media/tools
parent483a075709bb435ddf380aac050dc3b7a586d244 (diff)
downloadchromium_src-19ffd67a4c32136d1d2abc07c97dcbb7ec5af216.zip
chromium_src-19ffd67a4c32136d1d2abc07c97dcbb7ec5af216.tar.gz
chromium_src-19ffd67a4c32136d1d2abc07c97dcbb7ec5af216.tar.bz2
API to allow strategy class to work on the output buffer of OpenMAX
Added interface of OmxOutputSink to interact with OmxCodec to perform buffer negotiation and buffer read signaling. TEST=media_unittests --gtest_filter=Omx* BUG=32753 BUG=32754 BUG=32870 Review URL: http://codereview.chromium.org/593047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39247 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/tools')
-rw-r--r--media/tools/omx_test/file_sink.cc (renamed from media/tools/omx_test/file_writer_util.cc)63
-rw-r--r--media/tools/omx_test/file_sink.h (renamed from media/tools/omx_test/file_writer_util.h)33
-rw-r--r--media/tools/omx_test/omx_test.cc40
3 files changed, 92 insertions, 44 deletions
diff --git a/media/tools/omx_test/file_writer_util.cc b/media/tools/omx_test/file_sink.cc
index 0b96896..abee305 100644
--- a/media/tools/omx_test/file_writer_util.cc
+++ b/media/tools/omx_test/file_sink.cc
@@ -2,7 +2,7 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
-#include "media/tools/omx_test/file_writer_util.h"
+#include "media/tools/omx_test/file_sink.h"
#include "base/file_util.h"
#include "base/logging.h"
@@ -10,24 +10,36 @@
namespace media {
-bool FileWriter::Initialize() {
- // Opens the output file for writing.
- if (!output_filename_.empty()) {
- output_file_.Set(file_util::OpenFile(output_filename_, "wb"));
- if (!output_file_.get()) {
- LOG(ERROR) << "can't open dump file %s" << output_filename_;
- return false;
- }
- }
- return true;
+bool FileSink::AllocateEGLImages(int width, int height,
+ std::vector<EGLImageKHR>* images) {
+ NOTREACHED() << "This method is never used";
+ return false;
}
-void FileWriter::UpdateSize(int width, int height) {
- width_ = width;
- height_ = height;
+void FileSink::ReleaseEGLImages(const std::vector<EGLImageKHR>& images) {
+ NOTREACHED() << "This method is never used";
+}
+
+void FileSink::UseThisBuffer(int buffer_id, OMX_BUFFERHEADERTYPE* buffer) {
+ CHECK(omx_buffers_.find(buffer_id) == omx_buffers_.end());
+ omx_buffers_[buffer_id] = buffer;
}
-void FileWriter::Write(uint8* buffer, int size) {
+void FileSink::StopUsingThisBuffer(int id) {
+ omx_buffers_.erase(id);
+}
+
+void FileSink::BufferReady(int buffer_id, BufferUsedCallback* callback) {
+ CHECK(omx_buffers_.find(buffer_id) != omx_buffers_.end());
+ CHECK(callback);
+
+ OMX_BUFFERHEADERTYPE* omx_buffer = omx_buffers_[buffer_id];
+ uint8* buffer = omx_buffer->pBuffer;
+ int size = omx_buffer->nFilledLen;
+
+ // We never receive an end-of-stream buffer here.
+ CHECK(!(omx_buffer->nFlags & OMX_BUFFERFLAG_EOS));
+
if (size > copy_buf_size_) {
copy_buf_.reset(new uint8[size]);
copy_buf_size_ = size;
@@ -50,6 +62,27 @@ void FileWriter::Write(uint8* buffer, int size) {
if (output_file_.get())
fwrite(out_buffer, sizeof(uint8), size, output_file_.get());
+
+ // Always make the callback.
+ callback->Run(buffer_id);
+ delete callback;
+}
+
+bool FileSink::Initialize() {
+ // Opens the output file for writing.
+ if (!output_filename_.empty()) {
+ output_file_.Set(file_util::OpenFile(output_filename_, "wb"));
+ if (!output_file_.get()) {
+ LOG(ERROR) << "can't open dump file %s" << output_filename_;
+ return false;
+ }
+ }
+ return true;
+}
+
+void FileSink::UpdateSize(int width, int height) {
+ width_ = width;
+ height_ = height;
}
} // namespace media
diff --git a/media/tools/omx_test/file_writer_util.h b/media/tools/omx_test/file_sink.h
index f1427e9..58edb04 100644
--- a/media/tools/omx_test/file_writer_util.h
+++ b/media/tools/omx_test/file_sink.h
@@ -2,24 +2,26 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
-#ifndef MEDIA_TOOLS_OMX_TEST_FILE_WRITER_UTIL_H_
-#define MEDIA_TOOLS_OMX_TEST_FILE_WRITER_UTIL_H_
+#ifndef MEDIA_TOOLS_OMX_TEST_FILE_SINK_H_
+#define MEDIA_TOOLS_OMX_TEST_FILE_SINK_H_
+#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/scoped_handle.h"
#include "base/scoped_ptr.h"
+#include "media/omx/omx_output_sink.h"
namespace media {
// This class writes output of a frame decoded by OmxCodec and save it to
// a file.
-class FileWriter {
+class FileSink : public OmxOutputSink {
public:
- FileWriter(std::string output_filename,
- bool simulate_copy,
- bool enable_csc)
+ FileSink(std::string output_filename,
+ bool simulate_copy,
+ bool enable_csc)
: output_filename_(output_filename),
simulate_copy_(simulate_copy),
enable_csc_(enable_csc),
@@ -29,6 +31,15 @@ class FileWriter {
csc_buf_size_(0) {
}
+ // OmxOutputSink implementations.
+ virtual bool ProvidesEGLImages() const { return false; }
+ virtual bool AllocateEGLImages(int width, int height,
+ std::vector<EGLImageKHR>* images);
+ virtual void ReleaseEGLImages(const std::vector<EGLImageKHR>& images);
+ virtual void UseThisBuffer(int buffer_id, OMX_BUFFERHEADERTYPE* buffer);
+ virtual void StopUsingThisBuffer(int id);
+ virtual void BufferReady(int buffer_id, BufferUsedCallback* callback);
+
// Initialize this object. Returns true if successful.
bool Initialize();
@@ -43,16 +54,22 @@ class FileWriter {
bool simulate_copy_;
bool enable_csc_;
ScopedStdioHandle output_file_;
+
+ // Image properties.
int width_;
int height_;
+
+ // Buffers for copying and color space conversion.
scoped_array<uint8> copy_buf_;
int copy_buf_size_;
scoped_array<uint8> csc_buf_;
int csc_buf_size_;
- DISALLOW_COPY_AND_ASSIGN(FileWriter);
+ std::map<int, OMX_BUFFERHEADERTYPE*> omx_buffers_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileSink);
};
} // namespace media
-#endif // MEDIA_TOOLS_OMX_TEST_FILE_WRITER_UTIL_H_
+#endif // MEDIA_TOOLS_OMX_TEST_FILE_SINK_H_
diff --git a/media/tools/omx_test/omx_test.cc b/media/tools/omx_test/omx_test.cc
index d7dc672..3085181 100644
--- a/media/tools/omx_test/omx_test.cc
+++ b/media/tools/omx_test/omx_test.cc
@@ -19,20 +19,22 @@
#include "media/filters/bitstream_converter.h"
#include "media/omx/omx_codec.h"
#include "media/omx/omx_input_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"
-#include "media/tools/omx_test/file_writer_util.h"
+#include "media/tools/omx_test/file_sink.h"
using media::BlockFileReader;
using media::FFmpegFileReader;
using media::FileReader;
-using media::FileWriter;
+using media::FileSink;
using media::H264FileReader;
using media::OmxCodec;
using media::OmxConfigurator;
using media::OmxDecoderConfigurator;
using media::OmxEncoderConfigurator;
using media::OmxInputBuffer;
+using media::OmxOutputSink;
using media::YuvFileReader;
// This is the driver object to feed the decoder with data from a file.
@@ -40,11 +42,11 @@ using media::YuvFileReader;
// decoder.
class TestApp {
public:
- TestApp(OmxConfigurator* configurator, FileReader* file_reader,
- FileWriter* file_writer)
+ TestApp(OmxConfigurator* configurator, FileSink* file_sink,
+ FileReader* file_reader)
: configurator_(configurator),
file_reader_(file_reader),
- file_writer_(file_writer),
+ file_sink_(file_sink),
stopped_(false),
error_(false) {
}
@@ -56,7 +58,7 @@ class TestApp {
return false;;
}
- if (!file_writer_->Initialize()) {
+ if (!file_sink_->Initialize()) {
LOG(ERROR) << "can't initialize output writer";
return false;
}
@@ -92,7 +94,7 @@ class TestApp {
DCHECK_EQ(input_format.video_header.height,
output_format.video_header.height);
- file_writer_->UpdateSize(input_format.video_header.width,
+ file_sink_->UpdateSize(input_format.video_header.width,
input_format.video_header.height);
}
@@ -107,7 +109,8 @@ class TestApp {
FeedInputBuffer();
}
- void ReadCompleteCallback(uint8* buffer, int size) {
+ void ReadCompleteCallback(int buffer,
+ FileSink::BufferUsedCallback* callback) {
// This callback is received when the decoder has completed a decoding
// task and given us some output data. The buffer is owned by the decoder.
if (stopped_ || error_)
@@ -117,7 +120,7 @@ class TestApp {
first_sample_delivered_time_ = base::TimeTicks::HighResNow();
// If we are readding to the end, then stop.
- if (!size) {
+ if (buffer == OmxCodec::kEosBuffer) {
codec_->Stop(NewCallback(this, &TestApp::StopCallback));
return;
}
@@ -125,12 +128,11 @@ class TestApp {
// Read one more from the decoder.
codec_->Read(NewCallback(this, &TestApp::ReadCompleteCallback));
- if (file_writer_.get())
- file_writer_->Write(buffer, size);
+ if (file_sink_.get())
+ file_sink_->BufferReady(buffer, callback);
// could OMX IL return patial sample for decoder?
frame_count_++;
- bit_count_ += size << 3;
}
void FeedInputBuffer() {
@@ -147,7 +149,7 @@ class TestApp {
// Setup the |codec_| with the message loop of the current thread. Also
// setup component name, codec format and callbacks.
codec_ = new OmxCodec(&message_loop_);
- codec_->Setup(configurator_.release());
+ codec_->Setup(configurator_.get(), file_sink_.get());
codec_->SetErrorCallback(NewCallback(this, &TestApp::ErrorCallback));
codec_->SetFormatCallback(NewCallback(this, &TestApp::FormatCallback));
@@ -167,7 +169,6 @@ class TestApp {
void StartProfiler() {
start_time_ = base::TimeTicks::HighResNow();
frame_count_ = 0;
- bit_count_ = 0;
}
void StopProfiler() {
@@ -184,7 +185,6 @@ class TestApp {
printf("\n<<< fps : %d >>>", static_cast<int>(fps));
printf("\n<<< initial delay used(us): %d >>>",
static_cast<int>(delay.InMicroseconds()));
- // printf("\n<<< bitrate>>> : %I64d\n", bit_count_ * 1000000 / micro_sec);
printf("\n");
}
@@ -192,7 +192,7 @@ class TestApp {
MessageLoop message_loop_;
scoped_ptr<OmxConfigurator> configurator_;
scoped_ptr<FileReader> file_reader_;
- scoped_ptr<FileWriter> file_writer_;
+ scoped_ptr<FileSink> file_sink_;
// Internal states for execution.
bool stopped_;
@@ -202,7 +202,6 @@ class TestApp {
base::TimeTicks start_time_;
base::TimeTicks first_sample_delivered_time_;
int frame_count_;
- int bit_count_;
};
static std::string GetStringSwitch(const char* name) {
@@ -360,12 +359,11 @@ int main(int argc, char** argv) {
else
configurator = new OmxDecoderConfigurator(input, output);
- // Create a file writer.
- FileWriter* file_writer =
- new FileWriter(output_filename, copy, enable_csc);
+ // Create a file sink.
+ FileSink* file_sink = new FileSink(output_filename, copy, enable_csc);
// Create a test app object and initialize it.
- TestApp test(configurator, file_reader, file_writer);
+ TestApp test(configurator, file_sink, file_reader);
if (!test.Initialize()) {
LOG(ERROR) << "can't initialize this application";
return -1;