Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 88e44314

History | View | Annotate | Download (53.7 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 82
26
#define LIBAVFORMAT_VERSION_MICRO  0
27

    
28
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
29
                                               LIBAVFORMAT_VERSION_MINOR, \
30
                                               LIBAVFORMAT_VERSION_MICRO)
31
#define LIBAVFORMAT_VERSION     AV_VERSION(LIBAVFORMAT_VERSION_MAJOR,   \
32
                                           LIBAVFORMAT_VERSION_MINOR,   \
33
                                           LIBAVFORMAT_VERSION_MICRO)
34
#define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
35

    
36
#define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
37

    
38
/**
39
 * Those FF_API_* defines are not part of public API.
40
 * They may change, break or disappear at any time.
41
 */
42
#ifndef FF_API_MAX_STREAMS
43
#define FF_API_MAX_STREAMS   (LIBAVFORMAT_VERSION_MAJOR < 53)
44
#endif
45
#ifndef FF_API_OLD_METADATA
46
#define FF_API_OLD_METADATA  (LIBAVFORMAT_VERSION_MAJOR < 53)
47
#endif
48
#ifndef FF_API_URL_CLASS
49
#define FF_API_URL_CLASS     (LIBAVFORMAT_VERSION_MAJOR >= 53)
50
#endif
51
#ifndef FF_API_URL_RESETBUF
52
#define FF_API_URL_RESETBUF       (LIBAVFORMAT_VERSION_MAJOR < 53)
53
#endif
54
#ifndef FF_API_REGISTER_PROTOCOL
55
#define FF_API_REGISTER_PROTOCOL  (LIBAVFORMAT_VERSION_MAJOR < 53)
56
#endif
57
#ifndef FF_API_GUESS_FORMAT
58
#define FF_API_GUESS_FORMAT       (LIBAVFORMAT_VERSION_MAJOR < 53)
59
#endif
60
#ifndef FF_API_UDP_GET_FILE
61
#define FF_API_UDP_GET_FILE       (LIBAVFORMAT_VERSION_MAJOR < 53)
62
#endif
63
#ifndef FF_API_URL_SPLIT
64
#define FF_API_URL_SPLIT          (LIBAVFORMAT_VERSION_MAJOR < 53)
65
#endif
66

    
67
/**
68
 * I return the LIBAVFORMAT_VERSION_INT constant.  You got
69
 * a fucking problem with that, douchebag?
70
 */
71
unsigned avformat_version(void);
72

    
73
/**
74
 * Return the libavformat build-time configuration.
75
 */
76
const char *avformat_configuration(void);
77

    
78
/**
79
 * Return the libavformat license.
80
 */
81
const char *avformat_license(void);
82

    
83
#include <time.h>
84
#include <stdio.h>  /* FILE */
85
#include "libavcodec/avcodec.h"
86

    
87
#include "avio.h"
88

    
89
struct AVFormatContext;
90

    
91

    
92
/*
93
 * Public Metadata API.
94
 * The metadata API allows libavformat to export metadata tags to a client
95
 * application using a sequence of key/value pairs. Like all strings in FFmpeg,
96
 * metadata must be stored as UTF-8 encoded Unicode. Note that metadata
97
 * exported by demuxers isn't checked to be valid UTF-8 in most cases.
98
 * Important concepts to keep in mind:
99
 * 1. Keys are unique; there can never be 2 tags with the same key. This is
100
 *    also meant semantically, i.e., a demuxer should not knowingly produce
101
 *    several keys that are literally different but semantically identical.
102
 *    E.g., key=Author5, key=Author6. In this example, all authors must be
103
 *    placed in the same tag.
104
 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
105
 *    want to store, e.g., the email address of the child of producer Alice
106
 *    and actor Bob, that could have key=alice_and_bobs_childs_email_address.
107
 * 3. Several modifiers can be applied to the tag name. This is done by
108
 *    appending a dash character ('-') and the modifier name in the order
109
 *    they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng.
110
 *    a) language -- a tag whose value is localized for a particular language
111
 *       is appended with the ISO 639-2/B 3-letter language code.
112
 *       For example: Author-ger=Michael, Author-eng=Mike
113
 *       The original/default language is in the unqualified "Author" tag.
114
 *       A demuxer should set a default if it sets any translated tag.
115
 *    b) sorting  -- a modified version of a tag that should be used for
116
 *       sorting will have '-sort' appended. E.g. artist="The Beatles",
117
 *       artist-sort="Beatles, The".
118
 *
119
 * 4. Tag names are normally exported exactly as stored in the container to
120
 *    allow lossless remuxing to the same format. For container-independent
121
 *    handling of metadata, av_metadata_conv() can convert it to ffmpeg generic
122
 *    format. Follows a list of generic tag names:
123
 *
124
 * album        -- name of the set this work belongs to
125
 * album_artist -- main creator of the set/album, if different from artist.
126
 *                 e.g. "Various Artists" for compilation albums.
127
 * artist       -- main creator of the work
128
 * comment      -- any additional description of the file.
129
 * composer     -- who composed the work, if different from artist.
130
 * copyright    -- name of copyright holder.
131
 * date         -- date when the work was created, preferably in ISO 8601.
132
 * disc         -- number of a subset, e.g. disc in a multi-disc collection.
133
 * encoder      -- name/settings of the software/hardware that produced the file.
134
 * encoded_by   -- person/group who created the file.
135
 * filename     -- original name of the file.
136
 * genre        -- <self-evident>.
137
 * language     -- main language in which the work is performed, preferably
138
 *                 in ISO 639-2 format.
139
 * performer    -- artist who performed the work, if different from artist.
140
 *                 E.g for "Also sprach Zarathustra", artist would be "Richard
141
 *                 Strauss" and performer "London Philharmonic Orchestra".
142
 * publisher    -- name of the label/publisher.
143
 * title        -- name of the work.
144
 * track        -- number of this work in the set, can be in form current/total.
145
 */
146

    
147
#define AV_METADATA_MATCH_CASE      1
148
#define AV_METADATA_IGNORE_SUFFIX   2
149
#define AV_METADATA_DONT_STRDUP_KEY 4
150
#define AV_METADATA_DONT_STRDUP_VAL 8
151
#define AV_METADATA_DONT_OVERWRITE 16   ///< Don't overwrite existing tags.
152

    
153
typedef struct {
154
    char *key;
155
    char *value;
156
}AVMetadataTag;
157

    
158
typedef struct AVMetadata AVMetadata;
159
typedef struct AVMetadataConv AVMetadataConv;
160

    
161
/**
162
 * Get a metadata element with matching key.
163
 *
164
 * @param prev Set to the previous matching element to find the next.
165
 *             If set to NULL the first matching element is returned.
166
 * @param flags Allows case as well as suffix-insensitive comparisons.
167
 * @return Found tag or NULL, changing key or value leads to undefined behavior.
168
 */
