annotate file.c @ 21:3d2d2f8725f9 libavformat

jpeg detection fix - fixed imagepipe output
author bellard
date Sat, 11 Jan 2003 05:33:35 +0000
parents 3442cae3ecf9
children 65433f1b2549
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #ifndef CONFIG_WIN32
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)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #endif /* CONFIG_WIN32 */
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
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 if (flags & URL_WRONLY) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 access = O_CREAT | O_TRUNC | O_WRONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 access = O_RDONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 #ifdef CONFIG_WIN32
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 access |= O_BINARY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 fd = open(filename, access, 0666);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 if (fd < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 return -ENOENT;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 h->priv_data = (void *)fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 static int file_read(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 int fd = (int)h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 return read(fd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 static int file_write(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 int fd = (int)h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 return write(fd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 /* XXX: use llseek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 static offset_t file_seek(URLContext *h, offset_t pos, int whence)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 int fd = (int)h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 #ifdef CONFIG_WIN32
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 return _lseeki64(fd, pos, whence);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 return lseek(fd, pos, whence);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 static int file_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 int fd = (int)h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 return close(fd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 URLProtocol file_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 "file",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 file_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 file_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 file_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 file_seek,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 file_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 /* pipe protocol */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 static int pipe_open(URLContext *h, const char *filename, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 int fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 if (flags & URL_WRONLY) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 fd = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 fd = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 h->priv_data = (void *)fd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 static int pipe_read(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 int fd = (int)h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 return read(fd, buf, size);
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_write(URLContext *h, unsigned char *buf, int size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 int fd = (int)h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 return write(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_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 URLProtocol pipe_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 "pipe",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 pipe_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 pipe_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 pipe_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 pipe_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 };