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