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