169
AVMetadataTag *
170
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
171

    
172
#if FF_API_OLD_METADATA
173
/**
174
 * Set the given tag in *pm, overwriting an existing tag.
175
 *
176
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
177
 * a metadata struct is allocated and put in *pm.
178
 * @param key tag key to add to *pm (will be av_strduped)
179
 * @param value tag value to add to *pm (will be av_strduped)
180
 * @return >= 0 on success otherwise an error code <0
181
 * @deprecated Use av_metadata_set2() instead.
182
 */
183
attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
184
#endif
185

    
186
/**
187
 * Set the given tag in *pm, overwriting an existing tag.
188
 *
189
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
190
 * a metadata struct is allocated and put in *pm.
191
 * @param key tag key to add to *pm (will be av_strduped depending on flags)
192
 * @param value tag value to add to *pm (will be av_strduped depending on flags).
193
 *        Passing a NULL value will cause an existing tag to be deleted.
194
 * @return >= 0 on success otherwise an error code <0
195
 */
196
int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
197

    
198
/**
199
 * Convert all the metadata sets from ctx according to the source and
200
 * destination conversion tables. If one of the tables is NULL, then
201
 * tags are converted to/from ffmpeg generic tag names.
202
 *
203
 * @param d_conv destination tags format conversion table
204
 * @param s_conv source tags format conversion table
205
 */
206
void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
207
                                                   const AVMetadataConv *s_conv);
208

    
209
/**
210
 * Free all the memory allocated for an AVMetadata struct.
211
 */
212
void av_metadata_free(AVMetadata **m);
213

    
214

    
215
/* packet functions */
216

    
217

    
218
/**
219
 * Allocate and read the payload of a packet and initialize its
220
 * fields with default values.
221
 *
222
 * @param pkt packet
223
 * @param size desired payload size
224
 * @return >0 (read size) if OK, AVERROR_xxx otherwise
225
 */
226
int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
227

    
228

    
229
/*************************************************/
230
/* fractional numbers for exact pts handling */
231

    
232
/**
233
 * The exact value of the fractional number is: 'val + num / den'.
234
 * num is assumed to be 0 <= num < den.
235
 */
236
typedef struct AVFrac {
237
    int64_t val, num, den;
238
} AVFrac;
239

    
240
/*************************************************/
241
/* input/output formats */
242

    
243
struct AVCodecTag;
244

    
245
/**
246
 * This structure contains the data a format has to probe a file.
247
 */
248
typedef struct AVProbeData {
249
    const char *filename;
250
    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
251
    int buf_size;       /**< Size of buf except extra allocated bytes */
252
} AVProbeData;
253

    
254
#define AVPROBE_SCORE_MAX 100               ///< maximum score, half of that is used for file-extension-based detection
255
#define AVPROBE_PADDING_SIZE 32             ///< extra allocated bytes at the end of the probe buffer
256

    
257
typedef struct AVFormatParameters {
258
    AVRational time_base;
259
    int sample_rate;
260
    int channels;
261
    int width;
262
    int height;
263
    enum PixelFormat pix_fmt;
264
    int channel; /**< Used to select DV channel. */
265
    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
266
    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
267
    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
268
                                            stream packet (only meaningful if
269
                                            mpeg2ts_raw is TRUE). */
270
    unsigned int initial_pause:1;       /**< Do not begin to play the stream
271
                                            immediately (RTSP only). */
272
    unsigned int prealloced_context:1;
273
#if LIBAVFORMAT_VERSION_INT < (53<<16)
274
    attribute_deprecated enum CodecID video_codec_id;
275
    attribute_deprecated enum CodecID audio_codec_id;
276
#endif
277
} AVFormatParameters;
278

    
279
//! Demuxer will use url_fopen, no opened file should be provided by the caller.
280
#define AVFMT_NOFILE        0x0001
281
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
282
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
283
#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
284
                                      raw picture data. */
285
#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
286
#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
287
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
288
#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. */
289
#define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
290
#define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
291

    
292
typedef struct AVOutputFormat {
293
    const char *name;
294
    /**
295
     * Descriptive name for the format, meant to be more human-readable
296
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
297
     * to define it.
298
     */
299
    const char *long_name;
300
    const char *mime_type;
301
    const char *extensions; /**< comma-separated filename extensions */
302
    /**
303
     * size of private data so that it can be allocated in the wrapper
304
     */
305
    int priv_data_size;
306
    /* output support */
307
    enum CodecID audio_codec; /**< default audio codec */
308
    enum CodecID video_codec; /**< default video codec */
309
    int (*write_header)(struct AVFormatContext *);
310
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
311
    int (*write_trailer)(struct AVFormatContext *);
312
    /**
313
     * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER
314
     */
315
    int flags;
316
    /**
317
     * Currently only used to set pixel format if not YUV420P.
318
     */
319
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
320
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
321
                             AVPacket *in, int flush);
322

    
323
    /**
324
     * List of supported codec_id-codec_tag pairs, ordered by "better
325
     * choice first". The arrays are all terminated by CODEC_ID_NONE.
326
     */
327
    const struct AVCodecTag * const *codec_tag;
328

    
329
    enum CodecID subtitle_codec; /**< default subtitle codec */
330

    
331
    const AVMetadataConv *metadata_conv;
332

    
333
    /* private fields */
334
    struct AVOutputFormat *next;
