Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 094d9df7

History | View | Annotate | Download (42.2 KB)

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
typedef struct AVMetadata 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(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(AVMetadata **m, AVMetadataTag tag);
95

    
96
/**
97
 * Free all the memory allocated for an AVMetadata struct.
98
 */
99
void av_metadata_free(AVMetadata **m);
100

    
101

    
102
/* packet functions */
103

    
104
typedef struct AVPacket {
105
    /**
106
     * Presentation timestamp in time_base units.
107
     * This is the time at which the decompressed packet will be presented
108
     * to the user.
109
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
110
     * pts MUST be larger or equal to dts as presentation cannot happen before
111
     * decompression, unless one wants to view hex dumps. Some formats misuse
112
     * the terms dts and pts/cts to mean something different, these timestamps
113
     * must be converted to true pts/dts before they are stored in AVPacket.
114
     */
115
    int64_t pts;
116
    /**
117
     * Decompression timestamp in time_base units.
118
     * This is the time at which the packet is decompressed.
119
     * Can be AV_NOPTS_VALUE if it is not stored in the file.
120
     */
121
    int64_t dts;
122
    uint8_t *data;
123
    int   size;
124
    int   stream_index;
125
    int   flags;
126
    /**
127
     * Duration of this packet in time_base units, 0 if unknown.
128
     * Equals next_pts - this_pts in presentation order.
129
     */
130
    int   duration;
131
    void  (*destruct)(struct AVPacket *);
132
    void  *priv;
133
    int64_t pos;                            ///< byte position in stream, -1 if unknown
134

    
135
    /**
136
     * Time difference in stream time base units from the pts of this
137
     * packet to the point at which the output from the decoder has converged
138
     * independent from the availability of previous frames. That is, the
139
     * frames are virtually identical no matter if decoding started from
140
     * the very first frame or from this keyframe.
141
     * Is AV_NOPTS_VALUE if unknown.
142
     * This field is not the display duration of the current packet.
143
     *
144
     * The purpose of this field is to allow seeking in streams that have no
145
     * keyframes in the conventional sense. It corresponds to the
146
     * recovery point SEI in H.264 and match_time_delta in NUT. It is also
147
     * essential for some types of subtitle streams to ensure that all
148
     * subtitles are correctly displayed after seeking.
149
     */
150
    int64_t convergence_duration;
151
} AVPacket;
152
#define PKT_FLAG_KEY   0x0001
153

    
154
void av_destruct_packet_nofree(AVPacket *pkt);
155

    
156
/**
157
 * Default packet destructor.
158
 */
159
void av_destruct_packet(AVPacket *pkt);
160

    
161
/**
162
 * Initialize optional fields of a packet with default values.
163
 *
164
 * @param pkt packet
165
 */
166
void av_init_packet(AVPacket *pkt);
167

    
168
/**
169
 * Allocate the payload of a packet and initialize its fields with
170
 * default values.
171
 *
172
 * @param pkt packet
173
 * @param size wanted payload size
174
 * @return 0 if OK, AVERROR_xxx otherwise
175
 */
176
int av_new_packet(AVPacket *pkt, int size);
177

    
178
/**
179
 * Allocate and read the payload of a packet and initialize its fields with
180
 * default values.
181
 *
182
 * @param pkt packet
183
 * @param size desired payload size
184
 * @return >0 (read size) if OK, AVERROR_xxx otherwise
185
 */
186
int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
187

    
188
/**
189
 * @warning This is a hack - the packet memory allocation stuff is broken. The
190
 * packet is allocated if it was not really allocated.
191
 */
192
int av_dup_packet(AVPacket *pkt);
193

    
194
/**
195
 * Free a packet.
196
 *
197
 * @param pkt packet to free
198
 */
199
static inline void av_free_packet(AVPacket *pkt)
200
{
201
    if (pkt && pkt->destruct) {
202
        pkt->destruct(pkt);
203
    }
204
}
205

    
206
/*************************************************/
207
/* fractional numbers for exact pts handling */
208

    
209
/**
210
 * The exact value of the fractional number is: 'val + num / den'.
211
 * num is assumed to be 0 <= num < den.
212
 * @deprecated Use AVRational instead.
213
*/
214
typedef struct AVFrac {
215
    int64_t val, num, den;
216
} AVFrac;
217

    
218
/*************************************************/
219
/* input/output formats */
220

    
221
struct AVCodecTag;
222

    
223
struct AVFormatContext;
224

    
225
/** This structure contains the data a format has to probe a file. */
226
typedef struct AVProbeData {
227
    const char *filename;
228
    unsigned char *buf;
229
    int buf_size;
230
} AVProbeData;
231

    
232
#define AVPROBE_SCORE_MAX 100               ///< Maximum score, half of that is used for file-extension-based detection.
233
#define AVPROBE_PADDING_SIZE 32             ///< extra allocated bytes at the end of the probe buffer
234

    
235
typedef struct AVFormatParameters {
236
    AVRational time_base;
237
    int sample_rate;
238
    int channels;
239
    int width;
240
    int height;
241
    enum PixelFormat pix_fmt;
242
    int channel; /**< Used to select DV channel. */
243
    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
244
    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
245
    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
246
                                            stream packet (only meaningful if
247
                                            mpeg2ts_raw is TRUE). */
248
    unsigned int initial_pause:1;       /**< Do not begin to play the stream
249
                                            immediately (RTSP only). */
250
    unsigned int prealloced_context:1;
251
#if LIBAVFORMAT_VERSION_INT < (53<<16)
252
    enum CodecID video_codec_id;
253
    enum CodecID audio_codec_id;
254
#endif
255
} AVFormatParameters;
256

    
257
//! Demuxer will use url_fopen, no opened file should be provided by the caller.
258
#define AVFMT_NOFILE        0x0001
259
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
260
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
261
#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
262
                                      raw picture data. */
263
#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
264
#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
265
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
266
#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. */
267

    
268
typedef struct AVOutputFormat {
269
    const char *name;
270
    /**
271
     * Descriptive name for the format, meant to be more human-readable
272
     * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
273
     * to define it.
274
     */
275
    const char *long_name;
276
    const char *mime_type;
277
    const char *extensions; /**< comma-separated filename extensions */
278
    /** Size of private data so that it can be allocated in the wrapper. */
279
    int priv_data_size;
280
    /* output support */
281
    enum CodecID audio_codec; /**< default audio codec */
282
    enum CodecID video_codec; /**< default video codec */
283
    int (*write_header)(struct AVFormatContext *);
284
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
285
    int (*write_trailer)(struct AVFormatContext *);
286
    /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
287
    int flags;
288
    /** Currently only used to set pixel format if not YUV420P. */
289
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
290
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
291
                             AVPacket *in, int flush);
292

    
293
    /**
294
     * List of supported codec_id-codec_tag pairs, ordered by "better
295
     * choice first". The arrays are all CODEC_ID_NONE terminated.
296
     */
297
    const struct AVCodecTag * const *codec_tag;
298

    
299
    enum CodecID subtitle_codec; /**< default subtitle codec */
300

    
301
    /* private fields */
302
    struct AVOutputFormat *next;
303
} AVOutputFormat;
304

    
305
typedef struct AVInputFormat {
306
    const char *name;
307
    /**
308
     * Descriptive name for the format, meant to be more human-readable
309
     * than \p name. You \e should use the NULL_IF_CONFIG_SMALL() macro
310
     * to define it.
311
     */
312
    const char *long_name;
313
    /** Size of private data so that it can be allocated in the wrapper. */
314
    int priv_data_size;
315
    /**
316
     * Tell if a given file has a chance of being parsed by this format.
317
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
318
     * big so you do not have to check for that unless you need more.
319
     */
320
    int (*read_probe)(AVProbeData *);
321
    /** Read the format header and initialize the AVFormatContext
322
       structure. Return 0 if OK. 'ap' if non-NULL contains
323
       additional parameters. Only used in raw format right
324
       now. 'av_new_stream' should be called to create new streams.  */
325
    int (*read_header)(struct AVFormatContext *,
326
                       AVFormatParameters *ap);
327
    /** Read one packet and put it in 'pkt'. pts and flags are also
328
       set. 'av_new_stream' can be called only if the flag
329
       AVFMTCTX_NOHEADER is used. */
330
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
331
    /** Close the stream. The AVFormatContext and AVStreams are not
332
       freed by this function */
333
    int (*read_close)(struct AVFormatContext *);
334
    /**
335
     * Seek to a given timestamp relative to the frames in
336
     * stream component stream_index.
337
     * @param stream_index must not be -1
338
     * @param flags selects which direction should be preferred if no exact
339
     *              match is available
340
     * @return >= 0 on success (but not necessarily the new offset)
341
     */
342
    int (*read_seek)(struct AVFormatContext *,
343
                     int stream_index, int64_t timestamp, int flags);
344
    /**
345
     * Gets the next timestamp in stream[stream_index].time_base units.
346
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
347
     */
348
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
349
                              int64_t *pos, int64_t pos_limit);
