Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 25ae798c

History | View | Annotate | Download (52 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 78
26
#define LIBAVFORMAT_VERSION_MICRO  3
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

    
49
/**
50
 * I return the LIBAVFORMAT_VERSION_INT constant.  You got
51
 * a fucking problem with that, douchebag?
52
 */
53
unsigned avformat_version(void);
54

    
55
/**
56
 * Return the libavformat build-time configuration.
57
 */
58
const char *avformat_configuration(void);
59

    
60
/**
61
 * Return the libavformat license.
62
 */
63
const char *avformat_license(void);
64

    
65
#include <time.h>
66
#include <stdio.h>  /* FILE */
67
#include "libavcodec/avcodec.h"
68

    
69
#include "avio.h"
70

    
71
struct AVFormatContext;
72

    
73

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

    
129
#define AV_METADATA_MATCH_CASE      1
130
#define AV_METADATA_IGNORE_SUFFIX   2
131
#define AV_METADATA_DONT_STRDUP_KEY 4
132
#define AV_METADATA_DONT_STRDUP_VAL 8
133
#define AV_METADATA_DONT_OVERWRITE 16   ///< Don't overwrite existing tags.
134

    
135
typedef struct {
136
    char *key;
137
    char *value;
138
}AVMetadataTag;
139

    
140
typedef struct AVMetadata AVMetadata;
141
typedef struct AVMetadataConv AVMetadataConv;
142

    
143
/**
144
 * Get a metadata element with matching key.
145
 *
146
 * @param prev Set to the previous matching element to find the next.
147
 *             If set to NULL the first matching element is returned.
148
 * @param flags Allows case as well as suffix-insensitive comparisons.
149
 * @return Found tag or NULL, changing key or value leads to undefined behavior.
150
 */
151
AVMetadataTag *
152
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
153

    
154
#if FF_API_OLD_METADATA
155
/**
156
 * Set the given tag in *pm, overwriting an existing tag.
157
 *
158
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
159
 * a metadata struct is allocated and put in *pm.
160
 * @param key tag key to add to *pm (will be av_strduped)
161
 * @param value tag value to add to *pm (will be av_strduped)
162
 * @return >= 0 on success otherwise an error code <0
163
 * @deprecated Use av_metadata_set2() instead.
164
 */
165
attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
166
#endif
167

    
168
/**
169
 * Set the given tag in *pm, overwriting an existing tag.
170
 *
171
 * @param pm pointer to a pointer to a metadata struct. If *pm is NULL
172
 * a metadata struct is allocated and put in *pm.
173
 * @param key tag key to add to *pm (will be av_strduped depending on flags)
174
 * @param value tag value to add to *pm (will be av_strduped depending on flags).
175
 *        Passing a NULL value will cause an existing tag to be deleted.
176
 * @return >= 0 on success otherwise an error code <0
177
 */
178
int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
179

    
180
/**
181
 * Convert all the metadata sets from ctx according to the source and
182
 * destination conversion tables. If one of the tables is NULL, then
183
 * tags are converted to/from ffmpeg generic tag names.
184
 *
185
 * @param d_conv destination tags format conversion table
186
 * @param s_conv source tags format conversion table
187
 */
188
void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv,
189
                                                   const AVMetadataConv *s_conv);
190

    
191
/**
192
 * Free all the memory allocated for an AVMetadata struct.
193
 */
194
void av_metadata_free(AVMetadata **m);
195

    
196

    
197
/* packet functions */
198

    
199

    
200
/**
201
 * Allocate and read the payload of a packet and initialize its
202
 * fields with default values.
203
 *
204
 * @param pkt packet
205
 * @param size desired payload size
206
 * @return >0 (read size) if OK, AVERROR_xxx otherwise
207
 */
208
int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
209

    
210

    
211
/*************************************************/
212
/* fractional numbers for exact pts handling */
213

    
214
/**
215
 * The exact value of the fractional number is: 'val + num / den'.
216
 * num is assumed to be 0 <= num < den.
217
 */
218
typedef struct AVFrac {
219
    int64_t val, num, den;
220
} AVFrac;
221

    
222
/*************************************************/
223
/* input/output formats */
224

    
225
struct AVCodecTag;
226

    
227
/**
228
 * This structure contains the data a format has to probe a file.
229
 */
230
typedef struct AVProbeData {
231
    const char *filename;
232
    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
233
    int buf_size;       /**< Size of buf except extra allocated bytes */
234
} AVProbeData;
235

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

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

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

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

    
305
    /**
306
     * List of supported codec_id-codec_tag pairs, ordered by "better
307
     * choice first". The arrays are all terminated by CODEC_ID_NONE.
308
     */
309
    const struct AVCodecTag * const *codec_tag;
310

    
311
    enum CodecID subtitle_codec; /**< default subtitle codec */
312

    
313
    const AVMetadataConv *metadata_conv;
314

    
315
    /* private fields */
316
    struct AVOutputFormat *next;
