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