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