335
} AVOutputFormat;
336

    
337
typedef struct AVInputFormat {
338
    /**
339
     * A comma separated list of short names for the format. New names
340
     * may be appended with a minor bump.
341
     */
342
    const char *name;
343

    
344
    /**
345
     * Descriptive name for the format, meant to be more human-readable
346
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
347
     * to define it.
348
     */
349
    const char *long_name;
350

    
351
    /**
352
     * Size of private data so that it can be allocated in the wrapper.
353
     */
354
    int priv_data_size;
355

    
356
    /**
357
     * Tell if a given file has a chance of being parsed as this format.
358
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
359
     * big so you do not have to check for that unless you need more.
360
     */
361
    int (*read_probe)(AVProbeData *);
362

    
363
    /**
364
     * Read the format header and initialize the AVFormatContext
365
     * structure. Return 0 if OK. 'ap' if non-NULL contains
366
     * additional parameters. Only used in raw format right
367
     * now. 'av_new_stream' should be called to create new streams.
368
     */
369
    int (*read_header)(struct AVFormatContext *,
370
                       AVFormatParameters *ap);
371

    
372
    /**
373
     * Read one packet and put it in 'pkt'. pts and flags are also
374
     * set. 'av_new_stream' can be called only if the flag
375
     * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
376
     * background thread).
377
     * @return 0 on success, < 0 on error.
378
     *         When returning an error, pkt must not have been allocated
379
     *         or must be freed before returning
380
     */
381
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
382

    
383
    /**
384
     * Close the stream. The AVFormatContext and AVStreams are not
385
     * freed by this function
386
     */
387
    int (*read_close)(struct AVFormatContext *);
388

    
389
#if LIBAVFORMAT_VERSION_MAJOR < 53
390
    /**
391
     * Seek to a given timestamp relative to the frames in
392
     * stream component stream_index.
393
     * @param stream_index Must not be -1.
394
     * @param flags Selects which direction should be preferred if no exact
395
     *              match is available.
396
     * @return >= 0 on success (but not necessarily the new offset)
397
     */
398
    attribute_deprecated int (*read_seek)(struct AVFormatContext *,
399
                                          int stream_index, int64_t timestamp, int flags);
400
#endif
401
    /**
402
     * Gets the next timestamp in stream[stream_index].time_base units.
403
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
404
     */
405
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
406
                              int64_t *pos, int64_t pos_limit);
407

    
408
    /**
409
     * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
410
     */
411
    int flags;
412

    
413
    /**
414
     * If extensions are defined, then no probe is done. You should
415
     * usually not use extension format guessing because it is not
416
     * reliable enough
417
     */
418
    const char *extensions;
419

    
420
    /**
421
     * General purpose read-only value that the format can use.
422
     */
423
    int value;
424

    
425
    /**
426
     * Start/resume playing - only meaningful if using a network-based format
427
     * (RTSP).
428
     */
429
    int (*read_play)(struct AVFormatContext *);
430

    
431
    /**
432
     * Pause playing - only meaningful if using a network-based format
433
     * (RTSP).
434
     */
435
    int (*read_pause)(struct AVFormatContext *);
436

    
437
    const struct AVCodecTag * const *codec_tag;
438

    
439
    /**
440
     * Seek to timestamp ts.
441
     * Seeking will be done so that the point from which all active streams
442
     * can be presented successfully will be closest to ts and within min/max_ts.
443
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
444
     */
445
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
446

    
447
    const AVMetadataConv *metadata_conv;
448

    
449
    /* private fields */
450
    struct AVInputFormat *next;
451
} AVInputFormat;
452

    
453
enum AVStreamParseType {
454
    AVSTREAM_PARSE_NONE,
455
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
456
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
457
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
458
    AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
459
};
460

    
461
typedef struct AVIndexEntry {
462
    int64_t pos;
463
    int64_t timestamp;
464
#define AVINDEX_KEYFRAME 0x0001
465
    int flags:2;
466
    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).
467
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
468
} AVIndexEntry;
469

    
470
#define AV_DISPOSITION_DEFAULT   0x0001
471
#define AV_DISPOSITION_DUB       0x0002
472
#define AV_DISPOSITION_ORIGINAL  0x0004
473
#define AV_DISPOSITION_COMMENT   0x0008
474
#define AV_DISPOSITION_LYRICS    0x0010
475
#define AV_DISPOSITION_KARAOKE   0x0020
476

    
477
/**
478
 * Track should be used during playback by default.
479
 * Useful for subtitle track that should be displayed
480
 * even when user did not explicitly ask for subtitles.
481
 */
482
#define AV_DISPOSITION_FORCED    0x0040
483

    
484
/**
485
 * Stream structure.
486
 * New fields can be added to the end with minor version bumps.
487
 * Removal, reordering and changes to existing fields require a major
488
 * version bump.
489
 * sizeof(AVStream) must not be used outside libav*.
490
 */
491
typedef struct AVStream {
492
    int index;    /**< stream index in AVFormatContext */
493
    int id;       /**< format-specific stream ID */
494
    AVCodecContext *codec; /**< codec context */
495
    /**
496
     * Real base framerate of the stream.
497
     * This is the lowest framerate with which all timestamps can be
498
     * represented accurately (it is the least common multiple of all
499
     * framerates in the stream). Note, this value is just a guess!
500
     * For example, if the time base is 1/90000 and all frames have either
501
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
502
     */
503
    AVRational r_frame_rate;
504
    void *priv_data;
505

    
506
    /* internal data used in av_find_stream_info() */
507
    int64_t first_dts;
508

    
509
    /**
510
     * encoding: pts generation when outputting stream
511
     */
512
    struct AVFrac pts;
513

    
514
    /**
515
     * This is the fundamental unit of time (in seconds) in terms
516
     * of which frame timestamps are represented. For fixed-fps content,
517
     * time base should be 1/framerate and timestamp increments should be 1.
518
     */
519
    AVRational time_base;
520
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
521
    /* ffmpeg.c private use */
522
    int stream_copy; /**< If set, just copy stream. */
523
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
524

    
525
    //FIXME move stuff to a flags field?
526
    /**
527
     * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
528
     * MN: dunno if that is the right place for it
529
     */
530
    float quality;
531

    
532
    /**
533
     * Decoding: pts of the first frame of the stream, in stream time base.
534
     * Only set this if you are absolutely 100% sure that the value you set
535
     * it to really is the pts of the first frame.
536
     * This may be undefined (AV_NOPTS_VALUE).
537
     * @note The ASF header does NOT contain a correct start_time the ASF
538
     * demuxer must NOT set this.
539
     */
540
    int64_t start_time;
541

    
542
    /**
543
     * Decoding: duration of the stream, in stream time base.
544
     * If a source file does not specify a duration, but does specify
545
     * a bitrate, this value will be estimated from bitrate and file size.
546
     */
547
    int64_t duration;
548

    
549
#if FF_API_OLD_METADATA
550
    attribute_deprecated char language[4]; /**< ISO 639-2/B 3-letter language code (empty string if undefined) */
551
#endif
552

    
553
    /* av_read_frame() support */
554
    enum AVStreamParseType need_parsing;
555
    struct AVCodecParserContext *parser;
556

    
557
    int64_t cur_dts;
558
    int last_IP_duration;
559
    int64_t last_IP_pts;
560
    /* av_seek_frame() support */
561
    AVIndexEntry *index_entries; /**< Only used if the format does not
562
                                    support seeking natively. */
563
    int nb_index_entries;
564
    unsigned int index_entries_allocated_size;
565

    
566
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
567

    
568
#if LIBAVFORMAT_VERSION_INT < (53<<16)
569
    attribute_deprecated int64_t unused[4+1];
570
#endif
571

    
572
#if FF_API_OLD_METADATA
573
    attribute_deprecated char *filename; /**< source filename of the stream */
574
#endif
575

    
576
    int disposition; /**< AV_DISPOSITION_* bit field */
577

    
578
    AVProbeData probe_data;
579
#define MAX_REORDER_DELAY 16
580
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
581

    
582
    /**
583
     * sample aspect ratio (0 if unknown)
584
     * - encoding: Set by user.
585
     * - decoding: Set by libavformat.
586
     */
587
    AVRational sample_aspect_ratio;
588

    
589
    AVMetadata *metadata;
590

    
591
    /* Intended mostly for av_read_frame() support. Not supposed to be used by */
592
    /* external applications; try to use something else if at all possible.    */
593
    const uint8_t *cur_ptr;
594
    int cur_len;
595
    AVPacket cur_pkt;
596

    
597
    // Timestamp generation support:
598
    /**
599
     * Timestamp corresponding to the last dts sync point.
600
     *
601
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
602
     * a DTS is received from the underlying container. Otherwise set to
603
     * AV_NOPTS_VALUE by default.
604
     */
605
    int64_t reference_dts;
606

    
607
    /**
608
     * Number of packets to buffer for codec probing
609
     * NOT PART OF PUBLIC API
610
     */
611
#define MAX_PROBE_PACKETS 2500
612
    int probe_packets;
613

    
614
    /**
615
     * last packet in packet_buffer for this stream when muxing.
616
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
617
     */
618
    struct AVPacketList *last_in_packet_buffer;
619

    
620
    /**
621
     * Average framerate
622
     */
623
    AVRational avg_frame_rate;
624

    
625
    /**
626
     * Number of frames that have been demuxed during av_find_stream_info()
627
     */
628
    int codec_info_nb_frames;
629

    
630
    /**
631
     * Stream informations used internally by av_find_stream_info()
632
     */
633
#define MAX_STD_TIMEBASES (60*12+5)
634
    struct {
635
        int64_t last_dts;
636
        int64_t duration_gcd;
637
        int duration_count;
638
        double duration_error[MAX_STD_TIMEBASES];
639
        int64_t codec_info_duration;
640
    } *info;
641
} AVStream;
642

    
643
#define AV_PROGRAM_RUNNING 1
644

    
645
/**
646
 * New fields can be added to the end with minor version bumps.
647
 * Removal, reordering and changes to existing fields require a major
648
 * version bump.
649
 * sizeof(AVProgram) must not be used outside libav*.
650
 */
