Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 5cd62665

History | View | Annotate | Download (13.6 KB)

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