avformat.h 9.96 KB
Newer Older
Fabrice Bellard's avatar
Fabrice Bellard committed
1 2
#ifndef AVFORMAT_H
#define AVFORMAT_H
Fabrice Bellard's avatar
Fabrice Bellard committed
3

Fabrice Bellard's avatar
Fabrice Bellard committed
4 5
#define LIBAVFORMAT_VERSION_INT 0x000406  
#define LIBAVFORMAT_VERSION     "0.4.6"
6
#define LIBAVFORMAT_BUILD       4602
7

Fabrice Bellard's avatar
Fabrice Bellard committed
8 9 10 11 12 13
#include "avcodec.h"

#include "avio.h"

/* packet functions */

Fabrice Bellard's avatar
Fabrice Bellard committed
14 15
#define AV_NOPTS_VALUE 0

Fabrice Bellard's avatar
Fabrice Bellard committed
16 17 18 19 20 21
typedef struct AVPacket {
    INT64 pts;
    UINT8 *data;
    int size;
    int stream_index;
    int flags;
22
    int duration;       
Fabrice Bellard's avatar
Fabrice Bellard committed
23
#define PKT_FLAG_KEY   0x0001
24
#define PKT_FLAG_DROPPED_FRAME   0x0002
Fabrice Bellard's avatar
Fabrice Bellard committed
25 26 27 28 29 30
} AVPacket; 

int av_new_packet(AVPacket *pkt, int size);
void av_free_packet(AVPacket *pkt);

/*************************************************/
31
/* input/output formats */
Fabrice Bellard's avatar
Fabrice Bellard committed
32 33

struct AVFormatContext;
34 35 36 37 38 39 40 41 42

/* this structure contains the data a format has to probe a file */
typedef struct AVProbeData {
    char *filename;
    unsigned char *buf;
    int buf_size;
} AVProbeData;

#define AVPROBE_SCORE_MAX 100
Fabrice Bellard's avatar
Fabrice Bellard committed
43 44 45 46 47 48 49

typedef struct AVFormatParameters {
    int frame_rate;
    int sample_rate;
    int channels;
    int width;
    int height;
50
    enum PixelFormat pix_fmt;
Fabrice Bellard's avatar
Fabrice Bellard committed
51 52
} AVFormatParameters;

53 54 55 56 57 58 59
#define AVFMT_NOFILE        0x0001 /* no file should be opened */
#define AVFMT_NEEDNUMBER    0x0002 /* needs '%d' in filename */ 
#define AVFMT_NOHEADER      0x0004 /* signal that no header is present
                                      (streams are added dynamically) */
#define AVFMT_SHOW_IDS      0x0008 /* show format stream IDs numbers */
#define AVFMT_RGB24         0x0010 /* force RGB24 output for ppm (hack
                                      - need better api) */
Fabrice Bellard's avatar
Fabrice Bellard committed
60 61
#define AVFMT_RAWPICTURE    0x0020 /* format wants AVPicture structure for
                                      raw picture data */
62 63

typedef struct AVOutputFormat {
Fabrice Bellard's avatar
Fabrice Bellard committed
64 65 66 67
    const char *name;
    const char *long_name;
    const char *mime_type;
    const char *extensions; /* comma separated extensions */
68 69
    /* size of private data so that it can be allocated in the wrapper */
    int priv_data_size;
Fabrice Bellard's avatar
Fabrice Bellard committed
70 71 72 73 74 75
    /* output support */
    enum CodecID audio_codec; /* default audio codec */
    enum CodecID video_codec; /* default video codec */
    int (*write_header)(struct AVFormatContext *);
    int (*write_packet)(struct AVFormatContext *, 
                        int stream_index,
76
                        unsigned char *buf, int size, int force_pts);
Fabrice Bellard's avatar
Fabrice Bellard committed
77
    int (*write_trailer)(struct AVFormatContext *);
78 79 80 81 82
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
    int flags;
    /* private fields */
    struct AVOutputFormat *next;
} AVOutputFormat;
Fabrice Bellard's avatar
Fabrice Bellard committed
83

