Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 7916202b

History | View | Annotate | Download (57.3 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 94
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
#ifndef FF_API_ALLOC_FORMAT_CONTEXT
67
#define FF_API_ALLOC_FORMAT_CONTEXT    (LIBAVFORMAT_VERSION_MAJOR < 53)
68
#endif
69
#ifndef FF_API_PARSE_FRAME_PARAM
70
#define FF_API_PARSE_FRAME_PARAM       (LIBAVFORMAT_VERSION_MAJOR < 53)
71
#endif
72
#ifndef FF_API_READ_SEEK
73
#define FF_API_READ_SEEK               (LIBAVFORMAT_VERSION_MAJOR < 54)
74
#endif
75
#ifndef FF_API_LAVF_UNUSED
76
#define FF_API_LAVF_UNUSED             (LIBAVFORMAT_VERSION_MAJOR < 53)
77
#endif
78
#ifndef FF_API_PARAMETERS_CODEC_ID
79
#define FF_API_PARAMETERS_CODEC_ID     (LIBAVFORMAT_VERSION_MAJOR < 53)
80
#endif
81
#ifndef FF_API_FIRST_FORMAT
82
#define FF_API_FIRST_FORMAT            (LIBAVFORMAT_VERSION_MAJOR < 53)
83
#endif
84
#ifndef FF_API_SYMVER
85
#define FF_API_SYMVER                  (LIBAVFORMAT_VERSION_MAJOR < 53)
86
#endif
87

    
88
/**
89
 * I return the LIBAVFORMAT_VERSION_INT constant.  You got
90
 * a fucking problem with that, douchebag?
91
 */
92
unsigned avformat_version(void);
93

    
94
/**
95
 * Return the libavformat build-time configuration.
96
 */
97
const char *avformat_configuration(void);
98

    
99
/**
100
 * Return the libavformat license.
101
 */
102
const char *avformat_license(void);
103

    
104
#include <time.h>
105
#include <stdio.h>  /* FILE */
106
#include "libavcodec/avcodec.h"
107

    
108
#include "avio.h"
109

    
110
struct AVFormatContext;
111

    
112

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

    
170
#define AV_METADATA_MATCH_CASE      1
171
#define AV_METADATA_IGNORE_SUFFIX   2
172
#define AV_METADATA_DONT_STRDUP_KEY 4
173
#define AV_METADATA_DONT_STRDUP_VAL 8
174
#define AV_METADATA_DONT_OVERWRITE 16   ///< Don't overwrite existing tags.
175

    
176
typedef struct {
177
    char *key;
178
    char *value;
179
}AVMetadataTag;
180

    
181
typedef struct AVMetadata AVMetadata;
182
#if FF_API_OLD_METADATA
183
typedef struct AVMetadataConv AVMetadataConv;
184
#endif
185

    
186
/**
187
 * Get a metadata element with matching key.
188
 *
189
 * @param prev Set to the previous matching element to find the next.
190
 *             If set to NULL the first matching element is returned.
191
 * @param flags Allows case as well as suffix-insensitive comparisons.
192
 * @return Found tag or NULL, changing key or value leads to undefined behavior.
193
 */
194
AVMetadataTag *
195
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
196

    
197
#if FF_API_OLD_METADATA
198
/**
199
 * Set the given tag in *pm, overwriting an existing tag.
200
 *
201
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
202
 * a metadata struct is allocated and put in *pm.
203
 * @param key tag key to add to *pm (will be av_strduped)
204
 * @param value tag value to add to *pm (will be av_strduped)
205
 * @return >= 0 on success otherwise an error code <0
206
 * @deprecated Use av_metadata_set2() instead.
207
 */
208
attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
209
#endif
210

    
211
/**
212
 * Set the given tag in *pm, overwriting an existing tag.
213
 *
214
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
215
 * a metadata struct is allocated and put in *pm.
216
 * @param key tag key to add to *pm (will be av_strduped depending on flags)
217
 * @param value tag value to add to *pm (will be av_strduped depending on flags).
218
 *        Passing a NULL value will cause an existing tag to be deleted.
219
 * @return >= 0 on success otherwise an error code <0
220
 */
221
int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
222

    
223
#if FF_API_OLD_METADATA
224
/**
225
 * This function is provided for compatibility reason and currently does nothing.
226
 */
227
attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
228
                                                                        const AVMetadataConv *s_conv);
229
#endif
230

    
231
/**
232
 * Copy metadata from one AVMetadata struct into another.
233
 * @param dst pointer to a pointer to a AVMetadata struct. If *dst is NULL,
234
 *            this function will allocate a struct for you and put it in *dst
235
 * @param src pointer to source AVMetadata struct
236
 * @param flags flags to use when setting metadata in *dst
237
 * @note metadata is read using the AV_METADATA_IGNORE_SUFFIX flag
238
 */
239
void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags);
240

    
241
/**
242
 * Free all the memory allocated for an AVMetadata struct.
243
 */
244
void av_metadata_free(AVMetadata **m);
245

    
246

    
247
/* packet functions */
248

    
249

    
250
/**
251
 * Allocate and read the payload of a packet and initialize its
252
 * fields with default values.
253
 *
254
 * @param pkt packet
255
 * @param size desired payload size
256
 * @return >0 (read size) if OK, AVERROR_xxx otherwise
257
 */
258
int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
259

    
260

    
261
/**
262
 * Read data and append it to the current content of the AVPacket.
263
 * If pkt->size is 0 this is identical to av_get_packet.
264
 * Note that this uses av_grow_packet and thus involves a realloc
265
 * which is inefficient. Thus this function should only be used
266
 * when there is no reasonable way to know (an upper bound of)
267
 * the final size.
268
 *
269
 * @param pkt packet
270
 * @param size amount of data to read
271
 * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data
272
 *         will not be lost even if an error occurs.
273
 */
274
int av_append_packet(ByteIOContext *s, AVPacket *pkt, int size);
275

    
276
/*************************************************/
277
/* fractional numbers for exact pts handling */
278

    
279
/**
280
 * The exact value of the fractional number is: 'val + num / den'.
281
 * num is assumed to be 0 <= num < den.
282
 */
283
typedef struct AVFrac {
284
    int64_t val, num, den;
285
} AVFrac;
286

    
287
/*************************************************/
288
/* input/output formats */
289

    
290
struct AVCodecTag;
291

    
292
/**
293
 * This structure contains the data a format has to probe a file.
294
 */
