[FFmpeg-cvslog] file: Use a normal private context for storing the file descriptor
Martin Storsjö
git at videolan.org
Tue Sep 11 15:34:44 CEST 2012
ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Sun Sep 9 22:35:50 2012 +0300| [0697d81269ab07d91b3303923a4751c21c675439] | committer: Martin Storsjö
file: Use a normal private context for storing the file descriptor
Previously the file descriptor was stored in the priv_data pointer.
Signed-off-by: Martin Storsjö <martin at martin.st>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0697d81269ab07d91b3303923a4751c21c675439
---
libavformat/file.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/libavformat/file.c b/libavformat/file.c
index 0e3577d..3cfd28c 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -36,21 +36,26 @@
/* 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;
- return read(fd, buf, size);
+ FileContext *c = h->priv_data;
+ return read(c->fd, buf, size);
}
static int file_write(URLContext *h, const unsigned char *buf, int size)
{
- int fd = (intptr_t) h->priv_data;
- return write(fd, buf, size);
+ FileContext *c = h->priv_data;
+ return write(c->fd, buf, size);
}
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)
@@ -70,6 +75,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;
@@ -88,26 +94,26 @@ 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;
return 0;
}
/* 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) : 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 = {
@@ -119,6 +125,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 */
@@ -127,6 +134,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);
@@ -142,7 +150,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;
}
@@ -154,6 +162,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 */
More information about the ffmpeg-cvslog
mailing list