350
    /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
351
    int flags;
352
    /** If extensions are defined, then no probe is done. You should
353
       usually not use extension format guessing because it is not
354
       reliable enough */
355
    const char *extensions;
356
    /** General purpose read-only value that the format can use. */
357
    int value;
358

    
359
    /** Start/resume playing - only meaningful if using a network-based format
360
       (RTSP). */
361
    int (*read_play)(struct AVFormatContext *);
362

    
363
    /** Pause playing - only meaningful if using a network-based format
364
       (RTSP). */
365
    int (*read_pause)(struct AVFormatContext *);
366

    
367
    const struct AVCodecTag * const *codec_tag;
368

    
369
    /* private fields */
370
    struct AVInputFormat *next;
371
} AVInputFormat;
372

    
373
enum AVStreamParseType {
374
    AVSTREAM_PARSE_NONE,
375
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
376
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
377
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
378
};
379

    
380
typedef struct AVIndexEntry {
381
    int64_t pos;
382
    int64_t timestamp;
383
#define AVINDEX_KEYFRAME 0x0001
384
    int flags:2;
385
    int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment).
386
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
387
} AVIndexEntry;
388

    
389
#define AV_DISPOSITION_DEFAULT   0x0001
390
#define AV_DISPOSITION_DUB       0x0002
391
#define AV_DISPOSITION_ORIGINAL  0x0004
392
#define AV_DISPOSITION_COMMENT   0x0008
393
#define AV_DISPOSITION_LYRICS    0x0010
394
#define AV_DISPOSITION_KARAOKE   0x0020
395

    
396
/**
397
 * Stream structure.
398
 * New fields can be added to the end with minor version bumps.
399
 * Removal, reordering and changes to existing fields require a major
400
 * version bump.
401
 * sizeof(AVStream) must not be used outside libav*.
402
 */