295
typedef struct AVProbeData {
296
    const char *filename;
297
    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
298
    int buf_size;       /**< Size of buf except extra allocated bytes */
299
} AVProbeData;
300

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

    
304
typedef struct AVFormatParameters {
305
    AVRational time_base;
306
    int sample_rate;
307
    int channels;
308
    int width;
309
    int height;
310
    enum PixelFormat pix_fmt;
311
    int channel; /**< Used to select DV channel. */
312
    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
313
    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
314
    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
315
                                            stream packet (only meaningful if
316
                                            mpeg2ts_raw is TRUE). */
317
    unsigned int initial_pause:1;       /**< Do not begin to play the stream
318
                                            immediately (RTSP only). */
319
    unsigned int prealloced_context:1;
320
#if FF_API_PARAMETERS_CODEC_ID
321
    attribute_deprecated enum CodecID video_codec_id;
322
    attribute_deprecated enum CodecID audio_codec_id;
323
#endif
324
} AVFormatParameters;
325

    
326
//! Demuxer will use url_fopen, no opened file should be provided by the caller.
327
#define AVFMT_NOFILE        0x0001
328
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
329
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
330
#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
331
                                      raw picture data. */
332
#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
333
#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
334
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
335
#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. Note, muxers always require valid (monotone) timestamps */
336
#define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
337
#define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
338
#define AVFMT_NOSTREAMS     0x1000 /**< Format does not require any streams */
339

    
340
typedef struct AVOutputFormat {
341
    const char *name;
342
    /**
343
     * Descriptive name for the format, meant to be more human-readable
344
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
345
     * to define it.
346
     */
347
    const char *long_name;
348
    const char *mime_type;
349
    const char *extensions; /**< comma-separated filename extensions */
350
    /**
351
     * size of private data so that it can be allocated in the wrapper
352
     */
353
    int priv_data_size;
354
    /* output support */
355
    enum CodecID audio_codec; /**< default audio codec */
356
    enum CodecID video_codec; /**< default video codec */
357
    int (*write_header)(struct AVFormatContext *);
358
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
359
    int (*write_trailer)(struct AVFormatContext *);
360
    /**
361
     * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER
362
     */
363
    int flags;
364
    /**
365
     * Currently only used to set pixel format if not YUV420P.
366
     */
367
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
368
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
369
                             AVPacket *in, int flush);
370

    
371
    /**
372
     * List of supported codec_id-codec_tag pairs, ordered by "better
373
     * choice first". The arrays are all terminated by CODEC_ID_NONE.
374
     */
375
    const struct AVCodecTag * const *codec_tag;
376

    
377
    enum CodecID subtitle_codec; /**< default subtitle codec */
378

    
379
#if FF_API_OLD_METADATA
380
    const AVMetadataConv *metadata_conv;
381
#endif
382

    
383
    const AVClass *priv_class; ///< AVClass for the private context
384

    
385
    /* private fields */
386
    struct AVOutputFormat *next;
387
} AVOutputFormat;
388

    
389
typedef struct AVInputFormat {
390
    /**
391
     * A comma separated list of short names for the format. New names
392
     * may be appended with a minor bump.
393
     */
394
    const char *name;
395

    
396
    /**
397
     * Descriptive name for the format, meant to be more human-readable
398
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
399
     * to define it.
400
     */
401
    const char *long_name;
402

    
403
    /**
404
     * Size of private data so that it can be allocated in the wrapper.
405
     */
406
    int priv_data_size;
407

    
408
    /**
409
     * Tell if a given file has a chance of being parsed as this format.
410
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
411
     * big so you do not have to check for that unless you need more.
412
     */
413
    int (*read_probe)(AVProbeData *);
414

    
415
    /**
416
     * Read the format header and initialize the AVFormatContext
417
     * structure. Return 0 if OK. 'ap' if non-NULL contains
418
     * additional parameters. Only used in raw format right
419
     * now. 'av_new_stream' should be called to create new streams.
420
     */
421
    int (*read_header)(struct AVFormatContext *,
422
                       AVFormatParameters *ap);
423

    
424
    /**
425
     * Read one packet and put it in 'pkt'. pts and flags are also
426
     * set. 'av_new_stream' can be called only if the flag
427
     * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
428
     * background thread).
429
     * @return 0 on success, < 0 on error.
430
     *         When returning an error, pkt must not have been allocated
431
     *         or must be freed before returning
432
     */
433
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
434

    
435
    /**
436
     * Close the stream. The AVFormatContext and AVStreams are not
437
     * freed by this function
438
     */
439
    int (*read_close)(struct AVFormatContext *);
440

    
441
#if FF_API_READ_SEEK
442
    /**
443
     * Seek to a given timestamp relative to the frames in
444
     * stream component stream_index.
445
     * @param stream_index Must not be -1.
446
     * @param flags Selects which direction should be preferred if no exact
447
     *              match is available.
448
     * @return >= 0 on success (but not necessarily the new offset)
449
     */
450
    attribute_deprecated int (*read_seek)(struct AVFormatContext *,
451
                                          int stream_index, int64_t timestamp, int flags);
452
#endif
453
    /**
454
     * Gets the next timestamp in stream[stream_index].time_base units.
455
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
456
     */
457
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
458
                              int64_t *pos, int64_t pos_limit);
459

    
460
    /**
461
     * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
462
     */
463
    int flags;
464

    
465
    /**
466
     * If extensions are defined, then no probe is done. You should
467
     * usually not use extension format guessing because it is not
468
     * reliable enough
469
     */
470
    const char *extensions;
471

    
472
    /**
473
     * General purpose read-only value that the format can use.
474
     */
475
    int value;
476

    
477
    /**
478
     * Start/resume playing - only meaningful if using a network-based format
479
     * (RTSP).
480
     */
481
    int (*read_play)(struct AVFormatContext *);
482

    
483
    /**
484
     * Pause playing - only meaningful if using a network-based format
485
     * (RTSP).
486
     */
487
    int (*read_pause)(struct AVFormatContext *);
488

    
489
    const struct AVCodecTag * const *codec_tag;
490

    
491
    /**
492
     * Seek to timestamp ts.
493
     * Seeking will be done so that the point from which all active streams
494
     * can be presented successfully will be closest to ts and within min/max_ts.
495
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
496
     */
497
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
498

    
499
#if FF_API_OLD_METADATA
500
    const AVMetadataConv *metadata_conv;
501
#endif
502

    
503
    /* private fields */
504
    struct AVInputFormat *next;
