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