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