84 85 86 87 88 89 90 91
typedef struct AVInputFormat {
    const char *name;
    const char *long_name;
    /* size of private data so that it can be allocated in the wrapper */
    int priv_data_size;
    /* tell if a given file has a chance of being parsing by this format */
    int (*read_probe)(AVProbeData *);
    /* read the format header and initialize the AVFormatContext
Fabrice Bellard's avatar
Fabrice Bellard committed
92
       structure. Return 0 if OK. 'ap' if non NULL contains
93 94
       additionnal paramters. Only used in raw format right
       now. 'av_new_stream' should be called to create new streams.  */
Fabrice Bellard's avatar
Fabrice Bellard committed
95 96
    int (*read_header)(struct AVFormatContext *,
                       AVFormatParameters *ap);
97 98 99
    /* read one packet and put it in 'pkt'. pts and flags are also
       set. 'av_new_stream' can be called only if the flag
       AVFMT_NOHEADER is used. */
Fabrice Bellard's avatar
Fabrice Bellard committed
100 101 102 103 104 105 106
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
    /* close the stream. The AVFormatContext and AVStreams are not
       freed by this function */
    int (*read_close)(struct AVFormatContext *);
    /* seek at or before a given pts (given in microsecond). The pts
       origin is defined by the stream */
    int (*read_seek)(struct AVFormatContext *, INT64 pts);
107
    /* can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_NOHEADER */
Fabrice Bellard's avatar
Fabrice Bellard committed
108
    int flags;
109 110 111 112 113 114 115 116 117
    /* if extensions are defined, then no probe is done. You should
       usually not use extension format guessing because it is not
       reliable enough */
    const char *extensions;
    /* general purpose read only value that the format can use */
    int value;
    /* private fields */
    struct AVInputFormat *next;
} AVInputFormat;
Fabrice Bellard's avatar
Fabrice Bellard committed
118 119

typedef struct AVStream {
120 121
    int index;    /* stream index in AVFormatContext */
    int id;       /* format specific stream id */
Fabrice Bellard's avatar
Fabrice Bellard committed
122
    AVCodecContext codec; /* codec context */
123
    int r_frame_rate;     /* real frame rate of the stream */
124 125 126
    uint64_t time_length; /* real length of the stream in miliseconds */
    void* extra_data;     /* some extra data - i.e. longer WAVEFORMATEX */
    int extra_data_size;  /* size of extra data chunk */
Fabrice Bellard's avatar
Fabrice Bellard committed
127
    void *priv_data;
128 129 130 131
    /* internal data used in av_find_stream_info() */
    int codec_info_state;     
    int codec_info_nb_repeat_frames;
    int codec_info_nb_real_frames;
Fabrice Bellard's avatar
Fabrice Bellard committed
132 133
    /* ffmpeg.c private use */
    int stream_copy; /* if TRUE, just copy stream */
Fabrice Bellard's avatar
Fabrice Bellard committed
134 135 136 137 138 139
} AVStream;

#define MAX_STREAMS 20

/* format I/O context */
typedef struct AVFormatContext {
140 141 142
    /* can only be iformat or oformat, not both at the same time */
    struct AVInputFormat *iformat;
    struct AVOutputFormat *oformat;
Fabrice Bellard's avatar
Fabrice Bellard committed
143 144 145 146 147 148 149 150 151 152
    void *priv_data;
    ByteIOContext pb;
    int nb_streams;
    AVStream *streams[MAX_STREAMS];
    char filename[1024]; /* input or output filename */
    /* stream info */
    char title[512];
    char author[512];
    char copyright[512];
    char comment[512];
153
    int flags; /* format specific flags */
Fabrice Bellard's avatar
Fabrice Bellard committed
154 155 156 157 158 159 160 161 162 163 164
    /* This buffer is only needed when packets were already buffered but
       not decoded, for example to get the codec parameters in mpeg
       streams */
   struct AVPacketList *packet_buffer;
} AVFormatContext;

typedef struct AVPacketList {
    AVPacket pkt;
    struct AVPacketList *next;
} AVPacketList;

165 166
extern AVInputFormat *first_iformat;
extern AVOutputFormat *first_oformat;
Fabrice Bellard's avatar
Fabrice Bellard committed
167

168 169
/* XXX: use automatic init with either ELF sections or C file parser */
/* modules */
Fabrice Bellard's avatar
Fabrice Bellard committed
170

171 172 173 174 175 176
/* mpeg.c */
int mpegps_init(void);

/* mpegts.c */
extern AVInputFormat mpegts_demux;
int mpegts_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
177

178 179 180 181 182 183 184 185 186 187 188
/* rm.c */
int rm_init(void);

/* crc.c */
int crc_init(void);

/* img.c */
int img_init(void);

/* asf.c */
int asf_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
189 190

/* avienc.c */
191
int avienc_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
192

193 194
/* avidec.c */
int avidec_init(void);
195

196 197 198 199 200
/* swf.c */
int swf_init(void);

/* mov.c */
int mov_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
201

202 203
/* jpeg.c */
int jpeg_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
204

205
/* gif.c */
206 207
int gif_init(void);

208
/* au.c */
209
int au_init(void);
210

Fabrice Bellard's avatar
Fabrice Bellard committed
211
/* wav.c */
212
int wav_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
213 214

/* raw.c */
215
int raw_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
216

217 218 219
/* ogg.c */
int ogg_init(void);

220 221 222
/* dv.c */
int dv_init(void);