403
typedef struct AVStream {
404
    int index;    /**< stream index in AVFormatContext */
405
    int id;       /**< format-specific stream ID */
406
    AVCodecContext *codec; /**< codec context */
407
    /**
408
     * Real base frame rate of the stream.
409
     * This is the lowest frame rate with which all timestamps can be
410
     * represented accurately (it is the least common multiple of all
411
     * frame rates in the stream). Note, this value is just a guess!
412
     * For example if the time base is 1/90000 and all frames have either
413
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
414
     */
415
    AVRational r_frame_rate;
416
    void *priv_data;
417

    
418
    /* internal data used in av_find_stream_info() */
419
    int64_t first_dts;
420
    /** encoding: pts generation when outputting stream */
421
    struct AVFrac pts;
422

    
423
    /**
424
     * This is the fundamental unit of time (in seconds) in terms
425
     * of which frame timestamps are represented. For fixed-fps content,
426
     * time base should be 1/frame rate and timestamp increments should be 1.
427
     */
428
    AVRational time_base;
429
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
430
    /* ffmpeg.c private use */
431
    int stream_copy; /**< If set, just copy stream. */
432
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
433
    //FIXME move stuff to a flags field?
434
    /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
435
     * MN: dunno if that is the right place for it */
436
    float quality;
437
    /**
438
     * Decoding: pts of the first frame of the stream, in stream time base.
439
     * Only set this if you are absolutely 100% sure that the value you set
440
     * it to really is the pts of the first frame.
441
     * This may be undefined (AV_NOPTS_VALUE).
442
     * @note The ASF header does NOT contain a correct start_time the ASF
443
     * demuxer must NOT set this.
444
     */
445
    int64_t start_time;
446
    /**
447
     * Decoding: duration of the stream, in stream time base.
448
     * If a source file does not specify a duration, but does specify
449
     * a bitrate, this value will be estimated from bitrate and file size.
450
     */
451
    int64_t duration;
452

    
453
    char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */
454

    
455
    /* av_read_frame() support */
456
    enum AVStreamParseType need_parsing;
457
    struct AVCodecParserContext *parser;
458

    
459
    int64_t cur_dts;
460
    int last_IP_duration;
461
    int64_t last_IP_pts;
462
    /* av_seek_frame() support */
463
    AVIndexEntry *index_entries; /**< Only used if the format does not
464
                                    support seeking natively. */
465
    int nb_index_entries;
466
    unsigned int index_entries_allocated_size;
467

    
468
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
469

    
470
#if LIBAVFORMAT_VERSION_INT < (53<<16)
471
    int64_t unused[4+1];
472
#endif
473

    
474
    char *filename; /**< source filename of the stream */
475

    
476
    int disposition; /**< AV_DISPOSITION_* bit field */
477

    
478
    AVProbeData probe_data;
479
#define MAX_REORDER_DELAY 16
480
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
481

    
482
    /**
483
     * sample aspect ratio (0 if unknown)
484
     * - encoding: Set by user.
485
     * - decoding: Set by libavformat.
486
     */
487
    AVRational sample_aspect_ratio;
488

    
489
    AVMetadata *metadata;
490
} AVStream;
491

    
492
#define AV_PROGRAM_RUNNING 1
493

    
494
/**
495
 * New fields can be added to the end with minor version bumps.
496
 * Removal, reordering and changes to existing fields require a major
497
 * version bump.
498
 * sizeof(AVProgram) must not be used outside libav*.
499
 */
500
typedef struct AVProgram {
501
    int            id;
502
    char           *provider_name; ///< network name for DVB streams
503
    char           *name;          ///< service name for DVB streams
504
    int            flags;
505
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
506
    unsigned int   *stream_index;
507
    unsigned int   nb_stream_indexes;
508
    AVMetadata *metadata;
509
} AVProgram;
510

    
511
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
512
                                         (streams are added dynamically) */
