| Index: media/bench/file_protocol.cc
|
| ===================================================================
|
| --- media/bench/file_protocol.cc (revision 25978)
|
| +++ media/bench/file_protocol.cc (working copy)
|
| @@ -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 @@
|
| &WriteContext,
|
| &SeekContext,
|
| &CloseContext,
|
| + NULL, // *next
|
| + NULL, // url_read_pause
|
| + NULL, // url_read_seek
|
| + &GetHandle
|
| };
|
| +
|
|
|