Fabrice Bellard's avatar
Fabrice Bellard committed
223
/* ffm.c */
224
int ffm_init(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
225

Fabrice Bellard's avatar
Fabrice Bellard committed
226 227 228 229 230 231 232 233
/* rtsp.c */
extern AVInputFormat redir_demux;
int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f);

#include "rtp.h"

#include "rtsp.h"

234
/* utils.c */
Fabrice Bellard's avatar
Fabrice Bellard committed
235 236 237
#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
#define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24))

238 239
void av_register_input_format(AVInputFormat *format);
void av_register_output_format(AVOutputFormat *format);
240 241
AVOutputFormat *guess_stream_format(const char *short_name, 
                                    const char *filename, const char *mime_type);
242 243
AVOutputFormat *guess_format(const char *short_name, 
                             const char *filename, const char *mime_type);
Fabrice Bellard's avatar
Fabrice Bellard committed
244

245
void av_hex_dump(UINT8 *buf, int size);
Fabrice Bellard's avatar
Fabrice Bellard committed
246

Fabrice Bellard's avatar
Fabrice Bellard committed
247
void av_register_all(void);
Fabrice Bellard's avatar
Fabrice Bellard committed
248 249 250 251 252 253 254 255 256 257 258 259

typedef struct FifoBuffer {
    UINT8 *buffer;
    UINT8 *rptr, *wptr, *end;
} FifoBuffer;

int fifo_init(FifoBuffer *f, int size);
void fifo_free(FifoBuffer *f);
int fifo_size(FifoBuffer *f, UINT8 *rptr);
int fifo_read(FifoBuffer *f, UINT8 *buf, int buf_size, UINT8 **rptr_ptr);
void fifo_write(FifoBuffer *f, UINT8 *buf, int size, UINT8 **wptr_ptr);

260 261
/* media file input */
AVInputFormat *av_find_input_format(const char *short_name);
Fabrice Bellard's avatar
Fabrice Bellard committed
262
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
263 264 265 266 267 268 269 270 271 272 273 274 275
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, 
                       AVInputFormat *fmt,
                       int buf_size,
                       AVFormatParameters *ap);

#define AVERROR_UNKNOWN     (-1)  /* unknown error */
#define AVERROR_IO          (-2)  /* i/o error */
#define AVERROR_NUMEXPECTED (-3)  /* number syntax expected in filename */
#define AVERROR_INVALIDDATA (-4)  /* invalid data found */
#define AVERROR_NOMEM       (-5)  /* not enough memory */
#define AVERROR_NOFMT       (-6)  /* unknown format */

int av_find_stream_info(AVFormatContext *ic);
Fabrice Bellard's avatar
Fabrice Bellard committed
276 277
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
void av_close_input_file(AVFormatContext *s);
278
AVStream *av_new_stream(AVFormatContext *s, int id);
Fabrice Bellard's avatar
Fabrice Bellard committed
279

280 281
/* media file output */
int av_write_header(AVFormatContext *s);
282
int av_write_packet(AVFormatContext *s, AVPacket *pkt, int force_pts);
283
int av_write_trailer(AVFormatContext *s);
Fabrice Bellard's avatar
Fabrice Bellard committed
284 285 286 287 288 289 290 291

void dump_format(AVFormatContext *ic,
                 int index, 
                 const char *url,
                 int is_output);
int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
INT64 parse_date(const char *datestr, int duration);

Fabrice Bellard's avatar
Fabrice Bellard committed
292 293
INT64 av_gettime(void);

Fabrice Bellard's avatar
Fabrice Bellard committed
294 295 296 297 298 299 300 301
/* ffm specific for ffserver */
#define FFM_PACKET_SIZE 4096
offset_t ffm_read_write_index(int fd);
void ffm_write_write_index(int fd, offset_t pos);
void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);

int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);

Fabrice Bellard's avatar
Fabrice Bellard committed
302 303
int get_frame_filename(char *buf, int buf_size,
                       const char *path, int number);
304
int filename_number_test(const char *filename);
305

306 307 308
/* grab specific */
int video_grab_init(void);
int audio_init(void);
309 310 311

extern const char *v4l_device;
extern const char *audio_device;
Fabrice Bellard's avatar
Fabrice Bellard committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

#ifdef HAVE_AV_CONFIG_H
int strstart(const char *str, const char *val, const char **ptr);
int stristart(const char *str, const char *val, const char **ptr);
void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
int match_ext(const char *filename, const char *extensions);

struct in_addr;
int resolve_host(struct in_addr *sin_addr, const char *hostname);

void url_split(char *proto, int proto_size,
               char *hostname, int hostname_size,
               int *port_ptr,
               char *path, int path_size,
               const char *url);

#endif /* HAVE_AV_CONFIG_H */

#endif /* AVFORMAT_H */