513

    
514
typedef struct AVChapter {
515
    int id;                 ///< unique ID to identify the chapter
516
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
517
    int64_t start, end;     ///< chapter start/end time in time_base units
518
    char *title;            ///< chapter title
519
    AVMetadata *metadata;
520
} AVChapter;
521

    
522
#define MAX_STREAMS 20
523

    
524
/**
525
 * Format I/O context.
526
 * New fields can be added to the end with minor version bumps.
527
 * Removal, reordering and changes to existing fields require a major
528
 * version bump.
529
 * sizeof(AVFormatContext) must not be used outside libav*.
530
 */
531
typedef struct AVFormatContext {
532
    const AVClass *av_class; /**< Set by av_alloc_format_context. */
533
    /* Can only be iformat or oformat, not both at the same time. */
534
    struct AVInputFormat *iformat;
535
    struct AVOutputFormat *oformat;
536
    void *priv_data;
537
    ByteIOContext *pb;
538
    unsigned int nb_streams;
539
    AVStream *streams[MAX_STREAMS];
540
    char filename[1024]; /**< input or output filename */
541
    /* stream info */
542
    int64_t timestamp;
543
    char title[512];
544
    char author[512];
545
    char copyright[512];
546
    char comment[512];
547
    char album[512];
548
    int year;  /**< ID3 year, 0 if none */
549
    int track; /**< track number, 0 if none */
550
    char genre[32]; /**< ID3 genre */
551

    
552
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
553
    /* private data for pts handling (do not modify directly). */
554
    /** This buffer is only needed when packets were already buffered but
555
       not decoded, for example to get the codec parameters in MPEG
556
       streams. */
557
    struct AVPacketList *packet_buffer;
558

    
559
    /** Decoding: position of the first frame of the component, in
560
       AV_TIME_BASE fractional seconds. NEVER set this value directly:
561
       It is deduced from the AVStream values.  */
562
    int64_t start_time;
563
    /** Decoding: duration of the stream, in AV_TIME_BASE fractional
564
       seconds. NEVER set this value directly: it is deduced from the
565
       AVStream values.  */
566
    int64_t duration;
567
    /** decoding: total file size, 0 if unknown */
568
    int64_t file_size;
569
    /** Decoding: total stream bitrate in bit/s, 0 if not
570
       available. Never set it directly if the file_size and the
571
       duration are known as ffmpeg can compute it automatically. */
572
    int bit_rate;
573

    
574
    /* av_read_frame() support */
575
    AVStream *cur_st;
576
    const uint8_t *cur_ptr;
577
    int cur_len;
578
    AVPacket cur_pkt;
579

    
580
    /* av_seek_frame() support */
581
    int64_t data_offset; /** offset of the first packet */
582
    int index_built;
583

    
584
    int mux_rate;
585
    int packet_size;
586
    int preload;
587
    int max_delay;
588

    
589
#define AVFMT_NOOUTPUTLOOP -1
590
#define AVFMT_INFINITEOUTPUTLOOP 0
591
    /** number of times to loop output in formats that support it */
592
    int loop_output;
593

    
594
    int flags;
595
#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate pts if missing even if it requires parsing future frames.
596
#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
597
#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
598

    
599
    int loop_input;
600
    /** Decoding: size of data to probe; encoding: unused. */
601
    unsigned int probesize;
602

    
603
    /**
604
     * Maximum time (in AV_TIME_BASE units) during which the input should
605
     * be analyzed in av_find_stream_info().
606
     */
607
    int max_analyze_duration;
608

    
609
    const uint8_t *key;
610
    int keylen;
611

    
612
    unsigned int nb_programs;
613
    AVProgram **programs;
614

    
615
    /**
616
     * Forced video codec_id.
617
     * Demuxing: Set by user.
618
     */
619
    enum CodecID video_codec_id;
620
    /**
621
     * Forced audio codec_id.
622
     * Demuxing: Set by user.
623
     */
624
    enum CodecID audio_codec_id;
625
    /**
626
     * Forced subtitle codec_id.
627
     * Demuxing: Set by user.
628
     */
629
    enum CodecID subtitle_codec_id;
630

    
631
    /**
632
     * Maximum amount of memory in bytes to use per stream for the index.
633
     * If the needed index exceeds this size, entries will be discarded as
634
     * needed to maintain a smaller size. This can lead to slower or less
635
     * accurate seeking (depends on demuxer).
636
     * Demuxers for which a full in-memory index is mandatory will ignore
637
     * this.
638
     * muxing  : unused
639
     * demuxing: set by user
640
     */
641
    unsigned int max_index_size;
642

    
643
    /**
644
     * Maximum amount of memory in bytes to use for buffering frames
645
     * obtained from realtime capture devices.
646
     */
647
    unsigned int max_picture_buffer;
648

    
649
    unsigned int nb_chapters;
650
    AVChapter **chapters;
651

    
652
    /**
653
     * Flags to enable debugging.
654
     */
655
    int debug;
656
#define FF_FDEBUG_TS        0x0001
657

    
658
    /**
659
     * Raw packets from the demuxer, prior to parsing and decoding.
660
     * This buffer is used for buffering packets until the codec can
661
     * be identified, as parsing cannot be done without knowing the
662
     * codec.
663
     */
664
    struct AVPacketList *raw_packet_buffer;
665
    struct AVPacketList *raw_packet_buffer_end;
666

    
667
    struct AVPacketList *packet_buffer_end;
668

    
669
    AVMetadata *metadata;
670
} AVFormatContext;
671

    
672
typedef struct AVPacketList {
673
    AVPacket pkt;
674
    struct AVPacketList *next;
675
} AVPacketList;
676

    
677
#if LIBAVFORMAT_VERSION_INT < (53<<16)
678
extern AVInputFormat *first_iformat;
679
extern AVOutputFormat *first_oformat;
680
#endif
681

    
682
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
683
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
684

    
685
enum CodecID av_guess_image2_codec(const char *filename);
686

    
687
/* XXX: use automatic init with either ELF sections or C file parser */
688
/* modules */
689

    
690
/* utils.c */
691
void av_register_input_format(AVInputFormat *format);
692
void av_register_output_format(AVOutputFormat *format);
693
AVOutputFormat *guess_stream_format(const char *short_name,
694
                                    const char *filename,
695
                                    const char *mime_type);
