00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FFMPEG_AVFORMAT_H
00022 #define FFMPEG_AVFORMAT_H
00023
00024 #define LIBAVFORMAT_VERSION_INT ((52<<16)+(7<<8)+0)
00025 #define LIBAVFORMAT_VERSION 52.7.0
00026 #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
00027
00028 #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
00029
00030 #include <time.h>
00031 #include <stdio.h>
00032 #include "avcodec.h"
00033
00034 #include "avio.h"
00035
00036
00037
00038 typedef struct AVPacket {
00039 int64_t pts;
00040 int64_t dts;
00041 uint8_t *data;
00042 int size;
00043 int stream_index;
00044 int flags;
00045 int duration;
00046 void (*destruct)(struct AVPacket *);
00047 void *priv;
00048 int64_t pos;
00049 } AVPacket;
00050 #define PKT_FLAG_KEY 0x0001
00051
00052 void av_destruct_packet_nofree(AVPacket *pkt);
00053
00057 void av_destruct_packet(AVPacket *pkt);
00058
00064 void av_init_packet(AVPacket *pkt);
00065
00073 int av_new_packet(AVPacket *pkt, int size);
00074
00082 int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
00083
00088 int av_dup_packet(AVPacket *pkt);
00089
00095 static inline void av_free_packet(AVPacket *pkt)
00096 {
00097 if (pkt && pkt->destruct) {
00098 pkt->destruct(pkt);
00099 }
00100 }
00101
00102
00103
00104
00110 typedef struct AVFrac {
00111 int64_t val, num, den;
00112 } AVFrac attribute_deprecated;
00113
00114
00115
00116
00117 struct AVCodecTag;
00118
00119 struct AVFormatContext;
00120
00122 typedef struct AVProbeData {
00123 const char *filename;
00124 unsigned char *buf;
00125 int buf_size;
00126 } AVProbeData;
00127
00128 #define AVPROBE_SCORE_MAX 100
00129 #define AVPROBE_PADDING_SIZE 32
00130
00131 typedef struct AVFormatParameters {
00132 AVRational time_base;
00133 int sample_rate;
00134 int channels;
00135 int width;
00136 int height;
00137 enum PixelFormat pix_fmt;
00138 int channel;
00139 const char *standard;
00140 int mpeg2ts_raw:1;
00141 int mpeg2ts_compute_pcr:1;
00144 int initial_pause:1;
00146 int prealloced_context:1;
00147 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00148 enum CodecID video_codec_id;
00149 enum CodecID audio_codec_id;
00150 #endif
00151 } AVFormatParameters;
00152
00154 #define AVFMT_NOFILE 0x0001
00155 #define AVFMT_NEEDNUMBER 0x0002
00156 #define AVFMT_SHOW_IDS 0x0008
00157 #define AVFMT_RAWPICTURE 0x0020
00159 #define AVFMT_GLOBALHEADER 0x0040
00160 #define AVFMT_NOTIMESTAMPS 0x0080
00161 #define AVFMT_GENERIC_INDEX 0x0100
00163 typedef struct AVOutputFormat {
00164 const char *name;
00165 const char *long_name;
00166 const char *mime_type;
00167 const char *extensions;
00169 int priv_data_size;
00170
00171 enum CodecID audio_codec;
00172 enum CodecID video_codec;
00173 int (*write_header)(struct AVFormatContext *);
00174 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
00175 int (*write_trailer)(struct AVFormatContext *);
00177 int flags;
00179 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
00180 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
00181
00186 const struct AVCodecTag **codec_tag;
00187
00188 enum CodecID subtitle_codec;
00190
00191 struct AVOutputFormat *next;
00192 } AVOutputFormat;
00193
00194 typedef struct AVInputFormat {
00195 const char *name;
00196 const char *long_name;
00198 int priv_data_size;
00204 int (*read_probe)(AVProbeData *);
00209 int (*read_header)(struct AVFormatContext *,
00210 AVFormatParameters *ap);
00214 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
00217 int (*read_close)(struct AVFormatContext *);
00226 int (*read_seek)(struct AVFormatContext *,
00227 int stream_index, int64_t timestamp, int flags);
00232 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
00233 int64_t *pos, int64_t pos_limit);
00235 int flags;
00239 const char *extensions;
00241 int value;
00242
00245 int (*read_play)(struct AVFormatContext *);
00246
00249 int (*read_pause)(struct AVFormatContext *);
00250
00251 const struct AVCodecTag **codec_tag;
00252
00253
00254 struct AVInputFormat *next;
00255 } AVInputFormat;
00256
00257 enum AVStreamParseType {
00258 AVSTREAM_PARSE_NONE,
00259 AVSTREAM_PARSE_FULL,
00260 AVSTREAM_PARSE_HEADERS,
00261 AVSTREAM_PARSE_TIMESTAMPS,
00262 };
00263
00264 typedef struct AVIndexEntry {
00265 int64_t pos;
00266 int64_t timestamp;
00267 #define AVINDEX_KEYFRAME 0x0001
00268 int flags:2;
00269 int size:30;
00270 int min_distance;
00271 } AVIndexEntry;
00272
00280 typedef struct AVStream {
00281 int index;
00282 int id;
00283 AVCodecContext *codec;
00292 AVRational r_frame_rate;
00293 void *priv_data;
00294
00295
00296 int64_t first_dts;
00298 struct AVFrac pts;
00299
00306 AVRational time_base;
00307 int pts_wrap_bits;
00308
00309 int stream_copy;
00310 enum AVDiscard discard;
00311
00314 float quality;
00323 int64_t start_time;
00329 int64_t duration;
00330
00331 char language[4];
00333
00334 enum AVStreamParseType need_parsing;
00335 struct AVCodecParserContext *parser;
00336
00337 int64_t cur_dts;
00338 int last_IP_duration;
00339 int64_t last_IP_pts;
00340
00341 AVIndexEntry *index_entries;
00343 int nb_index_entries;
00344 unsigned int index_entries_allocated_size;
00345
00346 int64_t nb_frames;
00347
00348 #define MAX_REORDER_DELAY 4
00349 int64_t pts_buffer[MAX_REORDER_DELAY+1];
00350
00351 char *filename;
00352 } AVStream;
00353
00354 #define AV_PROGRAM_RUNNING 1
00355
00362 typedef struct AVProgram {
00363 int id;
00364 char *provider_name;
00365 char *name;
00366 int flags;
00367 enum AVDiscard discard;
00368 unsigned int *stream_index;
00369 unsigned int nb_stream_indexes;
00370 } AVProgram;
00371
00372 #define AVFMTCTX_NOHEADER 0x0001
00375 #define MAX_STREAMS 20
00376
00384 typedef struct AVFormatContext {
00385 const AVClass *av_class;
00386
00387 struct AVInputFormat *iformat;
00388 struct AVOutputFormat *oformat;
00389 void *priv_data;
00390 ByteIOContext *pb;
00391 unsigned int nb_streams;
00392 AVStream *streams[MAX_STREAMS];
00393 char filename[1024];
00394
00395 int64_t timestamp;
00396 char title[512];
00397 char author[512];
00398 char copyright[512];
00399 char comment[512];
00400 char album[512];
00401 int year;
00402 int track;
00403 char genre[32];
00405 int ctx_flags;
00406
00410 struct AVPacketList *packet_buffer;
00411
00415 int64_t start_time;
00419 int64_t duration;
00421 int64_t file_size;
00425 int bit_rate;
00426
00427
00428 AVStream *cur_st;
00429 const uint8_t *cur_ptr;
00430 int cur_len;
00431 AVPacket cur_pkt;
00432
00433
00434 int64_t data_offset;
00435 int index_built;
00436
00437 int mux_rate;
00438 int packet_size;
00439 int preload;
00440 int max_delay;
00441
00442 #define AVFMT_NOOUTPUTLOOP -1
00443 #define AVFMT_INFINITEOUTPUTLOOP 0
00444
00445 int loop_output;
00446
00447 int flags;
00448 #define AVFMT_FLAG_GENPTS 0x0001
00449 #define AVFMT_FLAG_IGNIDX 0x0002
00450 #define AVFMT_FLAG_NONBLOCK 0x0004
00451
00452 int loop_input;
00454 unsigned int probesize;
00455
00459 int max_analyze_duration;
00460
00461 const uint8_t *key;
00462 int keylen;
00463
00464 unsigned int nb_programs;
00465 AVProgram **programs;
00466
00471 enum CodecID video_codec_id;
00476 enum CodecID audio_codec_id;
00481 enum CodecID subtitle_codec_id;
00482
00493 unsigned int max_index_size;
00494 } AVFormatContext;
00495
00496 typedef struct AVPacketList {
00497 AVPacket pkt;
00498 struct AVPacketList *next;
00499 } AVPacketList;
00500
00501 #if LIBAVFORMAT_VERSION_INT < (53<<16)
00502 extern AVInputFormat *first_iformat;
00503 extern AVOutputFormat *first_oformat;
00504 #endif
00505
00506 AVInputFormat *av_iformat_next(AVInputFormat *f);
00507 AVOutputFormat *av_oformat_next(AVOutputFormat *f);
00508
00509 enum CodecID av_guess_image2_codec(const char *filename);
00510
00511
00512
00513
00514
00515 void av_register_input_format(AVInputFormat *format);
00516 void av_register_output_format(AVOutputFormat *format);
00517 AVOutputFormat *guess_stream_format(const char *short_name,
00518 const char *filename, const char *mime_type);
00519 AVOutputFormat *guess_format(const char *short_name,
00520 const char *filename, const char *mime_type);
00521
00525 enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
00526 const char *filename, const char *mime_type, enum CodecType type);
00527
00537 void av_hex_dump(FILE *f, uint8_t *buf, int size);
00538
00551 void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
00552
00560 void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
00561
00572 void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
00573
00574 void av_register_all(void);
00575
00577 enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
00578 unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
00579
00580
00581
00585 AVInputFormat *av_find_input_format(const char *short_name);
00586
00593 AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
00594
00599 int av_open_input_stream(AVFormatContext **ic_ptr,
00600 ByteIOContext *pb, const char *filename,
00601 AVInputFormat *fmt, AVFormatParameters *ap);
00602
00614 int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
00615 AVInputFormat *fmt,
00616 int buf_size,
00617 AVFormatParameters *ap);
00623 AVFormatContext *av_alloc_format_context(void);
00624
00637 int av_find_stream_info(AVFormatContext *ic);
00638
00649 int av_read_packet(AVFormatContext *s, AVPacket *pkt);
00650
00670 int av_read_frame(AVFormatContext *s, AVPacket *pkt);
00671
00683 int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
00684
00689 int av_read_play(AVFormatContext *s);
00690
00696 int av_read_pause(AVFormatContext *s);
00697
00702 void av_close_input_stream(AVFormatContext *s);
00703
00709 void av_close_input_file(AVFormatContext *s);
00710
00721 AVStream *av_new_stream(AVFormatContext *s, int id);
00722 AVProgram *av_new_program(AVFormatContext *s, int id);
00723
00733 void av_set_pts_info(AVStream *s, int pts_wrap_bits,
00734 int pts_num, int pts_den);
00735
00736 #define AVSEEK_FLAG_BACKWARD 1
00737 #define AVSEEK_FLAG_BYTE 2
00738 #define AVSEEK_FLAG_ANY 4
00739
00740 int av_find_default_stream_index(AVFormatContext *s);
00741
00750 int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
00751
00759 void ff_reduce_index(AVFormatContext *s, int stream_index);
00760
00766 int av_add_index_entry(AVStream *st,
00767 int64_t pos, int64_t timestamp, int size, int distance, int flags);
00768
00775 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
00776
00785 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
00786
00793 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 ));
00794
00796 int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
00797
00805 int av_write_header(AVFormatContext *s);
00806
00818 int av_write_frame(AVFormatContext *s, AVPacket *pkt);
00819
00834 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
00835
00850 int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
00851
00859 int av_write_trailer(AVFormatContext *s);
00860
00861 void dump_format(AVFormatContext *ic,
00862 int index,
00863 const char *url,
00864 int is_output);
00865
00870 attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
00871
00876 attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
00877
00904 int64_t parse_date(const char *datestr, int duration);
00905
00906 int64_t av_gettime(void);
00907
00908
00909 #define FFM_PACKET_SIZE 4096
00910 offset_t ffm_read_write_index(int fd);
00911 void ffm_write_write_index(int fd, offset_t pos);
00912 void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
00913
00920 int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
00921
00934 int av_get_frame_filename(char *buf, int buf_size,
00935 const char *path, int number);
00936
00943 int av_filename_number_test(const char *filename);
00944
00959 int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
00960
00961 #ifdef HAVE_AV_CONFIG_H
00962
00963 void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
00964
00965 #ifdef __GNUC__
00966 #define dynarray_add(tab, nb_ptr, elem)\
00967 do {\
00968 typeof(tab) _tab = (tab);\
00969 typeof(elem) _elem = (elem);\
00970 (void)sizeof(**_tab == _elem); \
00971 __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
00972 } while(0)
00973 #else
00974 #define dynarray_add(tab, nb_ptr, elem)\
00975 do {\
00976 __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
00977 } while(0)
00978 #endif
00979
00980 time_t mktimegm(struct tm *tm);
00981 struct tm *brktimegm(time_t secs, struct tm *tm);
00982 const char *small_strptime(const char *p, const char *fmt,
00983 struct tm *dt);
00984
00985 struct in_addr;
00986 int resolve_host(struct in_addr *sin_addr, const char *hostname);
00987
00988 void url_split(char *proto, int proto_size,
00989 char *authorization, int authorization_size,
00990 char *hostname, int hostname_size,
00991 int *port_ptr,
00992 char *path, int path_size,
00993 const char *url);
00994
00995 int match_ext(const char *filename, const char *extensions);
00996
00997 #endif
00998
00999 #endif