Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ 57fe80fe

History | View | Annotate | Download (51 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 74
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
 * I return the LIBAVFORMAT_VERSION_INT constant.  You got
40
 * a fucking problem with that, douchebag?
41
 */
42
unsigned avformat_version(void);
43

    
44
/**
45
 * Return the libavformat build-time configuration.
46
 */
47
const char *avformat_configuration(void);
48

    
49
/**
50
 * Return the libavformat license.
51
 */
52
const char *avformat_license(void);
53

    
54
#include <time.h>
55
#include <stdio.h>  /* FILE */
56
#include "libavcodec/avcodec.h"
57

    
58
#include "avio.h"
59

    
60
struct AVFormatContext;
61

    
62

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

    
118
#define AV_METADATA_MATCH_CASE      1
119
#define AV_METADATA_IGNORE_SUFFIX   2
120
#define AV_METADATA_DONT_STRDUP_KEY 4
121
#define AV_METADATA_DONT_STRDUP_VAL 8
122
#define AV_METADATA_DONT_OVERWRITE 16   ///< Don't overwrite existing tags.
123

    
124
typedef struct {
125
    char *key;
126
    char *value;
127
}AVMetadataTag;
128

    
129
typedef struct AVMetadata AVMetadata;
130
typedef struct AVMetadataConv AVMetadataConv;
131

    
132
/**
133
 * Get a metadata element with matching key.
134
 * @param prev Set to the previous matching element to find the next.
135
 *             If set to NULL the first matching element is returned.
136
 * @param flags Allows case as well as suffix-insensitive comparisons.
137
 * @return Found tag or NULL, changing key or value leads to undefined behavior.
138
 */
139
AVMetadataTag *
140
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
141

    
142
#if LIBAVFORMAT_VERSION_MAJOR == 52
143
/**
144
 * Set the given tag in m, overwriting an existing tag.
145
 * @param key tag key to add to m (will be av_strduped)
146
 * @param value tag value to add to m (will be av_strduped)
147
 * @return >= 0 on success otherwise an error code <0
148
 * @deprecated Use av_metadata_set2() instead.
149
 */
150
attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
151
#endif
152

    
153
/**
154
 * Set the given tag in m, overwriting an existing tag.
155
 * @param key tag key to add to m (will be av_strduped depending on flags)
156
 * @param value tag value to add to m (will be av_strduped depending on flags).
157
 *        Passing a NULL value will cause an existing tag to be deleted.
158
 * @return >= 0 on success otherwise an error code <0
159
 */
160
int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags);
161

    
162
/**
163
 * Convert all the metadata sets from ctx according to the source and
164
 * destination conversion tables. If one of the tables is NULL, then
165
 * tags are converted to/from ffmpeg generic tag names.
166
 * @param d_conv destination tags format conversion table
167
 * @param s_conv source tags format conversion table
168
 */
169
void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
170
                                                  const AVMetadataConv *s_conv);
171

    
172
/**
173
 * Free all the memory allocated for an AVMetadata struct.
174
 */
175
void av_metadata_free(AVMetadata **m);
176

    
177

    
178
/* packet functions */
179

    
180

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

    
191

    
192
/*************************************************/
193
/* fractional numbers for exact pts handling */
194

    
195
/**
196
 * The exact value of the fractional number is: 'val + num / den'.
197
 * num is assumed to be 0 <= num < den.
198
 */
199
typedef struct AVFrac {
200
    int64_t val, num, den;
201
} AVFrac;
202

    
203
/*************************************************/
204
/* input/output formats */
205

    
206
struct AVCodecTag;
207

    
208
/** This structure contains the data a format has to probe a file. */
209
typedef struct AVProbeData {
210
    const char *filename;
211
    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
212
    int buf_size;       /**< Size of buf except extra allocated bytes */
213
} AVProbeData;
214

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

    
218
typedef struct AVFormatParameters {
219
    AVRational time_base;
220
    int sample_rate;
221
    int channels;
222
    int width;
223
    int height;
224
    enum PixelFormat pix_fmt;
225
    int channel; /**< Used to select DV channel. */
226
    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
227
    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
228
    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
229
                                            stream packet (only meaningful if
230
                                            mpeg2ts_raw is TRUE). */
231
    unsigned int initial_pause:1;       /**< Do not begin to play the stream
232
                                            immediately (RTSP only). */
233
    unsigned int prealloced_context:1;
234
#if LIBAVFORMAT_VERSION_INT < (53<<16)
235
    enum CodecID video_codec_id;
236
    enum CodecID audio_codec_id;
237
#endif
238
} AVFormatParameters;
239

    
240
//! Demuxer will use url_fopen, no opened file should be provided by the caller.
241
#define AVFMT_NOFILE        0x0001
242
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
243
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
244
#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
245
                                      raw picture data. */
246
#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
247
#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
248
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
249
#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. */
250
#define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
251
#define AVFMT_NODIMENSIONS  0x0800 /**< Format does not need width/height */
252

    
253
typedef struct AVOutputFormat {
254
    const char *name;
255
    /**
256
     * Descriptive name for the format, meant to be more human-readable
257
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
258
     * to define it.
259
     */
260
    const char *long_name;
261
    const char *mime_type;
262
    const char *extensions; /**< comma-separated filename extensions */
263
    /** size of private data so that it can be allocated in the wrapper */
264
    int priv_data_size;
265
    /* output support */
266
    enum CodecID audio_codec; /**< default audio codec */
267
    enum CodecID video_codec; /**< default video codec */
268
    int (*write_header)(struct AVFormatContext *);
269
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
270
    int (*write_trailer)(struct AVFormatContext *);
271
    /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
272
    int flags;
273
    /** Currently only used to set pixel format if not YUV420P. */
274
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
275
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
276
                             AVPacket *in, int flush);
