export match_ext()
[libav.git] / libav / avformat.h
1 #ifndef AVFORMAT_H
2 #define AVFORMAT_H
3
4 #define LIBAVFORMAT_VERSION_INT 0x000406
5 #define LIBAVFORMAT_VERSION "0.4.6"
6 #define LIBAVFORMAT_BUILD 4602
7
8 #include "avcodec.h"
9
10 #include "avio.h"
11
12 /* packet functions */
13
14 #define AV_NOPTS_VALUE 0
15
16 typedef struct AVPacket {
17 INT64 pts; /* presentation time stamp in stream units (set av_set_pts_info) */
18 UINT8 *data;
19 int size;
20 int stream_index;
21 int flags;
22 int duration;
23 #define PKT_FLAG_KEY 0x0001
24 } AVPacket;
25
26 int av_new_packet(AVPacket *pkt, int size);
27 void av_free_packet(AVPacket *pkt);
28
29 /*************************************************/
30 /* fractional numbers for exact pts handling */
31
32 /* the exact value of the fractional number is: 'val + num / den'. num
33 is assumed to be such as 0 <= num < den */
34 typedef struct AVFrac {
35 INT64 val, num, den;
36 } AVFrac;
37
38 void av_frac_init(AVFrac *f, INT64 val, INT64 num, INT64 den);
39 void av_frac_add(AVFrac *f, INT64 incr);
40 void av_frac_set(AVFrac *f, INT64 val);
41
42 /*************************************************/
43 /* input/output formats */
44
45 struct AVFormatContext;
46
47 /* this structure contains the data a format has to probe a file */
48 typedef struct AVProbeData {
49 char *filename;
50 unsigned char *buf;
51 int buf_size;
52 } AVProbeData;
53
54 #define AVPROBE_SCORE_MAX 100
55
56 typedef struct AVFormatParameters {
57 int frame_rate;
58 int sample_rate;
59 int channels;
60 int width;
61 int height;
62 enum PixelFormat pix_fmt;
63 } AVFormatParameters;
64
65 #define AVFMT_NOFILE 0x0001 /* no file should be opened */
66 #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
67 #define AVFMT_NOHEADER 0x0004 /* signal that no header is present
68 (streams are added dynamically) */
69 #define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
70 #define AVFMT_RGB24 0x0010 /* force RGB24 output for ppm (hack
71 - need better api) */
72 #define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
73 raw picture data */
74
75 typedef struct AVOutputFormat {
76 const char *name;
77 const char *long_name;
78 const char *mime_type;
79 const char *extensions; /* comma separated extensions */
80 /* size of private data so that it can be allocated in the wrapper */
81 int priv_data_size;
82 /* output support */
83 enum CodecID audio_codec; /* default audio codec */
84 enum CodecID video_codec; /* default video codec */
85 int (*write_header)(struct AVFormatContext *);
86 /* XXX: change prototype for 64 bit pts */
87 int (*write_packet)(struct AVFormatContext *,
88 int stream_index,
89 unsigned char *buf, int size, int force_pts);
90 int (*write_trailer)(struct AVFormatContext *);
91 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
92 int flags;
93 /* private fields */
94 struct AVOutputFormat *next;
95 } AVOutputFormat;
96
97 typedef struct AVInputFormat {
98 const char *name;
99 const char *long_name;
100 /* size of private data so that it can be allocated in the wrapper */
101 int priv_data_size;
102 /* tell if a given file has a chance of being parsing by this format */
103 int (*read_probe)(AVProbeData *);
104 /* read the format header and initialize the AVFormatContext
105 structure. Return 0 if OK. 'ap' if non NULL contains
106 additionnal paramters. Only used in raw format right
107 now. 'av_new_stream' should be called to create new streams. */
108 int (*read_header)(struct AVFormatContext *,
109 AVFormatParameters *ap);
110 /* read one packet and put it in 'pkt'. pts and flags are also
111 set. 'av_new_stream' can be called only if the flag
112 AVFMT_NOHEADER is used. */
113 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
114 /* close the stream. The AVFormatContext and AVStreams are not
115 freed by this function */
116 int (*read_close)(struct AVFormatContext *);
117 /* seek at or before a given pts (given in microsecond). The pts
118 origin is defined by the stream */
119 int (*read_seek)(struct AVFormatContext *, INT64 pts);
120 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
121 int flags;
122 /* if extensions are defined, then no probe is done. You should
123 usually not use extension format guessing because it is not
124 reliable enough */
125 const char *extensions;
126 /* general purpose read only value that the format can use */
127 int value;
128 /* private fields */
129 struct AVInputFormat *next;
130 } AVInputFormat;
131
132 typedef struct AVStream {
133 int index; /* stream index in AVFormatContext */
134 int id; /* format specific stream id */
135 AVCodecContext codec; /* codec context */
136 int r_frame_rate; /* real frame rate of the stream */
137 uint64_t time_length; /* real length of the stream in miliseconds */
138 void *priv_data;
139 /* internal data used in av_find_stream_info() */
140 int codec_info_state;
141 int codec_info_nb_repeat_frames;
142 int codec_info_nb_real_frames;
143 /* PTS generation when outputing stream */
144 AVFrac pts;
145 /* ffmpeg.c private use */
146 int stream_copy; /* if TRUE, just copy stream */
147 } AVStream;
148
149 #define MAX_STREAMS 20
150
151 /* format I/O context */
152 typedef struct AVFormatContext {
153 /* can only be iformat or oformat, not both at the same time */
154 struct AVInputFormat *iformat;
155 struct AVOutputFormat *oformat;
156 void *priv_data;
157 ByteIOContext pb;
158 int nb_streams;
159 AVStream *streams[MAX_STREAMS];
160 char filename[1024]; /* input or output filename */
161 /* stream info */
162 char title[512];
163 char author[512];
164 char copyright[512];
165 char comment[512];
166 int flags; /* format specific flags */
167 /* private data for pts handling (do not modify directly) */
168 int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
169 int pts_num, pts_den; /* value to convert to seconds */
170 /* This buffer is only needed when packets were already buffered but
171 not decoded, for example to get the codec parameters in mpeg
172 streams */
173 struct AVPacketList *packet_buffer;
174 } AVFormatContext;
175
176 typedef struct AVPacketList {
177 AVPacket pkt;
178 struct AVPacketList *next;
179 } AVPacketList;
180
181 extern AVInputFormat *first_iformat;
182 extern AVOutputFormat *first_oformat;
183
184 /* XXX: use automatic init with either ELF sections or C file parser */
185 /* modules */
186
187 /* mpeg.c */
188 int mpegps_init(void);
189
190 /* mpegts.c */
191 extern AVInputFormat mpegts_demux;
192 int mpegts_init(void);
193
194 /* rm.c */
195 int rm_init(void);
196
197 /* crc.c */
198 int crc_init(void);
199
200 /* img.c */
201 int img_init(void);
202
203 /* asf.c */
204 int asf_init(void);
205
206 /* avienc.c */
207 int avienc_init(void);
208
209 /* avidec.c */
210 int avidec_init(void);
211
212 /* swf.c */
213 int swf_init(void);
214
215 /* mov.c */
216 int mov_init(void);
217
218 /* jpeg.c */
219 int jpeg_init(void);
220
221 /* gif.c */
222 int gif_init(void);
223
224 /* au.c */
225 int au_init(void);
226
227 /* wav.c */
228 int wav_init(void);
229
230 /* raw.c */
231 int raw_init(void);
232
233 /* ogg.c */
234 int ogg_init(void);
235
236 /* dv.c */
237 int dv_init(void);
238
239 /* ffm.c */
240 int ffm_init(void);
241
242 /* rtsp.c */
243 extern AVInputFormat redir_demux;
244 int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
245
246 #include "rtp.h"
247
248 #include "rtsp.h"
249
250 /* utils.c */
251 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
252 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
253
254 void av_register_input_format(AVInputFormat *format);
255 void av_register_output_format(AVOutputFormat *format);
256 AVOutputFormat *guess_stream_format(const char *short_name,
257 const char *filename, const char *mime_type);
258 AVOutputFormat *guess_format(const char *short_name,
259 const char *filename, const char *mime_type);
260
261 void av_hex_dump(UINT8 *buf, int size);
262
263 void av_register_all(void);
264
265 typedef struct FifoBuffer {
266 UINT8 *buffer;
267 UINT8 *rptr, *wptr, *end;
268 } FifoBuffer;
269
270 int fifo_init(FifoBuffer *f, int size);
271 void fifo_free(FifoBuffer *f);
272 int fifo_size(FifoBuffer *f, UINT8 *rptr);
273 int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
274 void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
275
276 /* media file input */
277 AVInputFormat *av_find_input_format(const char *short_name);
278 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
279 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
280 AVInputFormat *fmt,
281 int buf_size,
282 AVFormatParameters *ap);
283
284 #define AVERROR_UNKNOWN (-1) /* unknown error */
285 #define AVERROR_IO (-2) /* i/o error */
286 #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
287 #define AVERROR_INVALIDDATA (-4) /* invalid data found */
288 #define AVERROR_NOMEM (-5) /* not enough memory */
289 #define AVERROR_NOFMT (-6) /* unknown format */
290
291 int av_find_stream_info(AVFormatContext *ic);
292 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
293 void av_close_input_file(AVFormatContext *s);
294 AVStream *av_new_stream(AVFormatContext *s, int id);
295 void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
296 int pts_num, int pts_den);
297
298 /* media file output */
299 int av_write_header(AVFormatContext *s);
300 int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
301 int size);
302 int av_write_trailer(AVFormatContext *s);
303
304 void dump_format(AVFormatContext *ic,
305 int index,
306 const char *url,
307 int is_output);
308 int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
309 INT64 parse_date(const char *datestr, int duration);
310
311 INT64 av_gettime(void);
312
313 /* ffm specific for ffserver */
314 #define FFM_PACKET_SIZE 4096
315 offset_t ffm_read_write_index(int fd);
316 void ffm_write_write_index(int fd, offset_t pos);
317 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
318
319 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
320
321 int get_frame_filename(char *buf, int buf_size,
322 const char *path, int number);
323 int filename_number_test(const char *filename);
324
325 /* grab specific */
326 int video_grab_init(void);
327 int audio_init(void);
328
329 extern const char *v4l_device;
330 extern const char *audio_device;
331
332 #ifdef HAVE_AV_CONFIG_H
333 int strstart(const char *str, const char *val, const char **ptr);
334 int stristart(const char *str, const char *val, const char **ptr);
335 void pstrcpy(char *buf, int buf_size, const char *str);
336 char *pstrcat(char *buf, int buf_size, const char *s);
337
338 struct in_addr;
339 int resolve_host(struct in_addr *sin_addr, const char *hostname);
340
341 void url_split(char *proto, int proto_size,
342 char *hostname, int hostname_size,
343 int *port_ptr,
344 char *path, int path_size,
345 const char *url);
346
347 int match_ext(const char *filename, const char *extensions);
348
349 #endif /* HAVE_AV_CONFIG_H */
350
351 #endif /* AVFORMAT_H */