317
} AVOutputFormat;
318

    
319
typedef struct AVInputFormat {
320
    /**
321
     * A comma separated list of short names for the format. New names
322
     * may be appended with a minor bump.
323
     */
324
    const char *name;
325

    
326
    /**
327
     * Descriptive name for the format, meant to be more human-readable
328
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
329
     * to define it.
330
     */
331
    const char *long_name;
332

    
333
    /**
334
     * Size of private data so that it can be allocated in the wrapper.
335
     */
336
    int priv_data_size;
337

    
338
    /**
339
     * Tell if a given file has a chance of being parsed as this format.
340
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
341
     * big so you do not have to check for that unless you need more.
342
     */
343
    int (*read_probe)(AVProbeData *);
344

    
345
    /**
346
     * Read the format header and initialize the AVFormatContext
347
     * structure. Return 0 if OK. 'ap' if non-NULL contains
348
     * additional parameters. Only used in raw format right
349
     * now. 'av_new_stream' should be called to create new streams.
350
     */
351
    int (*read_header)(struct AVFormatContext *,
352
                       AVFormatParameters *ap);
353

    
354
    /**
355
     * Read one packet and put it in 'pkt'. pts and flags are also
356
     * set. 'av_new_stream' can be called only if the flag
357
     * AVFMTCTX_NOHEADER is used.
358
     * @return 0 on success, < 0 on error.
359
     *         When returning an error, pkt must not have been allocated
360
     *         or must be freed before returning
361
     */
362
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
363

    
364
    /**
365
     * Close the stream. The AVFormatContext and AVStreams are not
366
     * freed by this function
367
     */
368
    int (*read_close)(struct AVFormatContext *);
369

    
370
#if LIBAVFORMAT_VERSION_MAJOR < 53
371
    /**
372
     * Seek to a given timestamp relative to the frames in
373
     * stream component stream_index.
374
     * @param stream_index Must not be -1.
375
     * @param flags Selects which direction should be preferred if no exact
376
     *              match is available.
377
     * @return >= 0 on success (but not necessarily the new offset)
378
     */
379
    int (*read_seek)(struct AVFormatContext *,
380
                     int stream_index, int64_t timestamp, int flags);
381
#endif
382
    /**
383
     * Gets the next timestamp in stream[stream_index].time_base units.
384
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
385
     */
386
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
387
                              int64_t *pos, int64_t pos_limit);
388

    
389
    /**
390
     * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER.
391
     */
392
    int flags;
393

    
394
    /**
395
     * If extensions are defined, then no probe is done. You should
396
     * usually not use extension format guessing because it is not
397
     * reliable enough
398
     */
399
    const char *extensions;
400

    
401
    /**
402
     * General purpose read-only value that the format can use.
403
     */
404
    int value;
405

    
406
    /**
407
     * Start/resume playing - only meaningful if using a network-based format
408
     * (RTSP).
409
     */
410
    int (*read_play)(struct AVFormatContext *);
411

    
412
    /**
413
     * Pause playing - only meaningful if using a network-based format
414
     * (RTSP).
415
     */
416
    int (*read_pause)(struct AVFormatContext *);
417

    
418
    const struct AVCodecTag * const *codec_tag;
419

    
420
    /**
421
     * Seek to timestamp ts.
422
     * Seeking will be done so that the point from which all active streams
423
     * can be presented successfully will be closest to ts and within min/max_ts.
424
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
425
     */
426
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
427

    
428
    const AVMetadataConv *metadata_conv;
429

    
430
    /* private fields */
431
    struct AVInputFormat *next;
432
} AVInputFormat;
433

    
434
enum AVStreamParseType {
435
    AVSTREAM_PARSE_NONE,
436
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
437
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
438
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
439
    AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
440
};
441

    
442
typedef struct AVIndexEntry {
443
    int64_t pos;
444
    int64_t timestamp;
445
#define AVINDEX_KEYFRAME 0x0001
446
    int flags:2;
447
    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).
448
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
449
} AVIndexEntry;
450

    
451
#define AV_DISPOSITION_DEFAULT   0x0001
452
#define AV_DISPOSITION_DUB       0x0002
453
#define AV_DISPOSITION_ORIGINAL  0x0004
454
#define AV_DISPOSITION_COMMENT   0x0008
455
#define AV_DISPOSITION_LYRICS    0x0010
456
#define AV_DISPOSITION_KARAOKE   0x0020
457

    
458
/**
459
 * Track should be used during playback by default.
460
 * Useful for subtitle track that should be displayed
461
 * even when user did not explicitly ask for subtitles.
462
 */
463
#define AV_DISPOSITION_FORCED    0x0040
464

    
465
/**
466
 * Stream structure.
467
 * New fields can be added to the end with minor version bumps.
468
 * Removal, reordering and changes to existing fields require a major
469
 * version bump.
470
 * sizeof(AVStream) must not be used outside libav*.
471
 */
