8ab1dab542d468fd1d6425933f4cc52ebdbd772d
[libav.git] / libav / avformat.h
1
2 #define LIBAV_VERSION_INT 0x000406
3 #define LIBAV_VERSION "0.4.6"
4 #define LIBAV_BUILD 4601
5
6 #include "avcodec.h"
7
8 #include "avio.h"
9
10 /* packet functions */
11
12 typedef struct AVPacket {
13 INT64 pts;
14 UINT8 *data;
15 int size;
16 int stream_index;
17 int flags;
18 int duration;
19 #define PKT_FLAG_KEY 0x0001
20 #define PKT_FLAG_DROPPED_FRAME 0x0002
21 } AVPacket;
22
23 int av_new_packet(AVPacket *pkt, int size);
24 void av_free_packet(AVPacket *pkt);
25
26 /*************************************************/
27 /* input/output formats */
28
29 struct AVFormatContext;
30
31 /* this structure contains the data a format has to probe a file */
32 typedef struct AVProbeData {
33 char *filename;
34 unsigned char *buf;
35 int buf_size;
36 } AVProbeData;
37
38 #define AVPROBE_SCORE_MAX 100
39
40 typedef struct AVFormatParameters {
41 int frame_rate;
42 int sample_rate;
43 int channels;
44 int width;
45 int height;
46 enum PixelFormat pix_fmt;
47 } AVFormatParameters;
48
49 #define AVFMT_NOFILE 0x0001 /* no file should be opened */
50 #define AVFMT_NEEDNUMBER 0x0002 /* needs '%d' in filename */
51 #define AVFMT_NOHEADER 0x0004 /* signal that no header is present
52 (streams are added dynamically) */
53 #define AVFMT_SHOW_IDS 0x0008 /* show format stream IDs numbers */
54 #define AVFMT_RGB24 0x0010 /* force RGB24 output for ppm (hack
55 - need better api) */
56
57 typedef struct AVOutputFormat {
58 const char *name;
59 const char *long_name;
60 const char *mime_type;
61 const char *extensions; /* comma separated extensions */
62 /* size of private data so that it can be allocated in the wrapper */
63 int priv_data_size;
64 /* output support */
65 enum CodecID audio_codec; /* default audio codec */
66 enum CodecID video_codec; /* default video codec */
67 int (*write_header)(struct AVFormatContext *);
68 int (*write_packet)(struct AVFormatContext *,
69 int stream_index,
70 unsigned char *buf, int size, int force_pts);
71 int (*write_trailer)(struct AVFormatContext *);
72 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
73 int flags;
74 /* private fields */
75 struct AVOutputFormat *next;
76 } AVOutputFormat;
77
78 typedef struct AVInputFormat {
79 const char *name;
80 const char *long_name;
81 /* size of private data so that it can be allocated in the wrapper */
82 int priv_data_size;
83 /* tell if a given file has a chance of being parsing by this format */
84 int (*read_probe)(AVProbeData *);
85 /* read the format header and initialize the AVFormatContext
86 structure. Return 0 if OK. 'ap' if non NULL contains
87 additionnal paramters. Only used in raw format right
88 now. 'av_new_stream' should be called to create new streams. */
89 int (*read_header)(struct AVFormatContext *,
90 AVFormatParameters *ap);
91 /* read one packet and put it in 'pkt'. pts and flags are also
92 set. 'av_new_stream' can be called only if the flag
93 AVFMT_NOHEADER is used. */
94 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
95 /* close the stream. The AVFormatContext and AVStreams are not
96 freed by this function */
97 int (*read_close)(struct AVFormatContext *);
98 /* seek at or before a given pts (given in microsecond). The pts
99 origin is defined by the stream */
100 int (*read_seek)(struct AVFormatContext *, INT64 pts);
101 /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
102 int flags;
103 /* if extensions are defined, then no probe is done. You should
104 usually not use extension format guessing because it is not
105 reliable enough */
106 const char *extensions;
107 /* general purpose read only value that the format can use */
108 int value;
109 /* private fields */
110 struct AVInputFormat *next;
111 } AVInputFormat;
112
113 typedef struct AVStream {
114 int index; /* stream index in AVFormatContext */
115 int id; /* format specific stream id */
116 AVCodecContext codec; /* codec context */
117 int r_frame_rate; /* real frame rate of the stream */
118 void *priv_data;
119 /* internal data used in av_find_stream_info() */
120 int codec_info_state;
121 int codec_info_nb_repeat_frames;
122 int codec_info_nb_real_frames;
123 } AVStream;
124
125 #define MAX_STREAMS 20
126
127 /* format I/O context */
128 typedef struct AVFormatContext {
129 /* can only be iformat or oformat, not both at the same time */
130 struct AVInputFormat *iformat;
131 struct AVOutputFormat *oformat;
132 void *priv_data;
133 ByteIOContext pb;
134 int nb_streams;
135 AVStream *streams[MAX_STREAMS];
136 char filename[1024]; /* input or output filename */
137 /* stream info */
138 char title[512];
139 char author[512];
140 char copyright[512];
141 char comment[512];
142 int flags; /* format specific flags */
143 /* This buffer is only needed when packets were already buffered but
144 not decoded, for example to get the codec parameters in mpeg
145 streams */
146 struct AVPacketList *packet_buffer;
147 } AVFormatContext;
148
149 typedef struct AVPacketList {
150 AVPacket pkt;
151 struct AVPacketList *next;
152 } AVPacketList;
153
154 extern AVInputFormat *first_iformat;
155 extern AVOutputFormat *first_oformat;
156
157 /* XXX: use automatic init with either ELF sections or C file parser */
158 /* modules */
159
160 /* mpeg.c */
161 #define AVF_FLAG_VCD 0x00000001 /* VCD compatible MPEG-PS */
162 int mpegps_init(void);
163
164 /* mpegts.c */
165 extern AVInputFormat mpegts_demux;
166 int mpegts_init(void);
167
168 /* rm.c */
169 int rm_init(void);
170
171 /* crc.c */
172 int crc_init(void);
173
174 /* img.c */
175 int img_init(void);
176
177 /* asf.c */
178 int asf_init(void);
179
180 /* avienc.c */
181 int avienc_init(void);
182
183 /* avidec.c */
184 int avidec_init(void);
185
186 /* swf.c */
187 int swf_init(void);
188
189 /* mov.c */
190 int mov_init(void);
191
192 /* jpeg.c */
193 int jpeg_init(void);
194
195 /* gif.c */
196 int gif_init(void);
197
198 /* au.c */
199 int au_init(void);
200
201 /* wav.c */
202 int wav_init(void);
203
204 /* raw.c */
205 int raw_init(void);
206
207 /* ffm.c */
208 int ffm_init(void);
209
210 /* utils.c */
211 #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
212 #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))
213
214 void av_register_input_format(AVInputFormat *format);
215 void av_register_output_format(AVOutputFormat *format);
216 AVOutputFormat *guess_format(const char *short_name,
217 const char *filename, const char *mime_type);
218
219 int strstart(const char *str, const char *val, const char **ptr);
220 void pstrcpy(char *buf, int buf_size, const char *str);
221
222 int match_ext(const char *filename, const char *extensions);
223 void av_hex_dump(UINT8 *buf, int size);
224
225 void register_all(void);
226
227 INT64 gettime(void);
228
229 typedef struct FifoBuffer {
230 UINT8 *buffer;
231 UINT8 *rptr, *wptr, *end;
232 } FifoBuffer;
233
234 int fifo_init(FifoBuffer *f, int size);
235 void fifo_free(FifoBuffer *f);
236 int fifo_size(FifoBuffer *f, UINT8 *rptr);
237 int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
238 void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);
239
240 /* media file input */
241 AVInputFormat *av_find_input_format(const char *short_name);
242 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
243 AVInputFormat *fmt,
244 int buf_size,
245 AVFormatParameters *ap);
246
247 #define AVERROR_UNKNOWN (-1) /* unknown error */
248 #define AVERROR_IO (-2) /* i/o error */
249 #define AVERROR_NUMEXPECTED (-3) /* number syntax expected in filename */
250 #define AVERROR_INVALIDDATA (-4) /* invalid data found */
251 #define AVERROR_NOMEM (-5) /* not enough memory */
252 #define AVERROR_NOFMT (-6) /* unknown format */
253
254 int av_find_stream_info(AVFormatContext *ic);
255 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
256 void av_close_input_file(AVFormatContext *s);
257 AVStream *av_new_stream(AVFormatContext *s, int id);
258
259 /* media file output */
260 int av_write_header(AVFormatContext *s);
261 int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts);
262 int av_write_trailer(AVFormatContext *s);
263
264 void dump_format(AVFormatContext *ic,
265 int index,
266 const char *url,
267 int is_output);
268 int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
269 INT64 gettime(void);
270 INT64 parse_date(const char *datestr, int duration);
271
272 /* ffm specific for ffserver */
273 #define FFM_PACKET_SIZE 4096
274 offset_t ffm_read_write_index(int fd);
275 void ffm_write_write_index(int fd, offset_t pos);
276 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
277
278 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
279
280 int get_frame_filename(char *buf, int buf_size,
281 const char *path, int number);
282 int filename_number_test(const char *filename);
283
284 /* grab specific */
285 int video_grab_init(void);
286 int audio_init(void);
287
288 extern const char *v4l_device;
289 extern const char *audio_device;