277

    
278
    /**
279
     * List of supported codec_id-codec_tag pairs, ordered by "better
280
     * choice first". The arrays are all terminated by CODEC_ID_NONE.
281
     */
282
    const struct AVCodecTag * const *codec_tag;
283

    
284
    enum CodecID subtitle_codec; /**< default subtitle codec */
285

    
286
    const AVMetadataConv *metadata_conv;
287

    
288
    /* private fields */
289
    struct AVOutputFormat *next;
290
} AVOutputFormat;
291

    
292
typedef struct AVInputFormat {
293
    const char *name;
294
    /**
295
     * Descriptive name for the format, meant to be more human-readable
296
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
297
     * to define it.
298
     */
299
    const char *long_name;
300
    /** Size of private data so that it can be allocated in the wrapper. */
301
    int priv_data_size;
302
    /**
303
     * Tell if a given file has a chance of being parsed as this format.
304
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
305
     * big so you do not have to check for that unless you need more.
306
     */
307
    int (*read_probe)(AVProbeData *);
308
    /** Read the format header and initialize the AVFormatContext
309
       structure. Return 0 if OK. 'ap' if non-NULL contains
310
       additional parameters. Only used in raw format right
311
       now. 'av_new_stream' should be called to create new streams.  */
312
    int (*read_header)(struct AVFormatContext *,
313
                       AVFormatParameters *ap);
314
    /** Read one packet and put it in 'pkt'. pts and flags are also
315
       set. 'av_new_stream' can be called only if the flag
316
       AVFMTCTX_NOHEADER is used.
317
       @return 0 on success, < 0 on error.
318
               When returning an error, pkt must not have been allocated
319
               or must be freed before returning */
320
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
321
    /** Close the stream. The AVFormatContext and AVStreams are not
322
       freed by this function */
323
    int (*read_close)(struct AVFormatContext *);
324

    
325
#if LIBAVFORMAT_VERSION_MAJOR < 53
326
    /**
327
     * Seek to a given timestamp relative to the frames in
328
     * stream component stream_index.
329
     * @param stream_index Must not be -1.
330
     * @param flags Selects which direction should be preferred if no exact
331
     *              match is available.
332
     * @return >= 0 on success (but not necessarily the new offset)
333
     */
334
    int (*read_seek)(struct AVFormatContext *,
335
                     int stream_index, int64_t timestamp, int flags);
336
#endif
337
    /**
338
     * Gets the next timestamp in stream[stream_index].time_base units.
339
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
340
     */
341
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
342
                              int64_t *pos, int64_t pos_limit);
343
    /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
344
    int flags;
345
    /** If extensions are defined, then no probe is done. You should
346
       usually not use extension format guessing because it is not
347
       reliable enough */
348
    const char *extensions;
349
    /** General purpose read-only value that the format can use. */
350
    int value;
351

    
352
    /** Start/resume playing - only meaningful if using a network-based format
353
       (RTSP). */
354
    int (*read_play)(struct AVFormatContext *);
355

    
356
    /** Pause playing - only meaningful if using a network-based format
357
       (RTSP). */
358
    int (*read_pause)(struct AVFormatContext *);
359

    
360
    const struct AVCodecTag * const *codec_tag;
361

    
362
    /**
363
     * Seek to timestamp ts.
364
     * Seeking will be done so that the point from which all active streams
365
     * can be presented successfully will be closest to ts and within min/max_ts.
366
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
367
     */
368
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
369

    
370
    const AVMetadataConv *metadata_conv;
371

    
372
    /* private fields */
373
    struct AVInputFormat *next;
374
} AVInputFormat;
375

    
376
enum AVStreamParseType {
377
    AVSTREAM_PARSE_NONE,
378
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
379
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
380
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
381
    AVSTREAM_PARSE_FULL_ONCE,  /**< full parsing and repack of the first frame only, only implemented for H.264 currently */
382
};
383

    
384
typedef struct AVIndexEntry {
385
    int64_t pos;
386
    int64_t timestamp;
387
#define AVINDEX_KEYFRAME 0x0001
388
    int flags:2;
389
    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).
390
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
391
} AVIndexEntry;
392

    
393
#define AV_DISPOSITION_DEFAULT   0x0001
394
#define AV_DISPOSITION_DUB       0x0002
395
#define AV_DISPOSITION_ORIGINAL  0x0004
396
#define AV_DISPOSITION_COMMENT   0x0008
397
#define AV_DISPOSITION_LYRICS    0x0010
398
#define AV_DISPOSITION_KARAOKE   0x0020
399
/** Track should be used during playback by default.
400
    Useful for subtitle track that should be displayed
401
    even when user did not explicitly ask for subtitles. */
402
#define AV_DISPOSITION_FORCED    0x0040
403

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

    
426
    /* internal data used in av_find_stream_info() */
427
    int64_t first_dts;
428
    /** encoding: pts generation when outputting stream */
429
    struct AVFrac pts;
430

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

    
461
#if LIBAVFORMAT_VERSION_INT < (53<<16)
462
    char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