472
typedef struct AVStream {
473
    int index;    /**< stream index in AVFormatContext */
474
    int id;       /**< format-specific stream ID */
475
    AVCodecContext *codec; /**< codec context */
476
    /**
477
     * Real base framerate of the stream.
478
     * This is the lowest framerate with which all timestamps can be
479
     * represented accurately (it is the least common multiple of all
480
     * framerates in the stream). Note, this value is just a guess!
481
     * For example, if the time base is 1/90000 and all frames have either
482
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
483
     */
484
    AVRational r_frame_rate;
485
    void *priv_data;
486

    
487
    /* internal data used in av_find_stream_info() */
488
    int64_t first_dts;
489

    
490
    /**
491
     * encoding: pts generation when outputting stream
492
     */
493
    struct AVFrac pts;
494

    
495
    /**
496
     * This is the fundamental unit of time (in seconds) in terms
497
     * of which frame timestamps are represented. For fixed-fps content,
498
     * time base should be 1/framerate and timestamp increments should be 1.
499
     */
500
    AVRational time_base;
501
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
502
    /* ffmpeg.c private use */
503
    int stream_copy; /**< If set, just copy stream. */
504
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
505

    
506
    //FIXME move stuff to a flags field?
507
    /**
508
     * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
509
     * MN: dunno if that is the right place for it
510
     */
511
    float quality;
512

    
513
    /**
514
     * Decoding: pts of the first frame of the stream, in stream time base.
515
     * Only set this if you are absolutely 100% sure that the value you set
516
     * it to really is the pts of the first frame.
517
     * This may be undefined (AV_NOPTS_VALUE).
518
     * @note The ASF header does NOT contain a correct start_time the ASF
519
     * demuxer must NOT set this.
520
     */
521
    int64_t start_time;
522

    
523
    /**
524
     * Decoding: duration of the stream, in stream time base.
525
     * If a source file does not specify a duration, but does specify
526
     * a bitrate, this value will be estimated from bitrate and file size.
527
     */
528
    int64_t duration;
529

    
530
#if FF_API_OLD_METADATA
531
    char language[4]; /**< ISO 639-2/B 3-letter language code (empty string if undefined) */
532
#endif
533

    
534
    /* av_read_frame() support */
535
    enum AVStreamParseType need_parsing;
536
    struct AVCodecParserContext *parser;
537

    
538
    int64_t cur_dts;
539
    int last_IP_duration;
540
    int64_t last_IP_pts;
541
    /* av_seek_frame() support */
542
    AVIndexEntry *index_entries; /**< Only used if the format does not
543
                                    support seeking natively. */
544
    int nb_index_entries;
545
    unsigned int index_entries_allocated_size;
546

    
547
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
548

    
549
#if LIBAVFORMAT_VERSION_INT < (53<<16)
550
    int64_t unused[4+1];
551
#endif
552

    
553
#if FF_API_OLD_METADATA
554
    char *filename; /**< source filename of the stream */
555
#endif
556

    
557
    int disposition; /**< AV_DISPOSITION_* bit field */
558

    
559
    AVProbeData probe_data;
560
#define MAX_REORDER_DELAY 16
561
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
562

    
563
    /**
564
     * sample aspect ratio (0 if unknown)
565
     * - encoding: Set by user.
566
     * - decoding: Set by libavformat.
567
     */
568
    AVRational sample_aspect_ratio;
569

    
570
    AVMetadata *metadata;
571

    
572
    /* Intended mostly for av_read_frame() support. Not supposed to be used by */
573
    /* external applications; try to use something else if at all possible.    */
574
    const uint8_t *cur_ptr;
575
    int cur_len;
576
    AVPacket cur_pkt;
577

    
578
    // Timestamp generation support:
579
    /**
580
     * Timestamp corresponding to the last dts sync point.
581
     *
582
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
583
     * a DTS is received from the underlying container. Otherwise set to
584
     * AV_NOPTS_VALUE by default.
585
     */
586
    int64_t reference_dts;
587

    
588
    /**
589
     * Number of packets to buffer for codec probing
590
     * NOT PART OF PUBLIC API
591
     */
592
#define MAX_PROBE_PACKETS 2500
593
    int probe_packets;
594

    
595
    /**
596
     * last packet in packet_buffer for this stream when muxing.
597
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
598
     */
599
    struct AVPacketList *last_in_packet_buffer;
600

    
601
    /**
602
     * Average framerate
603
     */
604
    AVRational avg_frame_rate;
605

    
606
    /**
607
     * Number of frames that have been demuxed during av_find_stream_info()
608
     */
609
    int codec_info_nb_frames;
610
} AVStream;
611

    
612
#define AV_PROGRAM_RUNNING 1
613

    
614
/**
615
 * New fields can be added to the end with minor version bumps.
616
 * Removal, reordering and changes to existing fields require a major
617
 * version bump.
618
 * sizeof(AVProgram) must not be used outside libav*.
619
 */
620
typedef struct AVProgram {
621
    int            id;
622
#if FF_API_OLD_METADATA
623
    char           *provider_name; ///< network name for DVB streams
624
    char           *name;          ///< service name for DVB streams
625
#endif
626
    int            flags;
627
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
628
    unsigned int   *stream_index;
629
    unsigned int   nb_stream_indexes;
630
    AVMetadata *metadata;
631
} AVProgram;
632

    
633
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
634
                                         (streams are added dynamically) */
635

    
636
typedef struct AVChapter {
637
    int id;                 ///< unique ID to identify the chapter
638
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
639
    int64_t start, end;     ///< chapter start/end time in time_base units
640
#if FF_API_OLD_METADATA
641
    char *title;            ///< chapter title
642
#endif
643
    AVMetadata *metadata;
644
} AVChapter;
645

    
646
#if FF_API_MAX_STREAMS
647
#define MAX_STREAMS 20
648
#endif
649

    
650
/**
651
 * Format I/O context.
652
 * New fields can be added to the end with minor version bumps.
653
 * Removal, reordering and changes to existing fields require a major
654
 * version bump.
655
 * sizeof(AVFormatContext) must not be used outside libav*.
656
 */
