added missing formats in all functions - added monoblack, monowhite and gray8 support...
[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"
2a10020b 6#define LIBAVFORMAT_BUILD 4602
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;
de6d9b64
FB
63} AVFormatParameters;
64
b9a281db
FB
65#define AVFMT_NOFILE 0x0001 /* no file should be opened */
66#define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
67#define AVFMT_NOHEADER 0x0004 /* signal that no header is present
68 (streams are added dynamically) */
69#define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
70#define AVFMT_RGB24 0x0010 /* force RGB24 output for ppm (hack
71 - need better api) */
fb025625
FB
72#define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
73 raw picture data */
b9a281db
FB
74
75typedef struct AVOutputFormat {
de6d9b64
FB
76 const char *name;
77 const char *long_name;
78 const char *mime_type;
79 const char *extensions; /* comma separated extensions */
b9a281db
FB
80 /* size of private data so that it can be allocated in the wrapper */
81 int priv_data_size;
de6d9b64
FB
82 /* output support */
83 enum CodecID audio_codec; /* default audio codec */
84 enum CodecID video_codec; /* default video codec */
85 int (*write_header)(struct AVFormatContext *);
1e51d801 86 /* XXX: change prototype for 64 bit pts */
de6d9b64
FB
87 int (*write_packet)(struct AVFormatContext *,
88 int stream_index,
10bb7023 89 unsigned char *buf, int size, int force_pts);
de6d9b64 90 int (*write_trailer)(struct AVFormatContext *);
b9a281db
FB
91 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
92 int flags;
93 /* private fields */
94 struct AVOutputFormat *next;
95} AVOutputFormat;
de6d9b64 96
b9a281db
FB
97typedef struct AVInputFormat {
98 const char *name;
99 const char *long_name;
100 /* size of private data so that it can be allocated in the wrapper */
101 int priv_data_size;
102 /* tell if a given file has a chance of being parsing by this format */
103 int (*read_probe)(AVProbeData *);
104 /* read the format header and initialize the AVFormatContext
de6d9b64 105 structure. Return 0 if OK. 'ap' if non NULL contains
b9a281db
FB
106 additionnal paramters. Only used in raw format right
107 now. 'av_new_stream' should be called to create new streams. */
de6d9b64
FB
108 int (*read_header)(struct AVFormatContext *,
109 AVFormatParameters *ap);
b9a281db
FB
110 /* read one packet and put it in 'pkt'. pts and flags are also
111 set. 'av_new_stream' can be called only if the flag
112 AVFMT_NOHEADER is used. */
de6d9b64
FB
113 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
114 /* close the stream. The AVFormatContext and AVStreams are not
115 freed by this function */
116 int (*read_close)(struct AVFormatContext *);
117 /* seek at or before a given pts (given in microsecond). The pts
118 origin is defined by the stream */
119 int (*read_seek)(struct AVFormatContext *, INT64 pts);
b9a281db 120 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
de6d9b64 121 int flags;
b9a281db
FB
122 /* if extensions are defined, then no probe is done. You should
123 usually not use extension format guessing because it is not
124 reliable enough */
125 const char *extensions;
126 /* general purpose read only value that the format can use */
127 int value;
128 /* private fields */
129 struct AVInputFormat *next;
130} AVInputFormat;
de6d9b64
FB
131
132typedef struct AVStream {
b9a281db
FB
133 int index; /* stream index in AVFormatContext */
134 int id; /* format specific stream id */
de6d9b64 135 AVCodecContext codec; /* codec context */
76c0441b 136 int r_frame_rate; /* real frame rate of the stream */
2a10020b 137 uint64_t time_length; /* real length of the stream in miliseconds */
de6d9b64 138 void *priv_data;
b9a281db
FB
139 /* internal data used in av_find_stream_info() */
140 int codec_info_state;
141 int codec_info_nb_repeat_frames;
142 int codec_info_nb_real_frames;
1e51d801
FB
143 /* PTS generation when outputing stream */
144 AVFrac pts;
a48b7a6b
FB
145 /* ffmpeg.c private use */
146 int stream_copy; /* if TRUE, just copy stream */
1e491e29
MN
147 /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
148 * MN:dunno if thats the right place, for it */
149 float quality;
de6d9b64
FB
150} AVStream;
151
152#define MAX_STREAMS 20
153
154/* format I/O context */
155typedef struct AVFormatContext {
b9a281db
FB
156 /* can only be iformat or oformat, not both at the same time */
157 struct AVInputFormat *iformat;
158 struct AVOutputFormat *oformat;
de6d9b64
FB
159 void *priv_data;
160 ByteIOContext pb;
161 int nb_streams;
162 AVStream *streams[MAX_STREAMS];
163 char filename[1024]; /* input or output filename */
164 /* stream info */
165 char title[512];
166 char author[512];
167 char copyright[512];
168 char comment[512];
92b3e125 169 int flags; /* format specific flags */
916c80e9
FB
170 /* private data for pts handling (do not modify directly) */
171 int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
172 int pts_num, pts_den; /* value to convert to seconds */
de6d9b64
FB
173 /* This buffer is only needed when packets were already buffered but
174 not decoded, for example to get the codec parameters in mpeg
175 streams */
176 struct AVPacketList *packet_buffer;
177} AVFormatContext;
178
179typedef struct AVPacketList {
180 AVPacket pkt;
181 struct AVPacketList *next;
182} AVPacketList;
183
b9a281db
FB
184extern AVInputFormat *first_iformat;
185extern AVOutputFormat *first_oformat;
de6d9b64 186
b9a281db
FB
187/* XXX: use automatic init with either ELF sections or C file parser */
188/* modules */
de6d9b64 189
b9a281db 190/* mpeg.c */
b9a281db
FB
191int mpegps_init(void);
192
193/* mpegts.c */
194extern AVInputFormat mpegts_demux;
195int mpegts_init(void);
de6d9b64 196
b9a281db
FB
197/* rm.c */
198int rm_init(void);
199
200/* crc.c */
201int crc_init(void);
202
203/* img.c */
204int img_init(void);
205
206/* asf.c */
207int asf_init(void);
de6d9b64
FB
208
209/* avienc.c */
b9a281db 210int avienc_init(void);
de6d9b64 211
b9a281db
FB
212/* avidec.c */
213int avidec_init(void);
6cea494e 214
b9a281db
FB
215/* swf.c */
216int swf_init(void);
217
218/* mov.c */
219int mov_init(void);
de6d9b64 220
b9a281db
FB
221/* jpeg.c */
222int jpeg_init(void);
de6d9b64 223
6cea494e 224/* gif.c */
b9a281db
FB
225int gif_init(void);
226
6cea494e 227/* au.c */
b9a281db 228int au_init(void);
6cea494e 229
de6d9b64 230/* wav.c */
b9a281db 231int wav_init(void);
de6d9b64
FB
232
233/* raw.c */
b9a281db 234int raw_init(void);
de6d9b64 235
81e0d0b4
MH
236/* ogg.c */
237int ogg_init(void);
238
f20dca40
FB
239/* dv.c */
240int dv_init(void);
241
de6d9b64 242/* ffm.c */
b9a281db 243int ffm_init(void);
de6d9b64 244
fb025625
FB
245/* rtsp.c */
246extern AVInputFormat redir_demux;
247int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
248
249#include "rtp.h"
250
251#include "rtsp.h"
252
b9a281db 253/* utils.c */
de6d9b64
FB
254#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
255#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
256
b9a281db
FB
257void av_register_input_format(AVInputFormat *format);
258void av_register_output_format(AVOutputFormat *format);
36ada60c
PG
259AVOutputFormat *guess_stream_format(const char *short_name,
260 const char *filename, const char *mime_type);
b9a281db
FB
261AVOutputFormat *guess_format(const char *short_name,
262 const char *filename, const char *mime_type);
de6d9b64 263
b9a281db 264void av_hex_dump(UINT8 *buf, int size);
de6d9b64 265
94988531 266void av_register_all(void);
de6d9b64
FB
267
268typedef struct FifoBuffer {
269 UINT8 *buffer;
270 UINT8 *rptr, *wptr, *end;
271} FifoBuffer;
272
273int fifo_init(FifoBuffer *f, int size);
274void fifo_free(FifoBuffer *f);
275int fifo_size(FifoBuffer *f, UINT8 *rptr);
276int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
277void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
278
b9a281db
FB
279/* media file input */
280AVInputFormat *av_find_input_format(const char *short_name);
94988531 281AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
b9a281db
FB
282int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
283 AVInputFormat *fmt,
284 int buf_size,
285 AVFormatParameters *ap);
286
287#define AVERROR_UNKNOWN (-1) /* unknown error */
288#define AVERROR_IO (-2) /* i/o error */
289#define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
290#define AVERROR_INVALIDDATA (-4) /* invalid data found */
291#define AVERROR_NOMEM (-5) /* not enough memory */
292#define AVERROR_NOFMT (-6) /* unknown format */
293
294int av_find_stream_info(AVFormatContext *ic);
de6d9b64
FB
295int av_read_packet(AVFormatContext *s, AVPacket *pkt);
296void av_close_input_file(AVFormatContext *s);
b9a281db 297AVStream *av_new_stream(AVFormatContext *s, int id);
916c80e9
FB
298void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
299 int pts_num, int pts_den);
de6d9b64 300
b9a281db
FB
301/* media file output */
302int av_write_header(AVFormatContext *s);
1e51d801
FB
303int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
304 int size);
b9a281db 305int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
306
307void dump_format(AVFormatContext *ic,
308 int index,
309 const char *url,
310 int is_output);
311int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
de6d9b64
FB
312INT64 parse_date(const char *datestr, int duration);
313
94988531
FB
314INT64 av_gettime(void);
315
de6d9b64
FB
316/* ffm specific for ffserver */
317#define FFM_PACKET_SIZE 4096
318offset_t ffm_read_write_index(int fd);
319void ffm_write_write_index(int fd, offset_t pos);
320void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
321
322int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
323
813cae4b
FB
324int get_frame_filename(char *buf, int buf_size,
325 const char *path, int number);
b9a281db 326int filename_number_test(const char *filename);
96baaa6a 327
b9a281db
FB
328/* grab specific */
329int video_grab_init(void);
330int audio_init(void);
96baaa6a
FB
331
332extern const char *v4l_device;
333extern const char *audio_device;
fb025625
FB
334
335#ifdef HAVE_AV_CONFIG_H
336int strstart(const char *str, const char *val, const char **ptr);
337int stristart(const char *str, const char *val, const char **ptr);
338void pstrcpy(char *buf, int buf_size, const char *str);
339char *pstrcat(char *buf, int buf_size, const char *s);
fb025625
FB
340
341struct in_addr;
342int resolve_host(struct in_addr *sin_addr, const char *hostname);
343
344void url_split(char *proto, int proto_size,
345 char *hostname, int hostname_size,
346 int *port_ptr,
347 char *path, int path_size,
348 const char *url);
349
a941f391
FB
350int match_ext(const char *filename, const char *extensions);
351
fb025625
FB
352#endif /* HAVE_AV_CONFIG_H */
353
354#endif /* AVFORMAT_H */