505
} AVInputFormat;
506

    
507
enum AVStreamParseType {
508
    AVSTREAM_PARSE_NONE,
509
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
510
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
511
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
512
    AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
513
};
514

    
515
typedef struct AVIndexEntry {
516
    int64_t pos;
517
    int64_t timestamp;
518
#define AVINDEX_KEYFRAME 0x0001
519
    int flags:2;
520
    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).
521
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
522
} AVIndexEntry;
523

    
524
#define AV_DISPOSITION_DEFAULT   0x0001
525
#define AV_DISPOSITION_DUB       0x0002
526
#define AV_DISPOSITION_ORIGINAL  0x0004
527
#define AV_DISPOSITION_COMMENT   0x0008
528
#define AV_DISPOSITION_LYRICS    0x0010
529
#define AV_DISPOSITION_KARAOKE   0x0020
530

    
531
/**
532
 * Track should be used during playback by default.
533
 * Useful for subtitle track that should be displayed
534
 * even when user did not explicitly ask for subtitles.
535
 */
536
#define AV_DISPOSITION_FORCED    0x0040
537

    
538
/**
539
 * Stream structure.
540
 * New fields can be added to the end with minor version bumps.
541
 * Removal, reordering and changes to existing fields require a major
542
 * version bump.
543
 * sizeof(AVStream) must not be used outside libav*.
544
 */
545
typedef struct AVStream {
546
    int index;    /**< stream index in AVFormatContext */
547
    int id;       /**< format-specific stream ID */
548
    AVCodecContext *codec; /**< codec context */
549
    /**
550
     * Real base framerate of the stream.
551
     * This is the lowest framerate with which all timestamps can be
552
     * represented accurately (it is the least common multiple of all
553
     * framerates in the stream). Note, this value is just a guess!
554
     * For example, if the time base is 1/90000 and all frames have either
555
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
556
     */
557
    AVRational r_frame_rate;
558
    void *priv_data;
559

    
560
    /* internal data used in av_find_stream_info() */
561
    int64_t first_dts;
562

    
563
    /**
564
     * encoding: pts generation when outputting stream
565
     */
566
    struct AVFrac pts;
567

    
568
    /**
569
     * This is the fundamental unit of time (in seconds) in terms
570
     * of which frame timestamps are represented. For fixed-fps content,
571
     * time base should be 1/framerate and timestamp increments should be 1.
572
     */
573
    AVRational time_base;
574
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
575
    /* ffmpeg.c private use */
576
    int stream_copy; /**< If set, just copy stream. */
577
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
578

    
579
    //FIXME move stuff to a flags field?
580
    /**
581
     * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
582
     * MN: dunno if that is the right place for it
583
     */
584
    float quality;
585

    
586
    /**
587
     * Decoding: pts of the first frame of the stream, in stream time base.
588
     * Only set this if you are absolutely 100% sure that the value you set
589
     * it to really is the pts of the first frame.
590
     * This may be undefined (AV_NOPTS_VALUE).
591
     * @note The ASF header does NOT contain a correct start_time the ASF
592
     * demuxer must NOT set this.
593
     */
594
    int64_t start_time;
595

    
596
    /**
597
     * Decoding: duration of the stream, in stream time base.
598
     * If a source file does not specify a duration, but does specify
599
     * a bitrate, this value will be estimated from bitrate and file size.
600
     */
601
    int64_t duration;
602

    
603
#if FF_API_OLD_METADATA
604
    attribute_deprecated char language[4]; /**< ISO 639-2/B 3-letter language code (empty string if undefined) */
605
#endif
606

    
607
    /* av_read_frame() support */
608
    enum AVStreamParseType need_parsing;
609
    struct AVCodecParserContext *parser;
610

    
611
    int64_t cur_dts;
612
    int last_IP_duration;
613
    int64_t last_IP_pts;
614
    /* av_seek_frame() support */
615
    AVIndexEntry *index_entries; /**< Only used if the format does not
616
                                    support seeking natively. */
617
    int nb_index_entries;
618
    unsigned int index_entries_allocated_size;
619

    
620
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
621

    
622
#if FF_API_LAVF_UNUSED
623
    attribute_deprecated int64_t unused[4+1];
624
#endif
625

    
626
#if FF_API_OLD_METADATA
627
    attribute_deprecated char *filename; /**< source filename of the stream */
628
#endif
629

    
630
    int disposition; /**< AV_DISPOSITION_* bit field */
631

    
632
    AVProbeData probe_data;
633
#define MAX_REORDER_DELAY 16
634
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
635

    
636
    /**
637
     * sample aspect ratio (0 if unknown)
638
     * - encoding: Set by user.
639
     * - decoding: Set by libavformat.
640
     */
641
    AVRational sample_aspect_ratio;
642

    
643
    AVMetadata *metadata;
644

    
645
    /* Intended mostly for av_read_frame() support. Not supposed to be used by */
646
    /* external applications; try to use something else if at all possible.    */
647
    const uint8_t *cur_ptr;
648
    int cur_len;
649
    AVPacket cur_pkt;
650

    
651
    // Timestamp generation support:
652
    /**
653
     * Timestamp corresponding to the last dts sync point.
654
     *
655
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
656
     * a DTS is received from the underlying container. Otherwise set to
657
     * AV_NOPTS_VALUE by default.
658
     */
659
    int64_t reference_dts;
660

    
661
    /**
662
     * Number of packets to buffer for codec probing
663
     * NOT PART OF PUBLIC API
664
     */
665
#define MAX_PROBE_PACKETS 2500
666
    int probe_packets;
667

    
668
    /**
669
     * last packet in packet_buffer for this stream when muxing.
670
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
671
     */
672
    struct AVPacketList *last_in_packet_buffer;
673

    
674
    /**
675
     * Average framerate
676
     */
677
    AVRational avg_frame_rate;
678

    
679
    /**
680
     * Number of frames that have been demuxed during av_find_stream_info()
681
     */
682
    int codec_info_nb_frames;
683

    
684
    /**
685
     * Stream informations used internally by av_find_stream_info()
686
     */
687
#define MAX_STD_TIMEBASES (60*12+5)
688
    struct {
689
        int64_t last_dts;
690
        int64_t duration_gcd;
691
        int duration_count;
692
        double duration_error[MAX_STD_TIMEBASES];
693
        int64_t codec_info_duration;
694
    } *info;
695
} AVStream;
696

    
697
#define AV_PROGRAM_RUNNING 1
698

    
699
/**
700
 * New fields can be added to the end with minor version bumps.
701
 * Removal, reordering and changes to existing fields require a major
702
 * version bump.
703
 * sizeof(AVProgram) must not be used outside libav*.
704
 */