696
AVOutputFormat *guess_format(const char *short_name,
697
                             const char *filename,
698
                             const char *mime_type);
699

    
700
/**
701
 * Guesses the codec ID based upon muxer and filename.
702
 */
703
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
704
                            const char *filename, const char *mime_type,
705
                            enum CodecType type);
706

    
707
/**
708
 * Send a nice hexadecimal dump of a buffer to the specified file stream.
709
 *
710
 * @param f The file stream pointer where the dump should be sent to.
711
 * @param buf buffer
712
 * @param size buffer size
713
 *
714
 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
715
 */
716
void av_hex_dump(FILE *f, uint8_t *buf, int size);
717

    
718
/**
719
 * Send a nice hexadecimal dump of a buffer to the log.
720
 *
721
 * @param avcl A pointer to an arbitrary struct of which the first field is a
722
 * pointer to an AVClass struct.
723
 * @param level The importance level of the message, lower values signifying
724
 * higher importance.
725
 * @param buf buffer
726
 * @param size buffer size
727
 *
728
 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
729
 */
730
void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
731

    
732
/**
733
 * Send a nice dump of a packet to the specified file stream.
734
 *
735
 * @param f The file stream pointer where the dump should be sent to.
736
 * @param pkt packet to dump
737
 * @param dump_payload True if the payload must be displayed, too.
738
 */
739
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
740

    
741
/**
742
 * Send a nice dump of a packet to the log.
743
 *
744
 * @param avcl A pointer to an arbitrary struct of which the first field is a
745
 * pointer to an AVClass struct.
746
 * @param level The importance level of the message, lower values signifying
747
 * higher importance.
748
 * @param pkt packet to dump
749
 * @param dump_payload True if the payload must be displayed, too.
750
 */
751
void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
752

    
753
void av_register_all(void);
754

    
755
/** codec tag <-> codec id */
756
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
757
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
758

    
759
/* media file input */
760

    
761
/**
762
 * Finds AVInputFormat based on the short name of the input format.
763
 */
764
AVInputFormat *av_find_input_format(const char *short_name);
765

    
766
/**
767
 * Guess file format.
768
 *
769
 * @param is_opened Whether the file is already opened; determines whether
770
 *                  demuxers with or without AVFMT_NOFILE are probed.
771
 */
772
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
773

    
774
/**
775
 * Allocates all the structures needed to read an input stream.
776
 *        This does not open the needed codecs for decoding the stream[s].
777
 */
778
int av_open_input_stream(AVFormatContext **ic_ptr,
779
                         ByteIOContext *pb, const char *filename,
780
                         AVInputFormat *fmt, AVFormatParameters *ap);
781

    
782
/**
783
 * Open a media file as input. The codecs are not opened. Only the file
784
 * header (if present) is read.
785
 *
786
 * @param ic_ptr The opened media file handle is put here.
787
 * @param filename filename to open
788
 * @param fmt If non-NULL, force the file format to use.
789
 * @param buf_size optional buffer size (zero if default is OK)
790
 * @param ap Additional parameters needed when opening the file
791
 *           (NULL if default).
792
 * @return 0 if OK, AVERROR_xxx otherwise
793
 */
794
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
795
                       AVInputFormat *fmt,
