305085dba9be70d2e151b721db25a17e850dcf66
[libav.git] / libav / avformat.h
1 #ifndef AVFORMAT_H
2 #define AVFORMAT_H
3
4 #define LIBAVFORMAT_VERSION_INT 0x000406
5 #define LIBAVFORMAT_VERSION "0.4.6"
6 #define LIBAVFORMAT_BUILD 4602
7
8 #include "avcodec.h"
9
10 #include "avio.h"
11
12 /* packet functions */
13
14 #define AV_NOPTS_VALUE 0
15
16 typedef struct AVPacket {
17 INT64 pts; /* presentation time stamp in stream units (set av_set_pts_info) */
18 UINT8 *data;
19 int size;
20 int stream_index;
21 int flags;
22 int duration;
23 #define PKT_FLAG_KEY 0x0001
24 #define PKT_FLAG_DROPPED_FRAME 0x0002
25 } AVPacket;
26
27 int av_new_packet(AVPacket *pkt, int size);
28 void av_free_packet(AVPacket *pkt);
29
30 /*************************************************/
31 /* fractional numbers for exact pts handling */
32
33 /* the exact value of the fractional number is: 'val + num / den'. num
34 is assumed to be such as 0 <= num < den */
35 typedef struct AVFrac {
36 INT64 val, num, den;
37 } AVFrac;
38
39 void av_frac_init(AVFrac *f, INT64 val, INT64 num, INT64 den);
40 void av_frac_add(AVFrac *f, INT64 incr);
41 void av_frac_set(AVFrac *f, INT64 val);
42
43 /*************************************************/
44 /* input/output formats */
45
46 struct AVFormatContext;
47
48 /* this structure contains the data a format has to probe a file */
49 typedef struct AVProbeData {
50 char *filename;
51 unsigned char *buf;
52 int buf_size;
53 } AVProbeData;
54
55 #define AVPROBE_SCORE_MAX 100
56
57 typedef struct AVFormatParameters {
58 int frame_rate;
59 int sample_rate;
60 int channels;
61 int width;
62 int height;
63 enum PixelFormat pix_fmt;
64 } AVFormatParameters;
65
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 */
71 #define AVFMT_RGB24 0x0010 /* force RGB24 output for ppm (hack
72 - need better api) */
73 #define AVFMT_RAWPICTURE 0x0020 /* format wants AVPicture structure for
74 raw picture data */
75
76 typedef struct AVOutputFormat {
77 const char *name;
78 const char *long_name;
79 const char *mime_type;
80 const char *extensions; /* comma separated extensions */
81 /* size of private data so that it can be allocated in the wrapper */
82 int priv_data_size;
83 /* output support */
84 enum CodecID audio_codec; /* default audio codec */
85 enum CodecID video_codec; /* default video codec */
86 int (*write_header)(struct AVFormatContext *);
87 /* XXX: change prototype for 64 bit pts */
88 int (*write_packet)(struct AVFormatContext *,
89 int stream_index,
90 unsigned char *buf, int size, int force_pts);
91 int (*write_trailer)(struct AVFormatContext *);
92 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
93 int flags;
94 /* private fields */
95 struct AVOutputFormat *next;
96 } AVOutputFormat;
97
98 typedef 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
106 structure. Return 0 if OK. 'ap' if non NULL contains
107 additionnal paramters. Only used in raw format right
108 now. 'av_new_stream' should be called to create new streams. */
109 int (*read_header)(struct AVFormatContext *,
110 AVFormatParameters *ap);
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. */
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);
121 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
122 int flags;
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;
132
133 typedef struct AVStream {
134 int index; /* stream index in AVFormatContext */
135 int id; /* format specific stream id */
136 AVCodecContext codec; /* codec context */
137 int r_frame_rate; /* real frame rate of the stream */
138 uint64_t time_length; /* real length of the stream in miliseconds */
139 void *priv_data;
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;
144 /* PTS generation when outputing stream */
145 AVFrac pts;
146 /* ffmpeg.c private use */
147 int stream_copy; /* if TRUE, just copy stream */
148 } AVStream;
149
150 #define MAX_STREAMS 20
151
152 /* format I/O context */
153 typedef struct AVFormatContext {
154 /* can only be iformat or oformat, not both at the same time */
155 struct AVInputFormat *iformat;
156 struct AVOutputFormat *oformat;
157 void *priv_data;
158 ByteIOContext pb;
159 int nb_streams;
160 AVStream *streams[MAX_STREAMS];
161 char filename[1024]; /* input or output filename */
162 /* stream info */
163 char title[512];
164 char author[512];
165 char copyright[512];
166 char comment[512];
167 int flags; /* format specific flags */
168 /* private data for pts handling (do not modify directly) */
169 int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
170 int pts_num, pts_den; /* value to convert to seconds */
171 /* This buffer is only needed when packets were already buffered but
172 not decoded, for example to get the codec parameters in mpeg
173 streams */
174 struct AVPacketList *packet_buffer;
175 } AVFormatContext;
176
177 typedef struct AVPacketList {
178 AVPacket pkt;
179 struct AVPacketList *next;
180 } AVPacketList;
181
182 extern AVInputFormat *first_iformat;
183 extern AVOutputFormat *first_oformat;
184
185 /* XXX: use automatic init with either ELF sections or C file parser */
186 /* modules */
187
188 /* mpeg.c */
189 int mpegps_init(void);
190
191 /* mpegts.c */
192 extern AVInputFormat mpegts_demux;
193 int mpegts_init(void);
194
195 /* rm.c */
196 int rm_init(void);
197
198 /* crc.c */
199 int crc_init(void);
200
201 /* img.c */
202 int img_init(void);
203
204 /* asf.c */
205 int asf_init(void);
206
207 /* avienc.c */
208 int avienc_init(void);
209
210 /* avidec.c */
211 int avidec_init(void);
212
213 /* swf.c */
214 int swf_init(void);
215
216 /* mov.c */
217 int mov_init(void);
218
219 /* jpeg.c */
220 int jpeg_init(void);
221
222 /* gif.c */
223 int gif_init(void);
224
225 /* au.c */
226 int au_init(void);
227
228 /* wav.c */
229 int wav_init(void);
230
231 /* raw.c */
232 int raw_init(void);
233
234 /* ogg.c */
235 int ogg_init(void);
236
237 /* dv.c */
238 int dv_init(void);
239
240 /* ffm.c */
241 int ffm_init(void);
242
243 /* rtsp.c */
244 extern AVInputFormat redir_demux;
245 int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);
246
247 #include "rtp.h"
248
249 #include "rtsp.h"
250
251 /* utils.c */
252 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
253 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
254
255 void av_register_input_format(AVInputFormat *format);
256 void av_register_output_format(AVOutputFormat *format);
257 AVOutputFormat *guess_stream_format(const char *short_name,
258 const char *filename, const char *mime_type);
259 AVOutputFormat *guess_format(const char *short_name,
260 const char *filename, const char *mime_type);
261
262 void av_hex_dump(UINT8 *buf, int size);
263
264 void av_register_all(void);
265
266 typedef struct FifoBuffer {
267 UINT8 *buffer;
268 UINT8 *rptr, *wptr, *end;
269 } FifoBuffer;
270
271 int fifo_init(FifoBuffer *f, int size);
272 void fifo_free(FifoBuffer *f);
273 int fifo_size(FifoBuffer *f, UINT8 *rptr);
274 int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
275 void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
276
277 /* media file input */
278 AVInputFormat *av_find_input_format(const char *short_name);
279 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
280 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
281 AVInputFormat *fmt,
282 int buf_size,
283 AVFormatParameters *ap);
284
285 #define AVERROR_UNKNOWN (-1) /* unknown error */
286 #define AVERROR_IO (-2) /* i/o error */
287 #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
288 #define AVERROR_INVALIDDATA (-4) /* invalid data found */
289 #define AVERROR_NOMEM (-5) /* not enough memory */
290 #define AVERROR_NOFMT (-6) /* unknown format */
291
292 int av_find_stream_info(AVFormatContext *ic);
293 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
294 void av_close_input_file(AVFormatContext *s);
295 AVStream *av_new_stream(AVFormatContext *s, int id);
296 void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
297 int pts_num, int pts_den);
298
299 /* media file output */
300 int av_write_header(AVFormatContext *s);
301 int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf,
302 int size);
303 int av_write_trailer(AVFormatContext *s);
304
305 void dump_format(AVFormatContext *ic,
306 int index,
307 const char *url,
308 int is_output);
309 int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
310 INT64 parse_date(const char *datestr, int duration);
311
312 INT64 av_gettime(void);
313
314 /* ffm specific for ffserver */
315 #define FFM_PACKET_SIZE 4096
316 offset_t ffm_read_write_index(int fd);
317 void ffm_write_write_index(int fd, offset_t pos);
318 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
319
320 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
321
322 int get_frame_filename(char *buf, int buf_size,
323 const char *path, int number);
324 int filename_number_test(const char *filename);
325
326 /* grab specific */
327 int video_grab_init(void);
328 int audio_init(void);
329
330 extern const char *v4l_device;
331 extern const char *audio_device;
332
333 #ifdef HAVE_AV_CONFIG_H
334 int strstart(const char *str, const char *val, const char **ptr);
335 int stristart(const char *str, const char *val, const char **ptr);
336 void pstrcpy(char *buf, int buf_size, const char *str);
337 char *pstrcat(char *buf, int buf_size, const char *s);
338
339 struct in_addr;
340 int resolve_host(struct in_addr *sin_addr, const char *hostname);
341
342 void url_split(char *proto, int proto_size,
343 char *hostname, int hostname_size,
344 int *port_ptr,
345 char *path, int path_size,
346 const char *url);
347
348 #endif /* HAVE_AV_CONFIG_H */
349
350 #endif /* AVFORMAT_H */