705
typedef struct AVProgram {
706
    int            id;
707
#if FF_API_OLD_METADATA
708
    attribute_deprecated char           *provider_name; ///< network name for DVB streams
709
    attribute_deprecated char           *name;          ///< service name for DVB streams
710
#endif
711
    int            flags;
712
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
713
    unsigned int   *stream_index;
714
    unsigned int   nb_stream_indexes;
715
    AVMetadata *metadata;
716
} AVProgram;
717

    
718
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
719
                                         (streams are added dynamically) */
720

    
721
typedef struct AVChapter {
722
    int id;                 ///< unique ID to identify the chapter
723
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
724
    int64_t start, end;     ///< chapter start/end time in time_base units
725
#if FF_API_OLD_METADATA
726
    attribute_deprecated char *title;            ///< chapter title
727
#endif
728
    AVMetadata *metadata;
729
} AVChapter;
730

    
731
#if FF_API_MAX_STREAMS
732
#define MAX_STREAMS 20
733
#endif
734

    
735
/**
736
 * Format I/O context.
737
 * New fields can be added to the end with minor version bumps.
738
 * Removal, reordering and changes to existing fields require a major
739
 * version bump.
740
 * sizeof(AVFormatContext) must not be used outside libav*.
741
 */
742
typedef struct AVFormatContext {
743
    const AVClass *av_class; /**< Set by avformat_alloc_context. */
744
    /* Can only be iformat or oformat, not both at the same time. */
745
    struct AVInputFormat *iformat;
746
    struct AVOutputFormat *oformat;
747
    void *priv_data;
748
    ByteIOContext *pb;
749
    unsigned int nb_streams;
750
#if FF_API_MAX_STREAMS
751
    AVStream *streams[MAX_STREAMS];
752
#else
753
    AVStream **streams;
754
#endif
755
    char filename[1024]; /**< input or output filename */
756
    /* stream info */
757
    int64_t timestamp;
758
#if FF_API_OLD_METADATA
759
    attribute_deprecated char title[512];
760
    attribute_deprecated char author[512];
761
    attribute_deprecated char copyright[512];
762
    attribute_deprecated char comment[512];
763
    attribute_deprecated char album[512];
764
    attribute_deprecated int year;  /**< ID3 year, 0 if none */
765
    attribute_deprecated int track; /**< track number, 0 if none */
766
    attribute_deprecated char genre[32]; /**< ID3 genre */
767
#endif
768

    
769
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
770
    /* private data for pts handling (do not modify directly). */
771
    /**
772
     * This buffer is only needed when packets were already buffered but
773
     * not decoded, for example to get the codec parameters in MPEG
774
     * streams.
775
     */
776
    struct AVPacketList *packet_buffer;
777

    
778
    /**
779
     * Decoding: position of the first frame of the component, in
780
     * AV_TIME_BASE fractional seconds. NEVER set this value directly:
781
     * It is deduced from the AVStream values.
782
     */
783
    int64_t start_time;
784

    
785
    /**
786
     * Decoding: duration of the stream, in AV_TIME_BASE fractional
787
     * seconds. Only set this value if you know none of the individual stream
788
     * durations and also dont set any of them. This is deduced from the
789
     * AVStream values if not set.
790
     */
791
    int64_t duration;
792

    
793
    /**
794
     * decoding: total file size, 0 if unknown
795
     */
796
    int64_t file_size;
797

    
798
    /**
799
     * Decoding: total stream bitrate in bit/s, 0 if not
800
     * available. Never set it directly if the file_size and the
801
     * duration are known as FFmpeg can compute it automatically.
802
     */
803
    int bit_rate;
804

    
805
    /* av_read_frame() support */
806
    AVStream *cur_st;
807
#if FF_API_LAVF_UNUSED
808
    const uint8_t *cur_ptr_deprecated;
809
    int cur_len_deprecated;
810
    AVPacket cur_pkt_deprecated;
811
#endif
812

    
813
    /* av_seek_frame() support */
814
    int64_t data_offset; /**< offset of the first packet */
815
    int index_built;
816

    
817
    int mux_rate;
818
    unsigned int packet_size;
819
    int preload;
820
    int max_delay;
821

    
822
#define AVFMT_NOOUTPUTLOOP -1
823
#define AVFMT_INFINITEOUTPUTLOOP 0
824
    /**
825
     * number of times to loop output in formats that support it
826
     */
827
    int loop_output;
828

    
829
    int flags;
830
#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
831
#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
832
#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
833
#define AVFMT_FLAG_IGNDTS       0x0008 ///< Ignore DTS on frames that contain both DTS & PTS
834
#define AVFMT_FLAG_NOFILLIN     0x0010 ///< Do not infer any values from other values, just return what is stored in the container
835
#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
836
#define AVFMT_FLAG_RTP_HINT     0x0040 ///< Add RTP hinting to the output file
837

    
838
    int loop_input;
839

    
840
    /**
841
     * decoding: size of data to probe; encoding: unused.
842
     */
843
    unsigned int probesize;
844

    
845
    /**
846
     * Maximum time (in AV_TIME_BASE units) during which the input should
847
     * be analyzed in av_find_stream_info().
848
     */
849
    int max_analyze_duration;
850

    
851
    const uint8_t *key;
852
    int keylen;
853

    
854
    unsigned int nb_programs;
855
    AVProgram **programs;
856

    
857
    /**
858
     * Forced video codec_id.
859
     * Demuxing: Set by user.
860
     */
861
    enum CodecID video_codec_id;
862

    
863
    /**
864
     * Forced audio codec_id.
865
     * Demuxing: Set by user.
866
     */
867
    enum CodecID audio_codec_id;
868

    
869
    /**
870
     * Forced subtitle codec_id.
871
     * Demuxing: Set by user.
872
     */
873
    enum CodecID subtitle_codec_id;
874

    
875
    /**
876
     * Maximum amount of memory in bytes to use for the index of each stream.
877
     * If the index exceeds this size, entries will be discarded as
878
     * needed to maintain a smaller size. This can lead to slower or less
879
     * accurate seeking (depends on demuxer).
880
     * Demuxers for which a full in-memory index is mandatory will ignore
881
     * this.
882
     * muxing  : unused
883
     * demuxing: set by user
884
     */
885
    unsigned int max_index_size;
886

    
887
    /**
888
     * Maximum amount of memory in bytes to use for buffering frames
889
     * obtained from realtime capture devices.
890
     */
891
    unsigned int max_picture_buffer;
892

    
893
    unsigned int nb_chapters;
894
    AVChapter **chapters;
895

    
896
    /**
897
     * Flags to enable debugging.
898
     */
899
    int debug;
900
#define FF_FDEBUG_TS        0x0001
901

    
902
    /**
903
     * Raw packets from the demuxer, prior to parsing and decoding.
904
     * This buffer is used for buffering packets until the codec can
905
     * be identified, as parsing cannot be done without knowing the
906
     * codec.
907
     */
908
    struct AVPacketList *raw_packet_buffer;
909
    struct AVPacketList *raw_packet_buffer_end;
910

    
911
    struct AVPacketList *packet_buffer_end;
912

    
913
    AVMetadata *metadata;
914

    
915
    /**
916
     * Remaining size available for raw_packet_buffer, in bytes.
917
     * NOT PART OF PUBLIC API
918
     */
919
#define RAW_PACKET_BUFFER_SIZE 2500000
920
    int raw_packet_buffer_remaining_size;
921

    
922
    /**
923
     * Start time of the stream in real world time, in microseconds
924
     * since the unix epoch (00:00 1st January 1970). That is, pts=0
925
     * in the stream was captured at this real world time.
926
     * - encoding: Set by user.
927
     * - decoding: Unused.
928
     */
929
    int64_t start_time_realtime;
930
} AVFormatContext;
931

    
932
typedef struct AVPacketList {
933
    AVPacket pkt;
934
    struct AVPacketList *next;
935
} AVPacketList;
936

    
937
#if FF_API_FIRST_FORMAT
938
attribute_deprecated extern AVInputFormat *first_iformat;
939
attribute_deprecated extern AVOutputFormat *first_oformat;
940
#endif
941

    
942
/**
943
 * If f is NULL, returns the first registered input format,
944
 * if f is non-NULL, returns the next registered input format after f
945
 * or NULL if f is the last one.
946
 */