657
typedef struct AVFormatContext {
658
    const AVClass *av_class; /**< Set by avformat_alloc_context. */
659
    /* Can only be iformat or oformat, not both at the same time. */
660
    struct AVInputFormat *iformat;
661
    struct AVOutputFormat *oformat;
662
    void *priv_data;
663
    ByteIOContext *pb;
664
    unsigned int nb_streams;
665
    AVStream *streams[MAX_STREAMS];
666
    char filename[1024]; /**< input or output filename */
667
    /* stream info */
668
    int64_t timestamp;
669
#if FF_API_OLD_METADATA
670
    char title[512];
671
    char author[512];
672
    char copyright[512];
673
    char comment[512];
674
    char album[512];
675
    int year;  /**< ID3 year, 0 if none */
676
    int track; /**< track number, 0 if none */
677
    char genre[32]; /**< ID3 genre */
678
#endif
679

    
680
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
681
    /* private data for pts handling (do not modify directly). */
682
    /**
683
     * This buffer is only needed when packets were already buffered but
684
     * not decoded, for example to get the codec parameters in MPEG
685
     * streams.
686
     */
687
    struct AVPacketList *packet_buffer;
688

    
689
    /**
690
     * Decoding: position of the first frame of the component, in
691
     * AV_TIME_BASE fractional seconds. NEVER set this value directly:
692
     * It is deduced from the AVStream values.
693
     */
694
    int64_t start_time;
695

    
696
    /**
697
     * Decoding: duration of the stream, in AV_TIME_BASE fractional
698
     * seconds. Only set this value if you know none of the individual stream
699
     * durations and also dont set any of them. This is deduced from the
700
     * AVStream values if not set.
701
     */
702
    int64_t duration;
703

    
704
    /**
705
     * decoding: total file size, 0 if unknown
706
     */
707
    int64_t file_size;
708

    
709
    /**
710
     * Decoding: total stream bitrate in bit/s, 0 if not
711
     * available. Never set it directly if the file_size and the
712
     * duration are known as FFmpeg can compute it automatically.
713
     */
714
    int bit_rate;
715

    
716
    /* av_read_frame() support */
717
    AVStream *cur_st;
718
#if LIBAVFORMAT_VERSION_INT < (53<<16)
719
    const uint8_t *cur_ptr_deprecated;
720
    int cur_len_deprecated;
721
    AVPacket cur_pkt_deprecated;
722
#endif
723

    
724
    /* av_seek_frame() support */
725
    int64_t data_offset; /**< offset of the first packet */
726
    int index_built;
727

    
728
    int mux_rate;
729
    unsigned int packet_size;
730
    int preload;
731
    int max_delay;
732

    
733
#define AVFMT_NOOUTPUTLOOP -1
734
#define AVFMT_INFINITEOUTPUTLOOP 0
735
    /**
736
     * number of times to loop output in formats that support it
737
     */
738
    int loop_output;
739

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

    
749
    int loop_input;
750

    
751
    /**
752
     * decoding: size of data to probe; encoding: unused.
753
     */
754
    unsigned int probesize;
755

    
756
    /**
757
     * Maximum time (in AV_TIME_BASE units) during which the input should
758
     * be analyzed in av_find_stream_info().
759
     */
760
    int max_analyze_duration;
761

    
762
    const uint8_t *key;
763
    int keylen;
764

    
765
    unsigned int nb_programs;
766
    AVProgram **programs;
767

    
768
    /**
769
     * Forced video codec_id.
770
     * Demuxing: Set by user.
771
     */
772
    enum CodecID video_codec_id;
773

    
774
    /**
775
     * Forced audio codec_id.
776
     * Demuxing: Set by user.
777
     */
778
    enum CodecID audio_codec_id;
779

    
780
    /**
781
     * Forced subtitle codec_id.
782
     * Demuxing: Set by user.
783
     */
784
    enum CodecID subtitle_codec_id;
785

    
786
    /**
787
     * Maximum amount of memory in bytes to use for the index of each stream.
788
     * If the index exceeds this size, entries will be discarded as
789
     * needed to maintain a smaller size. This can lead to slower or less
790
     * accurate seeking (depends on demuxer).
791
     * Demuxers for which a full in-memory index is mandatory will ignore
792
     * this.
793
     * muxing  : unused
794
     * demuxing: set by user
795
     */
796
    unsigned int max_index_size;
797

    
798
    /**
799
     * Maximum amount of memory in bytes to use for buffering frames
800
     * obtained from realtime capture devices.
801
     */
802
    unsigned int max_picture_buffer;
803

    
804
    unsigned int nb_chapters;
805
    AVChapter **chapters;
806

    
807
    /**
808
     * Flags to enable debugging.
809
     */
810
    int debug;
811
#define FF_FDEBUG_TS        0x0001
812

    
813
    /**
814
     * Raw packets from the demuxer, prior to parsing and decoding.
815
     * This buffer is used for buffering packets until the codec can
816
     * be identified, as parsing cannot be done without knowing the
817
     * codec.
818
     */
819
    struct AVPacketList *raw_packet_buffer;
820
    struct AVPacketList *raw_packet_buffer_end;
821

    
822
    struct AVPacketList *packet_buffer_end;
823

    
824
    AVMetadata *metadata;
825

    
826
    /**
827
     * Remaining size available for raw_packet_buffer, in bytes.
828
     * NOT PART OF PUBLIC API
829
     */
830
#define RAW_PACKET_BUFFER_SIZE 2500000
831
    int raw_packet_buffer_remaining_size;
832

    
833
    /**
834
     * Start time of the stream in real world time, in microseconds
835
     * since the unix epoch (00:00 1st January 1970). That is, pts=0
836
     * in the stream was captured at this real world time.
837
     * - encoding: Set by user.
838
     * - decoding: Unused.
839
     */
840
    int64_t start_time_realtime;
841
} AVFormatContext;
842

    
843
typedef struct AVPacketList {
844
    AVPacket pkt;
845
    struct AVPacketList *next;
846
} AVPacketList;
847

    
848
#if LIBAVFORMAT_VERSION_INT < (53<<16)
849
extern AVInputFormat *first_iformat;
850
extern AVOutputFormat *first_oformat;
851
#endif
852

    
853
/**
854
 * If f is NULL, returns the first registered input format,
855
 * if f is non-NULL, returns the next registered input format after f
856
 * or NULL if f is the last one.
857
 */
