diff options
author | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-12 02:19:32 +0000 |
---|---|---|
committer | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-12 02:19:32 +0000 |
commit | eb268a94c2f15e9fb647f89dad2e312546e57095 (patch) | |
tree | e8a05d094ab649c1f0d055b42b44e97425eb85d0 /media/bench/file_protocol.cc | |
parent | d4b8eeef387561e1bc498e0cd632ba145637f7ed (diff) | |
download | chromium_src-eb268a94c2f15e9fb647f89dad2e312546e57095.zip chromium_src-eb268a94c2f15e9fb647f89dad2e312546e57095.tar.gz chromium_src-eb268a94c2f15e9fb647f89dad2e312546e57095.tar.bz2 |
Media Bench file IO redux to address mp4 parsing issue.
BUG=21322
TEST=run media_bench on regression corpus. Old version crashes/fails. New version should report errors and/or work.
Review URL: http://codereview.chromium.org/199049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26072 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/bench/file_protocol.cc')
-rw-r--r-- | media/bench/file_protocol.cc | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/media/bench/file_protocol.cc b/media/bench/file_protocol.cc index 517d101..cf44eee 100644 --- a/media/bench/file_protocol.cc +++ b/media/bench/file_protocol.cc @@ -4,56 +4,72 @@ #include "media/bench/file_protocol.h" -#include <stdio.h> +#include "build/build_config.h" + +#if defined(OS_WIN) +#include <io.h> +#else +#include <unistd.h> +#endif +#include <fcntl.h> + +#include "base/compiler_specific.h" #include "base/file_util.h" #include "base/logging.h" #include "media/filters/ffmpeg_common.h" +// warning C4996: 'open': The POSIX name for this item is deprecated. +MSVC_PUSH_DISABLE_WARNING(4996) + namespace { -FILE* ToFile(void* data) { - return reinterpret_cast<FILE*>(data); +int GetHandle(URLContext *h) { + return static_cast<int>(reinterpret_cast<intptr_t>(h->priv_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; + int access = O_RDONLY; + if (flags & URL_RDWR) { + access = O_CREAT | O_TRUNC | O_RDWR; + } else if (flags & URL_WRONLY) { + access = O_CREAT | O_TRUNC | O_WRONLY; + } +#ifdef O_BINARY + access |= O_BINARY; +#endif + int f = open(filename, access, 0666); + if (f == -1) + return AVERROR(ENOENT); + h->priv_data = reinterpret_cast<void*>(static_cast<intptr_t>(f)); h->is_streamed = false; return 0; } int ReadContext(URLContext* h, unsigned char* buf, int size) { - return fread(buf, 1, size, ToFile(h->priv_data)); + return read(GetHandle(h), buf, size); } int WriteContext(URLContext* h, unsigned char* buf, int size) { - NOTIMPLEMENTED(); - return AVERROR_IO; + return write(GetHandle(h), buf, size); } offset_t SeekContext(URLContext* h, offset_t offset, int whence) { #if defined(OS_WIN) - return static_cast<offset_t> (_fseeki64(ToFile(h->priv_data), - static_cast<int64>(offset), - whence)); + return lseek(GetHandle(h), static_cast<long>(offset), whence); #else - return fseek(ToFile(h->priv_data), offset, whence); + return lseek(GetHandle(h), offset, whence); #endif } int CloseContext(URLContext* h) { - if (file_util::CloseFile(ToFile(h->priv_data))) - return 0; - return AVERROR_IO; + return close(GetHandle(h)); } } // namespace +MSVC_POP_WARNING() + URLProtocol kFFmpegFileProtocol = { "file", &OpenContext, @@ -61,4 +77,9 @@ URLProtocol kFFmpegFileProtocol = { &WriteContext, &SeekContext, &CloseContext, + NULL, // *next + NULL, // url_read_pause + NULL, // url_read_seek + &GetHandle }; + |