947
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
948

    
949
/**
950
 * If f is NULL, returns the first registered output format,
951
 * if f is non-NULL, returns the next registered output format after f
952
 * or NULL if f is the last one.
953
 */
954
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
955

    
956
enum CodecID av_guess_image2_codec(const char *filename);
957

    
958
/* XXX: Use automatic init with either ELF sections or C file parser */
959
/* modules. */
960

    
961
/* utils.c */
962
void av_register_input_format(AVInputFormat *format);
963
void av_register_output_format(AVOutputFormat *format);
964
#if FF_API_GUESS_FORMAT
965
attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
966
                                    const char *filename,
967
                                    const char *mime_type);
968

    
969
/**
970
 * @deprecated Use av_guess_format() instead.
971
 */
972
attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
973
                                                  const char *filename,
974
                                                  const char *mime_type);
975
#endif
976

    
977
/**
978
 * Return the output format in the list of registered output formats
979
 * which best matches the provided parameters, or return NULL if
980
 * there is no match.
981
 *
982
 * @param short_name if non-NULL checks if short_name matches with the
983
 * names of the registered formats
984
 * @param filename if non-NULL checks if filename terminates with the
985
 * extensions of the registered formats
986
 * @param mime_type if non-NULL checks if mime_type matches with the
987
 * MIME type of the registered formats
988
 */
989
AVOutputFormat *av_guess_format(const char *short_name,
990
                                const char *filename,
991
                                const char *mime_type);
992

    
993
/**
994
 * Guess the codec ID based upon muxer and filename.
995
 */
996
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
997
                            const char *filename, const char *mime_type,
998
                            enum AVMediaType type);
999

    
1000
/**
1001
 * Send a nice hexadecimal dump of a buffer to the specified file stream.
1002
 *
1003
 * @param f The file stream pointer where the dump should be sent to.
1004
 * @param buf buffer
1005
 * @param size buffer size
1006
 *
1007
 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
1008
 */
1009
void av_hex_dump(FILE *f, uint8_t *buf, int size);
1010

    
1011
/**
1012
 * Send a nice hexadecimal dump of a buffer to the log.
1013
 *
1014
 * @param avcl A pointer to an arbitrary struct of which the first field is a
1015
 * pointer to an AVClass struct.
1016
 * @param level The importance level of the message, lower values signifying
1017
 * higher importance.
1018
 * @param buf buffer
1019
 * @param size buffer size
1020
 *
1021
 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
1022
 */
1023
void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
1024

    
1025
/**
1026
 * Send a nice dump of a packet to the specified file stream.
1027
 *
1028
 * @param f The file stream pointer where the dump should be sent to.
1029
 * @param pkt packet to dump
1030
 * @param dump_payload True if the payload must be displayed, too.
1031
 */
1032
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
1033

    
1034
/**
1035
 * Send a nice dump of a packet to the log.
1036
 *
1037
 * @param avcl A pointer to an arbitrary struct of which the first field is a
1038
 * pointer to an AVClass struct.
1039
 * @param level The importance level of the message, lower values signifying
1040
 * higher importance.
1041
 * @param pkt packet to dump
1042
 * @param dump_payload True if the payload must be displayed, too.
1043
 */
1044
void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
1045

    
1046
/**
1047
 * Initialize libavformat and register all the muxers, demuxers and
1048
 * protocols. If you do not call this function, then you can select
1049
 * exactly which formats you want to support.
1050
 *
1051
 * @see av_register_input_format()
1052
 * @see av_register_output_format()
1053
 * @see av_register_protocol()
1054
 */
1055
void av_register_all(void);
1056

    
1057
/**
1058
 * Get the CodecID for the given codec tag tag.
1059
 * If no codec id is found returns CODEC_ID_NONE.
1060
 *
1061
 * @param tags list of supported codec_id-codec_tag pairs, as stored
1062
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1063
 */
1064
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
1065

    
1066
/**
1067
 * Get the codec tag for the given codec id id.
1068
 * If no codec tag is found returns 0.
1069
 *
1070
 * @param tags list of supported codec_id-codec_tag pairs, as stored
1071
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
1072
 */
1073
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
1074

    
1075
/* media file input */
1076

    
1077
/**
1078
 * Find AVInputFormat based on the short name of the input format.
1079
 */
1080
AVInputFormat *av_find_input_format(const char *short_name);
1081

    
1082
/**
1083
 * Guess the file format.
1084
 *
1085
 * @param is_opened Whether the file is already opened; determines whether
1086
 *                  demuxers with or without AVFMT_NOFILE are probed.
1087
 */