796
                       int buf_size,
797
                       AVFormatParameters *ap);
798
/**
799
 * Allocate an AVFormatContext.
800
 * Can be freed with av_free() but do not forget to free everything you
801
 * explicitly allocated as well!
802
 */
803
AVFormatContext *av_alloc_format_context(void);
804

    
805
/**
806
 * Read packets of a media file to get stream information. This
807
 * is useful for file formats with no headers such as MPEG. This
808
 * function also computes the real frame rate in case of MPEG-2 repeat
809
 * frame mode.
810
 * The logical file position is not changed by this function;
811
 * examined packets may be buffered for later processing.
812
 *
813
 * @param ic media file handle
814
 * @return >=0 if OK, AVERROR_xxx on error
815
 * @todo Let the user decide somehow what information is needed so that
816
 *       we do not waste time getting stuff the user does not need.
817
 */
818
int av_find_stream_info(AVFormatContext *ic);
819

    
820
/**
821
 * Read a transport packet from a media file.
822
 *
823
 * This function is obsolete and should never be used.
824
 * Use av_read_frame() instead.
825
 *
826
 * @param s media file handle
827
 * @param pkt is filled
828
 * @return 0 if OK, AVERROR_xxx on error
829
 */
830
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
831

    
832
/**
833
 * Return the next frame of a stream.
834
 *
835
 * The returned packet is valid
836
 * until the next av_read_frame() or until av_close_input_file() and
837
 * must be freed with av_free_packet. For video, the packet contains
838
 * exactly one frame. For audio, it contains an integer number of
839
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
840
 * data). If the audio frames have a variable size (e.g. MPEG audio),
841
 * then it contains one frame.
842
 *
843
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
844
 * values in AVStream.timebase units (and guessed if the format cannot
845
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
846
 * has B-frames, so it is better to rely on pkt->dts if you do not
847
 * decompress the payload.
848
 *
849
 * @return 0 if OK, < 0 on error or end of file
850
 */
851
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
852

    
853
/**
854
 * Seek to the key frame at timestamp.
855
 * 'timestamp' in 'stream_index'.
856
 * @param stream_index If stream_index is (-1), a default
857
 * stream is selected, and timestamp is automatically converted
858
 * from AV_TIME_BASE units to the stream specific time_base.
859
 * @param timestamp Timestamp in AVStream.time_base units
860
 *        or, if no stream is specified, in AV_TIME_BASE units.
861
 * @param flags flags which select direction and seeking mode
862
 * @return >= 0 on success
863
 */
864
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
865
                  int flags);
866

    
867
/**
868
 * Start playing a network based stream (e.g. RTSP stream) at the
869
 * current position.
870
 */
871
int av_read_play(AVFormatContext *s);
872

    
873
/**
874
 * Pause a network based stream (e.g. RTSP stream).
875
 *
876
 * Use av_read_play() to resume it.
877
 */
878
int av_read_pause(AVFormatContext *s);
879

    
880
/**
881
 * Free a AVFormatContext allocated by av_open_input_stream.
882
 * @param s context to free
883
 */
884
void av_close_input_stream(AVFormatContext *s);
885

    
886
/**
887
 * Close a media file (but not its codecs).
888
 *
889
 * @param s media file handle
890
 */
891
void av_close_input_file(AVFormatContext *s);
892

    
893
/**
894
 * Add a new stream to a media file.
895
 *
896
 * Can only be called in the read_header() function. If the flag
897
 * AVFMTCTX_NOHEADER is in the format context, then new streams
898
 * can be added in read_packet too.
899
 *
900
 * @param s media file handle
901
 * @param id file-format-dependent stream ID
902
 */
903
AVStream *av_new_stream(AVFormatContext *s, int id);
904
AVProgram *av_new_program(AVFormatContext *s, int id);
905

    
906
/**
907
 * Add a new chapter.
908
 * This function is NOT part of the public API
909
 * and should ONLY be used by demuxers.
910
 *
911
 * @param s media file handle
912
 * @param id unique ID for this chapter
913
 * @param start chapter start time in time_base units
914
 * @param end chapter end time in time_base units
915
 * @param title chapter title
916
 *
917
 * @return AVChapter or NULL on error
918
 */
919
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
920
                          int64_t start, int64_t end, const char *title);
921

    
922
/**
923
 * Set the pts for a given stream.
924
 *
925
 * @param s stream
926
 * @param pts_wrap_bits number of bits effectively used by the pts
927
 *        (used for wrap control, 33 is the value for MPEG)
928
 * @param pts_num numerator to convert to seconds (MPEG: 1)
929
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
930
 */
931
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
932
                     int pts_num, int pts_den);
933

    
934
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
935
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
936
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
937

    
938
int av_find_default_stream_index(AVFormatContext *s);
939

    
940
/**
941
 * Gets the index for a specific timestamp.
942
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
943
 *                 to the timestamp which is <= the requested one, if backward
944
 *                 is 0, then it will be >=
945
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
946
 * @return < 0 if no such timestamp could be found
947
 */