858
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
859

    
860
/**
861
 * If f is NULL, returns the first registered output format,
862
 * if f is non-NULL, returns the next registered output format after f
863
 * or NULL if f is the last one.
864
 */
865
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
866

    
867
enum CodecID av_guess_image2_codec(const char *filename);
868

    
869
/* XXX: Use automatic init with either ELF sections or C file parser */
870
/* modules. */
871

    
872
/* utils.c */
873
void av_register_input_format(AVInputFormat *format);
874
void av_register_output_format(AVOutputFormat *format);
875
#if LIBAVFORMAT_VERSION_MAJOR < 53
876
attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
877
                                    const char *filename,
878
                                    const char *mime_type);
879

    
880
/**
881
 * @deprecated Use av_guess_format() instead.
882
 */
883
attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
884
                                                  const char *filename,
885
                                                  const char *mime_type);
886
#endif
887

    
888
/**
889
 * Return the output format in the list of registered output formats
890
 * which best matches the provided parameters, or return NULL if
891
 * there is no match.
892
 *
893
 * @param short_name if non-NULL checks if short_name matches with the
894
 * names of the registered formats
895
 * @param filename if non-NULL checks if filename terminates with the
896
 * extensions of the registered formats
897
 * @param mime_type if non-NULL checks if mime_type matches with the
898
 * MIME type of the registered formats
899
 */
900
AVOutputFormat *av_guess_format(const char *short_name,
901
                                const char *filename,
902
                                const char *mime_type);
903

    
904
/**
905
 * Guess the codec ID based upon muxer and filename.
906
 */
907
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
908
                            const char *filename, const char *mime_type,
909
                            enum AVMediaType type);
910

    
911
/**
912
 * Send a nice hexadecimal dump of a buffer to the specified file stream.
913
 *
914
 * @param f The file stream pointer where the dump should be sent to.
915
 * @param buf buffer
916
 * @param size buffer size
917
 *
918
 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
919
 */
920
void av_hex_dump(FILE *f, uint8_t *buf, int size);
921

    
922
/**
923
 * Send a nice hexadecimal dump of a buffer to the log.
924
 *
925
 * @param avcl A pointer to an arbitrary struct of which the first field is a
926
 * pointer to an AVClass struct.
927
 * @param level The importance level of the message, lower values signifying
928
 * higher importance.
929
 * @param buf buffer
930
 * @param size buffer size
931
 *
932
 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
933
 */
934
void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
935

    
936
/**
937
 * Send a nice dump of a packet to the specified file stream.
938
 *
939
 * @param f The file stream pointer where the dump should be sent to.
940
 * @param pkt packet to dump
941
 * @param dump_payload True if the payload must be displayed, too.
942
 */
943
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
944

    
945
/**
946
 * Send a nice dump of a packet to the log.
947
 *
948
 * @param avcl A pointer to an arbitrary struct of which the first field is a
949
 * pointer to an AVClass struct.
950
 * @param level The importance level of the message, lower values signifying
951
 * higher importance.
952
 * @param pkt packet to dump
953
 * @param dump_payload True if the payload must be displayed, too.
954
 */
955
void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
956

    
957
/**
958
 * Initialize libavformat and register all the muxers, demuxers and
959
 * protocols. If you do not call this function, then you can select
960
 * exactly which formats you want to support.
961
 *
962
 * @see av_register_input_format()
963
 * @see av_register_output_format()
964
 * @see av_register_protocol()
965
 */
966
void av_register_all(void);
967

    
968
/**
969
 * Get the CodecID for the given codec tag tag.
970
 * If no codec id is found returns CODEC_ID_NONE.
971
 *
972
 * @param tags list of supported codec_id-codec_tag pairs, as stored
973
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
974
 */
975
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
976

    
977
/**
978
 * Get the codec tag for the given codec id id.
979
 * If no codec tag is found returns 0.
980
 *
981
 * @param tags list of supported codec_id-codec_tag pairs, as stored
982
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
983
 */
984
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
985

    
986
/* media file input */
987

    
988
/**
989
 * Find AVInputFormat based on the short name of the input format.
990
 */
991
AVInputFormat *av_find_input_format(const char *short_name);
992

    
993
/**
994
 * Guess the file format.
995
 *
996
 * @param is_opened Whether the file is already opened; determines whether
997
 *                  demuxers with or without AVFMT_NOFILE are probed.
998
 */
999
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
1000

    
1001
/**
1002
 * Guess the file format.
1003
 *
1004
 * @param is_opened Whether the file is already opened; determines whether
1005
 *                  demuxers with or without AVFMT_NOFILE are probed.
1006
 * @param score_max A probe score larger that this is required to accept a
1007
 *                  detection, the variable is set to the actual detection
1008
 *                  score afterwards.
1009
 *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
1010
 *                  to retry with a larger probe buffer.
1011
 */
1012
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
1013

    
1014
/**
1015
 * Allocate all the structures needed to read an input stream.
1016
 *        This does not open the needed codecs for decoding the stream[s].
1017
 */
1018
int av_open_input_stream(AVFormatContext **ic_ptr,
1019
                         ByteIOContext *pb, const char *filename,
1020
                         AVInputFormat *fmt, AVFormatParameters *ap);