1088
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1089

    
1090
/**
1091
 * Guess the file format.
1092
 *
1093
 * @param is_opened Whether the file is already opened; determines whether
1094
 *                  demuxers with or without AVFMT_NOFILE are probed.
1095
 * @param score_max A probe score larger that this is required to accept a
1096
 *                  detection, the variable is set to the actual detection
1097
 *                  score afterwards.
1098
 *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1099
 *                  to retry with a larger probe buffer.
1100
 */
1101
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1102

    
1103
/**
1104
 * Allocate all the structures needed to read an input stream.
1105
 *        This does not open the needed codecs for decoding the stream[s].
1106
 */
1107
int av_open_input_stream(AVFormatContext **ic_ptr,
1108
                         ByteIOContext *pb, const char *filename,
1109
                         AVInputFormat *fmt, AVFormatParameters *ap);
1110

    
1111
/**
1112
 * Open a media file as input. The codecs are not opened. Only the file
1113
 * header (if present) is read.
1114
 *
1115
 * @param ic_ptr The opened media file handle is put here.
1116
 * @param filename filename to open
1117
 * @param fmt If non-NULL, force the file format to use.
1118
 * @param buf_size optional buffer size (zero if default is OK)
1119
 * @param ap Additional parameters needed when opening the file
1120
 *           (NULL if default).
1121
 * @return 0 if OK, AVERROR_xxx otherwise
1122
 */
1123
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1124
                       AVInputFormat *fmt,
1125
                       int buf_size,
1126
                       AVFormatParameters *ap);
1127

    
1128
#if FF_API_ALLOC_FORMAT_CONTEXT
1129
/**
1130
 * @deprecated Use avformat_alloc_context() instead.
1131
 */
1132
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
1133
#endif
1134

    
1135
/**
1136
 * Allocate an AVFormatContext.
1137
 * Can be freed with av_free() but do not forget to free everything you
1138
 * explicitly allocated as well!
1139
 */
1140
AVFormatContext *avformat_alloc_context(void);
1141

    
1142
/**
1143
 * Read packets of a media file to get stream information. This
1144
 * is useful for file formats with no headers such as MPEG. This
1145
 * function also computes the real framerate in case of MPEG-2 repeat
1146
 * frame mode.
1147
 * The logical file position is not changed by this function;
1148
 * examined packets may be buffered for later processing.
1149
 *
1150
 * @param ic media file handle
1151
 * @return >=0 if OK, AVERROR_xxx on error
1152
 * @todo Let the user decide somehow what information is needed so that
1153
 *       we do not waste time getting stuff the user does not need.
1154
 */
1155
int av_find_stream_info(AVFormatContext *ic);
1156

    
1157
/**
1158
 * Find the "best" stream in the file.
1159
 * The best stream is determined according to various heuristics as the most
1160
 * likely to be what the user expects.
1161
 * If the decoder parameter is non-NULL, av_find_best_stream will find the
1162
 * default decoder for the stream's codec; streams for which no decoder can
1163
 * be found are ignored.
1164
 *
1165
 * @param ic                media file handle
1166
 * @param type              stream type: video, audio, subtitles, etc.
1167
 * @param wanted_stream_nb  user-requested stream number,
1168
 *                          or -1 for automatic selection
1169
 * @param related_stream    try to find a stream related (eg. in the same
1170
 *                          program) to this one, or -1 if none
1171
 * @param decoder_ret       if non-NULL, returns the decoder for the
1172
 *                          selected stream
1173
 * @param flags             flags; none are currently defined
1174
 * @return  the non-negative stream number in case of success,
1175
 *          AVERROR_STREAM_NOT_FOUND if no stream with the requested type
1176
 *          could be found,
1177
 *          AVERROR_DECODER_NOT_FOUND if streams were found but no decoder
1178
 * @note  If av_find_best_stream returns successfully and decoder_ret is not
1179
 *        NULL, then *decoder_ret is guaranteed to be set to a valid AVCodec.
1180
 */
1181
int av_find_best_stream(AVFormatContext *ic,
1182
                        enum AVMediaType type,
1183
                        int wanted_stream_nb,
1184
                        int related_stream,
1185
                        AVCodec **decoder_ret,
1186
                        int flags);
1187

    
1188
/**
1189
 * Read a transport packet from a media file.
1190
 *
1191
 * This function is obsolete and should never be used.
1192
 * Use av_read_frame() instead.
1193
 *
1194
 * @param s media file handle
1195
 * @param pkt is filled
1196
 * @return 0 if OK, AVERROR_xxx on error
1197
 */
1198
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1199

    
1200
/**
1201
 * Return the next frame of a stream.
1202
 * This function returns what is stored in the file, and does not validate
1203
 * that what is there are valid frames for the decoder. It will split what is
1204
 * stored in the file into frames and return one for each call. It will not
1205
 * omit invalid data between valid frames so as to give the decoder the maximum
1206
 * information possible for decoding.
1207
 *
1208
 * The returned packet is valid
1209
 * until the next av_read_frame() or until av_close_input_file() and
1210
 * must be freed with av_free_packet. For video, the packet contains
1211
 * exactly one frame. For audio, it contains an integer number of
1212
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1213
 * data). If the audio frames have a variable size (e.g. MPEG audio),
1214
 * then it contains one frame.
1215
 *
1216
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1217
 * values in AVStream.time_base units (and guessed if the format cannot
1218
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1219
 * has B-frames, so it is better to rely on pkt->dts if you do not
1220
 * decompress the payload.
1221
 *
1222
 * @return 0 if OK, < 0 on error or end of file
1223
 */
1224
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1225

    
1226
/**
1227
 * Seek to the keyframe at timestamp.
1228
 * 'timestamp' in 'stream_index'.
1229
 * @param stream_index If stream_index is (-1), a default
1230
 * stream is selected, and timestamp is automatically converted
1231
 * from AV_TIME_BASE units to the stream specific time_base.
1232
 * @param timestamp Timestamp in AVStream.time_base units
1233
 *        or, if no stream is specified, in AV_TIME_BASE units.
1234
 * @param flags flags which select direction and seeking mode
1235
 * @return >= 0 on success
1236
 */
1237
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1238
                  int flags);