948
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
949

    
950
/**
951
 * Ensures the index uses less memory than the maximum specified in
952
 * AVFormatContext.max_index_size, by discarding entries if it grows
953
 * too large.
954
 * This function is not part of the public API and should only be called
955
 * by demuxers.
956
 */
957
void ff_reduce_index(AVFormatContext *s, int stream_index);
958

    
959
/**
960
 * Add an index entry into a sorted list. Update the entry if the list
961
 * already contains it.
962
 *
963
 * @param timestamp timestamp in the time base of the given stream
964
 */
965
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
966
                       int size, int distance, int flags);
967

    
968
/**
969
 * Does a binary search using av_index_search_timestamp() and
970
 * AVCodec.read_timestamp().
971
 * This is not supposed to be called directly by a user application,
972
 * but by demuxers.
973
 * @param target_ts target timestamp in the time base of the given stream
974
 * @param stream_index stream number
975
 */
976
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
977
                         int64_t target_ts, int flags);
978

    
979
/**
980
 * Updates cur_dts of all streams based on the given timestamp and AVStream.
981
 *
982
 * Stream ref_st unchanged, others set cur_dts in their native time base.
983
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
984
 * @param timestamp new dts expressed in time_base of param ref_st
985
 * @param ref_st reference stream giving time_base of param timestamp
986
 */
987
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
988

    
989
/**
990
 * Does a binary search using read_timestamp().
991
 * This is not supposed to be called directly by a user application,
992
 * but by demuxers.
993
 * @param target_ts target timestamp in the time base of the given stream
994
 * @param stream_index stream number
995
 */
996
int64_t av_gen_search(AVFormatContext *s, int stream_index,
997
                      int64_t target_ts, int64_t pos_min,
998
                      int64_t pos_max, int64_t pos_limit,
999
                      int64_t ts_min, int64_t ts_max,
1000
                      int flags, int64_t *ts_ret,
1001
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1002

    
1003
/** media file output */
1004
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1005

    
1006
/**
1007
 * Allocate the stream private data and write the stream header to an
1008
 * output media file.
1009
 *
1010
 * @param s media file handle
1011
 * @return 0 if OK, AVERROR_xxx on error
1012
 */
1013
int av_write_header(AVFormatContext *s);
1014

    
1015
/**
1016
 * Write a packet to an output media file.
1017
 *
1018
 * The packet shall contain one audio or video frame.
1019
 * The packet must be correctly interleaved according to the container
1020
 * specification, if not then av_interleaved_write_frame must be used.
1021
 *
1022
 * @param s media file handle
1023
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1024
              dts/pts, ...
1025
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1026
 */
1027
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1028

    
1029
/**
1030
 * Writes a packet to an output media file ensuring correct interleaving.
1031
 *
1032
 * The packet must contain one audio or video frame.
1033
 * If the packets are already correctly interleaved the application should
1034
 * call av_write_frame() instead as it is slightly faster. It is also important
1035
 * to keep in mind that completely non-interleaved input will need huge amounts
1036
 * of memory to interleave with this, so it is preferable to interleave at the
1037
 * demuxer level.
1038
 *
1039
 * @param s media file handle
1040
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1041
              dts/pts, ...
1042
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1043
 */
1044
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1045

    
1046
/**
1047
 * Interleave a packet per dts in an output media file.
1048
 *
1049
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1050
 * function, so they cannot be used after it, note calling av_free_packet()
1051
 * on them is still safe.
1052
 *
1053
 * @param s media file handle
1054
 * @param out the interleaved packet will be output here
1055
 * @param in the input packet
1056
 * @param flush 1 if no further packets are available as input and all
1057
 *              remaining packets should be output
1058
 * @return 1 if a packet was output, 0 if no packet could be output,
1059
 *         < 0 if an error occurred
1060
 */
1061
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1062
                                 AVPacket *pkt, int flush);
1063

    
1064
/**
1065
 * @brief Write the stream trailer to an output media file and
1066
 *        free the file private data.
1067
 *
1068
 * May only be called after a successful call to av_write_header.
1069
 *
1070
 * @param s media file handle
1071
 * @return 0 if OK, AVERROR_xxx on error
1072
 */
1073
int av_write_trailer(AVFormatContext *s);
1074

    
1075
void dump_format(AVFormatContext *ic,
1076
                 int index,
1077
                 const char *url,
1078
                 int is_output);
1079

    
1080
#if LIBAVFORMAT_VERSION_MAJOR < 53
1081
/**
1082
 * Parses width and height out of string str.
1083
 * @deprecated Use av_parse_video_frame_size instead.
1084
 */
1085
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1086
                                          const char *str);
