Export av_init_packet
[libav.git] / libavformat / avformat.h
CommitLineData
04d7f601
DB
1/*
2 * copyright (c) 2001 Fabrice Bellard
3 *
b78e7197
DB
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
04d7f601
DB
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
04d7f601 10 *
b78e7197 11 * FFmpeg is distributed in the hope that it will be useful,
04d7f601
DB
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
b78e7197 17 * License along with FFmpeg; if not, write to the Free Software
04d7f601
DB
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
fb025625
FB
21#ifndef AVFORMAT_H
22#define AVFORMAT_H
de6d9b64 23
a74008a4
JP
24#define LIBAVFORMAT_VERSION_INT ((51<<16)+(12<<8)+1)
25#define LIBAVFORMAT_VERSION 51.12.1
5aa083ee 26#define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
8026c3b5 27
5aa083ee 28#define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
4b1f4f23 29
f71869a4 30#include <time.h>
67070e4f 31#include <stdio.h> /* FILE */
de6d9b64
FB
32#include "avcodec.h"
33
de6d9b64
FB
34#include "avio.h"
35
36/* packet functions */
37
38typedef struct AVPacket {
2692067a
MN
39 int64_t pts; ///< presentation time stamp in time_base units
40 int64_t dts; ///< decompression time stamp in time_base units
0c1a9eda 41 uint8_t *data;
6fa5a56c
FB
42 int size;
43 int stream_index;
44 int flags;
2692067a 45 int duration; ///< presentation duration in time_base units (0 if not available)
6fa5a56c
FB
46 void (*destruct)(struct AVPacket *);
47 void *priv;
2692067a 48 int64_t pos; ///< byte position in stream, -1 if unknown
115329f1 49} AVPacket;
6fa5a56c
FB
50#define PKT_FLAG_KEY 0x0001
51
63dd1377 52void av_destruct_packet_nofree(AVPacket *pkt);
3217cb42
PI
53
54/**
55 * Default packet destructor.
56 */
90ad92b3 57void av_destruct_packet(AVPacket *pkt);
63dd1377 58
da24c5e3 59/* initialize optional fields of a packet */
659596f0 60void av_init_packet(AVPacket *pkt);
de6d9b64 61
3217cb42
PI
62/**
63 * Allocate the payload of a packet and intialized its fields to default values.
64 *
65 * @param pkt packet
66 * @param size wanted payload size
67 * @return 0 if OK. AVERROR_xxx otherwise.
68 */
de6d9b64 69int av_new_packet(AVPacket *pkt, int size);
3217cb42
PI
70
71/**
72 * Allocate and read the payload of a packet and intialized its fields to default values.
73 *
74 * @param pkt packet
75 * @param size wanted payload size
76 * @return >0 (read size) if OK. AVERROR_xxx otherwise.
77 */
2692067a 78int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
3217cb42 79
43d414ba
PI
80/**
81 * @warning This is a hack - the packet memory allocation stuff is broken. The
82 * packet is allocated if it was not really allocated
83 */
fb2758c8 84int av_dup_packet(AVPacket *pkt);
6fa5a56c
FB
85
86/**
87 * Free a packet
88 *
89 * @param pkt packet to free
90 */
91static inline void av_free_packet(AVPacket *pkt)
92{
342474ab 93 if (pkt && pkt->destruct) {
bb270c08 94 pkt->destruct(pkt);
342474ab 95 }
6fa5a56c 96}
de6d9b64
FB
97
98/*************************************************/
916c80e9
FB
99/* fractional numbers for exact pts handling */
100
671adb17
MC
101/**
102 * the exact value of the fractional number is: 'val + num / den'.
103 * num is assumed to be such as 0 <= num < den
104 * @deprecated Use AVRational instead
105*/
916c80e9 106typedef struct AVFrac {
115329f1 107 int64_t val, num, den;
955ab9a4 108} AVFrac attribute_deprecated;
916c80e9 109
916c80e9 110/*************************************************/
b9a281db 111/* input/output formats */
de6d9b64 112
7caf0cc6
MN
113struct AVCodecTag;
114
de6d9b64 115struct AVFormatContext;
b9a281db 116
43d414ba 117/** this structure contains the data a format has to probe a file */
b9a281db 118typedef struct AVProbeData {
5c91a675 119 const char *filename;
b9a281db
FB
120 unsigned char *buf;
121 int buf_size;
122} AVProbeData;
123
0288a747 124#define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection
87e87886 125#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
de6d9b64
FB
126
127typedef struct AVFormatParameters {
c0df9d75 128 AVRational time_base;
de6d9b64
FB
129 int sample_rate;
130 int channels;
131 int width;
132 int height;
4606ac8d 133 enum PixelFormat pix_fmt;
43d414ba 134 int channel; /**< used to select dv channel */
cc58300e 135#if LIBAVFORMAT_VERSION_INT < (52<<16)
43d414ba 136 const char *device; /**< video, audio or DV device */
cc58300e 137#endif
43d414ba
PI
138 const char *standard; /**< tv standard, NTSC, PAL, SECAM */
139 int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */
140 int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport
da24c5e3
FB
141 stream packet (only meaningful if
142 mpeg2ts_raw is TRUE */
43d414ba 143 int initial_pause:1; /**< do not begin to play the stream
fb2758c8 144 immediately (RTSP only) */
4eb72c6b 145 int prealloced_context:1;
5b6d5596
MN
146 enum CodecID video_codec_id;
147 enum CodecID audio_codec_id;
de6d9b64
FB
148} AVFormatParameters;
149
40d9c544
RD
150//! demuxer will use url_fopen, no opened file should be provided by the caller
151#define AVFMT_NOFILE 0x0001
43d414ba
PI
152#define AVFMT_NEEDNUMBER 0x0002 /**< needs '%d' in filename */
153#define AVFMT_SHOW_IDS 0x0008 /**< show format stream IDs numbers */
154#define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for
fb025625 155 raw picture data */
43d414ba
PI
156#define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */
157#define AVFMT_NOTIMESTAMPS 0x0080 /**< format doesnt need / has any timestamps */
158#define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */
b9a281db
FB
159
160typedef struct AVOutputFormat {
de6d9b64
FB
161 const char *name;
162 const char *long_name;
163 const char *mime_type;
cf29452b 164 const char *extensions; /**< comma separated filename extensions */
43d414ba 165 /** size of private data so that it can be allocated in the wrapper */
b9a281db 166 int priv_data_size;
de6d9b64 167 /* output support */
43d414ba
PI
168 enum CodecID audio_codec; /**< default audio codec */
169 enum CodecID video_codec; /**< default video codec */
de6d9b64 170 int (*write_header)(struct AVFormatContext *);
e928649b 171 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
de6d9b64 172 int (*write_trailer)(struct AVFormatContext *);
43d414ba 173 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
b9a281db 174 int flags;
43d414ba 175 /** currently only used to set pixel format if not YUV420P */
290c5fa6 176 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
fe2d6fe2 177 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush);
7caf0cc6
MN
178
179 /**
180 * list of supported codec_id-codec_tag pairs, ordered by "better choice first"
181 * the arrays are all CODEC_ID_NONE terminated
182 */
6c77805f 183 const struct AVCodecTag **codec_tag;
7caf0cc6 184
b9a281db
FB
185 /* private fields */
186 struct AVOutputFormat *next;
187} AVOutputFormat;
de6d9b64 188
b9a281db
FB
189typedef struct AVInputFormat {
190 const char *name;
191 const char *long_name;
43d414ba 192 /** size of private data so that it can be allocated in the wrapper */
b9a281db 193 int priv_data_size;
43d414ba 194 /** tell if a given file has a chance of being parsing by this format */
b9a281db 195 int (*read_probe)(AVProbeData *);
43d414ba 196 /** read the format header and initialize the AVFormatContext
de6d9b64 197 structure. Return 0 if OK. 'ap' if non NULL contains
e42dba48 198 additional paramters. Only used in raw format right
b9a281db 199 now. 'av_new_stream' should be called to create new streams. */
de6d9b64
FB
200 int (*read_header)(struct AVFormatContext *,
201 AVFormatParameters *ap);
43d414ba 202 /** read one packet and put it in 'pkt'. pts and flags are also
b9a281db 203 set. 'av_new_stream' can be called only if the flag
da24c5e3 204 AVFMTCTX_NOHEADER is used. */
de6d9b64 205 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
43d414ba 206 /** close the stream. The AVFormatContext and AVStreams are not
de6d9b64
FB
207 freed by this function */
208 int (*read_close)(struct AVFormatContext *);
115329f1
DB
209 /**
210 * seek to a given timestamp relative to the frames in
3ba1438d
MN
211 * stream component stream_index
212 * @param stream_index must not be -1
115329f1 213 * @param flags selects which direction should be preferred if no exact
3ba1438d
MN
214 * match is available
215 */
115329f1 216 int (*read_seek)(struct AVFormatContext *,
3ba1438d 217 int stream_index, int64_t timestamp, int flags);
8d14a25c
MN
218 /**
219 * gets the next timestamp in AV_TIME_BASE units.
220 */
221 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
222 int64_t *pos, int64_t pos_limit);
43d414ba 223 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER */
de6d9b64 224 int flags;
43d414ba 225 /** if extensions are defined, then no probe is done. You should
b9a281db
FB
226 usually not use extension format guessing because it is not
227 reliable enough */
228 const char *extensions;
43d414ba 229 /** general purpose read only value that the format can use */
b9a281db 230 int value;
fb2758c8 231
43d414ba 232 /** start/resume playing - only meaningful if using a network based format
fb2758c8
FB
233 (RTSP) */
234 int (*read_play)(struct AVFormatContext *);
235
43d414ba 236 /** pause playing - only meaningful if using a network based format
fb2758c8
FB
237 (RTSP) */
238 int (*read_pause)(struct AVFormatContext *);
239
6c77805f 240 const struct AVCodecTag **codec_tag;
7caf0cc6 241
b9a281db
FB
242 /* private fields */
243 struct AVInputFormat *next;
244} AVInputFormat;
de6d9b64 245
57004ff1
AJ
246enum AVStreamParseType {
247 AVSTREAM_PARSE_NONE,
248 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
249 AVSTREAM_PARSE_HEADERS, /**< only parse headers, don't repack */
250 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */
251};
252
fb2758c8
FB
253typedef struct AVIndexEntry {
254 int64_t pos;
255 int64_t timestamp;
256#define AVINDEX_KEYFRAME 0x0001
30a43f2d
MN
257 int flags:2;
258 int size:30; //yeah trying to keep the size of this small to reduce memory requirements (its 24 vs 32 byte due to possible 8byte align)
43d414ba 259 int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */
fb2758c8
FB
260} AVIndexEntry;
261
de6d9b64 262typedef struct AVStream {
43d414ba
PI
263 int index; /**< stream index in AVFormatContext */
264 int id; /**< format specific stream id */
265 AVCodecContext *codec; /**< codec context */
b4b87d48
MN
266 /**
267 * real base frame rate of the stream.
e3c97c3b
MN
268 * this is the lowest framerate with which all timestamps can be
269 * represented accurately (its the least common multiple of all
270 * framerates in the stream), Note, this value is just a guess!
115329f1 271 * for example if the timebase is 1/90000 and all frames have either
b4b87d48
MN
272 * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1
273 */
274 AVRational r_frame_rate;
de6d9b64 275 void *priv_data;
ea486ab3 276#if LIBAVFORMAT_VERSION_INT < (52<<16)
b9a281db 277 /* internal data used in av_find_stream_info() */
115329f1 278 int64_t codec_info_duration;
fb2758c8 279 int codec_info_nb_frames;
ea486ab3 280#endif
43d414ba 281 /** encoding: PTS generation when outputing stream */
1e51d801 282 AVFrac pts;
5b28c8c3
MN
283
284 /**
285 * this is the fundamental unit of time (in seconds) in terms
286 * of which frame timestamps are represented. for fixed-fps content,
287 * timebase should be 1/framerate and timestamp increments should be
288 * identically 1.
289 */
9ee91c2f 290 AVRational time_base;
43d414ba 291 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
a48b7a6b 292 /* ffmpeg.c private use */
15786dc4 293 int stream_copy; /**< if set, just copy stream */
f3356e9c 294 enum AVDiscard discard; ///< selects which packets can be discarded at will and dont need to be demuxed
b4aea108 295 //FIXME move stuff to a flags field?
43d414ba 296 /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame
1e491e29 297 * MN:dunno if thats the right place, for it */
115329f1 298 float quality;
25406e50 299 /** decoding: pts of the first frame of the stream, in stream time base. */
115329f1 300 int64_t start_time;
25406e50 301 /** decoding: duration of the stream, in stream time base. */
ee404803 302 int64_t duration;
fb2758c8 303
43d414ba 304 char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
09730260 305
fb2758c8 306 /* av_read_frame() support */
57004ff1 307 enum AVStreamParseType need_parsing;
fb2758c8 308 struct AVCodecParserContext *parser;
6ec87caa 309
fb2758c8
FB
310 int64_t cur_dts;
311 int last_IP_duration;
77405fc8 312 int64_t last_IP_pts;
fb2758c8 313 /* av_seek_frame() support */
43d414ba 314 AVIndexEntry *index_entries; /**< only used if the format does not
fb2758c8
FB
315 support seeking natively */
316 int nb_index_entries;
191e8ca7 317 unsigned int index_entries_allocated_size;
115329f1 318
b4b87d48 319 int64_t nb_frames; ///< number of frames in this stream if known or 0
504ee036
MN
320
321#define MAX_REORDER_DELAY 4
322 int64_t pts_buffer[MAX_REORDER_DELAY+1];
de6d9b64
FB
323} AVStream;
324
43d414ba 325#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
da24c5e3
FB
326 (streams are added dynamically) */
327
de6d9b64
FB
328#define MAX_STREAMS 20
329
330/* format I/O context */
331typedef struct AVFormatContext {
43d414ba 332 const AVClass *av_class; /**< set by av_alloc_format_context */
b9a281db
FB
333 /* can only be iformat or oformat, not both at the same time */
334 struct AVInputFormat *iformat;
335 struct AVOutputFormat *oformat;
de6d9b64
FB
336 void *priv_data;
337 ByteIOContext pb;
db69c2e5 338 unsigned int nb_streams;
de6d9b64 339 AVStream *streams[MAX_STREAMS];
43d414ba 340 char filename[1024]; /**< input or output filename */
de6d9b64 341 /* stream info */
4568325a 342 int64_t timestamp;
de6d9b64
FB
343 char title[512];
344 char author[512];
345 char copyright[512];
346 char comment[512];
6a58e151 347 char album[512];
43d414ba
PI
348 int year; /**< ID3 year, 0 if none */
349 int track; /**< track number, 0 if none */
350 char genre[32]; /**< ID3 genre */
6a58e151 351
43d414ba 352 int ctx_flags; /**< format specific flags, see AVFMTCTX_xx */
916c80e9 353 /* private data for pts handling (do not modify directly) */
43d414ba 354 /** This buffer is only needed when packets were already buffered but
de6d9b64
FB
355 not decoded, for example to get the codec parameters in mpeg
356 streams */
ee404803
FB
357 struct AVPacketList *packet_buffer;
358
43d414ba 359 /** decoding: position of the first frame of the component, in
ee404803
FB
360 AV_TIME_BASE fractional seconds. NEVER set this value directly:
361 it is deduced from the AVStream values. */
115329f1 362 int64_t start_time;
43d414ba 363 /** decoding: duration of the stream, in AV_TIME_BASE fractional
ee404803
FB
364 seconds. NEVER set this value directly: it is deduced from the
365 AVStream values. */
366 int64_t duration;
43d414ba 367 /** decoding: total file size. 0 if unknown */
ee404803 368 int64_t file_size;
43d414ba 369 /** decoding: total stream bitrate in bit/s, 0 if not
ee404803
FB
370 available. Never set it directly if the file_size and the
371 duration are known as ffmpeg can compute it automatically. */
372 int bit_rate;
fb2758c8
FB
373
374 /* av_read_frame() support */
375 AVStream *cur_st;
376 const uint8_t *cur_ptr;
377 int cur_len;
378 AVPacket cur_pkt;
379
fb2758c8 380 /* av_seek_frame() support */
43d414ba 381 int64_t data_offset; /** offset of the first packet */
fb2758c8 382 int index_built;
115329f1 383
2db3c638
MN
384 int mux_rate;
385 int packet_size;
17c88cb0
MN
386 int preload;
387 int max_delay;
8108551a 388
115329f1
DB
389#define AVFMT_NOOUTPUTLOOP -1
390#define AVFMT_INFINITEOUTPUTLOOP 0
43d414ba 391 /** number of times to loop output in formats that support it */
8108551a 392 int loop_output;
115329f1 393
30bc6613
MN
394 int flags;
395#define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames
2c00106c 396#define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index
5894e1bb
VP
397
398 int loop_input;
43d414ba 399 /** decoding: size of data to probe; encoding unused */
9e6c9470 400 unsigned int probesize;
a44b3c4d
MN
401
402 /**
403 * maximum duration in AV_TIME_BASE units over which the input should be analyzed in av_find_stream_info()
404 */
405 int max_analyze_duration;
c964c2c7
RD
406
407 const uint8_t *key;
408 int keylen;
de6d9b64
FB
409} AVFormatContext;
410
411typedef struct AVPacketList {
412 AVPacket pkt;
413 struct AVPacketList *next;
414} AVPacketList;
415
b9a281db
FB
416extern AVInputFormat *first_iformat;
417extern AVOutputFormat *first_oformat;
de6d9b64 418
5b6d5596 419enum CodecID av_guess_image2_codec(const char *filename);
290c5fa6 420
b9a281db
FB
421/* XXX: use automatic init with either ELF sections or C file parser */
422/* modules */
de6d9b64 423
fb025625
FB
424#include "rtp.h"
425
426#include "rtsp.h"
427
b9a281db 428/* utils.c */
b9a281db
FB
429void av_register_input_format(AVInputFormat *format);
430void av_register_output_format(AVOutputFormat *format);
115329f1 431AVOutputFormat *guess_stream_format(const char *short_name,
36ada60c 432 const char *filename, const char *mime_type);
115329f1 433AVOutputFormat *guess_format(const char *short_name,
b9a281db 434 const char *filename, const char *mime_type);
3217cb42
PI
435
436/**
437 * Guesses the codec id based upon muxer and filename.
438 */
115329f1 439enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
5b6d5596 440 const char *filename, const char *mime_type, enum CodecType type);
de6d9b64 441
3217cb42 442/**
750f0e1f
PI
443 * Send a nice hexadecimal dump of a buffer to the specified file stream.
444 *
445 * @param f The file stream pointer where the dump should be sent to.
3217cb42
PI
446 * @param buf buffer
447 * @param size buffer size
750f0e1f
PI
448 *
449 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
3217cb42 450 */
fb2758c8 451void av_hex_dump(FILE *f, uint8_t *buf, int size);
3217cb42
PI
452
453/**
750f0e1f
PI
454 * Send a nice hexadecimal dump of a buffer to the log.
455 *
456 * @param avcl A pointer to an arbitrary struct of which the first field is a
457 * pointer to an AVClass struct.
458 * @param level The importance level of the message, lower values signifying
459 * higher importance.
460 * @param buf buffer
461 * @param size buffer size
462 *
463 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
464 */
465void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
466
467/**
468 * Send a nice dump of a packet to the specified file stream.
469 *
470 * @param f The file stream pointer where the dump should be sent to.
3217cb42
PI
471 * @param pkt packet to dump
472 * @param dump_payload true if the payload must be displayed too
473 */
fb2758c8 474void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
de6d9b64 475
750f0e1f
PI
476/**
477 * Send a nice dump of a packet to the log.
478 *
479 * @param avcl A pointer to an arbitrary struct of which the first field is a
480 * pointer to an AVClass struct.
481 * @param level The importance level of the message, lower values signifying
482 * higher importance.
483 * @param pkt packet to dump
484 * @param dump_payload true if the payload must be displayed too
485 */
486void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
487
94988531 488void av_register_all(void);
de6d9b64 489
43d414ba 490/** codec tag <-> codec id */
6c77805f
MN
491enum CodecID av_codec_get_id(const struct AVCodecTag **tags, unsigned int tag);
492unsigned int av_codec_get_tag(const struct AVCodecTag **tags, enum CodecID id);
7caf0cc6 493
b9a281db 494/* media file input */
3217cb42
PI
495
496/**
497 * finds AVInputFormat based on input format's short name.
498 */
b9a281db 499AVInputFormat *av_find_input_format(const char *short_name);
3217cb42
PI
500
501/**
502 * Guess file format.
503 *
504 * @param is_opened whether the file is already opened, determines whether
505 * demuxers with or without AVFMT_NOFILE are probed
506 */
94988531 507AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
3217cb42
PI
508
509/**
510 * Allocates all the structures needed to read an input stream.
511 * This does not open the needed codecs for decoding the stream[s].
512 */
115329f1
DB
513int av_open_input_stream(AVFormatContext **ic_ptr,
514 ByteIOContext *pb, const char *filename,
da24c5e3 515 AVInputFormat *fmt, AVFormatParameters *ap);
3217cb42
PI
516
517/**
518 * Open a media file as input. The codec are not opened. Only the file
519 * header (if present) is read.
520 *
521 * @param ic_ptr the opened media file handle is put here
522 * @param filename filename to open.
523 * @param fmt if non NULL, force the file format to use
524 * @param buf_size optional buffer size (zero if default is OK)
e42dba48 525 * @param ap additional parameters needed when opening the file (NULL if default)
3217cb42
PI
526 * @return 0 if OK. AVERROR_xxx otherwise.
527 */
115329f1 528int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
b9a281db
FB
529 AVInputFormat *fmt,
530 int buf_size,
531 AVFormatParameters *ap);
43d414ba 532/** no av_open for output, so applications will need this: */
bc874dae 533AVFormatContext *av_alloc_format_context(void);
b9a281db 534
3217cb42
PI
535/**
536 * Read packets of a media file to get stream information. This
537 * is useful for file formats with no headers such as MPEG. This
538 * function also computes the real frame rate in case of mpeg2 repeat
539 * frame mode.
540 * The logical file position is not changed by this function;
541 * examined packets may be buffered for later processing.
542 *
543 * @param ic media file handle
544 * @return >=0 if OK. AVERROR_xxx if error.
545 * @todo let user decide somehow what information is needed so we dont waste time geting stuff the user doesnt need
546 */
b9a281db 547int av_find_stream_info(AVFormatContext *ic);
3217cb42
PI
548
549/**
550 * Read a transport packet from a media file.
551 *
552 * This function is absolete and should never be used.
553 * Use av_read_frame() instead.
554 *
555 * @param s media file handle
556 * @param pkt is filled
557 * @return 0 if OK. AVERROR_xxx if error.
558 */
de6d9b64 559int av_read_packet(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
560
561/**
562 * Return the next frame of a stream.
563 *
564 * The returned packet is valid
565 * until the next av_read_frame() or until av_close_input_file() and
566 * must be freed with av_free_packet. For video, the packet contains
567 * exactly one frame. For audio, it contains an integer number of
568 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
569 * data). If the audio frames have a variable size (e.g. MPEG audio),
570 * then it contains one frame.
571 *
572 * pkt->pts, pkt->dts and pkt->duration are always set to correct
a050f802 573 * values in AVStream.timebase units (and guessed if the format cannot
3217cb42
PI
574 * provided them). pkt->pts can be AV_NOPTS_VALUE if the video format
575 * has B frames, so it is better to rely on pkt->dts if you do not
576 * decompress the payload.
577 *
578 * @return 0 if OK, < 0 if error or end of file.
579 */
fb2758c8 580int av_read_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
581
582/**
583 * Seek to the key frame at timestamp.
584 * 'timestamp' in 'stream_index'.
585 * @param stream_index If stream_index is (-1), a default
586 * stream is selected, and timestamp is automatically converted
587 * from AV_TIME_BASE units to the stream specific time_base.
588 * @param timestamp timestamp in AVStream.time_base units
589 * or if there is no stream specified then in AV_TIME_BASE units
590 * @param flags flags which select direction and seeking mode
591 * @return >= 0 on success
592 */
3ba1438d 593int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags);
3217cb42
PI
594
595/**
596 * start playing a network based stream (e.g. RTSP stream) at the
597 * current position
598 */
fb2758c8 599int av_read_play(AVFormatContext *s);
3217cb42
PI
600
601/**
602 * Pause a network based stream (e.g. RTSP stream).
603 *
604 * Use av_read_play() to resume it.
605 */
fb2758c8 606int av_read_pause(AVFormatContext *s);
3217cb42
PI
607
608/**
609 * Close a media file (but not its codecs).
610 *
611 * @param s media file handle
612 */
de6d9b64 613void av_close_input_file(AVFormatContext *s);
3217cb42
PI
614
615/**
616 * Add a new stream to a media file.
617 *
618 * Can only be called in the read_header() function. If the flag
619 * AVFMTCTX_NOHEADER is in the format context, then new streams
620 * can be added in read_packet too.
621 *
622 * @param s media file handle
623 * @param id file format dependent stream id
624 */
b9a281db 625AVStream *av_new_stream(AVFormatContext *s, int id);
3217cb42
PI
626
627/**
628 * Set the pts for a given stream.
629 *
630 * @param s stream
631 * @param pts_wrap_bits number of bits effectively used by the pts
632 * (used for wrap control, 33 is the value for MPEG)
633 * @param pts_num numerator to convert to seconds (MPEG: 1)
634 * @param pts_den denominator to convert to seconds (MPEG: 90000)
635 */
9ee91c2f 636void av_set_pts_info(AVStream *s, int pts_wrap_bits,
916c80e9 637 int pts_num, int pts_den);
de6d9b64 638
3ba1438d
MN
639#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
640#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
27a5fe5f 641#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non keyframes
3ba1438d 642
b754978a 643int av_find_default_stream_index(AVFormatContext *s);
3217cb42
PI
644
645/**
646 * Gets the index for a specific timestamp.
647 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond to
648 * the timestamp which is <= the requested one, if backward is 0
649 * then it will be >=
650 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
651 * @return < 0 if no such timestamp could be found
652 */
dc56fc38 653int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
3217cb42
PI
654
655/**
656 * Add a index entry into a sorted list updateing if it is already there.
657 *
658 * @param timestamp timestamp in the timebase of the given stream
659 */
3e9245a9 660int av_add_index_entry(AVStream *st,
30a43f2d 661 int64_t pos, int64_t timestamp, int size, int distance, int flags);
3217cb42
PI
662
663/**
664 * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp().
665 * this isnt supposed to be called directly by a user application, but by demuxers
666 * @param target_ts target timestamp in the time base of the given stream
667 * @param stream_index stream number
668 */
3ba1438d 669int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
3217cb42
PI
670
671/**
672 * Updates cur_dts of all streams based on given timestamp and AVStream.
673 *
674 * Stream ref_st unchanged, others set cur_dts in their native timebase
675 * only needed for timestamp wrapping or if (dts not set and pts!=dts)
676 * @param timestamp new dts expressed in time_base of param ref_st
677 * @param ref_st reference stream giving time_base of param timestamp
678 */
22ffac70 679void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
3217cb42
PI
680
681/**
682 * Does a binary search using read_timestamp().
683 * this isnt supposed to be called directly by a user application, but by demuxers
684 * @param target_ts target timestamp in the time base of the given stream
685 * @param stream_index stream number
686 */
89ddd2a9 687int64_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 ));
b754978a 688
43d414ba 689/** media file output */
290c5fa6 690int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
3217cb42
PI
691
692/**
693 * allocate the stream private data and write the stream header to an
694 * output media file
695 *
696 * @param s media file handle
697 * @return 0 if OK. AVERROR_xxx if error.
698 */
b9a281db 699int av_write_header(AVFormatContext *s);
3217cb42
PI
700
701/**
702 * Write a packet to an output media file.
703 *
704 * The packet shall contain one audio or video frame.
705 * The packet must be correctly interleaved according to the container specification,
706 * if not then av_interleaved_write_frame must be used
707 *
708 * @param s media file handle
709 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
710 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
711 */
e928649b 712int av_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
713
714/**
715 * Writes a packet to an output media file ensuring correct interleaving.
716 *
717 * The packet must contain one audio or video frame.
718 * If the packets are already correctly interleaved the application should
719 * call av_write_frame() instead as its slightly faster, its also important
720 * to keep in mind that completly non interleaved input will need huge amounts
721 * of memory to interleave with this, so its prefereable to interleave at the
722 * demuxer level
723 *
724 * @param s media file handle
725 * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ...
726 * @return < 0 if error, = 0 if OK, 1 if end of stream wanted.
727 */
3c895fc0 728int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
729
730/**
731 * Interleave a packet per DTS in an output media file.
732 *
733 * Packets with pkt->destruct == av_destruct_packet will be freed inside this function,
734 * so they cannot be used after it, note calling av_free_packet() on them is still safe.
735 *
736 * @param s media file handle
737 * @param out the interleaved packet will be output here
738 * @param in the input packet
739 * @param flush 1 if no further packets are available as input and all
740 * remaining packets should be output
741 * @return 1 if a packet was output, 0 if no packet could be output,
742 * < 0 if an error occured
743 */
f21c0b4c 744int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush);
e928649b 745
3217cb42
PI
746/**
747 * @brief Write the stream trailer to an output media file and
748 * free the file private data.
749 *
750 * @param s media file handle
751 * @return 0 if OK. AVERROR_xxx if error.
752 */
b9a281db 753int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
754
755void dump_format(AVFormatContext *ic,
115329f1 756 int index,
de6d9b64
FB
757 const char *url,
758 int is_output);
3217cb42
PI
759
760/**
761 * parses width and height out of string str.
762 */
de6d9b64 763int parse_image_size(int *width_ptr, int *height_ptr, const char *str);
3217cb42
PI
764
765/**
766 * Converts frame rate from string to a fraction.
3217cb42 767 */
445f1b83 768int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg);
3217cb42
PI
769
770/**
771 * Converts date string to number of seconds since Jan 1st, 1970.
772 *
773 * @code
774 * Syntax:
775 * - If not a duration:
776 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
777 * Time is localtime unless Z is suffixed to the end. In this case GMT
778 * Return the date in micro seconds since 1970
779 *
780 * - If a duration:
781 * HH[:MM[:SS[.m...]]]
782 * S+[.m...]
783 * @endcode
784 */
0c1a9eda 785int64_t parse_date(const char *datestr, int duration);
de6d9b64 786
0c1a9eda 787int64_t av_gettime(void);
94988531 788
de6d9b64
FB
789/* ffm specific for ffserver */
790#define FFM_PACKET_SIZE 4096
791offset_t ffm_read_write_index(int fd);
792void ffm_write_write_index(int fd, offset_t pos);
793void ffm_set_write_index(AVFormatContext *s, offset_t pos, offset_t file_size);
794
3217cb42
PI
795/**
796 * Attempts to find a specific tag in a URL.
797 *
798 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
799 * Return 1 if found.
800 */
de6d9b64
FB
801int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
802
3217cb42
PI
803/**
804 * Returns in 'buf' the path with '%d' replaced by number.
805
806 * Also handles the '%0nd' format where 'n' is the total number
807 * of digits and '%%'.
808 *
809 * @param buf destination buffer
810 * @param buf_size destination buffer size
811 * @param path numbered sequence string
812 * @number frame number
813 * @return 0 if OK, -1 if format error.
814 */
5c07cf53
MB
815int av_get_frame_filename(char *buf, int buf_size,
816 const char *path, int number);
3217cb42
PI
817
818/**
819 * Check whether filename actually is a numbered sequence generator.
820 *
821 * @param filename possible numbered sequence string
822 * @return 1 if a valid numbered sequence string, 0 otherwise.
823 */
5c07cf53 824int av_filename_number_test(const char *filename);
96baaa6a 825
b9a281db
FB
826/* grab specific */
827int video_grab_init(void);
828int audio_init(void);
96baaa6a 829
86fd51fb
FB
830/* DV1394 */
831int dv1394_init(void);
f02be79d 832int dc1394_init(void);
fb025625
FB
833
834#ifdef HAVE_AV_CONFIG_H
f71869a4
FB
835
836#include "os_support.h"
837
fb025625
FB
838int strstart(const char *str, const char *val, const char **ptr);
839int stristart(const char *str, const char *val, const char **ptr);
840void pstrcpy(char *buf, int buf_size, const char *str);
841char *pstrcat(char *buf, int buf_size, const char *s);
fb025625 842
39f472c3
FB
843void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
844
e4e70d2e 845#ifdef __GNUC__
39f472c3
FB
846#define dynarray_add(tab, nb_ptr, elem)\
847do {\
848 typeof(tab) _tab = (tab);\
849 typeof(elem) _elem = (elem);\
850 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
851 __dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
852} while(0)
e4e70d2e
FH
853#else
854#define dynarray_add(tab, nb_ptr, elem)\
855do {\
856 __dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
857} while(0)
858#endif
39f472c3 859
f71869a4 860time_t mktimegm(struct tm *tm);
0c9fc6e1 861struct tm *brktimegm(time_t secs, struct tm *tm);
115329f1 862const char *small_strptime(const char *p, const char *fmt,
f71869a4
FB
863 struct tm *dt);
864
fb025625
FB
865struct in_addr;
866int resolve_host(struct in_addr *sin_addr, const char *hostname);
867
868void url_split(char *proto, int proto_size,
6ba5cbc6 869 char *authorization, int authorization_size,
fb025625
FB
870 char *hostname, int hostname_size,
871 int *port_ptr,
872 char *path, int path_size,
873 const char *url);
874
a941f391
FB
875int match_ext(const char *filename, const char *extensions);
876
fb025625
FB
877#endif /* HAVE_AV_CONFIG_H */
878
879#endif /* AVFORMAT_H */
f3356e9c 880