463
#endif
464

    
465
    /* av_read_frame() support */
466
    enum AVStreamParseType need_parsing;
467
    struct AVCodecParserContext *parser;
468

    
469
    int64_t cur_dts;
470
    int last_IP_duration;
471
    int64_t last_IP_pts;
472
    /* av_seek_frame() support */
473
    AVIndexEntry *index_entries; /**< Only used if the format does not
474
                                    support seeking natively. */
475
    int nb_index_entries;
476
    unsigned int index_entries_allocated_size;
477

    
478
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
479

    
480
#if LIBAVFORMAT_VERSION_INT < (53<<16)
481
    int64_t unused[4+1];
482

    
483
    char *filename; /**< source filename of the stream */
484
#endif
485

    
486
    int disposition; /**< AV_DISPOSITION_* bit field */
487

    
488
    AVProbeData probe_data;
489
#define MAX_REORDER_DELAY 16
490
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
491

    
492
    /**
493
     * sample aspect ratio (0 if unknown)
494
     * - encoding: Set by user.
495
     * - decoding: Set by libavformat.
496
     */
497
    AVRational sample_aspect_ratio;
498

    
499
    AVMetadata *metadata;
500

    
501
    /* Intended mostly for av_read_frame() support. Not supposed to be used by */
502
    /* external applications; try to use something else if at all possible.    */
503
    const uint8_t *cur_ptr;
504
    int cur_len;
505
    AVPacket cur_pkt;
506

    
507
    // Timestamp generation support:
508
    /**
509
     * Timestamp corresponding to the last dts sync point.
510
     *
511
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
512
     * a DTS is received from the underlying container. Otherwise set to
513
     * AV_NOPTS_VALUE by default.
514
     */
515
    int64_t reference_dts;
516

    
517
    /**
518
     * Number of packets to buffer for codec probing
519
     * NOT PART OF PUBLIC API
520
     */
521
#define MAX_PROBE_PACKETS 2500
522
    int probe_packets;
523

    
524
    /**
525
     * last packet in packet_buffer for this stream when muxing.
526
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
527
     */
528
    struct AVPacketList *last_in_packet_buffer;
529

    
530
    /**
531
     * Average framerate
532
     */
533
    AVRational avg_frame_rate;
534

    
535
    /**
536
     * Number of frames that have been demuxed during av_find_stream_info()
537
     */
538
    int codec_info_nb_frames;
539
} AVStream;
540

    
541
#define AV_PROGRAM_RUNNING 1
542

    
543
/**
544
 * New fields can be added to the end with minor version bumps.
545
 * Removal, reordering and changes to existing fields require a major
546
 * version bump.
547
 * sizeof(AVProgram) must not be used outside libav*.
548
 */
549
typedef struct AVProgram {
550
    int            id;
551
#if LIBAVFORMAT_VERSION_INT < (53<<16)
552
    char           *provider_name; ///< network name for DVB streams
553
    char           *name;          ///< service name for DVB streams
554
#endif
555
    int            flags;
556
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
557
    unsigned int   *stream_index;
558
    unsigned int   nb_stream_indexes;
559
    AVMetadata *metadata;
560
} AVProgram;
561

    
562
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
563
                                         (streams are added dynamically) */
564

    
565
typedef struct AVChapter {
566
    int id;                 ///< unique ID to identify the chapter
567
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
568
    int64_t start, end;     ///< chapter start/end time in time_base units
569
#if LIBAVFORMAT_VERSION_INT < (53<<16)
570
    char *title;            ///< chapter title
571
#endif
572
    AVMetadata *metadata;
573
} AVChapter;
574

    
575
#if LIBAVFORMAT_VERSION_MAJOR < 53
576
#define MAX_STREAMS 20
577
#endif
578

    
579
/**
580
 * Format I/O context.
581
 * New fields can be added to the end with minor version bumps.
582
 * Removal, reordering and changes to existing fields require a major
583
 * version bump.
584
 * sizeof(AVFormatContext) must not be used outside libav*.
585
 */