651
typedef struct AVProgram {
652
    int            id;
653
#if FF_API_OLD_METADATA
654
    attribute_deprecated char           *provider_name; ///< network name for DVB streams
655
    attribute_deprecated char           *name;          ///< service name for DVB streams
656
#endif
657
    int            flags;
658
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
659
    unsigned int   *stream_index;
660
    unsigned int   nb_stream_indexes;
661
    AVMetadata *metadata;
662
} AVProgram;
663

    
664
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
665
                                         (streams are added dynamically) */
666

    
667
typedef struct AVChapter {
668
    int id;                 ///< unique ID to identify the chapter
669
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
670
    int64_t start, end;     ///< chapter start/end time in time_base units
671
#if FF_API_OLD_METADATA
672
    attribute_deprecated char *title;            ///< chapter title
673
#endif
674
    AVMetadata *metadata;
675
} AVChapter;
676

    
677
#if FF_API_MAX_STREAMS
678
#define MAX_STREAMS 20
679
#endif
680

    
681
/**
682
 * Format I/O context.
683
 * New fields can be added to the end with minor version bumps.
684
 * Removal, reordering and changes to existing fields require a major
685
 * version bump.
686
 * sizeof(AVFormatContext) must not be used outside libav*.
687
 */
688
typedef struct AVFormatContext {
689
    const AVClass *av_class; /**< Set by avformat_alloc_context. */
690
    /* Can only be iformat or oformat, not both at the same time. */
691
    struct AVInputFormat *iformat;
692
    struct AVOutputFormat *oformat;
693
    void *priv_data;
694
    ByteIOContext *pb;
695
    unsigned int nb_streams;
696
#if FF_API_MAX_STREAMS
697
    AVStream *streams[MAX_STREAMS];
698
#else
699
    AVStream **streams;
700
#endif
701
    char filename[1024]; /**< input or output filename */
702
    /* stream info */
703
    int64_t timestamp;
704
#if FF_API_OLD_METADATA
705
    attribute_deprecated char title[512];
706
    attribute_deprecated char author[512];
707
    attribute_deprecated char copyright[512];
708
    attribute_deprecated char comment[512];
709
    attribute_deprecated char album[512];
710
    attribute_deprecated int year;  /**< ID3 year, 0 if none */
711
    attribute_deprecated int track; /**< track number, 0 if none */
712
    attribute_deprecated char genre[32]; /**< ID3 genre */
713
#endif
714

    
715
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
716
    /* private data for pts handling (do not modify directly). */
717
    /**
718
     * This buffer is only needed when packets were already buffered but
719
     * not decoded, for example to get the codec parameters in MPEG
720
     * streams.
721
     */
722
    struct AVPacketList *packet_buffer;
723

    
724
    /**
725
     * Decoding: position of the first frame of the component, in
726
     * AV_TIME_BASE fractional seconds. NEVER set this value directly:
727
     * It is deduced from the AVStream values.
728
     */
729
    int64_t start_time;
730

    
731
    /**
732
     * Decoding: duration of the stream, in AV_TIME_BASE fractional
733
     * seconds. Only set this value if you know none of the individual stream
734
     * durations and also dont set any of them. This is deduced from the
735
     * AVStream values if not set.
736
     */
737
    int64_t duration;
738

    
739
    /**
740
     * decoding: total file size, 0 if unknown
741
     */
742
    int64_t file_size;
743

    
744
    /**
745
     * Decoding: total stream bitrate in bit/s, 0 if not
746
     * available. Never set it directly if the file_size and the
747
     * duration are known as FFmpeg can compute it automatically.
748
     */
749
    int bit_rate;
750

    
751
    /* av_read_frame() support */
752
    AVStream *cur_st;
753
#if LIBAVFORMAT_VERSION_INT < (53<<16)
754
    const uint8_t *cur_ptr_deprecated;
755
    int cur_len_deprecated;
756
    AVPacket cur_pkt_deprecated;
757
#endif
758

    
759
    /* av_seek_frame() support */
760
    int64_t data_offset; /**< offset of the first packet */
761
    int index_built;
762

    
763
    int mux_rate;
764
    unsigned int packet_size;
765
    int preload;
766
    int max_delay;
767

    
768
#define AVFMT_NOOUTPUTLOOP -1
769
#define AVFMT_INFINITEOUTPUTLOOP 0
770
    /**
771
     * number of times to loop output in formats that support it
772
     */
773
    int loop_output;
774

    
775
    int flags;
776
#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
777
#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
778
#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
779
#define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
780
#define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container
781
#define AVFMT_FLAG_NOPARSE      0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled
782
#define AVFMT_FLAG_RTP_HINT     0x0040 ///< Add RTP hinting to the output file
783

    
784
    int loop_input;
785

    
786
    /**
787
     * decoding: size of data to probe; encoding: unused.
788
     */
789
    unsigned int probesize;
790

    
791
    /**
792
     * Maximum time (in AV_TIME_BASE units) during which the input should
793
     * be analyzed in av_find_stream_info().
794
     */
795
    int max_analyze_duration;
796

    
797
    const uint8_t *key;
798
    int keylen;
799

    
800
    unsigned int nb_programs;
801
    AVProgram **programs;
802

    
803
    /**
804
     * Forced video codec_id.
805
     * Demuxing: Set by user.
806
     */
807
    enum CodecID video_codec_id;
808

    
809
    /**
810
     * Forced audio codec_id.
811
     * Demuxing: Set by user.
812
     */
813
    enum CodecID audio_codec_id;
814

    
815
    /**
816
     * Forced subtitle codec_id.
817
     * Demuxing: Set by user.
818
     */
819
    enum CodecID subtitle_codec_id;
820

    
821
    /**
822
     * Maximum amount of memory in bytes to use for the index of each stream.
823
     * If the index exceeds this size, entries will be discarded as
824
     * needed to maintain a smaller size. This can lead to slower or less
825
     * accurate seeking (depends on demuxer).
826
     * Demuxers for which a full in-memory index is mandatory will ignore
827
     * this.
828
     * muxing  : unused
829
     * demuxing: set by user
830
     */
831
    unsigned int max_index_size;
832

    
833
    /**
834
     * Maximum amount of memory in bytes to use for buffering frames
835
     * obtained from realtime capture devices.
836
     */
837
    unsigned int max_picture_buffer;
838

    
839
    unsigned int nb_chapters;
840
    AVChapter **chapters;
841

    
842
    /**
843
     * Flags to enable debugging.
844
     */
845
    int debug;
846
#define FF_FDEBUG_TS        0x0001
847

    
848
    /**
849
     * Raw packets from the demuxer, prior to parsing and decoding.
850
     * This buffer is used for buffering packets until the codec can
851
     * be identified, as parsing cannot be done without knowing the
852
     * codec.
853
     */
854
    struct AVPacketList *raw_packet_buffer;
855
    struct AVPacketList *raw_packet_buffer_end;
856

    
857
    struct AVPacketList *packet_buffer_end;
858

    
859
    AVMetadata *metadata;
860

    
861
    /**
862
     * Remaining size available for raw_packet_buffer, in bytes.
863
     * NOT PART OF PUBLIC API
864
     */
865
#define RAW_PACKET_BUFFER_SIZE 2500000
866
    int raw_packet_buffer_remaining_size;
867

    
868
    /**
869
     * Start time of the stream in real world time, in microseconds
870
     * since the unix epoch (00:00 1st January 1970). That is, pts=0
871
     * in the stream was captured at this real world time.
872
     * - encoding: Set by user.
873
     * - decoding: Unused.
874
     */
875
    int64_t start_time_realtime;
876
} AVFormatContext;
877

    
878
typedef struct AVPacketList {
879
    AVPacket pkt;
880
    struct AVPacketList *next;
881
} AVPacketList;
882

    
883
#if LIBAVFORMAT_VERSION_INT < (53<<16)
884
attribute_deprecated extern AVInputFormat *first_iformat;
885
attribute_deprecated extern AVOutputFormat *first_oformat;
886
#endif
887

    
888
/**
889
 * If f is NULL, returns the first registered input format,
890
 * if f is non-NULL, returns the next registered input format after f
891
 * or NULL if f is the last one.
892
 */