1239

    
1240
/**
1241
 * Seek to timestamp ts.
1242
 * Seeking will be done so that the point from which all active streams
1243
 * can be presented successfully will be closest to ts and within min/max_ts.
1244
 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1245
 *
1246
 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1247
 * are the file position (this may not be supported by all demuxers).
1248
 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1249
 * in the stream with stream_index (this may not be supported by all demuxers).
1250
 * Otherwise all timestamps are in units of the stream selected by stream_index
1251
 * or if stream_index is -1, in AV_TIME_BASE units.
1252
 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1253
 * keyframes (this may not be supported by all demuxers).
1254
 *
1255
 * @param stream_index index of the stream which is used as time base reference
1256
 * @param min_ts smallest acceptable timestamp
1257
 * @param ts target timestamp
1258
 * @param max_ts largest acceptable timestamp
1259
 * @param flags flags
1260
 * @return >=0 on success, error code otherwise
1261
 *
1262
 * @note This is part of the new seek API which is still under construction.
1263
 *       Thus do not use this yet. It may change at any time, do not expect
1264
 *       ABI compatibility yet!
1265
 */
1266
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1267

    
1268
/**
1269
 * Start playing a network-based stream (e.g. RTSP stream) at the
1270
 * current position.
1271
 */
1272
int av_read_play(AVFormatContext *s);
1273

    
1274
/**
1275
 * Pause a network-based stream (e.g. RTSP stream).
1276
 *
1277
 * Use av_read_play() to resume it.
1278
 */
1279
int av_read_pause(AVFormatContext *s);
1280

    
1281
/**
1282
 * Free a AVFormatContext allocated by av_open_input_stream.
1283
 * @param s context to free
1284
 */
1285
void av_close_input_stream(AVFormatContext *s);
1286

    
1287
/**
1288
 * Close a media file (but not its codecs).
1289
 *
1290
 * @param s media file handle
1291
 */
1292
void av_close_input_file(AVFormatContext *s);
1293

    
1294
/**
1295
 * Add a new stream to a media file.
1296
 *
1297
 * Can only be called in the read_header() function. If the flag
1298
 * AVFMTCTX_NOHEADER is in the format context, then new streams
1299
 * can be added in read_packet too.
1300
 *
1301
 * @param s media file handle
1302
 * @param id file-format-dependent stream ID
1303
 */
1304
AVStream *av_new_stream(AVFormatContext *s, int id);
1305
AVProgram *av_new_program(AVFormatContext *s, int id);
1306

    
1307
/**
1308
 * Add a new chapter.
1309
 * This function is NOT part of the public API
1310
 * and should ONLY be used by demuxers.
1311
 *
1312
 * @param s media file handle
1313
 * @param id unique ID for this chapter
1314
 * @param start chapter start time in time_base units
1315
 * @param end chapter end time in time_base units
1316
 * @param title chapter title
1317
 *
1318
 * @return AVChapter or NULL on error
1319
 */
1320
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1321
                          int64_t start, int64_t end, const char *title);
1322

    
1323
/**
1324
 * Set the pts for a given stream.
1325
 *
1326
 * @param s stream
1327
 * @param pts_wrap_bits number of bits effectively used by the pts
1328
 *        (used for wrap control, 33 is the value for MPEG)
1329
 * @param pts_num numerator to convert to seconds (MPEG: 1)
1330
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1331
 */
1332
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1333
                     unsigned int pts_num, unsigned int pts_den);
1334

    
1335
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1336
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
1337
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
1338
#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
1339

    
1340
int av_find_default_stream_index(AVFormatContext *s);
1341

    
1342
/**
1343
 * Get the index for a specific timestamp.
1344
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1345
 *                 to the timestamp which is <= the requested one, if backward
1346
 *                 is 0, then it will be >=
1347
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1348
 * @return < 0 if no such timestamp could be found
1349
 */
1350
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1351

    
1352
/**
1353
 * Ensure the index uses less memory than the maximum specified in
1354
 * AVFormatContext.max_index_size by discarding entries if it grows
1355
 * too large.
1356
 * This function is not part of the public API and should only be called
1357
 * by demuxers.
1358
 */
1359
void ff_reduce_index(AVFormatContext *s, int stream_index);
1360

    
1361
/**
1362
 * Add an index entry into a sorted list. Update the entry if the list
1363
 * already contains it.
1364
 *
1365
 * @param timestamp timestamp in the time base of the given stream
1366
 */
1367
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1368
                       int size, int distance, int flags);
1369

    
1370
/**
1371
 * Perform a binary search using av_index_search_timestamp() and
1372
 * AVInputFormat.read_timestamp().
1373
 * This is not supposed to be called directly by a user application,
1374
 * but by demuxers.
1375
 * @param target_ts target timestamp in the time base of the given stream
1376
 * @param stream_index stream number
1377
 */
1378
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1379
                         int64_t target_ts, int flags);
1380

    
1381
/**
1382
 * Update cur_dts of all streams based on the given timestamp and AVStream.
1383
 *
1384
 * Stream ref_st unchanged, others set cur_dts in their native time base.
1385
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1386
 * @param timestamp new dts expressed in time_base of param ref_st
1387
 * @param ref_st reference stream giving time_base of param timestamp
1388
 */
1389
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1390

    
1391
/**
1392
 * Perform a binary search using read_timestamp().
1393
 * This is not supposed to be called directly by a user application,
1394
 * but by demuxers.
1395
 * @param target_ts target timestamp in the time base of the given stream
1396
 * @param stream_index stream number
1397
 */