586
typedef struct AVFormatContext {
587
    const AVClass *av_class; /**< Set by avformat_alloc_context. */
588
    /* Can only be iformat or oformat, not both at the same time. */
589
    struct AVInputFormat *iformat;
590
    struct AVOutputFormat *oformat;
591
    void *priv_data;
592
    ByteIOContext *pb;
593
    unsigned int nb_streams;
594
    AVStream *streams[MAX_STREAMS];
595
    char filename[1024]; /**< input or output filename */
596
    /* stream info */
597
    int64_t timestamp;
598
#if LIBAVFORMAT_VERSION_INT < (53<<16)
599
    char title[512];
600
    char author[512];
601
    char copyright[512];
602
    char comment[512];
603
    char album[512];
604
    int year;  /**< ID3 year, 0 if none */
605
    int track; /**< track number, 0 if none */
606
    char genre[32]; /**< ID3 genre */
607
#endif
608

    
609
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
610
    /* private data for pts handling (do not modify directly). */
611
    /** This buffer is only needed when packets were already buffered but
612
       not decoded, for example to get the codec parameters in MPEG
613
       streams. */
614
    struct AVPacketList *packet_buffer;
615

    
616
    /** Decoding: position of the first frame of the component, in
617
       AV_TIME_BASE fractional seconds. NEVER set this value directly:
618
       It is deduced from the AVStream values.  */
619
    int64_t start_time;
620
    /** Decoding: duration of the stream, in AV_TIME_BASE fractional
621
       seconds. Only set this value if you know none of the individual stream
622
       durations and also dont set any of them. This is deduced from the
623
       AVStream values if not set.  */
624
    int64_t duration;
625
    /** decoding: total file size, 0 if unknown */
626
    int64_t file_size;
627
    /** Decoding: total stream bitrate in bit/s, 0 if not
628
       available. Never set it directly if the file_size and the
629
       duration are known as FFmpeg can compute it automatically. */
630
    int bit_rate;
631

    
632
    /* av_read_frame() support */
633
    AVStream *cur_st;
634
#if LIBAVFORMAT_VERSION_INT < (53<<16)
635
    const uint8_t *cur_ptr_deprecated;
636
    int cur_len_deprecated;
637
    AVPacket cur_pkt_deprecated;
638
#endif
639

    
640
    /* av_seek_frame() support */
641
    int64_t data_offset; /** offset of the first packet */
642
    int index_built;
643

    
644
    int mux_rate;
645
    unsigned int packet_size;
646
    int preload;
647
    int max_delay;
648

    
649
#define AVFMT_NOOUTPUTLOOP -1
650
#define AVFMT_INFINITEOUTPUTLOOP 0
651
    /** number of times to loop output in formats that support it */
652
    int loop_output;
653

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

    
663
    int loop_input;
664
    /** decoding: size of data to probe; encoding: unused. */
665
    unsigned int probesize;
666

    
667
    /**
668
     * Maximum time (in AV_TIME_BASE units) during which the input should
669
     * be analyzed in av_find_stream_info().
670
     */
671
    int max_analyze_duration;
672

    
673
    const uint8_t *key;
674
    int keylen;
675

    
676
    unsigned int nb_programs;
677
    AVProgram **programs;
678

    
679
    /**
680
     * Forced video codec_id.
681
     * Demuxing: Set by user.
682
     */
683
    enum CodecID video_codec_id;
684
    /**
685
     * Forced audio codec_id.
686
     * Demuxing: Set by user.
687
     */
688
    enum CodecID audio_codec_id;
689
    /**
690
     * Forced subtitle codec_id.
691
     * Demuxing: Set by user.
692
     */
693
    enum CodecID subtitle_codec_id;
694

    
695
    /**
696
     * Maximum amount of memory in bytes to use for the index of each stream.
697
     * If the index exceeds this size, entries will be discarded as
698
     * needed to maintain a smaller size. This can lead to slower or less
699
     * accurate seeking (depends on demuxer).
700
     * Demuxers for which a full in-memory index is mandatory will ignore
701
     * this.
702
     * muxing  : unused
703
     * demuxing: set by user
704
     */
705
    unsigned int max_index_size;
706

    
707
    /**
708
     * Maximum amount of memory in bytes to use for buffering frames
709
     * obtained from realtime capture devices.
710
     */
711
    unsigned int max_picture_buffer;
712

    
713
    unsigned int nb_chapters;
714
    AVChapter **chapters;
715

    
716
    /**
717
     * Flags to enable debugging.
718
     */
719
    int debug;
720
#define FF_FDEBUG_TS        0x0001
721

    
722
    /**
723
     * Raw packets from the demuxer, prior to parsing and decoding.
724
     * This buffer is used for buffering packets until the codec can
725
     * be identified, as parsing cannot be done without knowing the
726
     * codec.
727
     */
728
    struct AVPacketList *raw_packet_buffer;
729
    struct AVPacketList *raw_packet_buffer_end;
730

    
731
    struct AVPacketList *packet_buffer_end;
732

    
733
    AVMetadata *metadata;
734

    
735
    /**
736
     * Remaining size available for raw_packet_buffer, in bytes.
737
     * NOT PART OF PUBLIC API
738
     */
739
#define RAW_PACKET_BUFFER_SIZE 2500000
740
    int raw_packet_buffer_remaining_size;
741

    
742
    /**
743
     * Start time of the stream in real world time, in microseconds
744
     * since the unix epoch (00:00 1st January 1970). That is, pts=0
745
     * in the stream was captured at this real world time.
746
     * - encoding: Set by user.
747
     * - decoding: Unused.
748
     */
749
    int64_t start_time_realtime;
750
} AVFormatContext;
751

    
752
typedef struct AVPacketList {
753
    AVPacket pkt;
754
    struct AVPacketList *next;
755
} AVPacketList;
756

    
757
#if LIBAVFORMAT_VERSION_INT < (53<<16)
758
extern AVInputFormat *first_iformat;
759
extern AVOutputFormat *first_oformat;
760
#endif
761

    
762
/**
763
 * If f is NULL, returns the first registered input format,
764
 * if f is non-NULL, returns the next registered input format after f
765
 * or NULL if f is the last one.
766
 */
767
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
768

    
769
/**
770
 * If f is NULL, returns the first registered output format,
771
 * if f is non-NULL, returns the next registered output format after f
772
 * or NULL if f is the last one.
773
 */
774
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
775

    
776
enum CodecID av_guess_image2_codec(const char *filename);
777

    
778
/* XXX: Use automatic init with either ELF sections or C file parser */
779
/* modules. */
780

    
781
/* utils.c */
782
void av_register_input_format(AVInputFormat *format);
783
void av_register_output_format(AVOutputFormat *format);
784
#if LIBAVFORMAT_VERSION_MAJOR < 53
785
attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name,
786
                                    const char *filename,