893
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
894

    
895
/**
896
 * If f is NULL, returns the first registered output format,
897
 * if f is non-NULL, returns the next registered output format after f
898
 * or NULL if f is the last one.
899
 */
900
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
901

    
902
enum CodecID av_guess_image2_codec(const char *filename);
903

    
904
/* XXX: Use automatic init with either ELF sections or C file parser */
905
/* modules. */
906

    
907
/* utils.c */
908
void av_register_input_format(AVInputFormat *format);
909
void av_register_output_format(AVOutputFormat *format);
910
#if FF_API_GUESS_FORMAT
911
attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
912
                                    const char *filename,
913
                                    const char *mime_type);
914

    
915
/**
916
 * @deprecated Use av_guess_format() instead.
917
 */
918
attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
919
                                                  const char *filename,
920
                                                  const char *mime_type);
921
#endif
922

    
923
/**
924
 * Return the output format in the list of registered output formats
925
 * which best matches the provided parameters, or return NULL if
926
 * there is no match.
927
 *
928
 * @param short_name if non-NULL checks if short_name matches with the
929
 * names of the registered formats
930
 * @param filename if non-NULL checks if filename terminates with the
931
 * extensions of the registered formats
932
 * @param mime_type if non-NULL checks if mime_type matches with the
933
 * MIME type of the registered formats
934
 */
935
AVOutputFormat *av_guess_format(const char *short_name,
936
                                const char *filename,
937
                                const char *mime_type);
938

    
939
/**
940
 * Guess the codec ID based upon muxer and filename.
941
 */
942
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
943
                            const char *filename, const char *mime_type,
944
                            enum AVMediaType type);
945

    
946
/**
947
 * Send a nice hexadecimal dump of a buffer to the specified file stream.
948
 *
949
 * @param f The file stream pointer where the dump should be sent to.
950
 * @param buf buffer
951
 * @param size buffer size
952
 *
953
 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
954
 */
955
void av_hex_dump(FILE *f, uint8_t *buf, int size);
956

    
957
/**
958
 * Send a nice hexadecimal dump of a buffer to the log.
959
 *
960
 * @param avcl A pointer to an arbitrary struct of which the first field is a
961
 * pointer to an AVClass struct.
962
 * @param level The importance level of the message, lower values signifying
963
 * higher importance.
964
 * @param buf buffer
965
 * @param size buffer size
966
 *
967
 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
968
 */