1398
int64_t av_gen_search(AVFormatContext *s, int stream_index,
1399
                      int64_t target_ts, int64_t pos_min,
1400
                      int64_t pos_max, int64_t pos_limit,
1401
                      int64_t ts_min, int64_t ts_max,
1402
                      int flags, int64_t *ts_ret,
1403
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1404

    
1405
/**
1406
 * media file output
1407
 */
1408
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1409

    
1410
/**
1411
 * Split a URL string into components.
1412
 *
1413
 * The pointers to buffers for storing individual components may be null,
1414
 * in order to ignore that component. Buffers for components not found are
1415
 * set to empty strings. If the port is not found, it is set to a negative
1416
 * value.
1417
 *
1418
 * @param proto the buffer for the protocol
1419
 * @param proto_size the size of the proto buffer
1420
 * @param authorization the buffer for the authorization
1421
 * @param authorization_size the size of the authorization buffer
1422
 * @param hostname the buffer for the host name
1423
 * @param hostname_size the size of the hostname buffer
1424
 * @param port_ptr a pointer to store the port number in
1425
 * @param path the buffer for the path
1426
 * @param path_size the size of the path buffer
1427
 * @param url the URL to split
1428
 */
1429
void av_url_split(char *proto,         int proto_size,
1430
                  char *authorization, int authorization_size,
1431
                  char *hostname,      int hostname_size,
1432
                  int *port_ptr,
1433
                  char *path,          int path_size,
1434
                  const char *url);
1435

    
1436
/**
1437
 * Allocate the stream private data and write the stream header to an
1438
 * output media file.
1439
 *
1440
 * @param s media file handle
1441
 * @return 0 if OK, AVERROR_xxx on error
1442
 */
1443
int av_write_header(AVFormatContext *s);
1444

    
1445
/**
1446
 * Write a packet to an output media file.
1447
 *
1448
 * The packet shall contain one audio or video frame.
1449
 * The packet must be correctly interleaved according to the container
1450
 * specification, if not then av_interleaved_write_frame must be used.
1451
 *
1452
 * @param s media file handle
1453
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1454
              dts/pts, ...
1455
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1456
 */
1457
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1458

    
1459
/**
1460
 * Write a packet to an output media file ensuring correct interleaving.
1461
 *
1462
 * The packet must contain one audio or video frame.
1463
 * If the packets are already correctly interleaved, the application should
1464
 * call av_write_frame() instead as it is slightly faster. It is also important
1465
 * to keep in mind that completely non-interleaved input will need huge amounts
1466
 * of memory to interleave with this, so it is preferable to interleave at the
1467
 * demuxer level.
1468
 *
1469
 * @param s media file handle
1470
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1471
              dts/pts, ...
1472
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1473
 */
1474
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1475

    
1476
/**
1477
 * Interleave a packet per dts in an output media file.
1478
 *
1479
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1480
 * function, so they cannot be used after it. Note that calling av_free_packet()
1481
 * on them is still safe.
1482
 *
1483
 * @param s media file handle
1484
 * @param out the interleaved packet will be output here
1485
 * @param pkt the input packet
1486
 * @param flush 1 if no further packets are available as input and all
1487
 *              remaining packets should be output
1488
 * @return 1 if a packet was output, 0 if no packet could be output,
1489
 *         < 0 if an error occurred
1490
 */
1491
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1492
                                 AVPacket *pkt, int flush);
1493

    
1494
/**
1495
 * Write the stream trailer to an output media file and free the
1496
 * file private data.
1497
 *
1498
 * May only be called after a successful call to av_write_header.
1499
 *
1500
 * @param s media file handle
1501
 * @return 0 if OK, AVERROR_xxx on error
1502
 */
1503
int av_write_trailer(AVFormatContext *s);
1504

    
1505
void dump_format(AVFormatContext *ic,
1506
                 int index,
1507
                 const char *url,
1508
                 int is_output);
1509

    
1510
#if FF_API_PARSE_FRAME_PARAM
1511
/**
1512
 * Parse width and height out of string str.
1513
 * @deprecated Use av_parse_video_frame_size instead.
1514
 */
1515
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1516
                                          const char *str);
1517

    
1518
/**
1519
 * Convert framerate from a string to a fraction.
1520
 * @deprecated Use av_parse_video_frame_rate instead.
1521
 */
1522
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1523
                                          const char *arg);
1524
#endif
1525

    
1526
/**
1527
 * Parse datestr and return a corresponding number of microseconds.
1528
 * @param datestr String representing a date or a duration.
1529
 * - If a date the syntax is:
1530
 * @code
1531
 *  now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]}
1532
 * @endcode
1533
 * If the value is "now" it takes the current time.
1534
 * Time is local time unless Z is appended, in which case it is
1535
 * interpreted as UTC.
1536
 * If the year-month-day part is not specified it takes the current
1537
 * year-month-day.
1538
 * @return the number of microseconds since 1st of January, 1970 up to
1539
 * the time of the parsed date or INT64_MIN if datestr cannot be
1540
 * successfully parsed.
1541
 * - If a duration the syntax is:
1542
 * @code
1543
 *  [-]HH[:MM[:SS[.m...]]]
1544
 *  [-]S+[.m...]
1545
 * @endcode
1546
 * @return the number of microseconds contained in a time interval
1547
 * with the specified duration or INT64_MIN if datestr cannot be
1548
 * successfully parsed.
1549
 * @param duration Flag which tells how to interpret datestr, if
1550
 * not zero datestr is interpreted as a duration, otherwise as a
1551
 * date.
1552
 */
1553
int64_t parse_date(const char *datestr, int duration);
1554

    
1555
/**
1556
 * Get the current time in microseconds.
1557
 */
1558
int64_t av_gettime(void);
1559

    
1560
/* ffm-specific for ffserver */
1561
#define FFM_PACKET_SIZE 4096
1562
int64_t ffm_read_write_index(int fd);
1563
int ffm_write_write_index(int fd, int64_t pos);
1564
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1565

    
1566
/**
1567
 * Attempt to find a specific tag in a URL.
1568
 *
1569
 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1570
 * Return 1 if found.
1571
 */
1572
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1573

    
1574
/**
1575
 * Return in 'buf' the path with '%d' replaced by a number.
1576
 *
1577
 * Also handles the '%0nd' format where 'n' is the total number
1578
 * of digits and '%%'.
1579
 *
1580
 * @param buf destination buffer
1581
 * @param buf_size destination buffer size
1582
 * @param path numbered sequence string
1583
 * @param number frame number
1584
 * @return 0 if OK, -1 on format error
1585
 */
1586
int av_get_frame_filename(char *buf, int buf_size,
1587
                          const char *path, int number);
1588

    
1589
/**
1590
 * Check whether filename actually is a numbered sequence generator.
1591
 *
1592
 * @param filename possible numbered sequence string
1593
 * @return 1 if a valid numbered sequence string, 0 otherwise
1594
 */
1595
int av_filename_number_test(const char *filename);
1596

    
1597
/**
1598
 * Generate an SDP for an RTP session.
1599
 *
1600
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1601
 *           array is composed by only one context, such context can contain
1602
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1603
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1604
 *           must contain only one AVStream.
1605
 * @param n_files number of AVCodecContexts contained in ac
1606
 * @param buff buffer where the SDP will be stored (must be allocated by
1607
 *             the caller)
1608
 * @param size the size of the buffer
1609
 * @return 0 if OK, AVERROR_xxx on error
1610
 */
1611
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1612

    
1613
/**
1614
 * Return a positive value if the given filename has one of the given
1615
 * extensions, 0 otherwise.
1616
 *
1617
 * @param extensions a comma-separated list of filename extensions
1618
 */
1619
int av_match_ext(const char *filename, const char *extensions);
1620

    
1621
#endif /* AVFORMAT_AVFORMAT_H */