787
                                    const char *mime_type);
788

    
789
/**
790
 * @deprecated Use av_guess_format() instead.
791
 */
792
attribute_deprecated AVOutputFormat *guess_format(const char *short_name,
793
                                                  const char *filename,
794
                                                  const char *mime_type);
795
#endif
796

    
797
/**
798
 * Return the output format in the list of registered output formats
799
 * which best matches the provided parameters, or return NULL if
800
 * there is no match.
801
 *
802
 * @param short_name if non-NULL checks if short_name matches with the
803
 * names of the registered formats
804
 * @param filename if non-NULL checks if filename terminates with the
805
 * extensions of the registered formats
806
 * @param mime_type if non-NULL checks if mime_type matches with the
807
 * MIME type of the registered formats
808
 */
809
AVOutputFormat *av_guess_format(const char *short_name,
810
                                const char *filename,
811
                                const char *mime_type);
812

    
813
/**
814
 * Guess the codec ID based upon muxer and filename.
815
 */
816
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
817
                            const char *filename, const char *mime_type,
818
                            enum AVMediaType type);
819

    
820
/**
821
 * Send a nice hexadecimal dump of a buffer to the specified file stream.
822
 *
823
 * @param f The file stream pointer where the dump should be sent to.
824
 * @param buf buffer
825
 * @param size buffer size
826
 *
827
 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
828
 */
829
void av_hex_dump(FILE *f, uint8_t *buf, int size);
830

    
831
/**
832
 * Send a nice hexadecimal dump of a buffer to the log.
833
 *
834
 * @param avcl A pointer to an arbitrary struct of which the first field is a
835
 * pointer to an AVClass struct.
836
 * @param level The importance level of the message, lower values signifying
837
 * higher importance.
838
 * @param buf buffer
839
 * @param size buffer size
840
 *
841
 * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log
842
 */
843
void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size);
844

    
845
/**
846
 * Send a nice dump of a packet to the specified file stream.
847
 *
848
 * @param f The file stream pointer where the dump should be sent to.
849
 * @param pkt packet to dump
850
 * @param dump_payload True if the payload must be displayed, too.
851
 */
852
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
853

    
854
/**
855
 * Send a nice dump of a packet to the log.
856
 *
857
 * @param avcl A pointer to an arbitrary struct of which the first field is a
858
 * pointer to an AVClass struct.
859
 * @param level The importance level of the message, lower values signifying
860
 * higher importance.
861
 * @param pkt packet to dump
862
 * @param dump_payload True if the payload must be displayed, too.
863
 */
864
void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload);
865

    
866
/**
867
 * Initialize libavformat and register all the muxers, demuxers and
868
 * protocols. If you do not call this function, then you can select
869
 * exactly which formats you want to support.
870
 *
871
 * @see av_register_input_format()
872
 * @see av_register_output_format()
873
 * @see av_register_protocol()
874
 */
875
void av_register_all(void);
876

    
877
/**
878
 * Get the CodecID for the given codec tag tag.
879
 * If no codec id is found returns CODEC_ID_NONE.
880
 *
881
 * @param tags list of supported codec_id-codec_tag pairs, as stored
882
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
883
 */
884
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
885

    
886
/**
887
 * Get the codec tag for the given codec id id.
888
 * If no codec tag is found returns 0.
889
 *
890
 * @param tags list of supported codec_id-codec_tag pairs, as stored
891
 * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag
892
 */
893
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
894

    
895
/* media file input */
896

    
897
/**
898
 * Find AVInputFormat based on the short name of the input format.
899
 */
900
AVInputFormat *av_find_input_format(const char *short_name);
901

    
902
/**
903
 * Guess the file format.
904
 *
905
 * @param is_opened Whether the file is already opened; determines whether
906
 *                  demuxers with or without AVFMT_NOFILE are probed.
907
 */
908
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
909

    
910
/**
911
 * Guess the file format.
912
 *
913
 * @param is_opened Whether the file is already opened; determines whether
914
 *                  demuxers with or without AVFMT_NOFILE are probed.
915
 * @param score_max A probe score larger that this is required to accept a
916
 *                  detection, the variable is set to the actual detection
917
 *                  score afterwards.
918
 *                  If the score is <= AVPROBE_SCORE_MAX / 4 it is recommended
919
 *                  to retry with a larger probe buffer.
920
 */
921
AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max);
922

    
923
/**
924
 * Allocate all the structures needed to read an input stream.
925
 *        This does not open the needed codecs for decoding the stream[s].
926
 */
927
int av_open_input_stream(AVFormatContext **ic_ptr,
928
                         ByteIOContext *pb, const char *filename,
929
                         AVInputFormat *fmt, AVFormatParameters *ap);
930

    
931
/**
932
 * Open a media file as input. The codecs are not opened. Only the file
933
 * header (if present) is read.
934
 *
935
 * @param ic_ptr The opened media file handle is put here.
936
 * @param filename filename to open
937
 * @param fmt If non-NULL, force the file format to use.
938
 * @param buf_size optional buffer size (zero if default is OK)
939
 * @param ap Additional parameters needed when opening the file
940
 *           (NULL if default).
941
 * @return 0 if OK, AVERROR_xxx otherwise
942
 */
943
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
944
                       AVInputFormat *fmt,
945
                       int buf_size,