1021

    
1022
/**
1023
 * Open a media file as input. The codecs are not opened. Only the file
1024
 * header (if present) is read.
1025
 *
1026
 * @param ic_ptr The opened media file handle is put here.
1027
 * @param filename filename to open
1028
 * @param fmt If non-NULL, force the file format to use.
1029
 * @param buf_size optional buffer size (zero if default is OK)
1030
 * @param ap Additional parameters needed when opening the file
1031
 *           (NULL if default).
1032
 * @return 0 if OK, AVERROR_xxx otherwise
1033
 */
1034
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
1035
                       AVInputFormat *fmt,
1036
                       int buf_size,
1037
                       AVFormatParameters *ap);
1038

    
1039
#if LIBAVFORMAT_VERSION_MAJOR < 53
1040
/**
1041
 * @deprecated Use avformat_alloc_context() instead.
1042
 */
1043
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
1044
#endif
1045

    
1046
/**
1047
 * Allocate an AVFormatContext.
1048
 * Can be freed with av_free() but do not forget to free everything you
1049
 * explicitly allocated as well!
1050
 */
1051
AVFormatContext *avformat_alloc_context(void);
1052

    
1053
/**
1054
 * Read packets of a media file to get stream information. This
1055
 * is useful for file formats with no headers such as MPEG. This
1056
 * function also computes the real framerate in case of MPEG-2 repeat
1057
 * frame mode.
1058
 * The logical file position is not changed by this function;
1059
 * examined packets may be buffered for later processing.
1060
 *
1061
 * @param ic media file handle
1062
 * @return >=0 if OK, AVERROR_xxx on error
1063
 * @todo Let the user decide somehow what information is needed so that
1064
 *       we do not waste time getting stuff the user does not need.
1065
 */
1066
int av_find_stream_info(AVFormatContext *ic);
1067

    
1068
/**
1069
 * Read a transport packet from a media file.
1070
 *
1071
 * This function is obsolete and should never be used.
1072
 * Use av_read_frame() instead.
1073
 *
1074
 * @param s media file handle
1075
 * @param pkt is filled
1076
 * @return 0 if OK, AVERROR_xxx on error
1077
 */
1078
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
1079

    
1080
/**
1081
 * Return the next frame of a stream.
1082
 *
1083
 * The returned packet is valid
1084
 * until the next av_read_frame() or until av_close_input_file() and
1085
 * must be freed with av_free_packet. For video, the packet contains
1086
 * exactly one frame. For audio, it contains an integer number of
1087
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
1088
 * data). If the audio frames have a variable size (e.g. MPEG audio),
1089
 * then it contains one frame.
1090
 *
1091
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1092
 * values in AVStream.time_base units (and guessed if the format cannot
1093
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1094
 * has B-frames, so it is better to rely on pkt->dts if you do not
1095
 * decompress the payload.
1096
 *
1097
 * @return 0 if OK, < 0 on error or end of file
1098
 */
1099
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1100

    
1101
/**
1102
 * Seek to the keyframe at timestamp.
1103
 * 'timestamp' in 'stream_index'.
1104
 * @param stream_index If stream_index is (-1), a default
1105
 * stream is selected, and timestamp is automatically converted
1106
 * from AV_TIME_BASE units to the stream specific time_base.
1107
 * @param timestamp Timestamp in AVStream.time_base units
1108
 *        or, if no stream is specified, in AV_TIME_BASE units.
1109
 * @param flags flags which select direction and seeking mode
1110
 * @return >= 0 on success
1111
 */
1112
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1113
                  int flags);
1114

    
1115
/**
1116
 * Seek to timestamp ts.
1117
 * Seeking will be done so that the point from which all active streams
1118
 * can be presented successfully will be closest to ts and within min/max_ts.
1119
 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1120
 *
1121
 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1122
 * are the file position (this may not be supported by all demuxers).
1123
 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1124
 * in the stream with stream_index (this may not be supported by all demuxers).
1125
 * Otherwise all timestamps are in units of the stream selected by stream_index
1126
 * or if stream_index is -1, in AV_TIME_BASE units.
1127
 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1128
 * keyframes (this may not be supported by all demuxers).
1129
 *
1130
 * @param stream_index index of the stream which is used as time base reference
1131
 * @param min_ts smallest acceptable timestamp
1132
 * @param ts target timestamp
1133
 * @param max_ts largest acceptable timestamp
1134
 * @param flags flags
1135
 * @return >=0 on success, error code otherwise
1136
 *
1137
 * @note This is part of the new seek API which is still under construction.
1138
 *       Thus do not use this yet. It may change at any time, do not expect
1139
 *       ABI compatibility yet!
1140
 */
1141
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1142

    
1143
/**
1144
 * Start playing a network-based stream (e.g. RTSP stream) at the
1145
 * current position.
1146
 */
1147
int av_read_play(AVFormatContext *s);
1148

    
1149
/**
1150
 * Pause a network-based stream (e.g. RTSP stream).
1151
 *
1152
 * Use av_read_play() to resume it.
1153
 */
1154
int av_read_pause(AVFormatContext *s);
1155

    
1156
/**
1157
 * Free a AVFormatContext allocated by av_open_input_stream.
1158
 * @param s context to free
1159
 */
1160
void av_close_input_stream(AVFormatContext *s);
1161

    
1162
/**
1163
 * Close a media file (but not its codecs).
1164
 *
1165
 * @param s media file handle
1166
 */
1167
void av_close_input_file(AVFormatContext *s);
1168

    
1169
/**
1170
 * Add a new stream to a media file.
1171
 *
1172
 * Can only be called in the read_header() function. If the flag
1173
 * AVFMTCTX_NOHEADER is in the format context, then new streams
1174
 * can be added in read_packet too.
1175
 *
1176
 * @param s media file handle
1177
 * @param id file-format-dependent stream ID
1178
 */
