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