946
                       AVFormatParameters *ap);
947

    
948
#if LIBAVFORMAT_VERSION_MAJOR < 53
949
/**
950
 * @deprecated Use avformat_alloc_context() instead.
951
 */
952
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
953
#endif
954

    
955
/**
956
 * Allocate an AVFormatContext.
957
 * Can be freed with av_free() but do not forget to free everything you
958
 * explicitly allocated as well!
959
 */
960
AVFormatContext *avformat_alloc_context(void);
961

    
962
/**
963
 * Read packets of a media file to get stream information. This
964
 * is useful for file formats with no headers such as MPEG. This
965
 * function also computes the real framerate in case of MPEG-2 repeat
966
 * frame mode.
967
 * The logical file position is not changed by this function;
968
 * examined packets may be buffered for later processing.
969
 *
970
 * @param ic media file handle
971
 * @return >=0 if OK, AVERROR_xxx on error
972
 * @todo Let the user decide somehow what information is needed so that
973
 *       we do not waste time getting stuff the user does not need.
974
 */
975
int av_find_stream_info(AVFormatContext *ic);
976

    
977
/**
978
 * Read a transport packet from a media file.
979
 *
980
 * This function is obsolete and should never be used.
981
 * Use av_read_frame() instead.
982
 *
983
 * @param s media file handle
984
 * @param pkt is filled
985
 * @return 0 if OK, AVERROR_xxx on error
986
 */
987
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
988

    
989
/**
990
 * Return the next frame of a stream.
991
 *
992
 * The returned packet is valid
993
 * until the next av_read_frame() or until av_close_input_file() and
994
 * must be freed with av_free_packet. For video, the packet contains
995
 * exactly one frame. For audio, it contains an integer number of
996
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
997
 * data). If the audio frames have a variable size (e.g. MPEG audio),
998
 * then it contains one frame.
999
 *
1000
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
1001
 * values in AVStream.time_base units (and guessed if the format cannot
1002
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
1003
 * has B-frames, so it is better to rely on pkt->dts if you do not
1004
 * decompress the payload.
1005
 *
1006
 * @return 0 if OK, < 0 on error or end of file
1007
 */
1008
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
1009

    
1010
/**
1011
 * Seek to the keyframe at timestamp.
1012
 * 'timestamp' in 'stream_index'.
1013
 * @param stream_index If stream_index is (-1), a default
1014
 * stream is selected, and timestamp is automatically converted
1015
 * from AV_TIME_BASE units to the stream specific time_base.
1016
 * @param timestamp Timestamp in AVStream.time_base units
1017
 *        or, if no stream is specified, in AV_TIME_BASE units.
1018
 * @param flags flags which select direction and seeking mode
1019
 * @return >= 0 on success
1020
 */
1021
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
1022
                  int flags);
1023

    
1024
/**
1025
 * Seek to timestamp ts.
1026
 * Seeking will be done so that the point from which all active streams
1027
 * can be presented successfully will be closest to ts and within min/max_ts.
1028
 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
1029
 *
1030
 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
1031
 * are the file position (this may not be supported by all demuxers).
1032
 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
1033
 * in the stream with stream_index (this may not be supported by all demuxers).
1034
 * Otherwise all timestamps are in units of the stream selected by stream_index
1035
 * or if stream_index is -1, in AV_TIME_BASE units.
1036
 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
1037
 * keyframes (this may not be supported by all demuxers).
1038
 *
1039
 * @param stream_index index of the stream which is used as time base reference
1040
 * @param min_ts smallest acceptable timestamp
1041
 * @param ts target timestamp
1042
 * @param max_ts largest acceptable timestamp
1043
 * @param flags flags
1044
 * @return >=0 on success, error code otherwise
1045
 *
1046
 * @note This is part of the new seek API which is still under construction.
1047
 *       Thus do not use this yet. It may change at any time, do not expect
1048
 *       ABI compatibility yet!
1049
 */
1050
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
1051

    
1052
/**
1053
 * Start playing a network-based stream (e.g. RTSP stream) at the
1054
 * current position.
1055
 */
1056
int av_read_play(AVFormatContext *s);
1057

    
1058
/**
1059
 * Pause a network-based stream (e.g. RTSP stream).
1060
 *
1061
 * Use av_read_play() to resume it.
1062
 */
1063
int av_read_pause(AVFormatContext *s);
1064

    
1065
/**
1066
 * Free a AVFormatContext allocated by av_open_input_stream.
1067
 * @param s context to free
1068
 */
1069
void av_close_input_stream(AVFormatContext *s);
1070

    
1071
/**
1072
 * Close a media file (but not its codecs).
1073
 *
1074
 * @param s media file handle
1075
 */
1076
void av_close_input_file(AVFormatContext *s);
1077

    
1078
/**
1079
 * Add a new stream to a media file.
1080
 *
1081
 * Can only be called in the read_header() function. If the flag
1082
 * AVFMTCTX_NOHEADER is in the format context, then new streams
1083
 * can be added in read_packet too.
1084
 *
1085
 * @param s media file handle
1086
 * @param id file-format-dependent stream ID
1087
 */
