removed os_support.h
[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
8026c3b5
AB
8#define LIBAVFORMAT_VERSION_INT 0x000408
9#define LIBAVFORMAT_VERSION "0.4.8"
ee404803 10#define LIBAVFORMAT_BUILD 4606
8026c3b5
AB
11#define LIBAVFORMAT_BUILD_STR "4606"
12
13#define LIBAVFORMAT_IDENT "FFmpeg" LIBAVFORMAT_VERSION "b" LIBAVFORMAT_BUILD_STR
4b1f4f23 14
de6d9b64
FB
15#include "avcodec.h"
16
de6d9b64
FB
17#include "avio.h"
18
19/* packet functions */
20
ee404803
FB
21#ifndef MAXINT64
22#define MAXINT64 int64_t_C(0x7fffffffffffffff)
23#endif
24
25#ifndef MININT64
26#define MININT64 int64_t_C(0x8000000000000000)
27#endif
28
29#define AV_NOPTS_VALUE MININT64
30#define AV_TIME_BASE 1000000
fb025625 31
de6d9b64 32typedef struct AVPacket {
0c1a9eda
ZK
33 int64_t pts; /* presentation time stamp in stream units (set av_set_pts_info) */
34 uint8_t *data;
6fa5a56c
FB
35 int size;
36 int stream_index;
37 int flags;
38 int duration;
39 void (*destruct)(struct AVPacket *);
40 void *priv;
de6d9b64 41} AVPacket;
6fa5a56c
FB
42#define PKT_FLAG_KEY 0x0001
43
44static inline void av_init_packet(AVPacket *pkt)
45{
46 pkt->pts = AV_NOPTS_VALUE;
47 pkt->flags = 0;
48 pkt->stream_index = 0;
49}
de6d9b64
FB
50
51int av_new_packet(AVPacket *pkt, int size);
6fa5a56c
FB
52
53/**
54 * Free a packet
55 *
56 * @param pkt packet to free
57 */
58static inline void av_free_packet(AVPacket *pkt)
59{
342474ab
MN
60 if (pkt && pkt->destruct) {
61 pkt->destruct(pkt);
62 }
6fa5a56c 63}
de6d9b64
FB
64
65/*************************************************/
916c80e9
FB
66/* fractional numbers for exact pts handling */
67
68/* the exact value of the fractional number is: 'val + num / den'. num
69 is assumed to be such as 0 <= num < den */
70typedef struct AVFrac {
0c1a9eda 71 int64_t val, num, den;
916c80e9
FB
72} AVFrac;
73
0c1a9eda
ZK
74void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den);
75void av_frac_add(AVFrac *f, int64_t incr);
76void av_frac_set(AVFrac *f, int64_t val);
916c80e9
FB
77
78/*************************************************/
b9a281db 79/* input/output formats */
de6d9b64
FB
80
81struct AVFormatContext;
b9a281db
FB
82
83/* this structure contains the data a format has to probe a file */
84typedef struct AVProbeData {
5c91a675 85 const char *filename;
b9a281db
FB
86 unsigned char *buf;
87 int buf_size;
88} AVProbeData;
89
90#define AVPROBE_SCORE_MAX 100
de6d9b64
FB
91
92typedef struct AVFormatParameters {
93 int frame_rate;
14bea432 94 int frame_rate_base;
de6d9b64
FB
95 int sample_rate;
96 int channels;
97 int width;
98 int height;
4606ac8d 99 enum PixelFormat pix_fmt;
290c5fa6 100 struct AVImageFormat *image_format;
7f172339
FB
101 int channel; /* used to select dv channel */
102 const char *device; /* video4linux, audio or DV device */
e3ee3283 103 const char *standard; /* tv standard, NTSC, PAL, SECAM */
de6d9b64
FB
104} AVFormatParameters;
105
b9a281db
FB
106#define AVFMT_NOFILE 0x0001 /* no file should be opened */
107#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
108#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
109 (streams are added dynamically) */
110#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
fb025625
FB
111#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
112 raw picture data */
b9a281db
FB
113
114typedef struct AVOutputFormat {
de6d9b64
FB
115 const char *name;
116 const char *long_name;
117 const char *mime_type;
118 const char *extensions; /* comma separated extensions */
b9a281db
FB
119 /* size of private data so that it can be allocated in the wrapper */
120 int priv_data_size;
de6d9b64
FB
121 /* output support */
122 enum CodecID audio_codec; /* default audio codec */
123 enum CodecID video_codec; /* default video codec */
124 int (*write_header)(struct AVFormatContext *);
1e51d801 125 /* XXX: change prototype for 64 bit pts */
de6d9b64
FB
126 int (*write_packet)(struct AVFormatContext *,
127 int stream_index,
10bb7023 128 unsigned char *buf, int size, int force_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];
92b3e125 216 int flags; /* format specific flags */
916c80e9
FB
217 /* private data for pts handling (do not modify directly) */
218 int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
219 int pts_num, pts_den; /* value to convert to seconds */
de6d9b64
FB
220 /* This buffer is only needed when packets were already buffered but
221 not decoded, for example to get the codec parameters in mpeg
222 streams */
ee404803
FB
223 struct AVPacketList *packet_buffer;
224
225 /* decoding: position of the first frame of the component, in
226 AV_TIME_BASE fractional seconds. NEVER set this value directly:
227 it is deduced from the AVStream values. */
228 int64_t start_time;
229 /* decoding: duration of the stream, in AV_TIME_BASE fractional
230 seconds. NEVER set this value directly: it is deduced from the
231 AVStream values. */
232 int64_t duration;
233 /* decoding: total file size. 0 if unknown */
234 int64_t file_size;
235 /* decoding: total stream bitrate in bit/s, 0 if not
236 available. Never set it directly if the file_size and the
237 duration are known as ffmpeg can compute it automatically. */
238 int bit_rate;
de6d9b64
FB
239} AVFormatContext;
240
241typedef struct AVPacketList {
242 AVPacket pkt;
243 struct AVPacketList *next;
244} AVPacketList;
245
b9a281db
FB
246extern AVInputFormat *first_iformat;
247extern AVOutputFormat *first_oformat;
de6d9b64 248
290c5fa6
FB
249/* still image support */
250struct AVInputImageContext;
251typedef struct AVInputImageContext AVInputImageContext;
252
253typedef struct AVImageInfo {
254 enum PixelFormat pix_fmt; /* requested pixel format */
255 int width; /* requested width */
256 int height; /* requested height */
7e2e1abf 257 int interleaved; /* image is interleaved (e.g. interleaved GIF) */
290c5fa6
FB
258 AVPicture pict; /* returned allocated image */
259} AVImageInfo;
260
3b1a27e0 261/* AVImageFormat.flags field constants */
7e2e1abf 262#define AVIMAGE_INTERLEAVED 0x0001 /* image format support interleaved output */
3b1a27e0 263
290c5fa6
FB
264typedef struct AVImageFormat {
265 const char *name;
266 const char *extensions;
267 /* tell if a given file has a chance of being parsing by this format */
268 int (*img_probe)(AVProbeData *);
269 /* read a whole image. 'alloc_cb' is called when the image size is
270 known so that the caller can allocate the image. If 'allo_cb'
271 returns non zero, then the parsing is aborted. Return '0' if
272 OK. */
273 int (*img_read)(ByteIOContext *,
274 int (*alloc_cb)(void *, AVImageInfo *info), void *);
275 /* write the image */
276 int supported_pixel_formats; /* mask of supported formats for output */
277 int (*img_write)(ByteIOContext *, AVImageInfo *);
3b1a27e0 278 int flags;
290c5fa6
FB
279 struct AVImageFormat *next;
280} AVImageFormat;
281
282void av_register_image_format(AVImageFormat *img_fmt);
283AVImageFormat *av_probe_image_format(AVProbeData *pd);
284AVImageFormat *guess_image_format(const char *filename);
285int av_read_image(ByteIOContext *pb, const char *filename,
286 AVImageFormat *fmt,
287 int (*alloc_cb)(void *, AVImageInfo *info), void *opaque);
288int av_write_image(ByteIOContext *pb, AVImageFormat *fmt, AVImageInfo *img);
289
290extern AVImageFormat *first_image_format;
291
292extern AVImageFormat pnm_image_format;
293extern AVImageFormat pbm_image_format;
294extern AVImageFormat pgm_image_format;
295extern AVImageFormat ppm_image_format;
8975ba81 296extern AVImageFormat pam_image_format;
290c5fa6
FB
297extern AVImageFormat pgmyuv_image_format;
298extern AVImageFormat yuv_image_format;
3a13f6bd 299#ifdef CONFIG_ZLIB
0e04e4e9 300extern AVImageFormat png_image_format;
3a13f6bd 301#endif
0250738f 302extern AVImageFormat jpeg_image_format;
cdc90af0 303extern AVImageFormat gif_image_format;
290c5fa6 304
b9a281db
FB
305/* XXX: use automatic init with either ELF sections or C file parser */
306/* modules */
de6d9b64 307
b9a281db 308/* mpeg.c */
ee404803 309extern AVInputFormat mpegps_demux;
b9a281db
FB
310int mpegps_init(void);
311
312/* mpegts.c */
313extern AVInputFormat mpegts_demux;
314int mpegts_init(void);
de6d9b64 315
b9a281db
FB
316/* rm.c */
317int rm_init(void);
318
319/* crc.c */
320int crc_init(void);
321
322/* img.c */
323int img_init(void);
324
325/* asf.c */
326int asf_init(void);
de6d9b64
FB
327
328/* avienc.c */
b9a281db 329int avienc_init(void);
de6d9b64 330
b9a281db
FB
331/* avidec.c */
332int avidec_init(void);
6cea494e 333
b9a281db
FB
334/* swf.c */
335int swf_init(void);
336
337/* mov.c */
338int mov_init(void);
de6d9b64 339
1cb5f7fd
MN
340/* movenc.c */
341int movenc_init(void);
342
d4f5d74a
GM
343/* flvenc.c */
344int flvenc_init(void);
345
346/* flvdec.c */
347int flvdec_init(void);
348
b9a281db
FB
349/* jpeg.c */
350int jpeg_init(void);
de6d9b64 351
6cea494e 352/* gif.c */
b9a281db
FB
353int gif_init(void);
354
6cea494e 355/* au.c */
b9a281db 356int au_init(void);
6cea494e 357
bc634f6f
ZK
358/* amr.c */
359int amr_init(void);
360
de6d9b64 361/* wav.c */
b9a281db 362int wav_init(void);
de6d9b64
FB
363
364/* raw.c */
b9a281db 365int raw_init(void);
de6d9b64 366
2864dfd5
RFI
367/* yuv4mpeg.c */
368int yuv4mpeg_init(void);
369
81e0d0b4
MH
370/* ogg.c */
371int ogg_init(void);
372
f20dca40
FB
373/* dv.c */
374int dv_init(void);
375
de6d9b64 376/* ffm.c */
b9a281db 377int ffm_init(void);
de6d9b64 378
fb025625
FB
379/* rtsp.c */
380extern AVInputFormat redir_demux;
381int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
382
3c96b4ef
MM
383/* 4xm.c */
384int fourxm_init(void);
385
3f16d933
MM
386/* psxstr.c */
387int str_init(void);
388
3ef8be2b
MM
389/* idroq.c */
390int roq_init(void);
391
392/* ipmovie.c */
393int ipmovie_init(void);
394
3aa180b8
AB
395/* nut.c */
396int nut_init(void);
397
493645eb
MM
398/* wc3movie.c */
399int wc3_init(void);
400
fb025625
FB
401#include "rtp.h"
402
403#include "rtsp.h"
404
290c5fa6
FB
405/* yuv4mpeg.c */
406extern AVOutputFormat yuv4mpegpipe_oformat;
407
b9a281db 408/* utils.c */
b9a281db
FB
409void av_register_input_format(AVInputFormat *format);
410void av_register_output_format(AVOutputFormat *format);
36ada60c
PG
411AVOutputFormat *guess_stream_format(const char *short_name,
412 const char *filename, const char *mime_type);
b9a281db
FB
413AVOutputFormat *guess_format(const char *short_name,
414 const char *filename, const char *mime_type);
de6d9b64 415
0c1a9eda 416void av_hex_dump(uint8_t *buf, int size);
de6d9b64 417
94988531 418void av_register_all(void);
de6d9b64
FB
419
420typedef struct FifoBuffer {
0c1a9eda
ZK
421 uint8_t *buffer;
422 uint8_t *rptr, *wptr, *end;
de6d9b64
FB
423} FifoBuffer;
424
425int fifo_init(FifoBuffer *f, int size);
426void fifo_free(FifoBuffer *f);
0c1a9eda
ZK
427int fifo_size(FifoBuffer *f, uint8_t *rptr);
428int fifo_read(FifoBuffer *f, uint8_t *buf, int buf_size, uint8_t **rptr_ptr);
429void fifo_write(FifoBuffer *f, uint8_t *buf, int size, uint8_t **wptr_ptr);
de6d9b64 430
b9a281db
FB
431/* media file input */
432AVInputFormat *av_find_input_format(const char *short_name);
94988531 433AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
b9a281db
FB
434int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
435 AVInputFormat *fmt,
436 int buf_size,
437 AVFormatParameters *ap);
438
439#define AVERROR_UNKNOWN (-1) /* unknown error */
440#define AVERROR_IO (-2) /* i/o error */
441#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
442#define AVERROR_INVALIDDATA (-4) /* invalid data found */
443#define AVERROR_NOMEM (-5) /* not enough memory */
444#define AVERROR_NOFMT (-6) /* unknown format */
445
446int av_find_stream_info(AVFormatContext *ic);
de6d9b64
FB
447int av_read_packet(AVFormatContext *s, AVPacket *pkt);
448void av_close_input_file(AVFormatContext *s);
b9a281db 449AVStream *av_new_stream(AVFormatContext *s, int id);
916c80e9
FB
450void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
451 int pts_num, int pts_den);
de6d9b64 452
b9a281db 453/* media file output */
290c5fa6 454int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
b9a281db 455int av_write_header(AVFormatContext *s);
1e51d801
FB
456int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
457 int size);
b9a281db 458int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
459
460void dump_format(AVFormatContext *ic,
461 int index,
462 const char *url,
463 int is_output);
464int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
445f1b83 465int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
0c1a9eda 466int64_t parse_date(const char *datestr, int duration);
de6d9b64 467
0c1a9eda 468int64_t av_gettime(void);
94988531 469
de6d9b64
FB
470/* ffm specific for ffserver */
471#define FFM_PACKET_SIZE 4096
472offset_t ffm_read_write_index(int fd);
473void ffm_write_write_index(int fd, offset_t pos);
474void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
475
476int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
477
813cae4b
FB
478int get_frame_filename(char *buf, int buf_size,
479 const char *path, int number);
b9a281db 480int filename_number_test(const char *filename);
96baaa6a 481
b9a281db
FB
482/* grab specific */
483int video_grab_init(void);
484int audio_init(void);
96baaa6a 485
86fd51fb
FB
486/* DV1394 */
487int dv1394_init(void);
fb025625
FB
488
489#ifdef HAVE_AV_CONFIG_H
490int strstart(const char *str, const char *val, const char **ptr);
491int stristart(const char *str, const char *val, const char **ptr);
492void pstrcpy(char *buf, int buf_size, const char *str);
493char *pstrcat(char *buf, int buf_size, const char *s);
fb025625 494
39f472c3
FB
495void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
496
497#define dynarray_add(tab, nb_ptr, elem)\
498do {\
499 typeof(tab) _tab = (tab);\
500 typeof(elem) _elem = (elem);\
501 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
502 __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
503} while(0)
504
fb025625
FB
505struct in_addr;
506int resolve_host(struct in_addr *sin_addr, const char *hostname);
507
508void url_split(char *proto, int proto_size,
509 char *hostname, int hostname_size,
510 int *port_ptr,
511 char *path, int path_size,
512 const char *url);
513
a941f391
FB
514int match_ext(const char *filename, const char *extensions);
515
fb025625
FB
516#endif /* HAVE_AV_CONFIG_H */
517
02d697aa
ZK
518#ifdef __cplusplus
519}
520#endif
521
fb025625 522#endif /* AVFORMAT_H */