skip preamble bytes
[libav.git] / libavformat / avformat.h
CommitLineData
fb025625
FB
1#ifndef AVFORMAT_H
2#define AVFORMAT_H
de6d9b64 3
02d697aa
ZK
4#ifdef __cplusplus
5extern "C" {
6#endif
7
94988531
FB
8#define LIBAVFORMAT_VERSION_INT 0x000406
9#define LIBAVFORMAT_VERSION "0.4.6"
ee404803 10#define LIBAVFORMAT_BUILD 4606
4b1f4f23 11
de6d9b64
FB
12#include "avcodec.h"
13
de6d9b64
FB
14#include "avio.h"
15
16/* packet functions */
17
ee404803
FB
18#ifndef MAXINT64
19#define MAXINT64 int64_t_C(0x7fffffffffffffff)
20#endif
21
22#ifndef MININT64
23#define MININT64 int64_t_C(0x8000000000000000)
24#endif
25
26#define AV_NOPTS_VALUE MININT64
27#define AV_TIME_BASE 1000000
fb025625 28
de6d9b64 29typedef struct AVPacket {
0c1a9eda
ZK
30 int64_t pts; /* presentation time stamp in stream units (set av_set_pts_info) */
31 uint8_t *data;
6fa5a56c
FB
32 int size;
33 int stream_index;
34 int flags;
35 int duration;
36 void (*destruct)(struct AVPacket *);
37 void *priv;
de6d9b64 38} AVPacket;
6fa5a56c
FB
39#define PKT_FLAG_KEY 0x0001
40
41static inline void av_init_packet(AVPacket *pkt)
42{
43 pkt->pts = AV_NOPTS_VALUE;
44 pkt->flags = 0;
45 pkt->stream_index = 0;
46}
de6d9b64
FB
47
48int av_new_packet(AVPacket *pkt, int size);
6fa5a56c
FB
49
50/**
51 * Free a packet
52 *
53 * @param pkt packet to free
54 */
55static inline void av_free_packet(AVPacket *pkt)
56{
342474ab
MN
57 if (pkt && pkt->destruct) {
58 pkt->destruct(pkt);
59 }
6fa5a56c 60}
de6d9b64
FB
61
62/*************************************************/
916c80e9
FB
63/* fractional numbers for exact pts handling */
64
65/* the exact value of the fractional number is: 'val + num / den'. num
66 is assumed to be such as 0 <= num < den */
67typedef struct AVFrac {
0c1a9eda 68 int64_t val, num, den;
916c80e9
FB
69} AVFrac;
70
0c1a9eda
ZK
71void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
72void av_frac_add(AVFrac *f, int64_t incr);
73void av_frac_set(AVFrac *f, int64_t val);
916c80e9
FB
74
75/*************************************************/
b9a281db 76/* input/output formats */
de6d9b64
FB
77
78struct AVFormatContext;
b9a281db
FB
79
80/* this structure contains the data a format has to probe a file */
81typedef struct AVProbeData {
5c91a675 82 const char *filename;
b9a281db
FB
83 unsigned char *buf;
84 int buf_size;
85} AVProbeData;
86
87#define AVPROBE_SCORE_MAX 100
de6d9b64
FB
88
89typedef struct AVFormatParameters {
90 int frame_rate;
14bea432 91 int frame_rate_base;
de6d9b64
FB
92 int sample_rate;
93 int channels;
94 int width;
95 int height;
4606ac8d 96 enum PixelFormat pix_fmt;
290c5fa6 97 struct AVImageFormat *image_format;
7f172339
FB
98 int channel; /* used to select dv channel */
99 const char *device; /* video4linux, audio or DV device */
e3ee3283 100 const char *standard; /* tv standard, NTSC, PAL, SECAM */
de6d9b64
FB
101} AVFormatParameters;
102
b9a281db
FB
103#define AVFMT_NOFILE 0x0001 /* no file should be opened */
104#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
105#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
106 (streams are added dynamically) */
107#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
fb025625
FB
108#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
109 raw picture data */
b9a281db
FB
110
111typedef struct AVOutputFormat {
de6d9b64
FB
112 const char *name;
113 const char *long_name;
114 const char *mime_type;
115 const char *extensions; /* comma separated extensions */
b9a281db
FB
116 /* size of private data so that it can be allocated in the wrapper */
117 int priv_data_size;
de6d9b64
FB
118 /* output support */
119 enum CodecID audio_codec; /* default audio codec */
120 enum CodecID video_codec; /* default video codec */
121 int (*write_header)(struct AVFormatContext *);
1e51d801 122 /* XXX: change prototype for 64 bit pts */
de6d9b64
FB
123 int (*write_packet)(struct AVFormatContext *,
124 int stream_index,
10bb7023 125 unsigned char *buf, int size, int force_pts);
de6d9b64 126 int (*write_trailer)(struct AVFormatContext *);
b9a281db
FB
127 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
128 int flags;
290c5fa6
FB
129 /* currently only used to set pixel format if not YUV420P */
130 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
b9a281db
FB
131 /* private fields */
132 struct AVOutputFormat *next;
133} AVOutputFormat;
de6d9b64 134
b9a281db
FB
135typedef struct AVInputFormat {
136 const char *name;
137 const char *long_name;
138 /* size of private data so that it can be allocated in the wrapper */
139 int priv_data_size;
140 /* tell if a given file has a chance of being parsing by this format */
141 int (*read_probe)(AVProbeData *);
142 /* read the format header and initialize the AVFormatContext
de6d9b64 143 structure. Return 0 if OK. 'ap' if non NULL contains
b9a281db
FB
144 additionnal paramters. Only used in raw format right
145 now. 'av_new_stream' should be called to create new streams. */
de6d9b64
FB
146 int (*read_header)(struct AVFormatContext *,
147 AVFormatParameters *ap);
b9a281db
FB
148 /* read one packet and put it in 'pkt'. pts and flags are also
149 set. 'av_new_stream' can be called only if the flag
150 AVFMT_NOHEADER is used. */
de6d9b64
FB
151 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
152 /* close the stream. The AVFormatContext and AVStreams are not
153 freed by this function */
154 int (*read_close)(struct AVFormatContext *);
155 /* seek at or before a given pts (given in microsecond). The pts
156 origin is defined by the stream */
0c1a9eda 157 int (*read_seek)(struct AVFormatContext *, int64_t pts);
b9a281db 158 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
de6d9b64 159 int flags;
b9a281db
FB
160 /* if extensions are defined, then no probe is done. You should
161 usually not use extension format guessing because it is not
162 reliable enough */
163 const char *extensions;
164 /* general purpose read only value that the format can use */
165 int value;
166 /* private fields */
167 struct AVInputFormat *next;
168} AVInputFormat;
de6d9b64
FB
169
170typedef struct AVStream {
b9a281db
FB
171 int index; /* stream index in AVFormatContext */
172 int id; /* format specific stream id */
de6d9b64 173 AVCodecContext codec; /* codec context */
76c0441b 174 int r_frame_rate; /* real frame rate of the stream */
14bea432 175 int r_frame_rate_base;/* real frame rate base of the stream */
de6d9b64 176 void *priv_data;
b9a281db
FB
177 /* internal data used in av_find_stream_info() */
178 int codec_info_state;
179 int codec_info_nb_repeat_frames;
180 int codec_info_nb_real_frames;
1e51d801
FB
181 /* PTS generation when outputing stream */
182 AVFrac pts;
a48b7a6b
FB
183 /* ffmpeg.c private use */
184 int stream_copy; /* if TRUE, just copy stream */
1e491e29
MN
185 /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
186 * MN:dunno if thats the right place, for it */
187 float quality;
ee404803
FB
188 /* decoding: position of the first frame of the component, in
189 AV_TIME_BASE fractional seconds. */
190 int64_t start_time;
191 /* decoding: duration of the stream, in AV_TIME_BASE fractional
192 seconds. */
193 int64_t duration;
de6d9b64
FB
194} AVStream;
195
196#define MAX_STREAMS 20
197
198/* format I/O context */
199typedef struct AVFormatContext {
b9a281db
FB
200 /* can only be iformat or oformat, not both at the same time */
201 struct AVInputFormat *iformat;
202 struct AVOutputFormat *oformat;
de6d9b64
FB
203 void *priv_data;
204 ByteIOContext pb;
205 int nb_streams;
206 AVStream *streams[MAX_STREAMS];
207 char filename[1024]; /* input or output filename */
208 /* stream info */
209 char title[512];
210 char author[512];
211 char copyright[512];
212 char comment[512];
92b3e125 213 int flags; /* format specific flags */
916c80e9
FB
214 /* private data for pts handling (do not modify directly) */
215 int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
216 int pts_num, pts_den; /* value to convert to seconds */
de6d9b64
FB
217 /* This buffer is only needed when packets were already buffered but
218 not decoded, for example to get the codec parameters in mpeg
219 streams */
ee404803
FB
220 struct AVPacketList *packet_buffer;
221
222 /* decoding: position of the first frame of the component, in
223 AV_TIME_BASE fractional seconds. NEVER set this value directly:
224 it is deduced from the AVStream values. */
225 int64_t start_time;
226 /* decoding: duration of the stream, in AV_TIME_BASE fractional
227 seconds. NEVER set this value directly: it is deduced from the
228 AVStream values. */
229 int64_t duration;
230 /* decoding: total file size. 0 if unknown */
231 int64_t file_size;
232 /* decoding: total stream bitrate in bit/s, 0 if not
233 available. Never set it directly if the file_size and the
234 duration are known as ffmpeg can compute it automatically. */
235 int bit_rate;
de6d9b64
FB
236} AVFormatContext;
237
238typedef struct AVPacketList {
239 AVPacket pkt;
240 struct AVPacketList *next;
241} AVPacketList;
242
b9a281db
FB
243extern AVInputFormat *first_iformat;
244extern AVOutputFormat *first_oformat;
de6d9b64 245
290c5fa6
FB
246/* still image support */
247struct AVInputImageContext;
248typedef struct AVInputImageContext AVInputImageContext;
249
250typedef struct AVImageInfo {
251 enum PixelFormat pix_fmt; /* requested pixel format */
252 int width; /* requested width */
253 int height; /* requested height */
7e2e1abf 254 int interleaved; /* image is interleaved (e.g. interleaved GIF) */
290c5fa6
FB
255 AVPicture pict; /* returned allocated image */
256} AVImageInfo;
257
3b1a27e0 258/* AVImageFormat.flags field constants */
7e2e1abf 259#define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
3b1a27e0 260
290c5fa6
FB
261typedef struct AVImageFormat {
262 const char *name;
263 const char *extensions;
264 /* tell if a given file has a chance of being parsing by this format */
265 int (*img_probe)(AVProbeData *);
266 /* read a whole image. 'alloc_cb' is called when the image size is
267 known so that the caller can allocate the image. If 'allo_cb'
268 returns non zero, then the parsing is aborted. Return '0' if
269 OK. */
270 int (*img_read)(ByteIOContext *,
271 int (*alloc_cb)(void *, AVImageInfo *info), void *);
272 /* write the image */
273 int supported_pixel_formats; /* mask of supported formats for output */
274 int (*img_write)(ByteIOContext *, AVImageInfo *);
3b1a27e0 275 int flags;
290c5fa6
FB
276 struct AVImageFormat *next;
277} AVImageFormat;
278
279void av_register_image_format(AVImageFormat *img_fmt);
280AVImageFormat *av_probe_image_format(AVProbeData *pd);
281AVImageFormat *guess_image_format(const char *filename);
282int av_read_image(ByteIOContext *pb, const char *filename,
283 AVImageFormat *fmt,
284 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
285int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
286
287extern AVImageFormat *first_image_format;
288
289extern AVImageFormat pnm_image_format;
290extern AVImageFormat pbm_image_format;
291extern AVImageFormat pgm_image_format;
292extern AVImageFormat ppm_image_format;
8975ba81 293extern AVImageFormat pam_image_format;
290c5fa6
FB
294extern AVImageFormat pgmyuv_image_format;
295extern AVImageFormat yuv_image_format;
3a13f6bd 296#ifdef CONFIG_ZLIB
0e04e4e9 297extern AVImageFormat png_image_format;
3a13f6bd 298#endif
0250738f 299extern AVImageFormat jpeg_image_format;
cdc90af0 300extern AVImageFormat gif_image_format;
290c5fa6 301
b9a281db
FB
302/* XXX: use automatic init with either ELF sections or C file parser */
303/* modules */
de6d9b64 304
b9a281db 305/* mpeg.c */
ee404803 306extern AVInputFormat mpegps_demux;
b9a281db
FB
307int mpegps_init(void);
308
309/* mpegts.c */
310extern AVInputFormat mpegts_demux;
311int mpegts_init(void);
de6d9b64 312
b9a281db
FB
313/* rm.c */
314int rm_init(void);
315
316/* crc.c */
317int crc_init(void);
318
319/* img.c */
320int img_init(void);
321
322/* asf.c */
323int asf_init(void);
de6d9b64
FB
324
325/* avienc.c */
b9a281db 326int avienc_init(void);
de6d9b64 327
b9a281db
FB
328/* avidec.c */
329int avidec_init(void);
6cea494e 330
b9a281db
FB
331/* swf.c */
332int swf_init(void);
333
334/* mov.c */
335int mov_init(void);
de6d9b64 336
1cb5f7fd
MN
337/* movenc.c */
338int movenc_init(void);
339
d4f5d74a
GM
340/* flvenc.c */
341int flvenc_init(void);
342
343/* flvdec.c */
344int flvdec_init(void);
345
b9a281db
FB
346/* jpeg.c */
347int jpeg_init(void);
de6d9b64 348
6cea494e 349/* gif.c */
b9a281db
FB
350int gif_init(void);
351
6cea494e 352/* au.c */
b9a281db 353int au_init(void);
6cea494e 354
bc634f6f
ZK
355/* amr.c */
356int amr_init(void);
357
de6d9b64 358/* wav.c */
b9a281db 359int wav_init(void);
de6d9b64
FB
360
361/* raw.c */
b9a281db 362int raw_init(void);
de6d9b64 363
2864dfd5
RFI
364/* yuv4mpeg.c */
365int yuv4mpeg_init(void);
366
81e0d0b4
MH
367/* ogg.c */
368int ogg_init(void);
369
f20dca40
FB
370/* dv.c */
371int dv_init(void);
372
de6d9b64 373/* ffm.c */
b9a281db 374int ffm_init(void);
de6d9b64 375
fb025625
FB
376/* rtsp.c */
377extern AVInputFormat redir_demux;
378int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
379
3c96b4ef
MM
380/* 4xm.c */
381int fourxm_init(void);
382
fb025625
FB
383#include "rtp.h"
384
385#include "rtsp.h"
386
290c5fa6
FB
387/* yuv4mpeg.c */
388extern AVOutputFormat yuv4mpegpipe_oformat;
389
b9a281db 390/* utils.c */
b9a281db
FB
391void av_register_input_format(AVInputFormat *format);
392void av_register_output_format(AVOutputFormat *format);
36ada60c
PG
393AVOutputFormat *guess_stream_format(const char *short_name,
394 const char *filename, const char *mime_type);
b9a281db
FB
395AVOutputFormat *guess_format(const char *short_name,
396 const char *filename, const char *mime_type);
de6d9b64 397
0c1a9eda 398void av_hex_dump(uint8_t *buf, int size);
de6d9b64 399
94988531 400void av_register_all(void);
de6d9b64
FB
401
402typedef struct FifoBuffer {
0c1a9eda
ZK
403 uint8_t *buffer;
404 uint8_t *rptr, *wptr, *end;
de6d9b64
FB
405} FifoBuffer;
406
407int fifo_init(FifoBuffer *f, int size);
408void fifo_free(FifoBuffer *f);
0c1a9eda
ZK
409int fifo_size(FifoBuffer *f, uint8_t *rptr);
410int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
411void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
de6d9b64 412
b9a281db
FB
413/* media file input */
414AVInputFormat *av_find_input_format(const char *short_name);
94988531 415AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
b9a281db
FB
416int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
417 AVInputFormat *fmt,
418 int buf_size,
419 AVFormatParameters *ap);
420
421#define AVERROR_UNKNOWN (-1) /* unknown error */
422#define AVERROR_IO (-2) /* i/o error */
423#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
424#define AVERROR_INVALIDDATA (-4) /* invalid data found */
425#define AVERROR_NOMEM (-5) /* not enough memory */
426#define AVERROR_NOFMT (-6) /* unknown format */
427
428int av_find_stream_info(AVFormatContext *ic);
de6d9b64
FB
429int av_read_packet(AVFormatContext *s, AVPacket *pkt);
430void av_close_input_file(AVFormatContext *s);
b9a281db 431AVStream *av_new_stream(AVFormatContext *s, int id);
916c80e9
FB
432void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
433 int pts_num, int pts_den);
de6d9b64 434
b9a281db 435/* media file output */
290c5fa6 436int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
b9a281db 437int av_write_header(AVFormatContext *s);
1e51d801
FB
438int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
439 int size);
b9a281db 440int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
441
442void dump_format(AVFormatContext *ic,
443 int index,
444 const char *url,
445 int is_output);
446int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
445f1b83 447int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
0c1a9eda 448int64_t parse_date(const char *datestr, int duration);
de6d9b64 449
0c1a9eda 450int64_t av_gettime(void);
94988531 451
de6d9b64
FB
452/* ffm specific for ffserver */
453#define FFM_PACKET_SIZE 4096
454offset_t ffm_read_write_index(int fd);
455void ffm_write_write_index(int fd, offset_t pos);
456void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
457
458int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
459
813cae4b
FB
460int get_frame_filename(char *buf, int buf_size,
461 const char *path, int number);
b9a281db 462int filename_number_test(const char *filename);
96baaa6a 463
b9a281db
FB
464/* grab specific */
465int video_grab_init(void);
466int audio_init(void);
96baaa6a 467
86fd51fb
FB
468/* DV1394 */
469int dv1394_init(void);
fb025625
FB
470
471#ifdef HAVE_AV_CONFIG_H
472int strstart(const char *str, const char *val, const char **ptr);
473int stristart(const char *str, const char *val, const char **ptr);
474void pstrcpy(char *buf, int buf_size, const char *str);
475char *pstrcat(char *buf, int buf_size, const char *s);
fb025625 476
39f472c3
FB
477void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
478
479#define dynarray_add(tab, nb_ptr, elem)\
480do {\
481 typeof(tab) _tab = (tab);\
482 typeof(elem) _elem = (elem);\
483 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
484 __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
485} while(0)
486
fb025625
FB
487struct in_addr;
488int resolve_host(struct in_addr *sin_addr, const char *hostname);
489
490void url_split(char *proto, int proto_size,
491 char *hostname, int hostname_size,
492 int *port_ptr,
493 char *path, int path_size,
494 const char *url);
495
a941f391
FB
496int match_ext(const char *filename, const char *extensions);
497
fb025625
FB
498#endif /* HAVE_AV_CONFIG_H */
499
02d697aa
ZK
500#ifdef __cplusplus
501}
502#endif
503
fb025625 504#endif /* AVFORMAT_H */