1088
AVStream *av_new_stream(AVFormatContext *s, int id);
1089
AVProgram *av_new_program(AVFormatContext *s, int id);
1090

    
1091
/**
1092
 * Add a new chapter.
1093
 * This function is NOT part of the public API
1094
 * and should ONLY be used by demuxers.
1095
 *
1096
 * @param s media file handle
1097
 * @param id unique ID for this chapter
1098
 * @param start chapter start time in time_base units
1099
 * @param end chapter end time in time_base units
1100
 * @param title chapter title
1101
 *
1102
 * @return AVChapter or NULL on error
1103
 */
1104
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
1105
                          int64_t start, int64_t end, const char *title);
1106

    
1107
/**
1108
 * Set the pts for a given stream.
1109
 *
1110
 * @param s stream
1111
 * @param pts_wrap_bits number of bits effectively used by the pts
1112
 *        (used for wrap control, 33 is the value for MPEG)
1113
 * @param pts_num numerator to convert to seconds (MPEG: 1)
1114
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
1115
 */
1116
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
1117
                     unsigned int pts_num, unsigned int pts_den);
1118

    
1119
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
1120
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
1121
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
1122
#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
1123

    
1124
int av_find_default_stream_index(AVFormatContext *s);
1125

    
1126
/**
1127
 * Get the index for a specific timestamp.
1128
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
1129
 *                 to the timestamp which is <= the requested one, if backward
1130
 *                 is 0, then it will be >=
1131
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
1132
 * @return < 0 if no such timestamp could be found
1133
 */
1134
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
1135

    
1136
/**
1137
 * Ensure the index uses less memory than the maximum specified in
1138
 * AVFormatContext.max_index_size by discarding entries if it grows
1139
 * too large.
1140
 * This function is not part of the public API and should only be called
1141
 * by demuxers.
1142
 */
1143
void ff_reduce_index(AVFormatContext *s, int stream_index);
1144

    
1145
/**
1146
 * Add an index entry into a sorted list. Update the entry if the list
1147
 * already contains it.
1148
 *
1149
 * @param timestamp timestamp in the time base of the given stream
1150
 */
1151
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1152
                       int size, int distance, int flags);
1153

    
1154
/**
1155
 * Perform a binary search using av_index_search_timestamp() and
1156
 * AVCodec.read_timestamp().
1157
 * This is not supposed to be called directly by a user application,
1158
 * but by demuxers.
1159
 * @param target_ts target timestamp in the time base of the given stream
1160
 * @param stream_index stream number
1161
 */
1162
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1163
                         int64_t target_ts, int flags);
1164

    
1165
/**
1166
 * Update cur_dts of all streams based on the given timestamp and AVStream.
1167
 *
1168
 * Stream ref_st unchanged, others set cur_dts in their native time base.
1169
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1170
 * @param timestamp new dts expressed in time_base of param ref_st
1171
 * @param ref_st reference stream giving time_base of param timestamp
1172
 */
1173
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1174

    
1175
/**
1176
 * Perform a binary search using read_timestamp().
1177
 * This is not supposed to be called directly by a user application,
1178
 * but by demuxers.
1179
 * @param target_ts target timestamp in the time base of the given stream
1180
 * @param stream_index stream number
1181
 */
1182
int64_t av_gen_search(AVFormatContext *s, int stream_index,
1183
                      int64_t target_ts, int64_t pos_min,
1184
                      int64_t pos_max, int64_t pos_limit,
1185
                      int64_t ts_min, int64_t ts_max,
1186
                      int flags, int64_t *ts_ret,
1187
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1188

    
1189
/** media file output */
1190
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1191

    
1192
/**
1193
 * Split a URL string into components.
1194
 *
1195
 * The pointers to buffers for storing individual components may be null,
1196
 * in order to ignore that component. Buffers for components not found are
1197
 * set to empty strings. If the port is not found, it is set to a negative
1198
 * value.
1199
 *
1200
 * @param proto the buffer for the protocol
1201
 * @param proto_size the size of the proto buffer
1202
 * @param authorization the buffer for the authorization
1203
 * @param authorization_size the size of the authorization buffer
1204
 * @param hostname the buffer for the host name
1205
 * @param hostname_size the size of the hostname buffer
1206
 * @param port_ptr a pointer to store the port number in
1207
 * @param path the buffer for the path
1208
 * @param path_size the size of the path buffer
1209
 * @param url the URL to split
1210
 */
1211
void av_url_split(char *proto,         int proto_size,
1212
                  char *authorization, int authorization_size,
1213
                  char *hostname,      int hostname_size,
1214
                  int *port_ptr,
1215
                  char *path,          int path_size,
1216
                  const char *url);
1217

    
1218
/**
1219
 * Allocate the stream private data and write the stream header to an
1220
 * output media file.
1221
 *
1222
 * @param s media file handle
1223
 * @return 0 if OK, AVERROR_xxx on error
1224
 */
1225
int av_write_header(AVFormatContext *s);
1226

    
1227
/**
1228
 * Write a packet to an output media file.
1229
 *
1230
 * The packet shall contain one audio or video frame.
1231
 * The packet must be correctly interleaved according to the container
1232
 * specification, if not then av_interleaved_write_frame must be used.
1233
 *
1234
 * @param s media file handle
1235
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1236
              dts/pts, ...
1237
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1238
 */
1239
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1240

    
1241
/**
1242
 * Write a packet to an output media file ensuring correct interleaving.
1243
 *
1244
 * The packet must contain one audio or video frame.
1245
 * If the packets are already correctly interleaved, the application should
1246
 * call av_write_frame() instead as it is slightly faster. It is also important
1247
 * to keep in mind that completely non-interleaved input will need huge amounts
1248
 * of memory to interleave with this, so it is preferable to interleave at the
1249
 * demuxer level.
1250
 *
1251
 * @param s media file handle
1252
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1253
              dts/pts, ...
1254
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1255
 */
1256
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1257

    
1258
/**
1259
 * Interleave a packet per dts in an output media file.
1260
 *
1261
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1262
 * function, so they cannot be used after it. Note that calling av_free_packet()
1263
 * on them is still safe.
1264
 *
1265
 * @param s media file handle
1266
 * @param out the interleaved packet will be output here
1267
 * @param pkt the input packet
1268
 * @param flush 1 if no further packets are available as input and all
1269
 *              remaining packets should be output
1270
 * @return 1 if a packet was output, 0 if no packet could be output,
1271
 *         < 0 if an error occurred
1272
 */
1273
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1274
                                 AVPacket *pkt, int flush);
