Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: media/bench/file_protocol.cc

Issue 199049: Media Bench file IO redux to address mp4 parsing issue. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/bench/bench.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
};
+
« no previous file with comments | « media/bench/bench.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698