1087

    
1088
/**
1089
 * Converts frame rate from string to a fraction.
1090
 * @deprecated Use av_parse_video_frame_rate instead.
1091
 */
1092
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1093
                                          const char *arg);
1094
#endif
1095

    
1096
/**
1097
 * Parses \p datestr and returns a corresponding number of microseconds.
1098
 * @param datestr String representing a date or a duration.
1099
 * - If a date the syntax is:
1100
 * @code
1101
 *  [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1102
 * @endcode
1103
 * Time is local time unless Z is appended, in which case it is
1104
 * interpreted as UTC.
1105
 * If the year-month-day part is not specified it takes the current
1106
 * year-month-day.
1107
 * Returns the number of microseconds since 1st of January, 1970 up to
1108
 * the time of the parsed date or INT64_MIN if \p datestr cannot be
1109
 * successfully parsed.
1110
 * - If a duration the syntax is:
1111
 * @code
1112
 *  [-]HH[:MM[:SS[.m...]]]
1113
 *  [-]S+[.m...]
1114
 * @endcode
1115
 * Returns the number of microseconds contained in a time interval
1116
 * with the specified duration or INT64_MIN if \p datestr cannot be
1117
 * successfully parsed.
1118
 * @param duration Flag which tells how to interpret \p datestr, if
1119
 * not zero \p datestr is interpreted as a duration, otherwise as a
1120
 * date.
1121
 */
1122
int64_t parse_date(const char *datestr, int duration);
1123

    
1124
/** Gets the current time in microseconds. */
1125
int64_t av_gettime(void);
1126

    
1127
/* ffm-specific for ffserver */
1128
#define FFM_PACKET_SIZE 4096
1129
int64_t ffm_read_write_index(int fd);
1130
void ffm_write_write_index(int fd, int64_t pos);
1131
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1132

    
1133
/**
1134
 * Attempts to find a specific tag in a URL.
1135
 *
1136
 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1137
 * Return 1 if found.
1138
 */
1139
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1140

    
1141
/**
1142
 * Returns in 'buf' the path with '%d' replaced by number.
1143
 *
1144
 * Also handles the '%0nd' format where 'n' is the total number
1145
 * of digits and '%%'.
1146
 *
1147
 * @param buf destination buffer
1148
 * @param buf_size destination buffer size
1149
 * @param path numbered sequence string
1150
 * @param number frame number
1151
 * @return 0 if OK, -1 on format error
1152
 */
1153
int av_get_frame_filename(char *buf, int buf_size,
1154
                          const char *path, int number);
1155

    
1156
/**
1157
 * Check whether filename actually is a numbered sequence generator.
1158
 *
1159
 * @param filename possible numbered sequence string
1160
 * @return 1 if a valid numbered sequence string, 0 otherwise
1161
 */
1162
int av_filename_number_test(const char *filename);
1163

    
1164
/**
1165
 * Generate an SDP for an RTP session.
1166
 *
1167
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1168
 *           array is composed by only one context, such context can contain
1169
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1170
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1171
 *           must contain only one AVStream.
1172
 * @param n_files number of AVCodecContexts contained in ac
1173
 * @param buff buffer where the SDP will be stored (must be allocated by
1174
 *             the caller)
1175
 * @param size the size of the buffer
1176
 * @return 0 if OK, AVERROR_xxx on error
1177
 */
1178
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1179

    
1180
#ifdef HAVE_AV_CONFIG_H
1181

    
1182
void ff_dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem);
1183

    
1184
#ifdef __GNUC__
1185
#define dynarray_add(tab, nb_ptr, elem)\
1186
do {\
1187
    __typeof__(tab) _tab = (tab);\
1188
    __typeof__(elem) _elem = (elem);\
1189
    (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1190
    ff_dynarray_add((unsigned long **)_tab, nb_ptr, (unsigned long)_elem);\
1191
} while(0)
1192
#else
1193
#define dynarray_add(tab, nb_ptr, elem)\
1194
do {\
1195
    ff_dynarray_add((unsigned long **)(tab), nb_ptr, (unsigned long)(elem));\
1196
} while(0)
1197
#endif
1198

    
1199
time_t mktimegm(struct tm *tm);
1200
struct tm *brktimegm(time_t secs, struct tm *tm);
1201
const char *small_strptime(const char *p, const char *fmt,
1202
                           struct tm *dt);
1203

    
1204
struct in_addr;
1205
int resolve_host(struct in_addr *sin_addr, const char *hostname);
1206

    
1207
void url_split(char *proto, int proto_size,
1208
               char *authorization, int authorization_size,
1209
               char *hostname, int hostname_size,
1210
               int *port_ptr,
1211
               char *path, int path_size,
1212
               const char *url);
1213

    
1214
int match_ext(const char *filename, const char *extensions);
1215

    
1216
#endif /* HAVE_AV_CONFIG_H */
1217

    
1218
#endif /* AVFORMAT_AVFORMAT_H */