969
void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
970

    
971
/**
972
 * Send a nice dump of a packet to the specified file stream.
973
 *
974
 * @param f The file stream pointer where the dump should be sent to.
975
 * @param pkt packet to dump
976
 * @param dump_payload True if the payload must be displayed, too.
977
 */
978
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
979

    
980
/**
981
 * Send a nice dump of a packet to the log.
982
 *
983
 * @param avcl A pointer to an arbitrary struct of which the first field is a
984
 * pointer to an AVClass struct.
985
 * @param level The importance level of the message, lower values signifying
986
 * higher importance.
987
 * @param pkt packet to dump
988
 * @param dump_payload True if the payload must be displayed, too.
989
 */
990
void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
991

    
992
/**
993
 * Initialize libavformat and register all the muxers, demuxers and
994
 * protocols. If you do not call this function, then you can select
995
 * exactly which formats you want to support.
996
 *
997
 * @see av_register_input_format()
998
 * @see av_register_output_format()
999
 * @see av_register_protocol()
1000
 */
1001
void av_register_all(void);
1002

    
1003
/**
1004
 * Get the CodecID for the given codec tag tag.
1005
 * If no codec id is found returns CODEC_ID_NONE.
1006
 *
1007
 * @param tags list of supported codec_id-codec_tag pairs, as stored
1008
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1009
 */
1010
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1011

    
1012
/**
1013
 * Get the codec tag for the given codec id id.
1014
 * If no codec tag is found returns 0.
1015
 *
1016
 * @param tags list of supported codec_id-codec_tag pairs, as stored
1017
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1018
 */
1019
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1020

    
1021
/* media file input */
1022

    
1023
/**
1024
 * Find AVInputFormat based on the short name of the input format.
1025
 */
1026
AVInputFormat *av_find_input_format(const char *short_name);
1027

    
1028
/**
1029
 * Guess the file format.
1030
 *
1031
 * @param is_opened Whether the file is already opened; determines whether
1032
 *                  demuxers with or without AVFMT_NOFILE are probed.
1033
 */
1034
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1035

    
1036
/**
1037
 * Guess the file format.
1038
 *
1039
 * @param is_opened Whether the file is already opened; determines whether
1040
 *                  demuxers with or without AVFMT_NOFILE are probed.
1041
 * @param score_max A probe score larger that this is required to accept a
1042
 *                  detection, the variable is set to the actual detection
1043
 *                  score afterwards.
1044
 *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1045
 *                  to retry with a larger probe buffer.
1046
 */
1047
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1048

    
1049
/**
1050
 * Allocate all the structures needed to read an input stream.
1051
 *        This does not open the needed codecs for decoding the stream[s].
1052
 */
1053
int av_open_input_stream(AVFormatContext **ic_ptr,
1054
                         ByteIOContext *pb, const char *filename,
1055
                         AVInputFormat *fmt, AVFormatParameters *ap);
1056

    
1057
/**
1058
 * Open a media file as input. The codecs are not opened. Only the file
1059
 * header (if present) is read.
1060
 *
1061
 * @param ic_ptr The opened media file handle is put here.
1062
 * @param filename filename to open
1063
 * @param fmt If non-NULL, force the file format to use.
1064
 * @param buf_size optional buffer size (zero if default is OK)
1065
 * @param ap Additional parameters needed when opening the file
1066
 *           (NULL if default).
1067
 * @return 0 if OK, AVERROR_xxx otherwise
1068
 */
1069
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1070
                       AVInputFormat *fmt,
1071
                       int buf_size,
1072
                       AVFormatParameters *ap);
1073

    
1074
#if LIBAVFORMAT_VERSION_MAJOR < 53
1075
/**
1076
 * @deprecated Use avformat_alloc_context() instead.
1077
 */
1078
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
1079
#endif
1080

    
1081
/**
1082
 * Allocate an AVFormatContext.
1083
 * Can be freed with av_free() but do not forget to free everything you
1084
 * explicitly allocated as well!
1085
 */
1086
AVFormatContext *avformat_alloc_context(void);
1087

    
1088
/**
1089
 * Read packets of a media file to get stream information. This
1090
 * is useful for file formats with no headers such as MPEG. This
1091
 * function also computes the real framerate in case of MPEG-2 repeat
1092
 * frame mode.
1093
 * The logical file position is not changed by this function;
1094
 * examined packets may be buffered for later processing.
1095
 *
1096
 * @param ic media file handle
1097
 * @return >=0 if OK, AVERROR_xxx on error
1098
 * @todo Let the user decide somehow what information is needed so that
1099
 *       we do not waste time getting stuff the user does not need.
1100
 */
1101
int av_find_stream_info(AVFormatContext *ic);
1102

    
1103
/**
1104
 * Read a transport packet from a media file.
1105
 *
1106
 * This function is obsolete and should never be used.
1107
 * Use av_read_frame() instead.
1108
 *
1109
 * @param s media file handle
1110
 * @param pkt is filled
1111
 * @return 0 if OK, AVERROR_xxx on error
1112
 */
1113
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1114

    
1115
/**
1116
 * Return the next frame of a stream.
1117
 * This function returns what is stored in the file, and does not validate
1118
 * that what is there are valid frames for the decoder. It will split what is
1119
 * stored in the file into frames and return one for each call. It will not
1120
 * omit invalid data between valid frames so as to give the decoder the maximum
1121
 * information possible for decoding.
1122
 *
1123
 * The returned packet is valid
1124
 * until the next av_read_frame() or until av_close_input_file() and
1125
 * must be freed with av_free_packet. For video, the packet contains
1126
 * exactly one frame. For audio, it contains an integer number of
1127
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1128
 * data). If the audio frames have a variable size (e.g. MPEG audio),
1129
 * then it contains one frame.
1130
 *
1131
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1132
 * values in AVStream.time_base units (and guessed if the format cannot
1133
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1134
 * has B-frames, so it is better to rely on pkt->dts if you do not
1135
 * decompress the payload.
1136
 *
1137
 * @return 0 if OK, < 0 on error or end of file
1138
 */
1139
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1140

    
1141
/**
1142
 * Seek to the keyframe at timestamp.
1143
 * 'timestamp' in 'stream_index'.
1144
 * @param stream_index If stream_index is (-1), a default
1145
 * stream is selected, and timestamp is automatically converted
1146
 * from AV_TIME_BASE units to the stream specific time_base.
1147
 * @param timestamp Timestamp in AVStream.time_base units
1148
 *        or, if no stream is specified, in AV_TIME_BASE units.
1149
 * @param flags flags which select direction and seeking mode
1150
 * @return >= 0 on success
1151
 */
1152
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1153
                  int flags);
