diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 01:58:02 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-04 01:58:02 +0000 |
commit | 49733c4c44dabddad2f24168a74a4d87c5fca9f2 (patch) | |
tree | ac69cb305b7e79df095c9cc9da66962e8a0aba7a | |
parent | a1878ad0988f156768a8b1b852055b39dcd3e0e5 (diff) | |
download | chromium_src-49733c4c44dabddad2f24168a74a4d87c5fca9f2.zip chromium_src-49733c4c44dabddad2f24168a74a4d87c5fca9f2.tar.gz chromium_src-49733c4c44dabddad2f24168a74a4d87c5fca9f2.tar.bz2 |
Implemented file URLProtocol for media_bench.
BUG=none
TEST=media_bench should work out of the box with chromium's ffmpeg binaries
Review URL: http://codereview.chromium.org/196018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25420 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/bench/bench.cc | 2 | ||||
-rw-r--r-- | media/bench/file_protocol.cc | 61 | ||||
-rw-r--r-- | media/bench/file_protocol.h | 14 | ||||
-rw-r--r-- | media/filters/ffmpeg_common.h | 3 | ||||
-rw-r--r-- | media/filters/ffmpeg_glue.h | 4 | ||||
-rw-r--r-- | media/media.gyp | 1 |
6 files changed, 81 insertions, 4 deletions
diff --git a/media/bench/bench.cc b/media/bench/bench.cc index c20d3b0..05f8da3 100644 --- a/media/bench/bench.cc +++ b/media/bench/bench.cc @@ -22,6 +22,7 @@ #include "base/string_util.h" #include "base/time.h" #include "media/base/media.h" +#include "media/bench/file_protocol.h" #include "media/filters/ffmpeg_common.h" #include "media/filters/ffmpeg_video_decoder.h" @@ -113,6 +114,7 @@ int main(int argc, const char** argv) { // Register FFmpeg and attempt to open file. avcodec_init(); av_register_all(); + av_register_protocol(&kFFmpegFileProtocol); AVFormatContext* format_context = NULL; if (av_open_input_file(&format_context, in_path.c_str(), NULL, 0, NULL) < 0) { std::cerr << "Could not open " << in_path << std::endl; diff --git a/media/bench/file_protocol.cc b/media/bench/file_protocol.cc new file mode 100644 index 0000000..fc1be89 --- /dev/null +++ b/media/bench/file_protocol.cc @@ -0,0 +1,61 @@ +// 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/bench/file_protocol.h" + +#include "base/file_util.h" +#include "base/logging.h" +#include "media/filters/ffmpeg_common.h" + +namespace { + +FILE* ToFile(void* data) { + return reinterpret_cast<FILE*>(data); +} + +// FFmpeg protocol interface. +int OpenContext(URLContext* h, const char* filename, int flags) { + FILE* file = file_util::OpenFile(filename, "rb"); + if (!file) + return AVERROR_IO; + + h->priv_data = file; + h->flags = URL_RDONLY; + h->is_streamed = false; + return 0; +} + +int ReadContext(URLContext* h, unsigned char* buf, int size) { + return fread(buf, 1, size, ToFile(h->priv_data)); +} + +int WriteContext(URLContext* h, unsigned char* buf, int size) { + NOTIMPLEMENTED(); + return AVERROR_IO; +} + +offset_t SeekContext(URLContext* h, offset_t offset, int whence) { +#if defined(OS_WIN) + return _fseeki64(ToFile(h->priv_data), offset, whence); +#else + return fseek(ToFile(h->priv_data), offset, whence); +#endif +} + +int CloseContext(URLContext* h) { + if (file_util::CloseFile(ToFile(h->priv_data))) + return 0; + return AVERROR_IO; +} + +} // namespace + +URLProtocol kFFmpegFileProtocol = { + "file", + &OpenContext, + &ReadContext, + &WriteContext, + &SeekContext, + &CloseContext, +}; diff --git a/media/bench/file_protocol.h b/media/bench/file_protocol.h new file mode 100644 index 0000000..3cfddad --- /dev/null +++ b/media/bench/file_protocol.h @@ -0,0 +1,14 @@ +// 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. +// +// Implements a basic file I/O URLProtocol for FFmpeg. Since we don't build +// FFmpeg binaries with protocols, we have to write our own. + +#ifndef MEDIA_BENCH_FILE_PROTOCOL_H_ +#define MEDIA_BENCH_FILE_PROTOCOL_H_ + +struct URLProtocol; +extern URLProtocol kFFmpegFileProtocol; + +#endif // MEDIA_BENCH_FILE_PROTOCOL_H_ diff --git a/media/filters/ffmpeg_common.h b/media/filters/ffmpeg_common.h index 5ccbae8..94f5af8 100644 --- a/media/filters/ffmpeg_common.h +++ b/media/filters/ffmpeg_common.h @@ -11,6 +11,9 @@ #include "base/compiler_specific.h" #include "base/singleton.h" +// Used with URLProtocol. +typedef int64 offset_t; + // Include FFmpeg header files. extern "C" { // Temporarily disable possible loss of data warning. diff --git a/media/filters/ffmpeg_glue.h b/media/filters/ffmpeg_glue.h index bc39ab2..1ae4ded 100644 --- a/media/filters/ffmpeg_glue.h +++ b/media/filters/ffmpeg_glue.h @@ -32,10 +32,6 @@ #include "base/lock.h" #include "base/singleton.h" -// FFmpeg forward declarations. -struct URLContext; -typedef int64 offset_t; - namespace media { class FFmpegURLProtocol { diff --git a/media/media.gyp b/media/media.gyp index 88bda0d..5bb4034 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -205,6 +205,7 @@ ], 'sources': [ 'bench/bench.cc', + 'bench/file_protocol.cc', ], }, { |