Commit | Line | Data |
---|---|---|
de6d9b64 FB |
1 | /* output byte stream handling */ |
2 | ||
3 | typedef long long offset_t; | |
4 | ||
5 | /* unbuffered I/O */ | |
6 | ||
7 | struct URLContext { | |
8 | struct URLProtocol *prot; | |
9 | int flags; | |
10 | int is_streamed; /* true if streamed (no seek possible), default = false */ | |
11 | int packet_size; | |
12 | void *priv_data; | |
13 | }; | |
14 | ||
15 | typedef struct URLFormat { | |
16 | char format_name[32]; | |
17 | int sample_rate; | |
18 | int frame_rate; | |
19 | int channels; | |
20 | int height; | |
21 | int width; | |
22 | int pix_fmt; | |
23 | } URLFormat; | |
24 | ||
25 | typedef struct URLContext URLContext; | |
26 | ||
27 | typedef struct URLPollEntry { | |
28 | URLContext *handle; | |
29 | int events; | |
30 | int revents; | |
31 | } URLPollEntry; | |
32 | ||
33 | #define URL_RDONLY 0 | |
34 | #define URL_WRONLY 1 | |
35 | int url_open(URLContext **h, const char *filename, int flags); | |
36 | int url_read(URLContext *h, unsigned char *buf, int size); | |
37 | int url_write(URLContext *h, unsigned char *buf, int size); | |
38 | offset_t url_seek(URLContext *h, offset_t pos, int whence); | |
39 | int url_getformat(URLContext *h, URLFormat *f); | |
40 | int url_close(URLContext *h); | |
41 | int url_exist(const char *filename); | |
42 | offset_t url_filesize(URLContext *h); | |
43 | /* not implemented */ | |
44 | int url_poll(URLPollEntry *poll_table, int n, int timeout); | |
45 | ||
46 | typedef struct URLProtocol { | |
47 | const char *name; | |
48 | int (*url_open)(URLContext *h, const char *filename, int flags); | |
49 | int (*url_read)(URLContext *h, unsigned char *buf, int size); | |
50 | int (*url_write)(URLContext *h, unsigned char *buf, int size); | |
51 | offset_t (*url_seek)(URLContext *h, offset_t pos, int whence); | |
52 | int (*url_close)(URLContext *h); | |
53 | /* get precise information about the format, if available. return | |
54 | -ENODATA if not available */ | |
55 | int (*url_getformat)(URLContext *h, URLFormat *f); | |
56 | struct URLProtocol *next; | |
57 | } URLProtocol; | |
58 | ||
59 | extern URLProtocol *first_protocol; | |
60 | ||
61 | int register_protocol(URLProtocol *protocol); | |
62 | ||
63 | typedef struct { | |
64 | unsigned char *buffer; | |
65 | int buffer_size; | |
66 | unsigned char *buf_ptr, *buf_end; | |
67 | void *opaque; | |
68 | int (*read_packet)(void *opaque, UINT8 *buf, int buf_size); | |
69 | void (*write_packet)(void *opaque, UINT8 *buf, int buf_size); | |
70 | int (*seek)(void *opaque, offset_t offset, int whence); | |
71 | offset_t pos; /* position in the file of the current buffer */ | |
72 | int must_flush; /* true if the next seek should flush */ | |
73 | int eof_reached; /* true if eof reached */ | |
74 | int write_flag; /* true if open for writing */ | |
75 | int is_streamed; | |
76 | int packet_size; | |
77 | } ByteIOContext; | |
78 | ||
79 | int init_put_byte(ByteIOContext *s, | |
80 | unsigned char *buffer, | |
81 | int buffer_size, | |
82 | int write_flag, | |
83 | void *opaque, | |
84 | int (*read_packet)(void *opaque, UINT8 *buf, int buf_size), | |
85 | void (*write_packet)(void *opaque, UINT8 *buf, int buf_size), | |
86 | int (*seek)(void *opaque, offset_t offset, int whence)); | |
87 | ||
88 | void put_byte(ByteIOContext *s, int b); | |
89 | void put_buffer(ByteIOContext *s, unsigned char *buf, int size); | |
90 | void put_le64(ByteIOContext *s, unsigned long long val); | |
91 | void put_be64(ByteIOContext *s, unsigned long long val); | |
92 | void put_le32(ByteIOContext *s, unsigned int val); | |
93 | void put_be32(ByteIOContext *s, unsigned int val); | |
94 | void put_le16(ByteIOContext *s, unsigned int val); | |
95 | void put_be16(ByteIOContext *s, unsigned int val); | |
96 | void put_tag(ByteIOContext *s, char *tag); | |
97 | ||
98 | offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence); | |
99 | void url_fskip(ByteIOContext *s, offset_t offset); | |
100 | offset_t url_ftell(ByteIOContext *s); | |
101 | int url_feof(ByteIOContext *s); | |
102 | ||
103 | void put_flush_packet(ByteIOContext *s); | |
104 | ||
105 | int get_buffer(ByteIOContext *s, unsigned char *buf, int size); | |
106 | int get_byte(ByteIOContext *s); | |
107 | unsigned int get_le32(ByteIOContext *s); | |
108 | unsigned long long get_le64(ByteIOContext *s); | |
109 | unsigned int get_le16(ByteIOContext *s); | |
110 | ||
111 | unsigned int get_be16(ByteIOContext *s); | |
112 | unsigned int get_be32(ByteIOContext *s); | |
113 | unsigned long long get_be64(ByteIOContext *s); | |
114 | ||
115 | extern inline int url_is_streamed(ByteIOContext *s) | |
116 | { | |
117 | return s->is_streamed; | |
118 | } | |
119 | /* get the prefered packet size of the device. All I/Os should be done | |
120 | by multiple of this size */ | |
121 | extern inline int url_get_packet_size(ByteIOContext *s) | |
122 | { | |
123 | return s->packet_size; | |
124 | } | |
125 | ||
126 | int url_fdopen(ByteIOContext *s, URLContext *h); | |
127 | int url_setbufsize(ByteIOContext *s, int buf_size); | |
128 | int url_fopen(ByteIOContext *s, const char *filename, int flags); | |
129 | int url_fclose(ByteIOContext *s); | |
130 | URLContext *url_fileno(ByteIOContext *s); | |
131 | ||
132 | int url_open_buf(ByteIOContext *s, UINT8 *buf, int buf_size, int flags); | |
133 | int url_close_buf(ByteIOContext *s); | |
134 | ||
135 | /* file.c */ | |
136 | extern URLProtocol file_protocol; | |
137 | extern URLProtocol pipe_protocol; | |
138 | ||
139 | /* udp.c */ | |
140 | extern URLProtocol udp_protocol; | |
141 | ||
142 | /* http.c */ | |
143 | extern URLProtocol http_protocol; | |
144 | ||
145 | /* audio.c */ | |
146 | extern const char *audio_device; | |
147 | extern URLProtocol audio_protocol; | |
148 | ||
149 | /* grab.c */ | |
150 | extern const char *v4l_device; | |
151 | extern URLProtocol video_protocol; |