summaryrefslogtreecommitdiff
path: root/libavformat/file.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-09-11 15:24:22 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-09-11 15:24:22 +0200
commitec7946853a24855cc4e889f788195f57ce59ccab (patch)
tree323a8434157c2136b0ebd5e563bb0b566ac5bb8c /libavformat/file.c
parent7b56dddd565438e5c9a9bfcd0a55e087ce0800fe (diff)
parent55e778bebd6352977eebe406b522e2e9aed7ce35 (diff)
downloadffmpeg-ec7946853a24855cc4e889f788195f57ce59ccab.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: rtpdec_jpeg: Add support for default quantizers x86: dsputil: Move specific optimization settings out of global init function avplay: get rid of ugly casts in the options table avplay: fix prototypes for option callbacks. flvdec: always set AVFMTCTX_NOHEADER. file: Use a normal private context for storing the file descriptor configure: Adjust the xgetbv instrinsic check configure: Add --disable-inline-asm command line option configure: Don't try to enable the log2 function on msvcrt Conflicts: configure ffplay.c libavcodec/x86/dsputil_mmx.c libavformat/file.c libavformat/flvdec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/file.c')
-rw-r--r--libavformat/file.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/libavformat/file.c b/libavformat/file.c
index 288275f6ef..906ecddd42 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -44,23 +44,28 @@
/* standard file protocol */
+typedef struct FileContext {
+ int fd;
+} FileContext;
+
static int file_read(URLContext *h, unsigned char *buf, int size)
{
- int fd = (intptr_t) h->priv_data;
- int r = read(fd, buf, size);
+ FileContext *c = h->priv_data;
+ int r = read(c->fd, buf, size);
return (-1 == r)?AVERROR(errno):r;
}
static int file_write(URLContext *h, const unsigned char *buf, int size)
{
- int fd = (intptr_t) h->priv_data;
- int r = write(fd, buf, size);
+ FileContext *c = h->priv_data;
+ int r = write(c->fd, buf, size);
return (-1 == r)?AVERROR(errno):r;
}
static int file_get_handle(URLContext *h)
{
- return (intptr_t) h->priv_data;
+ FileContext *c = h->priv_data;
+ return c->fd;
}
static int file_check(URLContext *h, int mask)
@@ -80,6 +85,7 @@ static int file_check(URLContext *h, int mask)
static int file_open(URLContext *h, const char *filename, int flags)
{
+ FileContext *c = h->priv_data;
int access;
int fd;
struct stat st;
@@ -99,7 +105,7 @@ static int file_open(URLContext *h, const char *filename, int flags)
fd = open(filename, access, 0666);
if (fd == -1)
return AVERROR(errno);
- h->priv_data = (void *) (intptr_t) fd;
+ c->fd = fd;
h->is_streamed = !fstat(fd, &st) && S_ISFIFO(st.st_mode);
@@ -109,19 +115,19 @@ static int file_open(URLContext *h, const char *filename, int flags)
/* XXX: use llseek */
static int64_t file_seek(URLContext *h, int64_t pos, int whence)
{
- int fd = (intptr_t) h->priv_data;
+ FileContext *c = h->priv_data;
if (whence == AVSEEK_SIZE) {
struct stat st;
- int ret = fstat(fd, &st);
+ int ret = fstat(c->fd, &st);
return ret < 0 ? AVERROR(errno) : (S_ISFIFO(st.st_mode) ? 0 : st.st_size);
}
- return lseek(fd, pos, whence);
+ return lseek(c->fd, pos, whence);
}
static int file_close(URLContext *h)
{
- int fd = (intptr_t) h->priv_data;
- return close(fd);
+ FileContext *c = h->priv_data;
+ return close(c->fd);
}
URLProtocol ff_file_protocol = {
@@ -133,6 +139,7 @@ URLProtocol ff_file_protocol = {
.url_close = file_close,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
+ .priv_data_size = sizeof(FileContext),
};
#endif /* CONFIG_FILE_PROTOCOL */
@@ -141,6 +148,7 @@ URLProtocol ff_file_protocol = {
static int pipe_open(URLContext *h, const char *filename, int flags)
{
+ FileContext *c = h->priv_data;
int fd;
char *final;
av_strstart(filename, "pipe:", &filename);
@@ -156,7 +164,7 @@ static int pipe_open(URLContext *h, const char *filename, int flags)
#if HAVE_SETMODE
setmode(fd, O_BINARY);
#endif
- h->priv_data = (void *) (intptr_t) fd;
+ c->fd = fd;
h->is_streamed = 1;
return 0;
}
@@ -168,6 +176,7 @@ URLProtocol ff_pipe_protocol = {
.url_write = file_write,
.url_get_file_handle = file_get_handle,
.url_check = file_check,
+ .priv_data_size = sizeof(FileContext),
};
#endif /* CONFIG_PIPE_PROTOCOL */