1179
AVStream *av_new_stream(AVFormatContext *s, int id);
1180
AVProgram *av_new_program(AVFormatContext *s, int id);
1181

    
1182
/**
1183
 * Add a new chapter.
1184
 * This function is NOT part of the public API
1185
 * and should ONLY be used by demuxers.
1186
 *
1187
 * @param s media file handle
1188
 * @param id unique ID for this chapter
1189
 * @param start chapter start time in time_base units
1190
 * @param end chapter end time in time_base units
1191
 * @param title chapter title
1192
 *
1193
 * @return AVChapter or NULL on error
1194
 */
1195
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1196
                          int64_t start, int64_t end, const char *title);
1197

    
1198
/**
1199
 * Set the pts for a given stream.
1200
 *
1201
 * @param s stream
1202
 * @param pts_wrap_bits number of bits effectively used by the pts
1203
 *        (used for wrap control, 33 is the value for MPEG)
1204
 * @param pts_num numerator to convert to seconds (MPEG: 1)
1205
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1206
 */
1207
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1208
                     unsigned int pts_num, unsigned int pts_den);
1209

    
1210
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1211
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
1212
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
1213
#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
1214

    
1215
int av_find_default_stream_index(AVFormatContext *s);
1216

    
1217
/**
1218
 * Get the index for a specific timestamp.
1219
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1220
 *                 to the timestamp which is <= the requested one, if backward
1221
 *                 is 0, then it will be >=
1222
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1223
 * @return < 0 if no such timestamp could be found
1224
 */
1225
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1226

    
1227
/**
1228
 * Ensure the index uses less memory than the maximum specified in
1229
 * AVFormatContext.max_index_size by discarding entries if it grows
1230
 * too large.
1231
 * This function is not part of the public API and should only be called
1232
 * by demuxers.
1233
 */
1234
void ff_reduce_index(AVFormatContext *s, int stream_index);
1235

    
1236
/**
1237
 * Add an index entry into a sorted list. Update the entry if the list
1238
 * already contains it.
1239
 *
1240
 * @param timestamp timestamp in the time base of the given stream
1241
 */
1242
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1243
                       int size, int distance, int flags);
1244

    
1245
/**
1246
 * Perform a binary search using av_index_search_timestamp() and
1247
 * AVInputFormat.read_timestamp().
1248
 * This is not supposed to be called directly by a user application,
1249
 * but by demuxers.
1250
 * @param target_ts target timestamp in the time base of the given stream
1251
 * @param stream_index stream number
1252
 */
1253
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1254
                         int64_t target_ts, int flags);
1255

    
1256
/**
1257
 * Update cur_dts of all streams based on the given timestamp and AVStream.
1258
 *
1259
 * Stream ref_st unchanged, others set cur_dts in their native time base.
1260
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1261
 * @param timestamp new dts expressed in time_base of param ref_st
1262
 * @param ref_st reference stream giving time_base of param timestamp
1263
 */
1264
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1265

    
1266
/**
1267
 * Perform a binary search using read_timestamp().
1268
 * This is not supposed to be called directly by a user application,
1269
 * but by demuxers.
1270
 * @param target_ts target timestamp in the time base of the given stream
1271
 * @param stream_index stream number
1272
 */
1273
int64_t av_gen_search(AVFormatContext *s, int stream_index,
1274
                      int64_t target_ts, int64_t pos_min,
1275
                      int64_t pos_max, int64_t pos_limit,
1276
                      int64_t ts_min, int64_t ts_max,
1277
                      int flags, int64_t *ts_ret,
1278
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1279

    
1280
/**
1281
 * media file output
1282
 */
1283
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1284

    
1285
/**
1286
 * Split a URL string into components.
1287
 *
1288
 * The pointers to buffers for storing individual components may be null,
1289
 * in order to ignore that component. Buffers for components not found are
1290
 * set to empty strings. If the port is not found, it is set to a negative
1291
 * value.
1292
 *
1293
 * @param proto the buffer for the protocol
1294
 * @param proto_size the size of the proto buffer
1295
 * @param authorization the buffer for the authorization
1296
 * @param authorization_size the size of the authorization buffer
1297
 * @param hostname the buffer for the host name
1298
 * @param hostname_size the size of the hostname buffer
1299
 * @param port_ptr a pointer to store the port number in
1300
 * @param path the buffer for the path
1301
 * @param path_size the size of the path buffer
1302
 * @param url the URL to split
1303
 */
1304
void av_url_split(char *proto,         int proto_size,
1305
                  char *authorization, int authorization_size,
1306
                  char *hostname,      int hostname_size,
1307
                  int *port_ptr,
1308
                  char *path,          int path_size,
1309
                  const char *url);
1310

    
1311
/**
1312
 * Allocate the stream private data and write the stream header to an
1313
 * output media file.
1314
 *
1315
 * @param s media file handle
1316
 * @return 0 if OK, AVERROR_xxx on error
1317
 */
1318
int av_write_header(AVFormatContext *s);
1319

    
1320
/**
1321
 * Write a packet to an output media file.
1322
 *
1323
 * The packet shall contain one audio or video frame.
1324
 * The packet must be correctly interleaved according to the container
1325
 * specification, if not then av_interleaved_write_frame must be used.
1326
 *
1327
 * @param s media file handle
1328
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1329
              dts/pts, ...
1330
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1331
 */
1332
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1333

    
1334
/**
1335
 * Write a packet to an output media file ensuring correct interleaving.
1336
 *
1337
 * The packet must contain one audio or video frame.
1338
 * If the packets are already correctly interleaved, the application should
1339
 * call av_write_frame() instead as it is slightly faster. It is also important
1340
 * to keep in mind that completely non-interleaved input will need huge amounts
1341
 * of memory to interleave with this, so it is preferable to interleave at the
1342
 * demuxer level.
1343
 *
1344
 * @param s media file handle
1345
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1346
              dts/pts, ...
1347
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1348
 */
1349
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1350

    
1351
/**
1352
 * Interleave a packet per dts in an output media file.
1353
 *
1354
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1355
 * function, so they cannot be used after it. Note that calling av_free_packet()
1356
 * on them is still safe.
1357
 *
1358
 * @param s media file handle
1359
 * @param out the interleaved packet will be output here
1360
 * @param pkt the input packet
1361
 * @param flush 1 if no further packets are available as input and all
1362
 *              remaining packets should be output
1363
 * @return 1 if a packet was output, 0 if no packet could be output,
1364
 *         < 0 if an error occurred
1365
 */
1366
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1367
                                 AVPacket *pkt, int flush);
