Read and decode block data in separate functions to prepare support for
[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
98790382
SS
21#ifndef AVFORMAT_AVFORMAT_H
22#define AVFORMAT_AVFORMAT_H
de6d9b64 23
800c289a 24#define LIBAVFORMAT_VERSION_MAJOR 52
6bf22e18 25#define LIBAVFORMAT_VERSION_MINOR 41
7c3c53c8 26#define LIBAVFORMAT_VERSION_MICRO 0
e97ac1e6 27
800c289a
MR
28#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
29 LIBAVFORMAT_VERSION_MINOR, \
30 LIBAVFORMAT_VERSION_MICRO)
31#define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \
32 LIBAVFORMAT_VERSION_MINOR, \
33 LIBAVFORMAT_VERSION_MICRO)
5aa083ee 34#define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT
8026c3b5 35
5aa083ee 36#define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
4b1f4f23 37
c97429e2
SS
38/**
39 * Returns the LIBAVFORMAT_VERSION_INT constant.
40 */
41unsigned avformat_version(void);
42
c1736936
DB
43/**
44 * Returns the libavformat build-time configuration.
45 */
46const char * avformat_configuration(void);
47
48/**
49 * Returns the libavformat license.
50 */
51const char * avformat_license(void);
52
f71869a4 53#include <time.h>
67070e4f 54#include <stdio.h> /* FILE */
76a448ed 55#include "libavcodec/avcodec.h"
de6d9b64 56
de6d9b64
FB
57#include "avio.h"
58
f610a9f2
AJ
59struct AVFormatContext;
60
a6d18a0e
MN
61
62/*
ea29242c
MM
63 * Public Metadata API.
64 * The metadata API allows libavformat to export metadata tags to a client
65 * application using a sequence of key/value pairs.
66 * Important concepts to keep in mind:
67 * 1. Keys are unique; there can never be 2 tags with the same key. This is
68 * also meant semantically, i.e., a demuxer should not knowingly produce
69 * several keys that are literally different but semantically identical.
70 * E.g., key=Author5, key=Author6. In this example, all authors must be
71 * placed in the same tag.
72 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
73 * want to store, e.g., the email address of the child of producer Alice
74 * and actor Bob, that could have key=alice_and_bobs_childs_email_address.
75 * 3. A tag whose value is localized for a particular language is appended
7e030c47 76 * with a dash character ('-') and the ISO 639-2/B 3-letter language code.
ea29242c
MM
77 * For example: Author-ger=Michael, Author-eng=Mike
78 * The original/default language is in the unqualified "Author" tag.
a6d18a0e
MN
79 * A demuxer should set a default if it sets any translated tag.
80 */
81
48a81c0f 82#define AV_METADATA_MATCH_CASE 1
a6d18a0e
MN
83#define AV_METADATA_IGNORE_SUFFIX 2
84
85typedef struct {
86 char *key;
87 char *value;
bc1d2afb 88}AVMetadataTag;
a6d18a0e 89
e232c252 90typedef struct AVMetadata AVMetadata;
f610a9f2 91typedef struct AVMetadataConv AVMetadataConv;
a6d18a0e
MN
92
93/**
22e77e44
DB
94 * Gets a metadata element with matching key.
95 * @param prev Set to the previous matching element to find the next.
96 * @param flags Allows case as well as suffix-insensitive comparisons.
97 * @return Found tag or NULL, changing key or value leads to undefined behavior.
a6d18a0e 98 */
bc1d2afb 99AVMetadataTag *
e232c252 100av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
a6d18a0e
MN
101
102/**
22e77e44
DB
103 * Sets the given tag in m, overwriting an existing tag.
104 * @param key tag key to add to m (will be av_strduped)
105 * @param value tag value to add to m (will be av_strduped)
106 * @return >= 0 on success otherwise an error code <0
a6d18a0e 107 */
5ea7ce88 108int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
a6d18a0e 109
094d9df7 110/**
d1b9adf2 111 * Converts all the metadata sets from ctx according to the source and
f610a9f2
AJ
112 * destination conversion tables.
113 * @param d_conv destination tags format conversion table
114 * @param s_conv source tags format conversion table
115 */
116void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
117 const AVMetadataConv *s_conv);
118
119/**
22e77e44 120 * Frees all the memory allocated for an AVMetadata struct.
094d9df7
AJ
121 */
122void av_metadata_free(AVMetadata **m);
123
a6d18a0e 124
de6d9b64
FB
125/* packet functions */
126
3217cb42
PI
127
128/**
d1b9adf2
SS
129 * Allocates and reads the payload of a packet and initializes its
130 * fields with default values.
3217cb42
PI
131 *
132 * @param pkt packet
4f57fa8c
DB
133 * @param size desired payload size
134 * @return >0 (read size) if OK, AVERROR_xxx otherwise
3217cb42 135 */
2692067a 136int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
3217cb42 137
de6d9b64
FB
138
139/*************************************************/
916c80e9
FB
140/* fractional numbers for exact pts handling */
141
671adb17 142/**
4f57fa8c
DB
143 * The exact value of the fractional number is: 'val + num / den'.
144 * num is assumed to be 0 <= num < den.
4c08b2bd 145 */
916c80e9 146typedef struct AVFrac {
115329f1 147 int64_t val, num, den;
52e57500 148} AVFrac;
916c80e9 149
916c80e9 150/*************************************************/
b9a281db 151/* input/output formats */
de6d9b64 152
7caf0cc6
MN
153struct AVCodecTag;
154
4f57fa8c 155/** This structure contains the data a format has to probe a file. */
b9a281db 156typedef struct AVProbeData {
5c91a675 157 const char *filename;
e5f58f81 158 unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
159 int buf_size; /**< Size of buf except extra allocated bytes */
b9a281db
FB
160} AVProbeData;
161
22e77e44 162#define AVPROBE_SCORE_MAX 100 ///< maximum score, half of that is used for file-extension-based detection
87e87886 163#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer
de6d9b64
FB
164
165typedef struct AVFormatParameters {
c0df9d75 166 AVRational time_base;
de6d9b64
FB
167 int sample_rate;
168 int channels;
169 int width;
170 int height;
4606ac8d 171 enum PixelFormat pix_fmt;
4f57fa8c
DB
172 int channel; /**< Used to select DV channel. */
173 const char *standard; /**< TV standard, NTSC, PAL, SECAM */
174 unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */
175 unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
72e043dd 176 stream packet (only meaningful if
4f57fa8c
DB
177 mpeg2ts_raw is TRUE). */
178 unsigned int initial_pause:1; /**< Do not begin to play the stream
179 immediately (RTSP only). */
72e043dd 180 unsigned int prealloced_context:1;
71957315 181#if LIBAVFORMAT_VERSION_INT < (53<<16)
5b6d5596
MN
182 enum CodecID video_codec_id;
183 enum CodecID audio_codec_id;
71957315 184#endif
de6d9b64
FB
185} AVFormatParameters;
186
4f57fa8c 187//! Demuxer will use url_fopen, no opened file should be provided by the caller.
40d9c544 188#define AVFMT_NOFILE 0x0001
4f57fa8c
DB
189#define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */
190#define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */
191#define AVFMT_RAWPICTURE 0x0020 /**< Format wants AVPicture structure for
192 raw picture data. */
193#define AVFMT_GLOBALHEADER 0x0040 /**< Format wants global header. */
194#define AVFMT_NOTIMESTAMPS 0x0080 /**< Format does not need / have any timestamps. */
195#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
196#define AVFMT_TS_DISCONT 0x0200 /**< Format allows timestamp discontinuities. */
25918212 197#define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */
b9a281db
FB
198
199typedef struct AVOutputFormat {
de6d9b64 200 const char *name;
bde15e74
SS
201 /**
202 * Descriptive name for the format, meant to be more human-readable
819174fa 203 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
204 * to define it.
205 */
de6d9b64
FB
206 const char *long_name;
207 const char *mime_type;
4f57fa8c 208 const char *extensions; /**< comma-separated filename extensions */
22e77e44 209 /** size of private data so that it can be allocated in the wrapper */
b9a281db 210 int priv_data_size;
de6d9b64 211 /* output support */
43d414ba
PI
212 enum CodecID audio_codec; /**< default audio codec */
213 enum CodecID video_codec; /**< default video codec */
de6d9b64 214 int (*write_header)(struct AVFormatContext *);
e928649b 215 int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
de6d9b64 216 int (*write_trailer)(struct AVFormatContext *);
43d414ba 217 /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
b9a281db 218 int flags;
4f57fa8c 219 /** Currently only used to set pixel format if not YUV420P. */
290c5fa6 220 int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
78cb7273
DB
221 int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
222 AVPacket *in, int flush);
7caf0cc6
MN
223
224 /**
78cb7273 225 * List of supported codec_id-codec_tag pairs, ordered by "better
22e77e44 226 * choice first". The arrays are all terminated by CODEC_ID_NONE.
7caf0cc6 227 */
c1854592 228 const struct AVCodecTag * const *codec_tag;
7caf0cc6 229
11bf3847
AJ
230 enum CodecID subtitle_codec; /**< default subtitle codec */
231
719e721a 232 const AVMetadataConv *metadata_conv;
f610a9f2 233
b9a281db
FB
234 /* private fields */
235 struct AVOutputFormat *next;
236} AVOutputFormat;
de6d9b64 237
b9a281db
FB
238typedef struct AVInputFormat {
239 const char *name;
bde15e74
SS
240 /**
241 * Descriptive name for the format, meant to be more human-readable
819174fa 242 * than name. You should use the NULL_IF_CONFIG_SMALL() macro
bde15e74
SS
243 * to define it.
244 */
b9a281db 245 const char *long_name;
4f57fa8c 246 /** Size of private data so that it can be allocated in the wrapper. */
b9a281db 247 int priv_data_size;
65d7d68b 248 /**
22e77e44 249 * Tell if a given file has a chance of being parsed as this format.
5d81d641
DB
250 * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
251 * big so you do not have to check for that unless you need more.
65d7d68b 252 */
b9a281db 253 int (*read_probe)(AVProbeData *);
4f57fa8c
DB
254 /** Read the format header and initialize the AVFormatContext
255 structure. Return 0 if OK. 'ap' if non-NULL contains
256 additional parameters. Only used in raw format right
b9a281db 257 now. 'av_new_stream' should be called to create new streams. */
de6d9b64
FB
258 int (*read_header)(struct AVFormatContext *,
259 AVFormatParameters *ap);
4f57fa8c 260 /** Read one packet and put it in 'pkt'. pts and flags are also
b9a281db 261 set. 'av_new_stream' can be called only if the flag
6883ebe4
RD
262 AVFMTCTX_NOHEADER is used.
263 @return 0 on success, < 0 on error.
264 When returning an error, pkt must not have been allocated
265 or must be freed before returning */
de6d9b64 266 int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
4f57fa8c 267 /** Close the stream. The AVFormatContext and AVStreams are not
de6d9b64
FB
268 freed by this function */
269 int (*read_close)(struct AVFormatContext *);
1de2db8f
MN
270
271#if LIBAVFORMAT_VERSION_MAJOR < 53
115329f1 272 /**
4f57fa8c
DB
273 * Seek to a given timestamp relative to the frames in
274 * stream component stream_index.
22e77e44
DB
275 * @param stream_index Must not be -1.
276 * @param flags Selects which direction should be preferred if no exact
277 * match is available.
05ce0f11 278 * @return >= 0 on success (but not necessarily the new offset)
3ba1438d 279 */
115329f1 280 int (*read_seek)(struct AVFormatContext *,
3ba1438d 281 int stream_index, int64_t timestamp, int flags);
1de2db8f 282#endif
8d14a25c 283 /**
4f57fa8c 284 * Gets the next timestamp in stream[stream_index].time_base units.
d9526386 285 * @return the timestamp or AV_NOPTS_VALUE if an error occurred
8d14a25c
MN
286 */
287 int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
288 int64_t *pos, int64_t pos_limit);
4f57fa8c 289 /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
de6d9b64 290 int flags;
4f57fa8c 291 /** If extensions are defined, then no probe is done. You should
b9a281db
FB
292 usually not use extension format guessing because it is not
293 reliable enough */
294 const char *extensions;
4f57fa8c 295 /** General purpose read-only value that the format can use. */
b9a281db 296 int value;
fb2758c8 297
d1b9adf2 298 /** Starts/resumes playing - only meaningful if using a network-based format
4f57fa8c 299 (RTSP). */
fb2758c8
FB
300 int (*read_play)(struct AVFormatContext *);
301
d1b9adf2 302 /** Pauses playing - only meaningful if using a network-based format
4f57fa8c 303 (RTSP). */
fb2758c8
FB
304 int (*read_pause)(struct AVFormatContext *);
305
c1854592 306 const struct AVCodecTag * const *codec_tag;
7caf0cc6 307
1de2db8f 308 /**
d1b9adf2 309 * Seeks to timestamp ts.
1de2db8f
MN
310 * Seeking will be done so that the point from which all active streams
311 * can be presented successfully will be closest to ts and within min/max_ts.
312 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
313 */
882fb0a3 314 int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1de2db8f 315
719e721a 316 const AVMetadataConv *metadata_conv;
f610a9f2 317
b9a281db
FB
318 /* private fields */
319 struct AVInputFormat *next;
320} AVInputFormat;
de6d9b64 321
57004ff1
AJ
322enum AVStreamParseType {
323 AVSTREAM_PARSE_NONE,
324 AVSTREAM_PARSE_FULL, /**< full parsing and repack */
4f57fa8c 325 AVSTREAM_PARSE_HEADERS, /**< Only parse headers, do not repack. */
78cb7273 326 AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
57004ff1
AJ
327};
328
fb2758c8
FB
329typedef struct AVIndexEntry {
330 int64_t pos;
331 int64_t timestamp;
332#define AVINDEX_KEYFRAME 0x0001
30a43f2d 333 int flags:2;
4f57fa8c
DB
334 int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
335 int min_distance; /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
fb2758c8
FB
336} AVIndexEntry;
337
90c2295b
ES
338#define AV_DISPOSITION_DEFAULT 0x0001
339#define AV_DISPOSITION_DUB 0x0002
340#define AV_DISPOSITION_ORIGINAL 0x0004
341#define AV_DISPOSITION_COMMENT 0x0008
342#define AV_DISPOSITION_LYRICS 0x0010
343#define AV_DISPOSITION_KARAOKE 0x0020
344
ba66ae94
MN
345/**
346 * Stream structure.
347 * New fields can be added to the end with minor version bumps.
8bfb108b 348 * Removal, reordering and changes to existing fields require a major
ba66ae94 349 * version bump.
8bfb108b 350 * sizeof(AVStream) must not be used outside libav*.
ba66ae94 351 */
de6d9b64 352typedef struct AVStream {
43d414ba 353 int index; /**< stream index in AVFormatContext */
4f57fa8c 354 int id; /**< format-specific stream ID */
43d414ba 355 AVCodecContext *codec; /**< codec context */
b4b87d48 356 /**
22e77e44
DB
357 * Real base framerate of the stream.
358 * This is the lowest framerate with which all timestamps can be
864ff8c1 359 * represented accurately (it is the least common multiple of all
22e77e44
DB
360 * framerates in the stream). Note, this value is just a guess!
361 * For example, if the time base is 1/90000 and all frames have either
4f57fa8c 362 * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
b4b87d48
MN
363 */
364 AVRational r_frame_rate;
de6d9b64 365 void *priv_data;
82583548 366
b9a281db 367 /* internal data used in av_find_stream_info() */
82583548 368 int64_t first_dts;
4f57fa8c 369 /** encoding: pts generation when outputting stream */
a9fd2b19 370 struct AVFrac pts;
5b28c8c3
MN
371
372 /**
8bfb108b
DB
373 * This is the fundamental unit of time (in seconds) in terms
374 * of which frame timestamps are represented. For fixed-fps content,
22e77e44 375 * time base should be 1/framerate and timestamp increments should be 1.
5b28c8c3 376 */
9ee91c2f 377 AVRational time_base;
43d414ba 378 int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
a48b7a6b 379 /* ffmpeg.c private use */
4f57fa8c
DB
380 int stream_copy; /**< If set, just copy stream. */
381 enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
b4aea108 382 //FIXME move stuff to a flags field?
4f57fa8c 383 /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
755bfeab 384 * MN: dunno if that is the right place for it */
115329f1 385 float quality;
6d96a9b9 386 /**
8bfb108b
DB
387 * Decoding: pts of the first frame of the stream, in stream time base.
388 * Only set this if you are absolutely 100% sure that the value you set
389 * it to really is the pts of the first frame.
4854c253 390 * This may be undefined (AV_NOPTS_VALUE).
8bfb108b
DB
391 * @note The ASF header does NOT contain a correct start_time the ASF
392 * demuxer must NOT set this.
6d96a9b9 393 */
115329f1 394 int64_t start_time;
e26381b6 395 /**
8bfb108b 396 * Decoding: duration of the stream, in stream time base.
e26381b6 397 * If a source file does not specify a duration, but does specify
4f57fa8c 398 * a bitrate, this value will be estimated from bitrate and file size.
e26381b6 399 */
ee404803 400 int64_t duration;
fb2758c8 401
827f7e28 402#if LIBAVFORMAT_VERSION_INT < (53<<16)
7e030c47 403 char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
827f7e28 404#endif
09730260 405
fb2758c8 406 /* av_read_frame() support */
57004ff1 407 enum AVStreamParseType need_parsing;
fb2758c8 408 struct AVCodecParserContext *parser;
6ec87caa 409
fb2758c8 410 int64_t cur_dts;
635fbcb1
MN
411 int last_IP_duration;
412 int64_t last_IP_pts;
fb2758c8 413 /* av_seek_frame() support */
4f57fa8c
DB
414 AVIndexEntry *index_entries; /**< Only used if the format does not
415 support seeking natively. */
fb2758c8 416 int nb_index_entries;
191e8ca7 417 unsigned int index_entries_allocated_size;
115329f1 418
b4b87d48 419 int64_t nb_frames; ///< number of frames in this stream if known or 0
504ee036 420
0d84a8f6
BC
421#if LIBAVFORMAT_VERSION_INT < (53<<16)
422 int64_t unused[4+1];
f8d7c9d3
ES
423
424 char *filename; /**< source filename of the stream */
827f7e28 425#endif
90c2295b 426
4f57fa8c 427 int disposition; /**< AV_DISPOSITION_* bit field */
0bef08e5
MN
428
429 AVProbeData probe_data;
0d84a8f6
BC
430#define MAX_REORDER_DELAY 16
431 int64_t pts_buffer[MAX_REORDER_DELAY+1];
c30a4489
AJ
432
433 /**
434 * sample aspect ratio (0 if unknown)
435 * - encoding: Set by user.
436 * - decoding: Set by libavformat.
437 */
438 AVRational sample_aspect_ratio;
f526adaf 439
e232c252 440 AVMetadata *metadata;
3a41c2f7
MN
441
442 /* av_read_frame() support */
443 const uint8_t *cur_ptr;
444 int cur_len;
445 AVPacket cur_pkt;
27ca0a79
IS
446
447 // Timestamp generation support:
448 /**
449 * Timestamp corresponding to the last dts sync point.
450 *
451 * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
452 * a DTS is received from the underlying container. Otherwise set to
453 * AV_NOPTS_VALUE by default.
454 */
455 int64_t reference_dts;
86cb7e33
BC
456
457 /**
458 * Number of packets to buffer for codec probing
459 * NOT PART OF PUBLIC API
460 */
48616887 461#define MAX_PROBE_PACKETS 2500
86cb7e33 462 int probe_packets;
ddce56ef
MN
463
464 /**
e07b882b 465 * last packet in packet_buffer for this stream when muxing.
ddce56ef
MN
466 * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
467 */
e07b882b 468 struct AVPacketList *last_in_packet_buffer;
de6d9b64
FB
469} AVStream;
470
15afa396
NS
471#define AV_PROGRAM_RUNNING 1
472
ba66ae94 473/**
ba66ae94 474 * New fields can be added to the end with minor version bumps.
8bfb108b 475 * Removal, reordering and changes to existing fields require a major
ba66ae94 476 * version bump.
8bfb108b 477 * sizeof(AVProgram) must not be used outside libav*.
ba66ae94 478 */
15afa396
NS
479typedef struct AVProgram {
480 int id;
827f7e28 481#if LIBAVFORMAT_VERSION_INT < (53<<16)
4f57fa8c
DB
482 char *provider_name; ///< network name for DVB streams
483 char *name; ///< service name for DVB streams
827f7e28 484#endif
15afa396
NS
485 int flags;
486 enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller
526efa10
NS
487 unsigned int *stream_index;
488 unsigned int nb_stream_indexes;
e232c252 489 AVMetadata *metadata;
15afa396
NS
490} AVProgram;
491
43d414ba 492#define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present
da24c5e3
FB
493 (streams are added dynamically) */
494
79d7836a 495typedef struct AVChapter {
4f57fa8c
DB
496 int id; ///< unique ID to identify the chapter
497 AVRational time_base; ///< time base in which the start/end timestamps are specified
8931e7b4 498 int64_t start, end; ///< chapter start/end time in time_base units
827f7e28 499#if LIBAVFORMAT_VERSION_INT < (53<<16)
c2fb6be4 500 char *title; ///< chapter title
827f7e28 501#endif
e232c252 502 AVMetadata *metadata;
79d7836a
AK
503} AVChapter;
504
de6d9b64
FB
505#define MAX_STREAMS 20
506
252f17e2 507/**
4f57fa8c 508 * Format I/O context.
252f17e2 509 * New fields can be added to the end with minor version bumps.
8bfb108b 510 * Removal, reordering and changes to existing fields require a major
252f17e2 511 * version bump.
8bfb108b 512 * sizeof(AVFormatContext) must not be used outside libav*.
252f17e2 513 */
de6d9b64 514typedef struct AVFormatContext {
1447aac4 515 const AVClass *av_class; /**< Set by avformat_alloc_context. */
4f57fa8c 516 /* Can only be iformat or oformat, not both at the same time. */
b9a281db
FB
517 struct AVInputFormat *iformat;
518 struct AVOutputFormat *oformat;
de6d9b64 519 void *priv_data;
899681cd 520 ByteIOContext *pb;
db69c2e5 521 unsigned int nb_streams;
de6d9b64 522 AVStream *streams[MAX_STREAMS];
43d414ba 523 char filename[1024]; /**< input or output filename */
de6d9b64 524 /* stream info */
4568325a 525 int64_t timestamp;
827f7e28 526#if LIBAVFORMAT_VERSION_INT < (53<<16)
de6d9b64
FB
527 char title[512];
528 char author[512];
529 char copyright[512];
530 char comment[512];
6a58e151 531 char album[512];
43d414ba
PI
532 int year; /**< ID3 year, 0 if none */
533 int track; /**< track number, 0 if none */
534 char genre[32]; /**< ID3 genre */
827f7e28 535#endif
6a58e151 536
4f57fa8c
DB
537 int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
538 /* private data for pts handling (do not modify directly). */
43d414ba 539 /** This buffer is only needed when packets were already buffered but
4f57fa8c
DB
540 not decoded, for example to get the codec parameters in MPEG
541 streams. */
ee404803
FB
542 struct AVPacketList *packet_buffer;
543
4f57fa8c 544 /** Decoding: position of the first frame of the component, in
ee404803 545 AV_TIME_BASE fractional seconds. NEVER set this value directly:
4f57fa8c 546 It is deduced from the AVStream values. */
115329f1 547 int64_t start_time;
4f57fa8c 548 /** Decoding: duration of the stream, in AV_TIME_BASE fractional
ee404803
FB
549 seconds. NEVER set this value directly: it is deduced from the
550 AVStream values. */
551 int64_t duration;
4f57fa8c 552 /** decoding: total file size, 0 if unknown */
ee404803 553 int64_t file_size;
4f57fa8c 554 /** Decoding: total stream bitrate in bit/s, 0 if not
ee404803 555 available. Never set it directly if the file_size and the
22e77e44 556 duration are known as FFmpeg can compute it automatically. */
ee404803 557 int bit_rate;
fb2758c8
FB
558
559 /* av_read_frame() support */
560 AVStream *cur_st;
3a41c2f7
MN
561#if LIBAVFORMAT_VERSION_INT < (53<<16)
562 const uint8_t *cur_ptr_deprecated;
563 int cur_len_deprecated;
564 AVPacket cur_pkt_deprecated;
565#endif
fb2758c8 566
fb2758c8 567 /* av_seek_frame() support */
43d414ba 568 int64_t data_offset; /** offset of the first packet */
fb2758c8 569 int index_built;
115329f1 570
2db3c638 571 int mux_rate;
92400be2 572 unsigned int packet_size;
17c88cb0
MN
573 int preload;
574 int max_delay;
8108551a 575
115329f1
DB
576#define AVFMT_NOOUTPUTLOOP -1
577#define AVFMT_INFINITEOUTPUTLOOP 0
43d414ba 578 /** number of times to loop output in formats that support it */
8108551a 579 int loop_output;
115329f1 580
30bc6613 581 int flags;
22e77e44 582#define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames.
4f57fa8c
DB
583#define AVFMT_FLAG_IGNIDX 0x0002 ///< Ignore index.
584#define AVFMT_FLAG_NONBLOCK 0x0004 ///< Do not block when reading packets from input.
5894e1bb
VP
585
586 int loop_input;
22e77e44 587 /** decoding: size of data to probe; encoding: unused. */
9e6c9470 588 unsigned int probesize;
a44b3c4d
MN
589
590 /**
4f57fa8c
DB
591 * Maximum time (in AV_TIME_BASE units) during which the input should
592 * be analyzed in av_find_stream_info().
a44b3c4d
MN
593 */
594 int max_analyze_duration;
c964c2c7
RD
595
596 const uint8_t *key;
597 int keylen;
15afa396
NS
598
599 unsigned int nb_programs;
600 AVProgram **programs;
62600469
MN
601
602 /**
603 * Forced video codec_id.
4f57fa8c 604 * Demuxing: Set by user.
62600469
MN
605 */
606 enum CodecID video_codec_id;
607 /**
608 * Forced audio codec_id.
4f57fa8c 609 * Demuxing: Set by user.
62600469
MN
610 */
611 enum CodecID audio_codec_id;
612 /**
613 * Forced subtitle codec_id.
4f57fa8c 614 * Demuxing: Set by user.
62600469
MN
615 */
616 enum CodecID subtitle_codec_id;
3dea63bd
PK
617
618 /**
22e77e44
DB
619 * Maximum amount of memory in bytes to use for the index of each stream.
620 * If the index exceeds this size, entries will be discarded as
3dea63bd
PK
621 * needed to maintain a smaller size. This can lead to slower or less
622 * accurate seeking (depends on demuxer).
4f57fa8c 623 * Demuxers for which a full in-memory index is mandatory will ignore
3dea63bd
PK
624 * this.
625 * muxing : unused
626 * demuxing: set by user
627 */
628 unsigned int max_index_size;
ab8ab30c
RP
629
630 /**
ffa71b2b 631 * Maximum amount of memory in bytes to use for buffering frames
4f57fa8c 632 * obtained from realtime capture devices.
ab8ab30c
RP
633 */
634 unsigned int max_picture_buffer;
79d7836a 635
fbabf1e9 636 unsigned int nb_chapters;
79d7836a 637 AVChapter **chapters;
45b2b05f
MN
638
639 /**
4f57fa8c 640 * Flags to enable debugging.
45b2b05f
MN
641 */
642 int debug;
643#define FF_FDEBUG_TS 0x0001
0bef08e5
MN
644
645 /**
4f57fa8c 646 * Raw packets from the demuxer, prior to parsing and decoding.
0bef08e5
MN
647 * This buffer is used for buffering packets until the codec can
648 * be identified, as parsing cannot be done without knowing the
649 * codec.
650 */
651 struct AVPacketList *raw_packet_buffer;
5c5b1731
MR
652 struct AVPacketList *raw_packet_buffer_end;
653
654 struct AVPacketList *packet_buffer_end;
47146dfb 655
e232c252 656 AVMetadata *metadata;
af122d6a
BC
657
658 /**
659 * Remaining size available for raw_packet_buffer, in bytes.
660 * NOT PART OF PUBLIC API
661 */
48616887 662#define RAW_PACKET_BUFFER_SIZE 2500000
af122d6a 663 int raw_packet_buffer_remaining_size;
de6d9b64
FB
664} AVFormatContext;
665
666typedef struct AVPacketList {
667 AVPacket pkt;
668 struct AVPacketList *next;
669} AVPacketList;
670
84be6e72 671#if LIBAVFORMAT_VERSION_INT < (53<<16)
b9a281db
FB
672extern AVInputFormat *first_iformat;
673extern AVOutputFormat *first_oformat;
84be6e72
MN
674#endif
675
aeedac95
SS
676/**
677 * If f is NULL, returns the first registered input format,
22e77e44 678 * if f is non-NULL, returns the next registered input format after f
aeedac95
SS
679 * or NULL if f is the last one.
680 */
84be6e72 681AVInputFormat *av_iformat_next(AVInputFormat *f);
aeedac95
SS
682
683/**
684 * If f is NULL, returns the first registered output format,
22e77e44 685 * if f is non-NULL, returns the next registered output format after f
aeedac95
SS
686 * or NULL if f is the last one.
687 */
84be6e72 688AVOutputFormat *av_oformat_next(AVOutputFormat *f);
de6d9b64 689
5b6d5596 690enum CodecID av_guess_image2_codec(const char *filename);
290c5fa6 691
22e77e44
DB
692/* XXX: Use automatic init with either ELF sections or C file parser */
693/* modules. */
de6d9b64 694
b9a281db 695/* utils.c */
b9a281db
FB
696void av_register_input_format(AVInputFormat *format);
697void av_register_output_format(AVOutputFormat *format);
115329f1 698AVOutputFormat *guess_stream_format(const char *short_name,
78cb7273
DB
699 const char *filename,
700 const char *mime_type);
115329f1 701AVOutputFormat *guess_format(const char *short_name,
78cb7273
DB
702 const char *filename,
703 const char *mime_type);
3217cb42
PI
704
705/**
4f57fa8c 706 * Guesses the codec ID based upon muxer and filename.
3217cb42 707 */
115329f1 708enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
78cb7273
DB
709 const char *filename, const char *mime_type,
710 enum CodecType type);
de6d9b64 711
3217cb42 712/**
d1b9adf2 713 * Sends a nice hexadecimal dump of a buffer to the specified file stream.
750f0e1f
PI
714 *
715 * @param f The file stream pointer where the dump should be sent to.
3217cb42
PI
716 * @param buf buffer
717 * @param size buffer size
750f0e1f
PI
718 *
719 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
3217cb42 720 */
fb2758c8 721void av_hex_dump(FILE *f, uint8_t *buf, int size);
3217cb42
PI
722
723/**
d1b9adf2 724 * Sends a nice hexadecimal dump of a buffer to the log.
750f0e1f
PI
725 *
726 * @param avcl A pointer to an arbitrary struct of which the first field is a
727 * pointer to an AVClass struct.
728 * @param level The importance level of the message, lower values signifying
729 * higher importance.
730 * @param buf buffer
731 * @param size buffer size
732 *
733 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
734 */
735void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
736
737/**
d1b9adf2 738 * Sends a nice dump of a packet to the specified file stream.
750f0e1f
PI
739 *
740 * @param f The file stream pointer where the dump should be sent to.
3217cb42 741 * @param pkt packet to dump
4f57fa8c 742 * @param dump_payload True if the payload must be displayed, too.
3217cb42 743 */
fb2758c8 744void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
de6d9b64 745
750f0e1f 746/**
d1b9adf2 747 * Sends a nice dump of a packet to the log.
750f0e1f
PI
748 *
749 * @param avcl A pointer to an arbitrary struct of which the first field is a
750 * pointer to an AVClass struct.
751 * @param level The importance level of the message, lower values signifying
752 * higher importance.
753 * @param pkt packet to dump
4f57fa8c 754 * @param dump_payload True if the payload must be displayed, too.
750f0e1f
PI
755 */
756void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
757
4815e246 758/**
d1b9adf2 759 * Initializes libavformat and registers all the muxers, demuxers and
4815e246
SS
760 * protocols. If you do not call this function, then you can select
761 * exactly which formats you want to support.
762 *
763 * @see av_register_input_format()
764 * @see av_register_output_format()
5d377501 765 * @see av_register_protocol()
4815e246 766 */
94988531 767void av_register_all(void);
de6d9b64 768
43d414ba 769/** codec tag <-> codec id */
15545a09
SS
770enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
771unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
7caf0cc6 772
b9a281db 773/* media file input */
3217cb42
PI
774
775/**
4f57fa8c 776 * Finds AVInputFormat based on the short name of the input format.
3217cb42 777 */
b9a281db 778AVInputFormat *av_find_input_format(const char *short_name);
3217cb42
PI
779
780/**
d1b9adf2 781 * Guesses the file format.
3217cb42 782 *
4f57fa8c
DB
783 * @param is_opened Whether the file is already opened; determines whether
784 * demuxers with or without AVFMT_NOFILE are probed.
3217cb42 785 */
94988531 786AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
3217cb42
PI
787
788/**
789 * Allocates all the structures needed to read an input stream.
790 * This does not open the needed codecs for decoding the stream[s].
791 */
115329f1
DB
792int av_open_input_stream(AVFormatContext **ic_ptr,
793 ByteIOContext *pb, const char *filename,
da24c5e3 794 AVInputFormat *fmt, AVFormatParameters *ap);
3217cb42
PI
795
796/**
d1b9adf2 797 * Opens a media file as input. The codecs are not opened. Only the file
3217cb42
PI
798 * header (if present) is read.
799 *
4f57fa8c
DB
800 * @param ic_ptr The opened media file handle is put here.
801 * @param filename filename to open
802 * @param fmt If non-NULL, force the file format to use.
3217cb42 803 * @param buf_size optional buffer size (zero if default is OK)
78cb7273
DB
804 * @param ap Additional parameters needed when opening the file
805 * (NULL if default).
4f57fa8c 806 * @return 0 if OK, AVERROR_xxx otherwise
3217cb42 807 */
115329f1 808int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
b9a281db
FB
809 AVInputFormat *fmt,
810 int buf_size,
811 AVFormatParameters *ap);
88a28965
SS
812
813#if LIBAVFORMAT_VERSION_MAJOR < 53
814/**
815 * @deprecated Use avformat_alloc_context() instead.
816 */
817attribute_deprecated AVFormatContext *av_alloc_format_context(void);
818#endif
819
88808c60 820/**
d1b9adf2 821 * Allocates an AVFormatContext.
5d81d641 822 * Can be freed with av_free() but do not forget to free everything you
88808c60
MN
823 * explicitly allocated as well!
824 */
88a28965 825AVFormatContext *avformat_alloc_context(void);
b9a281db 826
3217cb42 827/**
d1b9adf2 828 * Reads packets of a media file to get stream information. This
3217cb42 829 * is useful for file formats with no headers such as MPEG. This
22e77e44 830 * function also computes the real framerate in case of MPEG-2 repeat
3217cb42
PI
831 * frame mode.
832 * The logical file position is not changed by this function;
833 * examined packets may be buffered for later processing.
834 *
835 * @param ic media file handle
4f57fa8c
DB
836 * @return >=0 if OK, AVERROR_xxx on error
837 * @todo Let the user decide somehow what information is needed so that
838 * we do not waste time getting stuff the user does not need.
3217cb42 839 */
b9a281db 840int av_find_stream_info(AVFormatContext *ic);
3217cb42
PI
841
842/**
d1b9adf2 843 * Reads a transport packet from a media file.
3217cb42 844 *
864ff8c1 845 * This function is obsolete and should never be used.
3217cb42
PI
846 * Use av_read_frame() instead.
847 *
848 * @param s media file handle
849 * @param pkt is filled
4f57fa8c 850 * @return 0 if OK, AVERROR_xxx on error
3217cb42 851 */
de6d9b64 852int av_read_packet(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
853
854/**
d1b9adf2 855 * Returns the next frame of a stream.
3217cb42
PI
856 *
857 * The returned packet is valid
858 * until the next av_read_frame() or until av_close_input_file() and
859 * must be freed with av_free_packet. For video, the packet contains
860 * exactly one frame. For audio, it contains an integer number of
861 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
862 * data). If the audio frames have a variable size (e.g. MPEG audio),
863 * then it contains one frame.
864 *
865 * pkt->pts, pkt->dts and pkt->duration are always set to correct
22e77e44 866 * values in AVStream.time_base units (and guessed if the format cannot
4f57fa8c
DB
867 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
868 * has B-frames, so it is better to rely on pkt->dts if you do not
3217cb42
PI
869 * decompress the payload.
870 *
4f57fa8c 871 * @return 0 if OK, < 0 on error or end of file
3217cb42 872 */
fb2758c8 873int av_read_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
874
875/**
d1b9adf2 876 * Seeks to the keyframe at timestamp.
3217cb42
PI
877 * 'timestamp' in 'stream_index'.
878 * @param stream_index If stream_index is (-1), a default
879 * stream is selected, and timestamp is automatically converted
880 * from AV_TIME_BASE units to the stream specific time_base.
4f57fa8c
DB
881 * @param timestamp Timestamp in AVStream.time_base units
882 * or, if no stream is specified, in AV_TIME_BASE units.
3217cb42
PI
883 * @param flags flags which select direction and seeking mode
884 * @return >= 0 on success
885 */
78cb7273
DB
886int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
887 int flags);
3217cb42
PI
888
889/**
d1b9adf2 890 * Seeks to timestamp ts.
d04768fa
MN
891 * Seeking will be done so that the point from which all active streams
892 * can be presented successfully will be closest to ts and within min/max_ts.
893 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
894 *
22e77e44 895 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
d04768fa 896 * are the file position (this may not be supported by all demuxers).
22e77e44 897 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
d04768fa 898 * in the stream with stream_index (this may not be supported by all demuxers).
22e77e44
DB
899 * Otherwise all timestamps are in units of the stream selected by stream_index
900 * or if stream_index is -1, in AV_TIME_BASE units.
901 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
d04768fa
MN
902 * keyframes (this may not be supported by all demuxers).
903 *
22e77e44 904 * @param stream_index index of the stream which is used as time base reference
d04768fa
MN
905 * @param min_ts smallest acceptable timestamp
906 * @param ts target timestamp
907 * @param max_ts largest acceptable timestamp
908 * @param flags flags
909 * @returns >=0 on success, error code otherwise
998b6f7c 910 *
22e77e44
DB
911 * @NOTE This is part of the new seek API which is still under construction.
912 * Thus do not use this yet. It may change at any time, do not expect
913 * ABI compatibility yet!
d04768fa
MN
914 */
915int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
916
917/**
d1b9adf2 918 * Starts playing a network-based stream (e.g. RTSP stream) at the
4f57fa8c 919 * current position.
3217cb42 920 */
fb2758c8 921int av_read_play(AVFormatContext *s);
3217cb42
PI
922
923/**
d1b9adf2 924 * Pauses a network-based stream (e.g. RTSP stream).
3217cb42
PI
925 *
926 * Use av_read_play() to resume it.
927 */
fb2758c8 928int av_read_pause(AVFormatContext *s);
3217cb42
PI
929
930/**
d1b9adf2 931 * Frees a AVFormatContext allocated by av_open_input_stream.
2506fd54
RD
932 * @param s context to free
933 */
934void av_close_input_stream(AVFormatContext *s);
935
936/**
d1b9adf2 937 * Closes a media file (but not its codecs).
3217cb42
PI
938 *
939 * @param s media file handle
940 */
de6d9b64 941void av_close_input_file(AVFormatContext *s);
3217cb42
PI
942
943/**
d1b9adf2 944 * Adds a new stream to a media file.
3217cb42
PI
945 *
946 * Can only be called in the read_header() function. If the flag
947 * AVFMTCTX_NOHEADER is in the format context, then new streams
948 * can be added in read_packet too.
949 *
950 * @param s media file handle
4f57fa8c 951 * @param id file-format-dependent stream ID
3217cb42 952 */
b9a281db 953AVStream *av_new_stream(AVFormatContext *s, int id);
15afa396 954AVProgram *av_new_program(AVFormatContext *s, int id);
3217cb42
PI
955
956/**
d1b9adf2 957 * Adds a new chapter.
79d7836a 958 * This function is NOT part of the public API
4f57fa8c 959 * and should ONLY be used by demuxers.
79d7836a
AK
960 *
961 * @param s media file handle
4f57fa8c 962 * @param id unique ID for this chapter
abd2256d
MN
963 * @param start chapter start time in time_base units
964 * @param end chapter end time in time_base units
79d7836a 965 * @param title chapter title
5c37f43a 966 *
4f57fa8c 967 * @return AVChapter or NULL on error
79d7836a 968 */
78cb7273
DB
969AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
970 int64_t start, int64_t end, const char *title);
79d7836a
AK
971
972/**
d1b9adf2 973 * Sets the pts for a given stream.
3217cb42
PI
974 *
975 * @param s stream
976 * @param pts_wrap_bits number of bits effectively used by the pts
977 * (used for wrap control, 33 is the value for MPEG)
978 * @param pts_num numerator to convert to seconds (MPEG: 1)
979 * @param pts_den denominator to convert to seconds (MPEG: 90000)
980 */
9ee91c2f 981void av_set_pts_info(AVStream *s, int pts_wrap_bits,
dec14949 982 unsigned int pts_num, unsigned int pts_den);
de6d9b64 983
3ba1438d
MN
984#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
985#define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes
4f57fa8c 986#define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes
2bf74f49 987#define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number
3ba1438d 988
b754978a 989int av_find_default_stream_index(AVFormatContext *s);
3217cb42
PI
990
991/**
992 * Gets the index for a specific timestamp.
4f57fa8c
DB
993 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
994 * to the timestamp which is <= the requested one, if backward
995 * is 0, then it will be >=
3217cb42
PI
996 * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
997 * @return < 0 if no such timestamp could be found
998 */
dc56fc38 999int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
3217cb42
PI
1000
1001/**
3dea63bd 1002 * Ensures the index uses less memory than the maximum specified in
22e77e44 1003 * AVFormatContext.max_index_size by discarding entries if it grows
3dea63bd
PK
1004 * too large.
1005 * This function is not part of the public API and should only be called
1006 * by demuxers.
1007 */
1008void ff_reduce_index(AVFormatContext *s, int stream_index);
1009
1010/**
d1b9adf2 1011 * Adds an index entry into a sorted list. Updates the entry if the list
4f57fa8c 1012 * already contains it.
3217cb42 1013 *
4f57fa8c 1014 * @param timestamp timestamp in the time base of the given stream
3217cb42 1015 */
78cb7273
DB
1016int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1017 int size, int distance, int flags);
3217cb42
PI
1018
1019/**
78cb7273
DB
1020 * Does a binary search using av_index_search_timestamp() and
1021 * AVCodec.read_timestamp().
1022 * This is not supposed to be called directly by a user application,
1023 * but by demuxers.
3217cb42
PI
1024 * @param target_ts target timestamp in the time base of the given stream
1025 * @param stream_index stream number
1026 */
78cb7273
DB
1027int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1028 int64_t target_ts, int flags);
3217cb42
PI
1029
1030/**
4f57fa8c 1031 * Updates cur_dts of all streams based on the given timestamp and AVStream.
3217cb42 1032 *
4f57fa8c
DB
1033 * Stream ref_st unchanged, others set cur_dts in their native time base.
1034 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
3217cb42
PI
1035 * @param timestamp new dts expressed in time_base of param ref_st
1036 * @param ref_st reference stream giving time_base of param timestamp
1037 */
22ffac70 1038void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
3217cb42
PI
1039
1040/**
1041 * Does a binary search using read_timestamp().
78cb7273
DB
1042 * This is not supposed to be called directly by a user application,
1043 * but by demuxers.
3217cb42
PI
1044 * @param target_ts target timestamp in the time base of the given stream
1045 * @param stream_index stream number
1046 */
78cb7273
DB
1047int64_t av_gen_search(AVFormatContext *s, int stream_index,
1048 int64_t target_ts, int64_t pos_min,
1049 int64_t pos_max, int64_t pos_limit,
1050 int64_t ts_min, int64_t ts_max,
1051 int flags, int64_t *ts_ret,
1052 int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
b754978a 1053
43d414ba 1054/** media file output */
290c5fa6 1055int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
3217cb42
PI
1056
1057/**
d1b9adf2 1058 * Allocates the stream private data and writes the stream header to an
755bfeab 1059 * output media file.
3217cb42
PI
1060 *
1061 * @param s media file handle
4f57fa8c 1062 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1063 */
b9a281db 1064int av_write_header(AVFormatContext *s);
3217cb42
PI
1065
1066/**
d1b9adf2 1067 * Writes a packet to an output media file.
3217cb42
PI
1068 *
1069 * The packet shall contain one audio or video frame.
78cb7273
DB
1070 * The packet must be correctly interleaved according to the container
1071 * specification, if not then av_interleaved_write_frame must be used.
3217cb42
PI
1072 *
1073 * @param s media file handle
78cb7273
DB
1074 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1075 dts/pts, ...
4f57fa8c 1076 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1077 */
e928649b 1078int av_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1079
1080/**
1081 * Writes a packet to an output media file ensuring correct interleaving.
1082 *
1083 * The packet must contain one audio or video frame.
22e77e44 1084 * If the packets are already correctly interleaved, the application should
90b5b51e
DB
1085 * call av_write_frame() instead as it is slightly faster. It is also important
1086 * to keep in mind that completely non-interleaved input will need huge amounts
1087 * of memory to interleave with this, so it is preferable to interleave at the
1088 * demuxer level.
3217cb42
PI
1089 *
1090 * @param s media file handle
78cb7273
DB
1091 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1092 dts/pts, ...
4f57fa8c 1093 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
3217cb42 1094 */
3c895fc0 1095int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
3217cb42
PI
1096
1097/**
d1b9adf2 1098 * Interleaves a packet per dts in an output media file.
3217cb42 1099 *
78cb7273 1100 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
22e77e44 1101 * function, so they cannot be used after it. Note that calling av_free_packet()
78cb7273 1102 * on them is still safe.
3217cb42
PI
1103 *
1104 * @param s media file handle
1105 * @param out the interleaved packet will be output here
1106 * @param in the input packet
1107 * @param flush 1 if no further packets are available as input and all
1108 * remaining packets should be output
1109 * @return 1 if a packet was output, 0 if no packet could be output,
d9526386 1110 * < 0 if an error occurred
3217cb42 1111 */
78cb7273
DB
1112int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1113 AVPacket *pkt, int flush);
e928649b 1114
3217cb42 1115/**
2b75bde6
SS
1116 * Writes the stream trailer to an output media file and frees the
1117 * file private data.
3217cb42 1118 *
dc76fe13
RD
1119 * May only be called after a successful call to av_write_header.
1120 *
3217cb42 1121 * @param s media file handle
4f57fa8c 1122 * @return 0 if OK, AVERROR_xxx on error
3217cb42 1123 */
b9a281db 1124int av_write_trailer(AVFormatContext *s);
de6d9b64
FB
1125
1126void dump_format(AVFormatContext *ic,
115329f1 1127 int index,
de6d9b64
FB
1128 const char *url,
1129 int is_output);
3217cb42 1130
1ca9133f 1131#if LIBAVFORMAT_VERSION_MAJOR < 53
3217cb42 1132/**
4f57fa8c 1133 * Parses width and height out of string str.
26ef3220 1134 * @deprecated Use av_parse_video_frame_size instead.
3217cb42 1135 */
78cb7273
DB
1136attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1137 const char *str);
3217cb42
PI
1138
1139/**
22e77e44 1140 * Converts framerate from a string to a fraction.
26ef3220 1141 * @deprecated Use av_parse_video_frame_rate instead.
3217cb42 1142 */
78cb7273
DB
1143attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1144 const char *arg);
1ca9133f 1145#endif
3217cb42
PI
1146
1147/**
819174fa 1148 * Parses datestr and returns a corresponding number of microseconds.
f9436161
SS
1149 * @param datestr String representing a date or a duration.
1150 * - If a date the syntax is:
3217cb42 1151 * @code
3217cb42 1152 * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
3217cb42 1153 * @endcode
4f57fa8c 1154 * Time is local time unless Z is appended, in which case it is
f9436161 1155 * interpreted as UTC.
4f57fa8c 1156 * If the year-month-day part is not specified it takes the current
f9436161
SS
1157 * year-month-day.
1158 * Returns the number of microseconds since 1st of January, 1970 up to
819174fa 1159 * the time of the parsed date or INT64_MIN if datestr cannot be
f9436161
SS
1160 * successfully parsed.
1161 * - If a duration the syntax is:
1162 * @code
1163 * [-]HH[:MM[:SS[.m...]]]
1164 * [-]S+[.m...]
1165 * @endcode
1166 * Returns the number of microseconds contained in a time interval
819174fa 1167 * with the specified duration or INT64_MIN if datestr cannot be
7338d368 1168 * successfully parsed.
819174fa
SS
1169 * @param duration Flag which tells how to interpret datestr, if
1170 * not zero datestr is interpreted as a duration, otherwise as a
f9436161 1171 * date.
3217cb42 1172 */
0c1a9eda 1173int64_t parse_date(const char *datestr, int duration);
de6d9b64 1174
fff5e687 1175/** Gets the current time in microseconds. */
0c1a9eda 1176int64_t av_gettime(void);
94988531 1177
4f57fa8c 1178/* ffm-specific for ffserver */
de6d9b64 1179#define FFM_PACKET_SIZE 4096
bc5c918e 1180int64_t ffm_read_write_index(int fd);
6fcce4f9 1181int ffm_write_write_index(int fd, int64_t pos);
bc5c918e 1182void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
de6d9b64 1183
3217cb42
PI
1184/**
1185 * Attempts to find a specific tag in a URL.
1186 *
1187 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1188 * Return 1 if found.
1189 */
de6d9b64
FB
1190int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1191
3217cb42 1192/**
22e77e44 1193 * Returns in 'buf' the path with '%d' replaced by a number.
4f57fa8c 1194 *
3217cb42
PI
1195 * Also handles the '%0nd' format where 'n' is the total number
1196 * of digits and '%%'.
1197 *
1198 * @param buf destination buffer
1199 * @param buf_size destination buffer size
1200 * @param path numbered sequence string
8ea0e802 1201 * @param number frame number
4f57fa8c 1202 * @return 0 if OK, -1 on format error
3217cb42 1203 */
5c07cf53
MB
1204int av_get_frame_filename(char *buf, int buf_size,
1205 const char *path, int number);
3217cb42
PI
1206
1207/**
d1b9adf2 1208 * Checks whether filename actually is a numbered sequence generator.
3217cb42
PI
1209 *
1210 * @param filename possible numbered sequence string
4f57fa8c 1211 * @return 1 if a valid numbered sequence string, 0 otherwise
3217cb42 1212 */
5c07cf53 1213int av_filename_number_test(const char *filename);
96baaa6a 1214
c5388c07 1215/**
d1b9adf2 1216 * Generates an SDP for an RTP session.
c5388c07
LA
1217 *
1218 * @param ac array of AVFormatContexts describing the RTP streams. If the
1219 * array is composed by only one context, such context can contain
1220 * multiple AVStreams (one AVStream per RTP stream). Otherwise,
1221 * all the contexts in the array (an AVCodecContext per RTP stream)
4f57fa8c 1222 * must contain only one AVStream.
8767b80f
LA
1223 * @param n_files number of AVCodecContexts contained in ac
1224 * @param buff buffer where the SDP will be stored (must be allocated by
4f57fa8c 1225 * the caller)
8767b80f 1226 * @param size the size of the buffer
4f57fa8c 1227 * @return 0 if OK, AVERROR_xxx on error
c5388c07 1228 */
8767b80f 1229int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
c5388c07 1230
fb025625 1231#ifdef HAVE_AV_CONFIG_H
f71869a4 1232
2db5da97 1233void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
39f472c3 1234
e4e70d2e 1235#ifdef __GNUC__
39f472c3
FB
1236#define dynarray_add(tab, nb_ptr, elem)\
1237do {\
72ab9d7f
DP
1238 __typeof__(tab) _tab = (tab);\
1239 __typeof__(elem) _elem = (elem);\
39f472c3 1240 (void)sizeof(**_tab == _elem); /* check that types are compatible */\
2db5da97 1241 ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
39f472c3 1242} while(0)
e4e70d2e
FH
1243#else
1244#define dynarray_add(tab, nb_ptr, elem)\
1245do {\
2db5da97 1246 ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
e4e70d2e
FH
1247} while(0)
1248#endif
39f472c3 1249
f71869a4 1250time_t mktimegm(struct tm *tm);
0c9fc6e1 1251struct tm *brktimegm(time_t secs, struct tm *tm);
115329f1 1252const char *small_strptime(const char *p, const char *fmt,
f71869a4
FB
1253 struct tm *dt);
1254
fb025625
FB
1255struct in_addr;
1256int resolve_host(struct in_addr *sin_addr, const char *hostname);
1257
1258void url_split(char *proto, int proto_size,
6ba5cbc6 1259 char *authorization, int authorization_size,
fb025625
FB
1260 char *hostname, int hostname_size,
1261 int *port_ptr,
1262 char *path, int path_size,
1263 const char *url);
1264
a3303178
SS
1265/**
1266 * Returns a positive value if the given filename has one of the given
1267 * extensions, 0 otherwise.
1268 *
1269 * @param extensions a comma-separated list of filename extensions
1270 */
a941f391
FB
1271int match_ext(const char *filename, const char *extensions);
1272
fb025625
FB
1273#endif /* HAVE_AV_CONFIG_H */
1274
98790382 1275#endif /* AVFORMAT_AVFORMAT_H */