00001
00002
00003
00004
00005 #ifndef AVFORMAT_H
00006 #define AVFORMAT_H
00007
00008 #ifdef __cplusplus
00009 extern "C" {
00010 #endif
00011
00012 #define LIBAVFORMAT_VERSION_INT ((51<<16)+(8<<8)+0)
00013 #define LIBAVFORMAT_VERSION 51.8.0
00014 #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
00015
00016 #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
00017
00018 #include <time.h>
00019 #include <stdio.h>
00020 #include "avcodec.h"
00021
00022 #include "avio.h"
00023
00024 typedef struct AVPacket {
00025 int64_t pts;
00026 int64_t dts;
00027 uint8_t *data;
00028 int size;
00029 int stream_index;
00030 int flags;
00031 int duration;
00032 void (*destruct)(struct AVPacket *);
00033 void *priv;
00034 int64_t pos;
00035 } AVPacket;
00036 #define PKT_FLAG_KEY 0x0001
00037
00038 void av_destruct_packet_nofree(AVPacket *pkt);
00039 void av_destruct_packet(AVPacket *pkt);
00040
00041 static inline void av_init_packet(AVPacket *pkt)
00042 {
00043 pkt->pts = AV_NOPTS_VALUE;
00044 pkt->dts = AV_NOPTS_VALUE;
00045 pkt->pos = -1;
00046 pkt->duration = 0;
00047 pkt->flags = 0;
00048 pkt->stream_index = 0;
00049 pkt->destruct= av_destruct_packet_nofree;
00050 }
00051
00052 int av_new_packet(AVPacket *pkt, int size);
00053 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
00054 int av_dup_packet(AVPacket *pkt);
00055
00056 static inline void av_free_packet(AVPacket *pkt)
00057 {
00058 if (pkt && pkt->destruct) {
00059 pkt->destruct(pkt);
00060 }
00061 }
00062
00063 typedef struct AVFrac {
00064 int64_t val, num, den;
00065 } AVFrac attribute_deprecated;
00066
00067 struct AVCodecTag;
00068
00069 struct AVFormatContext;
00070
00071 typedef struct AVProbeData {
00072 const char *filename;
00073 unsigned char *buf;
00074 int buf_size;
00075 } AVProbeData;
00076
00077 #define AVPROBE_SCORE_MAX 100
00078
00079 typedef struct AVFormatParameters {
00080 AVRational time_base;
00081 int sample_rate;
00082 int channels;
00083 int width;
00084 int height;
00085 enum PixelFormat pix_fmt;
00086 int channel;
00087 const char *device;
00088 const char *standard;
00089 int mpeg2ts_raw:1;
00090 int mpeg2ts_compute_pcr:1;
00091 int initial_pause:1;
00092 int prealloced_context:1;
00093 enum CodecID video_codec_id;
00094 enum CodecID audio_codec_id;
00095 } AVFormatParameters;
00096
00097 #define AVFMT_NOFILE 0x0001
00098 #define AVFMT_NEEDNUMBER 0x0002
00099 #define AVFMT_SHOW_IDS 0x0008
00100 #define AVFMT_RAWPICTURE 0x0020
00101 #define AVFMT_GLOBALHEADER 0x0040
00102 #define AVFMT_NOTIMESTAMPS 0x0080
00103
00104 typedef struct AVOutputFormat {
00105 const char *name;
00106 const char *long_name;
00107 const char *mime_type;
00108 const char *extensions;
00109
00110 int priv_data_size;
00111
00112 enum CodecID audio_codec;
00113 enum CodecID video_codec;
00114 int (*write_header)(struct AVFormatContext *);
00115 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00116 int (*write_trailer)(struct AVFormatContext *);
00117
00118 int flags;
00119
00120 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
00121 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
00122
00123
00124 const struct AVCodecTag **codec_tag;
00125
00126
00127 struct AVOutputFormat *next;
00128 } AVOutputFormat;
00129
00130 typedef struct AVInputFormat {
00131 const char *name;
00132 const char *long_name;
00133
00134 int priv_data_size;
00135
00136 int (*read_probe)(AVProbeData *);
00137
00138 int (*read_header)(struct AVFormatContext *,
00139 AVFormatParameters *ap);
00140
00141 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00142
00143 int (*read_close)(struct AVFormatContext *);
00144
00145 int (*read_seek)(struct AVFormatContext *,
00146 int stream_index, int64_t timestamp, int flags);
00147
00148 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00149 int64_t *pos, int64_t pos_limit);
00150
00151 int flags;
00152
00153 const char *extensions;
00154
00155 int value;
00156
00157
00158 int (*read_play)(struct AVFormatContext *);
00159
00160
00161 int (*read_pause)(struct AVFormatContext *);
00162
00163 const struct AVCodecTag **codec_tag;
00164
00165
00166 struct AVInputFormat *next;
00167 } AVInputFormat;
00168
00169 typedef struct AVIndexEntry {
00170 int64_t pos;
00171 int64_t timestamp;
00172 #define AVINDEX_KEYFRAME 0x0001
00173 int flags:2;
00174 int size:30;
00175 int min_distance;
00176 } AVIndexEntry;
00177
00178 typedef struct AVStream {
00179 int index;
00180 int id;
00181 AVCodecContext *codec;
00182
00183 AVRational r_frame_rate;
00184 void *priv_data;
00185
00186 int64_t codec_info_duration;
00187 int codec_info_nb_frames;
00188
00189 AVFrac pts;
00190
00191
00192 AVRational time_base;
00193 int pts_wrap_bits;
00194
00195 int stream_copy;
00196 enum AVDiscard discard;
00197
00198
00199 float quality;
00200
00201 int64_t start_time;
00202
00203 int64_t duration;
00204
00205 char language[4];
00206
00207
00208 int need_parsing;
00209 struct AVCodecParserContext *parser;
00210
00211 int64_t cur_dts;
00212 int last_IP_duration;
00213 int64_t last_IP_pts;
00214
00215 AVIndexEntry *index_entries;
00216 int nb_index_entries;
00217 unsigned int index_entries_allocated_size;
00218
00219 int64_t nb_frames;
00220
00221 #define MAX_REORDER_DELAY 4
00222 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00223 } AVStream;
00224
00225 #define AVFMTCTX_NOHEADER 0x0001
00226
00227 #define MAX_STREAMS 20
00228
00229 typedef struct AVFormatContext {
00230 const AVClass *av_class;
00231
00232 struct AVInputFormat *iformat;
00233 struct AVOutputFormat *oformat;
00234 void *priv_data;
00235 ByteIOContext pb;
00236 unsigned int nb_streams;
00237 AVStream *streams[MAX_STREAMS];
00238 char filename[1024];
00239
00240 int64_t timestamp;
00241 char title[512];
00242 char author[512];
00243 char copyright[512];
00244 char comment[512];
00245 char album[512];
00246 int year;
00247 int track;
00248 char genre[32];
00249
00250 int ctx_flags;
00251
00252
00253 struct AVPacketList *packet_buffer;
00254
00255
00256 int64_t start_time;
00257
00258 int64_t duration;
00259
00260 int64_t file_size;
00261
00262 int bit_rate;
00263
00264
00265 AVStream *cur_st;
00266 const uint8_t *cur_ptr;
00267 int cur_len;
00268 AVPacket cur_pkt;
00269
00270
00271 int64_t data_offset;
00272 int index_built;
00273
00274 int mux_rate;
00275 int packet_size;
00276 int preload;
00277 int max_delay;
00278
00279 #define AVFMT_NOOUTPUTLOOP -1
00280 #define AVFMT_INFINITEOUTPUTLOOP 0
00281
00282 int loop_output;
00283
00284 int flags;
00285 #define AVFMT_FLAG_GENPTS 0x0001
00286 #define AVFMT_FLAG_IGNIDX 0x0002
00287
00288 int loop_input;
00289
00290 unsigned int probesize;
00291
00292
00293 int max_analyze_duration;
00294 } AVFormatContext;
00295
00296 typedef struct AVPacketList {
00297 AVPacket pkt;
00298 struct AVPacketList *next;
00299 } AVPacketList;
00300
00301 extern AVInputFormat *first_iformat;
00302 extern AVOutputFormat *first_oformat;
00303
00304 enum CodecID av_guess_image2_codec(const char *filename);
00305
00306 #include "rtp.h"
00307
00308 #include "rtsp.h"
00309
00310 void av_register_input_format(AVInputFormat *format);
00311 void av_register_output_format(AVOutputFormat *format);
00312 AVOutputFormat *guess_stream_format(const char *short_name,
00313 const char *filename, const char *mime_type);
00314 AVOutputFormat *guess_format(const char *short_name,
00315 const char *filename, const char *mime_type);
00316 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
00317 const char *filename, const char *mime_type, enum CodecType type);
00318
00319 void av_hex_dump(FILE *f, uint8_t *buf, int size);
00320 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
00321
00322 void av_register_all(void);
00323
00324 enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
00325 unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
00326
00327 AVInputFormat *av_find_input_format(const char *short_name);
00328 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
00329 int av_open_input_stream(AVFormatContext **ic_ptr,
00330 ByteIOContext *pb, const char *filename,
00331 AVInputFormat *fmt, AVFormatParameters *ap);
00332 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
00333 AVInputFormat *fmt,
00334 int buf_size,
00335 AVFormatParameters *ap);
00336
00337 AVFormatContext *av_alloc_format_context(void);
00338
00339 #define AVERROR_UNKNOWN (-1)
00340 #define AVERROR_IO (-2)
00341 #define AVERROR_NUMEXPECTED (-3)
00342 #define AVERROR_INVALIDDATA (-4)
00343 #define AVERROR_NOMEM (-5)
00344 #define AVERROR_NOFMT (-6)
00345 #define AVERROR_NOTSUPP (-7)
00346
00347 int av_find_stream_info(AVFormatContext *ic);
00348 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
00349 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
00350 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
00351 int av_read_play(AVFormatContext *s);
00352 int av_read_pause(AVFormatContext *s);
00353 void av_close_input_file(AVFormatContext *s);
00354 AVStream *av_new_stream(AVFormatContext *s, int id);
00355 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
00356 int pts_num, int pts_den);
00357
00358 #define AVSEEK_FLAG_BACKWARD 1
00359 #define AVSEEK_FLAG_BYTE 2
00360 #define AVSEEK_FLAG_ANY 4
00361
00362 int av_find_default_stream_index(AVFormatContext *s);
00363 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
00364 int av_add_index_entry(AVStream *st,
00365 int64_t pos, int64_t timestamp, int size, int distance, int flags);
00366 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
00367 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
00368 int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
00369
00370 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
00371 int av_write_header(AVFormatContext *s);
00372 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
00373 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
00374 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
00375
00376 int av_write_trailer(AVFormatContext *s);
00377
00378 void dump_format(AVFormatContext *ic,
00379 int index,
00380 const char *url,
00381 int is_output);
00382 int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
00383 int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
00384 int64_t parse_date(const char *datestr, int duration);
00385
00386 int64_t av_gettime(void);
00387
00388 #define FFM_PACKET_SIZE 4096
00389 offset_t ffm_read_write_index(int fd);
00390 void ffm_write_write_index(int fd, offset_t pos);
00391 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
00392
00393 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
00394
00395 int av_get_frame_filename(char *buf, int buf_size,
00396 const char *path, int number);
00397 int av_filename_number_test(const char *filename);
00398
00399 int video_grab_init(void);
00400 int audio_init(void);
00401
00402 int dv1394_init(void);
00403 int dc1394_init(void);
00404
00405 #ifdef HAVE_AV_CONFIG_H
00406
00407 #include "os_support.h"
00408
00409 int strstart(const char *str, const char *val, const char **ptr);
00410 int stristart(const char *str, const char *val, const char **ptr);
00411 void pstrcpy(char *buf, int buf_size, const char *str);
00412 char *pstrcat(char *buf, int buf_size, const char *s);
00413
00414 void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
00415
00416 #ifdef __GNUC__
00417 #define dynarray_add(tab, nb_ptr, elem)\
00418 do {\
00419 typeof(tab) _tab = (tab);\
00420 typeof(elem) _elem = (elem);\
00421 (void)sizeof(**_tab == _elem); \
00422 __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
00423 } while(0)
00424 #else
00425 #define dynarray_add(tab, nb_ptr, elem)\
00426 do {\
00427 __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
00428 } while(0)
00429 #endif
00430
00431 time_t mktimegm(struct tm *tm);
00432 struct tm *brktimegm(time_t secs, struct tm *tm);
00433 const char *small_strptime(const char *p, const char *fmt,
00434 struct tm *dt);
00435
00436 struct in_addr;
00437 int resolve_host(struct in_addr *sin_addr, const char *hostname);
00438
00439 void url_split(char *proto, int proto_size,
00440 char *authorization, int authorization_size,
00441 char *hostname, int hostname_size,
00442 int *port_ptr,
00443 char *path, int path_size,
00444 const char *url);
00445
00446 int match_ext(const char *filename, const char *extensions);
00447
00448 #endif
00449
00450 #ifdef __cplusplus
00451 }
00452 #endif
00453
00454 #endif
00455