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