1154

    
1155
/**
1156
 * Seek to timestamp ts.
1157
 * Seeking will be done so that the point from which all active streams
1158
 * can be presented successfully will be closest to ts and within min/max_ts.
1159
 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1160
 *
1161
 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1162
 * are the file position (this may not be supported by all demuxers).
1163
 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1164
 * in the stream with stream_index (this may not be supported by all demuxers).
1165
 * Otherwise all timestamps are in units of the stream selected by stream_index
1166
 * or if stream_index is -1, in AV_TIME_BASE units.
1167
 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1168
 * keyframes (this may not be supported by all demuxers).
1169
 *
1170
 * @param stream_index index of the stream which is used as time base reference
1171
 * @param min_ts smallest acceptable timestamp
1172
 * @param ts target timestamp
1173
 * @param max_ts largest acceptable timestamp
1174
 * @param flags flags
1175
 * @return >=0 on success, error code otherwise
1176
 *
1177
 * @note This is part of the new seek API which is still under construction.
1178
 *       Thus do not use this yet. It may change at any time, do not expect
1179
 *       ABI compatibility yet!
1180
 */
1181
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1182

    
1183
/**
1184
 * Start playing a network-based stream (e.g. RTSP stream) at the
1185
 * current position.
1186
 */
1187
int av_read_play(AVFormatContext *s);
1188

    
1189
/**
1190
 * Pause a network-based stream (e.g. RTSP stream).
1191
 *
1192
 * Use av_read_play() to resume it.
1193
 */
1194
int av_read_pause(AVFormatContext *s);
1195

    
1196
/**
1197
 * Free a AVFormatContext allocated by av_open_input_stream.
1198
 * @param s context to free
1199
 */
1200
void av_close_input_stream(AVFormatContext *s);
1201

    
1202
/**
1203
 * Close a media file (but not its codecs).
1204
 *
1205
 * @param s media file handle
1206
 */
1207
void av_close_input_file(AVFormatContext *s);
1208

    
1209
/**
1210
 * Add a new stream to a media file.
1211
 *
1212
 * Can only be called in the read_header() function. If the flag
1213
 * AVFMTCTX_NOHEADER is in the format context, then new streams
1214
 * can be added in read_packet too.
1215
 *
1216
 * @param s media file handle
1217
 * @param id file-format-dependent stream ID
1218
 */
1219
AVStream *av_new_stream(AVFormatContext *s, int id);
1220
AVProgram *av_new_program(AVFormatContext *s, int id);
1221

    
1222
/**
1223
 * Add a new chapter.
1224
 * This function is NOT part of the public API
1225
 * and should ONLY be used by demuxers.
1226
 *
1227
 * @param s media file handle
1228
 * @param id unique ID for this chapter
1229
 * @param start chapter start time in time_base units
1230
 * @param end chapter end time in time_base units
1231
 * @param title chapter title
1232
 *
1233
 * @return AVChapter or NULL on error
1234
 */
1235
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1236
                          int64_t start, int64_t end, const char *title);
1237

    
1238
/**
1239
 * Set the pts for a given stream.
1240
 *
1241
 * @param s stream
1242
 * @param pts_wrap_bits number of bits effectively used by the pts
1243
 *        (used for wrap control, 33 is the value for MPEG)
1244
 * @param pts_num numerator to convert to seconds (MPEG: 1)
1245
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1246
 */
1247
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1248
                     unsigned int pts_num, unsigned int pts_den);
1249

    
1250
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1251
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
1252
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
1253
#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
1254

    
1255
int av_find_default_stream_index(AVFormatContext *s);
1256

    
1257
/**
1258
 * Get the index for a specific timestamp.
1259
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1260
 *                 to the timestamp which is <= the requested one, if backward
1261
 *                 is 0, then it will be >=
1262
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1263
 * @return < 0 if no such timestamp could be found
1264
 */
1265
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1266

    
1267
/**
1268
 * Ensure the index uses less memory than the maximum specified in
1269
 * AVFormatContext.max_index_size by discarding entries if it grows
1270
 * too large.
1271
 * This function is not part of the public API and should only be called
1272
 * by demuxers.
1273
 */
1274
void ff_reduce_index(AVFormatContext *s, int stream_index);
1275

    
1276
/**
1277
 * Add an index entry into a sorted list. Update the entry if the list
1278
 * already contains it.
1279
 *
1280
 * @param timestamp timestamp in the time base of the given stream
1281
 */
1282
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1283
                       int size, int distance, int flags);
1284

    
1285
/**
1286
 * Perform a binary search using av_index_search_timestamp() and
1287
 * AVInputFormat.read_timestamp().
1288
 * This is not supposed to be called directly by a user application,
1289
 * but by demuxers.
1290
 * @param target_ts target timestamp in the time base of the given stream
1291
 * @param stream_index stream number
1292
 */
1293
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1294
                         int64_t target_ts, int flags);
1295

    
1296
/**
1297
 * Update cur_dts of all streams based on the given timestamp and AVStream.
1298
 *
1299
 * Stream ref_st unchanged, others set cur_dts in their native time base.
1300
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1301
 * @param timestamp new dts expressed in time_base of param ref_st
1302
 * @param ref_st reference stream giving time_base of param timestamp
1303
 */
1304
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1305

    
1306
/**
1307
 * Perform a binary search using read_timestamp().
1308
 * This is not supposed to be called directly by a user application,
1309
 * but by demuxers.
1310
 * @param target_ts target timestamp in the time base of the given stream
1311
 * @param stream_index stream number
1312
 */