1275

    
1276
/**
1277
 * Write the stream trailer to an output media file and free the
1278
 * file private data.
1279
 *
1280
 * May only be called after a successful call to av_write_header.
1281
 *
1282
 * @param s media file handle
1283
 * @return 0 if OK, AVERROR_xxx on error
1284
 */
1285
int av_write_trailer(AVFormatContext *s);
1286

    
1287
void dump_format(AVFormatContext *ic,
1288
                 int index,
1289
                 const char *url,
1290
                 int is_output);
1291

    
1292
#if LIBAVFORMAT_VERSION_MAJOR < 53
1293
/**
1294
 * Parse width and height out of string str.
1295
 * @deprecated Use av_parse_video_frame_size instead.
1296
 */
1297
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1298
                                          const char *str);
1299

    
1300
/**
1301
 * Convert framerate from a string to a fraction.
1302
 * @deprecated Use av_parse_video_frame_rate instead.
1303
 */
1304
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1305
                                          const char *arg);
1306
#endif
1307

    
1308
/**
1309
 * Parse datestr and return a corresponding number of microseconds.
1310
 * @param datestr String representing a date or a duration.
1311
 * - If a date the syntax is:
1312
 * @code
1313
 *  now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]}
1314
 * @endcode
1315
 * If the value is "now" it takes the current time.
1316
 * Time is local time unless Z is appended, in which case it is
1317
 * interpreted as UTC.
1318
 * If the year-month-day part is not specified it takes the current
1319
 * year-month-day.
1320
 * @return the number of microseconds since 1st of January, 1970 up to
1321
 * the time of the parsed date or INT64_MIN if datestr cannot be
1322
 * successfully parsed.
1323
 * - If a duration the syntax is:
1324
 * @code
1325
 *  [-]HH[:MM[:SS[.m...]]]
1326
 *  [-]S+[.m...]
1327
 * @endcode
1328
 * @return the number of microseconds contained in a time interval
1329
 * with the specified duration or INT64_MIN if datestr cannot be
1330
 * successfully parsed.
1331
 * @param duration Flag which tells how to interpret datestr, if
1332
 * not zero datestr is interpreted as a duration, otherwise as a
1333
 * date.
1334
 */
1335
int64_t parse_date(const char *datestr, int duration);
1336

    
1337
/** Get the current time in microseconds. */
1338
int64_t av_gettime(void);
1339

    
1340
/* ffm-specific for ffserver */
1341
#define FFM_PACKET_SIZE 4096
1342
int64_t ffm_read_write_index(int fd);
1343
int ffm_write_write_index(int fd, int64_t pos);
1344
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1345

    
1346
/**
1347
 * Attempt to find a specific tag in a URL.
1348
 *
1349
 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1350
 * Return 1 if found.
1351
 */
1352
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1353

    
1354
/**
1355
 * Return in 'buf' the path with '%d' replaced by a number.
1356
 *
1357
 * Also handles the '%0nd' format where 'n' is the total number
1358
 * of digits and '%%'.
1359
 *
1360
 * @param buf destination buffer
1361
 * @param buf_size destination buffer size
1362
 * @param path numbered sequence string
1363
 * @param number frame number
1364
 * @return 0 if OK, -1 on format error
1365
 */
1366
int av_get_frame_filename(char *buf, int buf_size,
1367
                          const char *path, int number);
1368

    
1369
/**
1370
 * Check whether filename actually is a numbered sequence generator.
1371
 *
1372
 * @param filename possible numbered sequence string
1373
 * @return 1 if a valid numbered sequence string, 0 otherwise
1374
 */
1375
int av_filename_number_test(const char *filename);
1376

    
1377
/**
1378
 * Generate an SDP for an RTP session.
1379
 *
1380
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1381
 *           array is composed by only one context, such context can contain
1382
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1383
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1384
 *           must contain only one AVStream.
1385
 * @param n_files number of AVCodecContexts contained in ac
1386
 * @param buff buffer where the SDP will be stored (must be allocated by
1387
 *             the caller)
1388
 * @param size the size of the buffer
1389
 * @return 0 if OK, AVERROR_xxx on error
1390
 */
1391
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1392

    
1393
/**
1394
 * Return a positive value if the given filename has one of the given
1395
 * extensions, 0 otherwise.
1396
 *
1397
 * @param extensions a comma-separated list of filename extensions
1398
 */
1399
int av_match_ext(const char *filename, const char *extensions);
1400

    
1401
#endif /* AVFORMAT_AVFORMAT_H */