annotate file.c @ 1297:f63d2066f478 libavformat

Allow to store the the track number though the IPRT (part) tag in AVI. Patch by Panagiotis Issaris % takis P issaris A uhasselt P be% Original thread: Date: Sep 6, 2006 6:00 PM Subject: [Ffmpeg-devel] [PATCH] Enable track tag in AVI
author gpoirier
date Thu, 07 Sep 2006 16:33:24 +0000
parents 2a0c729ac640
children 0899bfe4105c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Buffered file io for ffmpeg system
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include <fcntl.h>
1171
2a0c729ac640 CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents: 896
diff changeset
21 #ifndef __MINGW32__
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <sys/ioctl.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <sys/time.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #include <io.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #define open(fname,oflag,pmode) _open(fname,oflag,pmode)
1171
2a0c729ac640 CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents: 896
diff changeset
28 #endif /* __MINGW32__ */
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 /* standard file protocol */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 static int file_open(URLContext *h, const char *filename, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 int access;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 int fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37
3
3442cae3ecf9 fixed 'file:' in URLs
bellard
parents: 0
diff changeset
38 strstart(filename, "file:", &filename);
3442cae3ecf9 fixed 'file:' in URLs
bellard
parents: 0
diff changeset
39
364
0d74e8abcb3d avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 332
diff changeset
40 if (flags & URL_RDWR) {
0d74e8abcb3d avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 332
diff changeset
41 access = O_CREAT | O_TRUNC | O_RDWR;
0d74e8abcb3d avio patch by (Gildas Bazin <gbazin at altern dot org>)
michael
parents: 332
diff changeset
42 } else if (flags & URL_WRONLY) {
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 access = O_CREAT | O_TRUNC | O_WRONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 access = O_RDONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 }
1171
2a0c729ac640 CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents: 896
diff changeset
47 #if defined(__MINGW32__) || defined(CONFIG_OS2) || defined(__CYGWIN__)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 access |= O_BINARY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 fd = open(filename, access, 0666);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 if (fd < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 return -ENOENT;
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
53 h->priv_data = (void *)(size_t)fd;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 static int file_read(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 {
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
59 int fd = (size_t)h->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 return read(fd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 static int file_write(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 {
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
65 int fd = (size_t)h->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 return write(fd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 /* XXX: use llseek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 {
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
72 int fd = (size_t)h->priv_data;
1171
2a0c729ac640 CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents: 896
diff changeset
73 #if defined(__MINGW32__)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 return _lseeki64(fd, pos, whence);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 return lseek(fd, pos, whence);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 static int file_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 {
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
82 int fd = (size_t)h->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 return close(fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 URLProtocol file_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 "file",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 file_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 file_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 file_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 file_seek,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 file_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 /* pipe protocol */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 static int pipe_open(URLContext *h, const char *filename, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 int fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 if (flags & URL_WRONLY) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 fd = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 fd = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 }
1171
2a0c729ac640 CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents: 896
diff changeset
106 #if defined(__MINGW32__) || defined(CONFIG_OS2) || defined(__CYGWIN__)
394
c7a3987b4462 untested win32 binary pipe fix
michael
parents: 364
diff changeset
107 setmode(fd, O_BINARY);
c7a3987b4462 untested win32 binary pipe fix
michael
parents: 364
diff changeset
108 #endif
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
109 h->priv_data = (void *)(size_t)fd;
605
deece487318e fixing pipe seek bug
michael
parents: 449
diff changeset
110 h->is_streamed = 1;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 static int pipe_read(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 {
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
116 int fd = (size_t)h->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 return read(fd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 static int pipe_write(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 {
396
96f8086bc2ba warning patrol
mellum
parents: 394
diff changeset
122 int fd = (size_t)h->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 return write(fd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 static int pipe_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 URLProtocol pipe_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 "pipe",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 pipe_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 pipe_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 pipe_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 pipe_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 };