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