1313
int64_t av_gen_search(AVFormatContext *s, int stream_index,
1314
                      int64_t target_ts, int64_t pos_min,
1315
                      int64_t pos_max, int64_t pos_limit,
1316
                      int64_t ts_min, int64_t ts_max,
1317
                      int flags, int64_t *ts_ret,
1318
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1319

    
1320
/**
1321
 * media file output
1322
 */
1323
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1324

    
1325
/**
1326
 * Split a URL string into components.
1327
 *
1328
 * The pointers to buffers for storing individual components may be null,
1329
 * in order to ignore that component. Buffers for components not found are
1330
 * set to empty strings. If the port is not found, it is set to a negative
1331
 * value.
1332
 *
1333
 * @param proto the buffer for the protocol
1334
 * @param proto_size the size of the proto buffer
1335
 * @param authorization the buffer for the authorization
1336
 * @param authorization_size the size of the authorization buffer
1337
 * @param hostname the buffer for the host name
1338
 * @param hostname_size the size of the hostname buffer
1339
 * @param port_ptr a pointer to store the port number in
1340
 * @param path the buffer for the path
1341
 * @param path_size the size of the path buffer
1342
 * @param url the URL to split
1343
 */
1344
void av_url_split(char *proto,         int proto_size,
1345
                  char *authorization, int authorization_size,
1346
                  char *hostname,      int hostname_size,
1347
                  int *port_ptr,
1348
                  char *path,          int path_size,
1349
                  const char *url);
1350

    
1351
/**
1352
 * Allocate the stream private data and write the stream header to an
1353
 * output media file.
1354
 *
1355
 * @param s media file handle
1356
 * @return 0 if OK, AVERROR_xxx on error
1357
 */
1358
int av_write_header(AVFormatContext *s);
1359

    
1360
/**
1361
 * Write a packet to an output media file.
1362
 *
1363
 * The packet shall contain one audio or video frame.
1364
 * The packet must be correctly interleaved according to the container
1365
 * specification, if not then av_interleaved_write_frame must be used.
1366
 *
1367
 * @param s media file handle
1368
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1369
              dts/pts, ...
1370
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1371
 */
1372
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1373

    
1374
/**
1375
 * Write a packet to an output media file ensuring correct interleaving.
1376
 *
1377
 * The packet must contain one audio or video frame.
1378
 * If the packets are already correctly interleaved, the application should
1379
 * call av_write_frame() instead as it is slightly faster. It is also important
1380
 * to keep in mind that completely non-interleaved input will need huge amounts
1381
 * of memory to interleave with this, so it is preferable to interleave at the
1382
 * demuxer level.
1383
 *
1384
 * @param s media file handle
1385
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1386
              dts/pts, ...
1387
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1388
 */
1389
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1390

    
1391
/**
1392
 * Interleave a packet per dts in an output media file.
1393
 *
1394
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1395
 * function, so they cannot be used after it. Note that calling av_free_packet()
1396
 * on them is still safe.
1397
 *
1398
 * @param s media file handle
1399
 * @param out the interleaved packet will be output here
1400
 * @param pkt the input packet
1401
 * @param flush 1 if no further packets are available as input and all
1402
 *              remaining packets should be output
1403
 * @return 1 if a packet was output, 0 if no packet could be output,
1404
 *         < 0 if an error occurred
1405
 */
1406
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1407
                                 AVPacket *pkt, int flush);
1408

    
1409
/**
1410
 * Write the stream trailer to an output media file and free the
1411
 * file private data.
1412
 *
1413
 * May only be called after a successful call to av_write_header.
1414
 *
1415
 * @param s media file handle
1416
 * @return 0 if OK, AVERROR_xxx on error
1417
 */
1418
int av_write_trailer(AVFormatContext *s);
1419

    
1420
void dump_format(AVFormatContext *ic,
1421
                 int index,
1422
                 const char *url,
1423
                 int is_output);
1424

    
1425
#if LIBAVFORMAT_VERSION_MAJOR < 53
1426
/**
1427
 * Parse width and height out of string str.
1428
 * @deprecated Use av_parse_video_frame_size instead.
1429
 */
1430
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1431
                                          const char *str);
1432

    
1433
/**
1434
 * Convert framerate from a string to a fraction.
1435
 * @deprecated Use av_parse_video_frame_rate instead.
1436
 */
1437
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1438
                                          const char *arg);
1439
#endif
1440

    
1441
/**
1442
 * Parse datestr and return a corresponding number of microseconds.
1443
 * @param datestr String representing a date or a duration.
1444
 * - If a date the syntax is:
1445
 * @code
1446
 *  now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]}
1447
 * @endcode
1448
 * If the value is "now" it takes the current time.
1449
 * Time is local time unless Z is appended, in which case it is
1450
 * interpreted as UTC.
1451
 * If the year-month-day part is not specified it takes the current
1452
 * year-month-day.
1453
 * @return the number of microseconds since 1st of January, 1970 up to
1454
 * the time of the parsed date or INT64_MIN if datestr cannot be
1455
 * successfully parsed.
1456
 * - If a duration the syntax is:
1457
 * @code
1458
 *  [-]HH[:MM[:SS[.m...]]]
1459
 *  [-]S+[.m...]
1460
 * @endcode
1461
 * @return the number of microseconds contained in a time interval
1462
 * with the specified duration or INT64_MIN if datestr cannot be
1463
 * successfully parsed.
1464
 * @param duration Flag which tells how to interpret datestr, if
1465
 * not zero datestr is interpreted as a duration, otherwise as a
1466
 * date.
1467
 */
1468
int64_t parse_date(const char *datestr, int duration);
1469

    
1470
/**
1471
 * Get the current time in microseconds.
1472
 */
1473
int64_t av_gettime(void);
1474

    
1475
/* ffm-specific for ffserver */
1476
#define FFM_PACKET_SIZE 4096
1477
int64_t ffm_read_write_index(int fd);
1478
int ffm_write_write_index(int fd, int64_t pos);
1479
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1480

    
1481
/**
1482
 * Attempt to find a specific tag in a URL.
1483
 *
1484
 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1485
 * Return 1 if found.
1486
 */
1487
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1488

    
1489
/**
1490
 * Return in 'buf' the path with '%d' replaced by a number.
1491
 *
1492
 * Also handles the '%0nd' format where 'n' is the total number
1493
 * of digits and '%%'.
1494
 *
1495
 * @param buf destination buffer
1496
 * @param buf_size destination buffer size
1497
 * @param path numbered sequence string
1498
 * @param number frame number
1499
 * @return 0 if OK, -1 on format error
1500
 */
1501
int av_get_frame_filename(char *buf, int buf_size,
1502
                          const char *path, int number);
1503

    
1504
/**
1505
 * Check whether filename actually is a numbered sequence generator.
1506
 *
1507
 * @param filename possible numbered sequence string
1508
 * @return 1 if a valid numbered sequence string, 0 otherwise
1509
 */
1510
int av_filename_number_test(const char *filename);
1511

    
1512
/**
1513
 * Generate an SDP for an RTP session.
1514
 *
1515
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1516
 *           array is composed by only one context, such context can contain
1517
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1518
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1519
 *           must contain only one AVStream.
1520
 * @param n_files number of AVCodecContexts contained in ac
1521
 * @param buff buffer where the SDP will be stored (must be allocated by
1522
 *             the caller)
1523
 * @param size the size of the buffer
1524
 * @return 0 if OK, AVERROR_xxx on error
1525
 */
1526
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1527

    
1528
/**
1529
 * Return a positive value if the given filename has one of the given
1530
 * extensions, 0 otherwise.
1531
 *
1532
 * @param extensions a comma-separated list of filename extensions
1533
 */
1534
int av_match_ext(const char *filename, const char *extensions);
1535

    
1536
#endif /* AVFORMAT_AVFORMAT_H */