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