1368

    
1369
/**
1370
 * Write the stream trailer to an output media file and free the
1371
 * file private data.
1372
 *
1373
 * May only be called after a successful call to av_write_header.
1374
 *
1375
 * @param s media file handle
1376
 * @return 0 if OK, AVERROR_xxx on error
1377
 */
1378
int av_write_trailer(AVFormatContext *s);
1379

    
1380
void dump_format(AVFormatContext *ic,
1381
                 int index,
1382
                 const char *url,
1383
                 int is_output);
1384

    
1385
#if LIBAVFORMAT_VERSION_MAJOR < 53
1386
/**
1387
 * Parse width and height out of string str.
1388
 * @deprecated Use av_parse_video_frame_size instead.
1389
 */
1390
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1391
                                          const char *str);
1392

    
1393
/**
1394
 * Convert framerate from a string to a fraction.
1395
 * @deprecated Use av_parse_video_frame_rate instead.
1396
 */
1397
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1398
                                          const char *arg);
1399
#endif
1400

    
1401
/**
1402
 * Parse datestr and return a corresponding number of microseconds.
1403
 * @param datestr String representing a date or a duration.
1404
 * - If a date the syntax is:
1405
 * @code
1406
 *  now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]}
1407
 * @endcode
1408
 * If the value is "now" it takes the current time.
1409
 * Time is local time unless Z is appended, in which case it is
1410
 * interpreted as UTC.
1411
 * If the year-month-day part is not specified it takes the current
1412
 * year-month-day.
1413
 * @return the number of microseconds since 1st of January, 1970 up to
1414
 * the time of the parsed date or INT64_MIN if datestr cannot be
1415
 * successfully parsed.
1416
 * - If a duration the syntax is:
1417
 * @code
1418
 *  [-]HH[:MM[:SS[.m...]]]
1419
 *  [-]S+[.m...]
1420
 * @endcode
1421
 * @return the number of microseconds contained in a time interval
1422
 * with the specified duration or INT64_MIN if datestr cannot be
1423
 * successfully parsed.
1424
 * @param duration Flag which tells how to interpret datestr, if
1425
 * not zero datestr is interpreted as a duration, otherwise as a
1426
 * date.
1427
 */
1428
int64_t parse_date(const char *datestr, int duration);
1429

    
1430
/**
1431
 * Get the current time in microseconds.
1432
 */
1433
int64_t av_gettime(void);
1434

    
1435
/* ffm-specific for ffserver */
1436
#define FFM_PACKET_SIZE 4096
1437
int64_t ffm_read_write_index(int fd);
1438
int ffm_write_write_index(int fd, int64_t pos);
1439
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1440

    
1441
/**
1442
 * Attempt to find a specific tag in a URL.
1443
 *
1444
 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1445
 * Return 1 if found.
1446
 */
1447
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1448

    
1449
/**
1450
 * Return in 'buf' the path with '%d' replaced by a number.
1451
 *
1452
 * Also handles the '%0nd' format where 'n' is the total number
1453
 * of digits and '%%'.
1454
 *
1455
 * @param buf destination buffer
1456
 * @param buf_size destination buffer size
1457
 * @param path numbered sequence string
1458
 * @param number frame number
1459
 * @return 0 if OK, -1 on format error
1460
 */
1461
int av_get_frame_filename(char *buf, int buf_size,
1462
                          const char *path, int number);
1463

    
1464
/**
1465
 * Check whether filename actually is a numbered sequence generator.
1466
 *
1467
 * @param filename possible numbered sequence string
1468
 * @return 1 if a valid numbered sequence string, 0 otherwise
1469
 */
1470
int av_filename_number_test(const char *filename);
1471

    
1472
/**
1473
 * Generate an SDP for an RTP session.
1474
 *
1475
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1476
 *           array is composed by only one context, such context can contain
1477
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1478
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1479
 *           must contain only one AVStream.
1480
 * @param n_files number of AVCodecContexts contained in ac
1481
 * @param buff buffer where the SDP will be stored (must be allocated by
1482
 *             the caller)
1483
 * @param size the size of the buffer
1484
 * @return 0 if OK, AVERROR_xxx on error
1485
 */
1486
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1487

    
1488
/**
1489
 * Return a positive value if the given filename has one of the given
1490
 * extensions, 0 otherwise.
1491
 *
1492
 * @param extensions a comma-separated list of filename extensions
1493
 */
1494
int av_match_ext(const char *filename, const char *extensions);
1495

    
1496
#endif /* AVFORMAT_AVFORMAT_H */