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