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