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