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