Statistics
| Branch: | Revision:

ffmpeg / libavformat / avformat.h @ e07b882b

History | View | Annotate | Download (44.3 KB)

1
/*
2
 * copyright (c) 2001 Fabrice Bellard
3
 *
4
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * FFmpeg is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with FFmpeg; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20

    
21
#ifndef AVFORMAT_AVFORMAT_H
22
#define AVFORMAT_AVFORMAT_H
23

    
24
#define LIBAVFORMAT_VERSION_MAJOR 52
25
#define LIBAVFORMAT_VERSION_MINOR 38
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
 * Returns the LIBAVFORMAT_VERSION_INT constant.
40
 */
41
unsigned avformat_version(void);
42

    
43
#include <time.h>
44
#include <stdio.h>  /* FILE */
45
#include "libavcodec/avcodec.h"
46

    
47
#include "avio.h"
48

    
49
struct AVFormatContext;
50

    
51

    
52
/*
53
 * Public Metadata API.
54
 * The metadata API allows libavformat to export metadata tags to a client
55
 * application using a sequence of key/value pairs.
56
 * Important concepts to keep in mind:
57
 * 1. Keys are unique; there can never be 2 tags with the same key. This is
58
 *    also meant semantically, i.e., a demuxer should not knowingly produce
59
 *    several keys that are literally different but semantically identical.
60
 *    E.g., key=Author5, key=Author6. In this example, all authors must be
61
 *    placed in the same tag.
62
 * 2. Metadata is flat, not hierarchical; there are no subtags. If you
63
 *    want to store, e.g., the email address of the child of producer Alice
64
 *    and actor Bob, that could have key=alice_and_bobs_childs_email_address.
65
 * 3. A tag whose value is localized for a particular language is appended
66
 *    with a dash character ('-') and the ISO 639-2/B 3-letter language code.
67
 *    For example: Author-ger=Michael, Author-eng=Mike
68
 *    The original/default language is in the unqualified "Author" tag.
69
 *    A demuxer should set a default if it sets any translated tag.
70
 */
71

    
72
#define AV_METADATA_MATCH_CASE      1
73
#define AV_METADATA_IGNORE_SUFFIX   2
74

    
75
typedef struct {
76
    char *key;
77
    char *value;
78
}AVMetadataTag;
79

    
80
typedef struct AVMetadata AVMetadata;
81
typedef struct AVMetadataConv AVMetadataConv;
82

    
83
/**
84
 * Gets a metadata element with matching key.
85
 * @param prev Set to the previous matching element to find the next.
86
 * @param flags Allows case as well as suffix-insensitive comparisons.
87
 * @return Found tag or NULL, changing key or value leads to undefined behavior.
88
 */
89
AVMetadataTag *
90
av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags);
91

    
92
/**
93
 * Sets the given tag in m, overwriting an existing tag.
94
 * @param key tag key to add to m (will be av_strduped)
95
 * @param value tag value to add to m (will be av_strduped)
96
 * @return >= 0 on success otherwise an error code <0
97
 */
98
int av_metadata_set(AVMetadata **pm, const char *key, const char *value);
99

    
100
/**
101
 * Converts all the metadata sets from ctx according to the source and
102
 * destination conversion tables.
103
 * @param d_conv destination tags format conversion table
104
 * @param s_conv source tags format conversion table
105
 */
106
void av_metadata_conv(struct AVFormatContext *ctx,const AVMetadataConv *d_conv,
107
                                                  const AVMetadataConv *s_conv);
108

    
109
/**
110
 * Frees all the memory allocated for an AVMetadata struct.
111
 */
112
void av_metadata_free(AVMetadata **m);
113

    
114

    
115
/* packet functions */
116

    
117

    
118
/**
119
 * Allocates and reads the payload of a packet and initializes its
120
 * fields with default values.
121
 *
122
 * @param pkt packet
123
 * @param size desired payload size
124
 * @return >0 (read size) if OK, AVERROR_xxx otherwise
125
 */
126
int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size);
127

    
128

    
129
/*************************************************/
130
/* fractional numbers for exact pts handling */
131

    
132
/**
133
 * The exact value of the fractional number is: 'val + num / den'.
134
 * num is assumed to be 0 <= num < den.
135
 */
136
typedef struct AVFrac {
137
    int64_t val, num, den;
138
} AVFrac;
139

    
140
/*************************************************/
141
/* input/output formats */
142

    
143
struct AVCodecTag;
144

    
145
/** This structure contains the data a format has to probe a file. */
146
typedef struct AVProbeData {
147
    const char *filename;
148
    unsigned char *buf; /**< Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero. */
149
    int buf_size;       /**< Size of buf except extra allocated bytes */
150
} AVProbeData;
151

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

    
155
typedef struct AVFormatParameters {
156
    AVRational time_base;
157
    int sample_rate;
158
    int channels;
159
    int width;
160
    int height;
161
    enum PixelFormat pix_fmt;
162
    int channel; /**< Used to select DV channel. */
163
    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
164
    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
165
    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
166
                                            stream packet (only meaningful if
167
                                            mpeg2ts_raw is TRUE). */
168
    unsigned int initial_pause:1;       /**< Do not begin to play the stream
169
                                            immediately (RTSP only). */
170
    unsigned int prealloced_context:1;
171
#if LIBAVFORMAT_VERSION_INT < (53<<16)
172
    enum CodecID video_codec_id;
173
    enum CodecID audio_codec_id;
174
#endif
175
} AVFormatParameters;
176

    
177
//! Demuxer will use url_fopen, no opened file should be provided by the caller.
178
#define AVFMT_NOFILE        0x0001
179
#define AVFMT_NEEDNUMBER    0x0002 /**< Needs '%d' in filename. */
180
#define AVFMT_SHOW_IDS      0x0008 /**< Show format stream IDs numbers. */
181
#define AVFMT_RAWPICTURE    0x0020 /**< Format wants AVPicture structure for
182
                                      raw picture data. */
183
#define AVFMT_GLOBALHEADER  0x0040 /**< Format wants global header. */
184
#define AVFMT_NOTIMESTAMPS  0x0080 /**< Format does not need / have any timestamps. */
185
#define AVFMT_GENERIC_INDEX 0x0100 /**< Use generic index building code. */
186
#define AVFMT_TS_DISCONT    0x0200 /**< Format allows timestamp discontinuities. */
187
#define AVFMT_VARIABLE_FPS  0x0400 /**< Format allows variable fps. */
188

    
189
typedef struct AVOutputFormat {
190
    const char *name;
191
    /**
192
     * Descriptive name for the format, meant to be more human-readable
193
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
194
     * to define it.
195
     */
196
    const char *long_name;
197
    const char *mime_type;
198
    const char *extensions; /**< comma-separated filename extensions */
199
    /** size of private data so that it can be allocated in the wrapper */
200
    int priv_data_size;
201
    /* output support */
202
    enum CodecID audio_codec; /**< default audio codec */
203
    enum CodecID video_codec; /**< default video codec */
204
    int (*write_header)(struct AVFormatContext *);
205
    int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
206
    int (*write_trailer)(struct AVFormatContext *);
207
    /** can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER */
208
    int flags;
209
    /** Currently only used to set pixel format if not YUV420P. */
210
    int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *);
211
    int (*interleave_packet)(struct AVFormatContext *, AVPacket *out,
212
                             AVPacket *in, int flush);
213

    
214
    /**
215
     * List of supported codec_id-codec_tag pairs, ordered by "better
216
     * choice first". The arrays are all terminated by CODEC_ID_NONE.
217
     */
218
    const struct AVCodecTag * const *codec_tag;
219

    
220
    enum CodecID subtitle_codec; /**< default subtitle codec */
221

    
222
    const AVMetadataConv *metadata_conv;
223

    
224
    /* private fields */
225
    struct AVOutputFormat *next;
226
} AVOutputFormat;
227

    
228
typedef struct AVInputFormat {
229
    const char *name;
230
    /**
231
     * Descriptive name for the format, meant to be more human-readable
232
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
233
     * to define it.
234
     */
235
    const char *long_name;
236
    /** Size of private data so that it can be allocated in the wrapper. */
237
    int priv_data_size;
238
    /**
239
     * Tell if a given file has a chance of being parsed as this format.
240
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
241
     * big so you do not have to check for that unless you need more.
242
     */
243
    int (*read_probe)(AVProbeData *);
244
    /** Read the format header and initialize the AVFormatContext
245
       structure. Return 0 if OK. 'ap' if non-NULL contains
246
       additional parameters. Only used in raw format right
247
       now. 'av_new_stream' should be called to create new streams.  */
248
    int (*read_header)(struct AVFormatContext *,
249
                       AVFormatParameters *ap);
250
    /** Read one packet and put it in 'pkt'. pts and flags are also
251
       set. 'av_new_stream' can be called only if the flag
252
       AVFMTCTX_NOHEADER is used.
253
       @return 0 on success, < 0 on error.
254
               When returning an error, pkt must not have been allocated
255
               or must be freed before returning */
256
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);
257
    /** Close the stream. The AVFormatContext and AVStreams are not
258
       freed by this function */
259
    int (*read_close)(struct AVFormatContext *);
260

    
261
#if LIBAVFORMAT_VERSION_MAJOR < 53
262
    /**
263
     * Seek to a given timestamp relative to the frames in
264
     * stream component stream_index.
265
     * @param stream_index Must not be -1.
266
     * @param flags Selects which direction should be preferred if no exact
267
     *              match is available.
268
     * @return >= 0 on success (but not necessarily the new offset)
269
     */
270
    int (*read_seek)(struct AVFormatContext *,
271
                     int stream_index, int64_t timestamp, int flags);
272
#endif
273
    /**
274
     * Gets the next timestamp in stream[stream_index].time_base units.
275
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
276
     */
277
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
278
                              int64_t *pos, int64_t pos_limit);
279
    /** Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. */
280
    int flags;
281
    /** If extensions are defined, then no probe is done. You should
282
       usually not use extension format guessing because it is not
283
       reliable enough */
284
    const char *extensions;
285
    /** General purpose read-only value that the format can use. */
286
    int value;
287

    
288
    /** Starts/resumes playing - only meaningful if using a network-based format
289
       (RTSP). */
290
    int (*read_play)(struct AVFormatContext *);
291

    
292
    /** Pauses playing - only meaningful if using a network-based format
293
       (RTSP). */
294
    int (*read_pause)(struct AVFormatContext *);
295

    
296
    const struct AVCodecTag * const *codec_tag;
297

    
298
    /**
299
     * Seeks to timestamp ts.
300
     * Seeking will be done so that the point from which all active streams
301
     * can be presented successfully will be closest to ts and within min/max_ts.
302
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
303
     */
304
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
305

    
306
    const AVMetadataConv *metadata_conv;
307

    
308
    /* private fields */
309
    struct AVInputFormat *next;
310
} AVInputFormat;
311

    
312
enum AVStreamParseType {
313
    AVSTREAM_PARSE_NONE,
314
    AVSTREAM_PARSE_FULL,       /**< full parsing and repack */
315
    AVSTREAM_PARSE_HEADERS,    /**< Only parse headers, do not repack. */
316
    AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on a packet boundary */
317
};
318

    
319
typedef struct AVIndexEntry {
320
    int64_t pos;
321
    int64_t timestamp;
322
#define AVINDEX_KEYFRAME 0x0001
323
    int flags:2;
324
    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).
325
    int min_distance;         /**< Minimum distance between this and the previous keyframe, used to avoid unneeded searching. */
326
} AVIndexEntry;
327

    
328
#define AV_DISPOSITION_DEFAULT   0x0001
329
#define AV_DISPOSITION_DUB       0x0002
330
#define AV_DISPOSITION_ORIGINAL  0x0004
331
#define AV_DISPOSITION_COMMENT   0x0008
332
#define AV_DISPOSITION_LYRICS    0x0010
333
#define AV_DISPOSITION_KARAOKE   0x0020
334

    
335
/**
336
 * Stream structure.
337
 * New fields can be added to the end with minor version bumps.
338
 * Removal, reordering and changes to existing fields require a major
339
 * version bump.
340
 * sizeof(AVStream) must not be used outside libav*.
341
 */
342
typedef struct AVStream {
343
    int index;    /**< stream index in AVFormatContext */
344
    int id;       /**< format-specific stream ID */
345
    AVCodecContext *codec; /**< codec context */
346
    /**
347
     * Real base framerate of the stream.
348
     * This is the lowest framerate with which all timestamps can be
349
     * represented accurately (it is the least common multiple of all
350
     * framerates in the stream). Note, this value is just a guess!
351
     * For example, if the time base is 1/90000 and all frames have either
352
     * approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
353
     */
354
    AVRational r_frame_rate;
355
    void *priv_data;
356

    
357
    /* internal data used in av_find_stream_info() */
358
    int64_t first_dts;
359
    /** encoding: pts generation when outputting stream */
360
    struct AVFrac pts;
361

    
362
    /**
363
     * This is the fundamental unit of time (in seconds) in terms
364
     * of which frame timestamps are represented. For fixed-fps content,
365
     * time base should be 1/framerate and timestamp increments should be 1.
366
     */
367
    AVRational time_base;
368
    int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */
369
    /* ffmpeg.c private use */
370
    int stream_copy; /**< If set, just copy stream. */
371
    enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed.
372
    //FIXME move stuff to a flags field?
373
    /** Quality, as it has been removed from AVCodecContext and put in AVVideoFrame.
374
     * MN: dunno if that is the right place for it */
375
    float quality;
376
    /**
377
     * Decoding: pts of the first frame of the stream, in stream time base.
378
     * Only set this if you are absolutely 100% sure that the value you set
379
     * it to really is the pts of the first frame.
380
     * This may be undefined (AV_NOPTS_VALUE).
381
     * @note The ASF header does NOT contain a correct start_time the ASF
382
     * demuxer must NOT set this.
383
     */
384
    int64_t start_time;
385
    /**
386
     * Decoding: duration of the stream, in stream time base.
387
     * If a source file does not specify a duration, but does specify
388
     * a bitrate, this value will be estimated from bitrate and file size.
389
     */
390
    int64_t duration;
391

    
392
#if LIBAVFORMAT_VERSION_INT < (53<<16)
393
    char language[4]; /** ISO 639-2/B 3-letter language code (empty string if undefined) */
394
#endif
395

    
396
    /* av_read_frame() support */
397
    enum AVStreamParseType need_parsing;
398
    struct AVCodecParserContext *parser;
399

    
400
    int64_t cur_dts;
401
    int last_IP_duration;
402
    int64_t last_IP_pts;
403
    /* av_seek_frame() support */
404
    AVIndexEntry *index_entries; /**< Only used if the format does not
405
                                    support seeking natively. */
406
    int nb_index_entries;
407
    unsigned int index_entries_allocated_size;
408

    
409
    int64_t nb_frames;                 ///< number of frames in this stream if known or 0
410

    
411
#if LIBAVFORMAT_VERSION_INT < (53<<16)
412
    int64_t unused[4+1];
413

    
414
    char *filename; /**< source filename of the stream */
415
#endif
416

    
417
    int disposition; /**< AV_DISPOSITION_* bit field */
418

    
419
    AVProbeData probe_data;
420
#define MAX_REORDER_DELAY 16
421
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
422

    
423
    /**
424
     * sample aspect ratio (0 if unknown)
425
     * - encoding: Set by user.
426
     * - decoding: Set by libavformat.
427
     */
428
    AVRational sample_aspect_ratio;
429

    
430
    AVMetadata *metadata;
431

    
432
    /* av_read_frame() support */
433
    const uint8_t *cur_ptr;
434
    int cur_len;
435
    AVPacket cur_pkt;
436

    
437
    // Timestamp generation support:
438
    /**
439
     * Timestamp corresponding to the last dts sync point.
440
     *
441
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
442
     * a DTS is received from the underlying container. Otherwise set to
443
     * AV_NOPTS_VALUE by default.
444
     */
445
    int64_t reference_dts;
446

    
447
    /**
448
     * Number of packets to buffer for codec probing
449
     * NOT PART OF PUBLIC API
450
     */
451
#define MAX_PROBE_PACKETS 100
452
    int probe_packets;
453

    
454
    /**
455
     * last packet in packet_buffer for this stream when muxing.
456
     * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav*
457
     */
458
    struct AVPacketList *last_in_packet_buffer;
459
} AVStream;
460

    
461
#define AV_PROGRAM_RUNNING 1
462

    
463
/**
464
 * New fields can be added to the end with minor version bumps.
465
 * Removal, reordering and changes to existing fields require a major
466
 * version bump.
467
 * sizeof(AVProgram) must not be used outside libav*.
468
 */
469
typedef struct AVProgram {
470
    int            id;
471
#if LIBAVFORMAT_VERSION_INT < (53<<16)
472
    char           *provider_name; ///< network name for DVB streams
473
    char           *name;          ///< service name for DVB streams
474
#endif
475
    int            flags;
476
    enum AVDiscard discard;        ///< selects which program to discard and which to feed to the caller
477
    unsigned int   *stream_index;
478
    unsigned int   nb_stream_indexes;
479
    AVMetadata *metadata;
480
} AVProgram;
481

    
482
#define AVFMTCTX_NOHEADER      0x0001 /**< signal that no header is present
483
                                         (streams are added dynamically) */
484

    
485
typedef struct AVChapter {
486
    int id;                 ///< unique ID to identify the chapter
487
    AVRational time_base;   ///< time base in which the start/end timestamps are specified
488
    int64_t start, end;     ///< chapter start/end time in time_base units
489
#if LIBAVFORMAT_VERSION_INT < (53<<16)
490
    char *title;            ///< chapter title
491
#endif
492
    AVMetadata *metadata;
493
} AVChapter;
494

    
495
#define MAX_STREAMS 20
496

    
497
/**
498
 * Format I/O context.
499
 * New fields can be added to the end with minor version bumps.
500
 * Removal, reordering and changes to existing fields require a major
501
 * version bump.
502
 * sizeof(AVFormatContext) must not be used outside libav*.
503
 */
504
typedef struct AVFormatContext {
505
    const AVClass *av_class; /**< Set by avformat_alloc_context. */
506
    /* Can only be iformat or oformat, not both at the same time. */
507
    struct AVInputFormat *iformat;
508
    struct AVOutputFormat *oformat;
509
    void *priv_data;
510
    ByteIOContext *pb;
511
    unsigned int nb_streams;
512
    AVStream *streams[MAX_STREAMS];
513
    char filename[1024]; /**< input or output filename */
514
    /* stream info */
515
    int64_t timestamp;
516
#if LIBAVFORMAT_VERSION_INT < (53<<16)
517
    char title[512];
518
    char author[512];
519
    char copyright[512];
520
    char comment[512];
521
    char album[512];
522
    int year;  /**< ID3 year, 0 if none */
523
    int track; /**< track number, 0 if none */
524
    char genre[32]; /**< ID3 genre */
525
#endif
526

    
527
    int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */
528
    /* private data for pts handling (do not modify directly). */
529
    /** This buffer is only needed when packets were already buffered but
530
       not decoded, for example to get the codec parameters in MPEG
531
       streams. */
532
    struct AVPacketList *packet_buffer;
533

    
534
    /** Decoding: position of the first frame of the component, in
535
       AV_TIME_BASE fractional seconds. NEVER set this value directly:
536
       It is deduced from the AVStream values.  */
537
    int64_t start_time;
538
    /** Decoding: duration of the stream, in AV_TIME_BASE fractional
539
       seconds. NEVER set this value directly: it is deduced from the
540
       AVStream values.  */
541
    int64_t duration;
542
    /** decoding: total file size, 0 if unknown */
543
    int64_t file_size;
544
    /** Decoding: total stream bitrate in bit/s, 0 if not
545
       available. Never set it directly if the file_size and the
546
       duration are known as FFmpeg can compute it automatically. */
547
    int bit_rate;
548

    
549
    /* av_read_frame() support */
550
    AVStream *cur_st;
551
#if LIBAVFORMAT_VERSION_INT < (53<<16)
552
    const uint8_t *cur_ptr_deprecated;
553
    int cur_len_deprecated;
554
    AVPacket cur_pkt_deprecated;
555
#endif
556

    
557
    /* av_seek_frame() support */
558
    int64_t data_offset; /** offset of the first packet */
559
    int index_built;
560

    
561
    int mux_rate;
562
    unsigned int packet_size;
563
    int preload;
564
    int max_delay;
565

    
566
#define AVFMT_NOOUTPUTLOOP -1
567
#define AVFMT_INFINITEOUTPUTLOOP 0
568
    /** number of times to loop output in formats that support it */
569
    int loop_output;
570

    
571
    int flags;
572
#define AVFMT_FLAG_GENPTS       0x0001 ///< Generate missing pts even if it requires parsing future frames.
573
#define AVFMT_FLAG_IGNIDX       0x0002 ///< Ignore index.
574
#define AVFMT_FLAG_NONBLOCK     0x0004 ///< Do not block when reading packets from input.
575

    
576
    int loop_input;
577
    /** decoding: size of data to probe; encoding: unused. */
578
    unsigned int probesize;
579

    
580
    /**
581
     * Maximum time (in AV_TIME_BASE units) during which the input should
582
     * be analyzed in av_find_stream_info().
583
     */
584
    int max_analyze_duration;
585

    
586
    const uint8_t *key;
587
    int keylen;
588

    
589
    unsigned int nb_programs;
590
    AVProgram **programs;
591

    
592
    /**
593
     * Forced video codec_id.
594
     * Demuxing: Set by user.
595
     */
596
    enum CodecID video_codec_id;
597
    /**
598
     * Forced audio codec_id.
599
     * Demuxing: Set by user.
600
     */
601
    enum CodecID audio_codec_id;
602
    /**
603
     * Forced subtitle codec_id.
604
     * Demuxing: Set by user.
605
     */
606
    enum CodecID subtitle_codec_id;
607

    
608
    /**
609
     * Maximum amount of memory in bytes to use for the index of each stream.
610
     * If the index exceeds this size, entries will be discarded as
611
     * needed to maintain a smaller size. This can lead to slower or less
612
     * accurate seeking (depends on demuxer).
613
     * Demuxers for which a full in-memory index is mandatory will ignore
614
     * this.
615
     * muxing  : unused
616
     * demuxing: set by user
617
     */
618
    unsigned int max_index_size;
619

    
620
    /**
621
     * Maximum amount of memory in bytes to use for buffering frames
622
     * obtained from realtime capture devices.
623
     */
624
    unsigned int max_picture_buffer;
625

    
626
    unsigned int nb_chapters;
627
    AVChapter **chapters;
628

    
629
    /**
630
     * Flags to enable debugging.
631
     */
632
    int debug;
633
#define FF_FDEBUG_TS        0x0001
634

    
635
    /**
636
     * Raw packets from the demuxer, prior to parsing and decoding.
637
     * This buffer is used for buffering packets until the codec can
638
     * be identified, as parsing cannot be done without knowing the
639
     * codec.
640
     */
641
    struct AVPacketList *raw_packet_buffer;
642
    struct AVPacketList *raw_packet_buffer_end;
643

    
644
    struct AVPacketList *packet_buffer_end;
645

    
646
    AVMetadata *metadata;
647

    
648
    /**
649
     * Remaining size available for raw_packet_buffer, in bytes.
650
     * NOT PART OF PUBLIC API
651
     */
652
#define RAW_PACKET_BUFFER_SIZE 32000
653
    int raw_packet_buffer_remaining_size;
654
} AVFormatContext;
655

    
656
typedef struct AVPacketList {
657
    AVPacket pkt;
658
    struct AVPacketList *next;
659
} AVPacketList;
660

    
661
#if LIBAVFORMAT_VERSION_INT < (53<<16)
662
extern AVInputFormat *first_iformat;
663
extern AVOutputFormat *first_oformat;
664
#endif
665

    
666
/**
667
 * If f is NULL, returns the first registered input format,
668
 * if f is non-NULL, returns the next registered input format after f
669
 * or NULL if f is the last one.
670
 */
671
AVInputFormat  *av_iformat_next(AVInputFormat  *f);
672

    
673
/**
674
 * If f is NULL, returns the first registered output format,
675
 * if f is non-NULL, returns the next registered output format after f
676
 * or NULL if f is the last one.
677
 */
678
AVOutputFormat *av_oformat_next(AVOutputFormat *f);
679

    
680
enum CodecID av_guess_image2_codec(const char *filename);
681

    
682
/* XXX: Use automatic init with either ELF sections or C file parser */
683
/* modules. */
684

    
685
/* utils.c */
686
void av_register_input_format(AVInputFormat *format);
687
void av_register_output_format(AVOutputFormat *format);
688
AVOutputFormat *guess_stream_format(const char *short_name,
689
                                    const char *filename,
690
                                    const char *mime_type);
691
AVOutputFormat *guess_format(const char *short_name,
692
                             const char *filename,
693
                             const char *mime_type);
694

    
695
/**
696
 * Guesses the codec ID based upon muxer and filename.
697
 */
698
enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name,
699
                            const char *filename, const char *mime_type,
700
                            enum CodecType type);
701

    
702
/**
703
 * Sends a nice hexadecimal dump of a buffer to the specified file stream.
704
 *
705
 * @param f The file stream pointer where the dump should be sent to.
706
 * @param buf buffer
707
 * @param size buffer size
708
 *
709
 * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log
710
 */
711
void av_hex_dump(FILE *f, uint8_t *buf, int size);
712

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

    
727
/**
728
 * Sends a nice dump of a packet to the specified file stream.
729
 *
730
 * @param f The file stream pointer where the dump should be sent to.
731
 * @param pkt packet to dump
732
 * @param dump_payload True if the payload must be displayed, too.
733
 */
734
void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload);
735

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

    
748
/**
749
 * Initializes libavformat and registers all the muxers, demuxers and
750
 * protocols. If you do not call this function, then you can select
751
 * exactly which formats you want to support.
752
 *
753
 * @see av_register_input_format()
754
 * @see av_register_output_format()
755
 * @see av_register_protocol()
756
 */
757
void av_register_all(void);
758

    
759
/** codec tag <-> codec id */
760
enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag);
761
unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id);
762

    
763
/* media file input */
764

    
765
/**
766
 * Finds AVInputFormat based on the short name of the input format.
767
 */
768
AVInputFormat *av_find_input_format(const char *short_name);
769

    
770
/**
771
 * Guesses the file format.
772
 *
773
 * @param is_opened Whether the file is already opened; determines whether
774
 *                  demuxers with or without AVFMT_NOFILE are probed.
775
 */
776
AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened);
777

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

    
786
/**
787
 * Opens a media file as input. The codecs are not opened. Only the file
788
 * header (if present) is read.
789
 *
790
 * @param ic_ptr The opened media file handle is put here.
791
 * @param filename filename to open
792
 * @param fmt If non-NULL, force the file format to use.
793
 * @param buf_size optional buffer size (zero if default is OK)
794
 * @param ap Additional parameters needed when opening the file
795
 *           (NULL if default).
796
 * @return 0 if OK, AVERROR_xxx otherwise
797
 */
798
int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
799
                       AVInputFormat *fmt,
800
                       int buf_size,
801
                       AVFormatParameters *ap);
802

    
803
#if LIBAVFORMAT_VERSION_MAJOR < 53
804
/**
805
 * @deprecated Use avformat_alloc_context() instead.
806
 */
807
attribute_deprecated AVFormatContext *av_alloc_format_context(void);
808
#endif
809

    
810
/**
811
 * Allocates an AVFormatContext.
812
 * Can be freed with av_free() but do not forget to free everything you
813
 * explicitly allocated as well!
814
 */
815
AVFormatContext *avformat_alloc_context(void);
816

    
817
/**
818
 * Reads packets of a media file to get stream information. This
819
 * is useful for file formats with no headers such as MPEG. This
820
 * function also computes the real framerate in case of MPEG-2 repeat
821
 * frame mode.
822
 * The logical file position is not changed by this function;
823
 * examined packets may be buffered for later processing.
824
 *
825
 * @param ic media file handle
826
 * @return >=0 if OK, AVERROR_xxx on error
827
 * @todo Let the user decide somehow what information is needed so that
828
 *       we do not waste time getting stuff the user does not need.
829
 */
830
int av_find_stream_info(AVFormatContext *ic);
831

    
832
/**
833
 * Reads a transport packet from a media file.
834
 *
835
 * This function is obsolete and should never be used.
836
 * Use av_read_frame() instead.
837
 *
838
 * @param s media file handle
839
 * @param pkt is filled
840
 * @return 0 if OK, AVERROR_xxx on error
841
 */
842
int av_read_packet(AVFormatContext *s, AVPacket *pkt);
843

    
844
/**
845
 * Returns the next frame of a stream.
846
 *
847
 * The returned packet is valid
848
 * until the next av_read_frame() or until av_close_input_file() and
849
 * must be freed with av_free_packet. For video, the packet contains
850
 * exactly one frame. For audio, it contains an integer number of
851
 * frames if each frame has a known fixed size (e.g. PCM or ADPCM
852
 * data). If the audio frames have a variable size (e.g. MPEG audio),
853
 * then it contains one frame.
854
 *
855
 * pkt->pts, pkt->dts and pkt->duration are always set to correct
856
 * values in AVStream.time_base units (and guessed if the format cannot
857
 * provide them). pkt->pts can be AV_NOPTS_VALUE if the video format
858
 * has B-frames, so it is better to rely on pkt->dts if you do not
859
 * decompress the payload.
860
 *
861
 * @return 0 if OK, < 0 on error or end of file
862
 */
863
int av_read_frame(AVFormatContext *s, AVPacket *pkt);
864

    
865
/**
866
 * Seeks to the keyframe at timestamp.
867
 * 'timestamp' in 'stream_index'.
868
 * @param stream_index If stream_index is (-1), a default
869
 * stream is selected, and timestamp is automatically converted
870
 * from AV_TIME_BASE units to the stream specific time_base.
871
 * @param timestamp Timestamp in AVStream.time_base units
872
 *        or, if no stream is specified, in AV_TIME_BASE units.
873
 * @param flags flags which select direction and seeking mode
874
 * @return >= 0 on success
875
 */
876
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
877
                  int flags);
878

    
879
/**
880
 * Seeks to timestamp ts.
881
 * Seeking will be done so that the point from which all active streams
882
 * can be presented successfully will be closest to ts and within min/max_ts.
883
 * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
884
 *
885
 * If flags contain AVSEEK_FLAG_BYTE, then all timestamps are in bytes and
886
 * are the file position (this may not be supported by all demuxers).
887
 * If flags contain AVSEEK_FLAG_FRAME, then all timestamps are in frames
888
 * in the stream with stream_index (this may not be supported by all demuxers).
889
 * Otherwise all timestamps are in units of the stream selected by stream_index
890
 * or if stream_index is -1, in AV_TIME_BASE units.
891
 * If flags contain AVSEEK_FLAG_ANY, then non-keyframes are treated as
892
 * keyframes (this may not be supported by all demuxers).
893
 *
894
 * @param stream_index index of the stream which is used as time base reference
895
 * @param min_ts smallest acceptable timestamp
896
 * @param ts target timestamp
897
 * @param max_ts largest acceptable timestamp
898
 * @param flags flags
899
 * @returns >=0 on success, error code otherwise
900
 *
901
 * @NOTE This is part of the new seek API which is still under construction.
902
 *       Thus do not use this yet. It may change at any time, do not expect
903
 *       ABI compatibility yet!
904
 */
905
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
906

    
907
/**
908
 * Starts playing a network-based stream (e.g. RTSP stream) at the
909
 * current position.
910
 */
911
int av_read_play(AVFormatContext *s);
912

    
913
/**
914
 * Pauses a network-based stream (e.g. RTSP stream).
915
 *
916
 * Use av_read_play() to resume it.
917
 */
918
int av_read_pause(AVFormatContext *s);
919

    
920
/**
921
 * Frees a AVFormatContext allocated by av_open_input_stream.
922
 * @param s context to free
923
 */
924
void av_close_input_stream(AVFormatContext *s);
925

    
926
/**
927
 * Closes a media file (but not its codecs).
928
 *
929
 * @param s media file handle
930
 */
931
void av_close_input_file(AVFormatContext *s);
932

    
933
/**
934
 * Adds a new stream to a media file.
935
 *
936
 * Can only be called in the read_header() function. If the flag
937
 * AVFMTCTX_NOHEADER is in the format context, then new streams
938
 * can be added in read_packet too.
939
 *
940
 * @param s media file handle
941
 * @param id file-format-dependent stream ID
942
 */
943
AVStream *av_new_stream(AVFormatContext *s, int id);
944
AVProgram *av_new_program(AVFormatContext *s, int id);
945

    
946
/**
947
 * Adds a new chapter.
948
 * This function is NOT part of the public API
949
 * and should ONLY be used by demuxers.
950
 *
951
 * @param s media file handle
952
 * @param id unique ID for this chapter
953
 * @param start chapter start time in time_base units
954
 * @param end chapter end time in time_base units
955
 * @param title chapter title
956
 *
957
 * @return AVChapter or NULL on error
958
 */
959
AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base,
960
                          int64_t start, int64_t end, const char *title);
961

    
962
/**
963
 * Sets the pts for a given stream.
964
 *
965
 * @param s stream
966
 * @param pts_wrap_bits number of bits effectively used by the pts
967
 *        (used for wrap control, 33 is the value for MPEG)
968
 * @param pts_num numerator to convert to seconds (MPEG: 1)
969
 * @param pts_den denominator to convert to seconds (MPEG: 90000)
970
 */
971
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
972
                     unsigned int pts_num, unsigned int pts_den);
973

    
974
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward
975
#define AVSEEK_FLAG_BYTE     2 ///< seeking based on position in bytes
976
#define AVSEEK_FLAG_ANY      4 ///< seek to any frame, even non-keyframes
977
#define AVSEEK_FLAG_FRAME    8 ///< seeking based on frame number
978

    
979
int av_find_default_stream_index(AVFormatContext *s);
980

    
981
/**
982
 * Gets the index for a specific timestamp.
983
 * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond
984
 *                 to the timestamp which is <= the requested one, if backward
985
 *                 is 0, then it will be >=
986
 *              if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise
987
 * @return < 0 if no such timestamp could be found
988
 */
989
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags);
990

    
991
/**
992
 * Ensures the index uses less memory than the maximum specified in
993
 * AVFormatContext.max_index_size by discarding entries if it grows
994
 * too large.
995
 * This function is not part of the public API and should only be called
996
 * by demuxers.
997
 */
998
void ff_reduce_index(AVFormatContext *s, int stream_index);
999

    
1000
/**
1001
 * Adds an index entry into a sorted list. Updates the entry if the list
1002
 * already contains it.
1003
 *
1004
 * @param timestamp timestamp in the time base of the given stream
1005
 */
1006
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp,
1007
                       int size, int distance, int flags);
1008

    
1009
/**
1010
 * Does a binary search using av_index_search_timestamp() and
1011
 * AVCodec.read_timestamp().
1012
 * This is not supposed to be called directly by a user application,
1013
 * but by demuxers.
1014
 * @param target_ts target timestamp in the time base of the given stream
1015
 * @param stream_index stream number
1016
 */
1017
int av_seek_frame_binary(AVFormatContext *s, int stream_index,
1018
                         int64_t target_ts, int flags);
1019

    
1020
/**
1021
 * Updates cur_dts of all streams based on the given timestamp and AVStream.
1022
 *
1023
 * Stream ref_st unchanged, others set cur_dts in their native time base.
1024
 * Only needed for timestamp wrapping or if (dts not set and pts!=dts).
1025
 * @param timestamp new dts expressed in time_base of param ref_st
1026
 * @param ref_st reference stream giving time_base of param timestamp
1027
 */
1028
void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
1029

    
1030
/**
1031
 * Does a binary search using read_timestamp().
1032
 * This is not supposed to be called directly by a user application,
1033
 * but by demuxers.
1034
 * @param target_ts target timestamp in the time base of the given stream
1035
 * @param stream_index stream number
1036
 */
1037
int64_t av_gen_search(AVFormatContext *s, int stream_index,
1038
                      int64_t target_ts, int64_t pos_min,
1039
                      int64_t pos_max, int64_t pos_limit,
1040
                      int64_t ts_min, int64_t ts_max,
1041
                      int flags, int64_t *ts_ret,
1042
                      int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
1043

    
1044
/** media file output */
1045
int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap);
1046

    
1047
/**
1048
 * Allocates the stream private data and writes the stream header to an
1049
 * output media file.
1050
 *
1051
 * @param s media file handle
1052
 * @return 0 if OK, AVERROR_xxx on error
1053
 */
1054
int av_write_header(AVFormatContext *s);
1055

    
1056
/**
1057
 * Writes a packet to an output media file.
1058
 *
1059
 * The packet shall contain one audio or video frame.
1060
 * The packet must be correctly interleaved according to the container
1061
 * specification, if not then av_interleaved_write_frame must be used.
1062
 *
1063
 * @param s media file handle
1064
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1065
              dts/pts, ...
1066
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1067
 */
1068
int av_write_frame(AVFormatContext *s, AVPacket *pkt);
1069

    
1070
/**
1071
 * Writes a packet to an output media file ensuring correct interleaving.
1072
 *
1073
 * The packet must contain one audio or video frame.
1074
 * If the packets are already correctly interleaved, the application should
1075
 * call av_write_frame() instead as it is slightly faster. It is also important
1076
 * to keep in mind that completely non-interleaved input will need huge amounts
1077
 * of memory to interleave with this, so it is preferable to interleave at the
1078
 * demuxer level.
1079
 *
1080
 * @param s media file handle
1081
 * @param pkt The packet, which contains the stream_index, buf/buf_size,
1082
              dts/pts, ...
1083
 * @return < 0 on error, = 0 if OK, 1 if end of stream wanted
1084
 */
1085
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt);
1086

    
1087
/**
1088
 * Interleaves a packet per dts in an output media file.
1089
 *
1090
 * Packets with pkt->destruct == av_destruct_packet will be freed inside this
1091
 * function, so they cannot be used after it. Note that calling av_free_packet()
1092
 * on them is still safe.
1093
 *
1094
 * @param s media file handle
1095
 * @param out the interleaved packet will be output here
1096
 * @param in the input packet
1097
 * @param flush 1 if no further packets are available as input and all
1098
 *              remaining packets should be output
1099
 * @return 1 if a packet was output, 0 if no packet could be output,
1100
 *         < 0 if an error occurred
1101
 */
1102
int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
1103
                                 AVPacket *pkt, int flush);
1104

    
1105
/**
1106
 * Writes the stream trailer to an output media file and frees the
1107
 * file private data.
1108
 *
1109
 * May only be called after a successful call to av_write_header.
1110
 *
1111
 * @param s media file handle
1112
 * @return 0 if OK, AVERROR_xxx on error
1113
 */
1114
int av_write_trailer(AVFormatContext *s);
1115

    
1116
void dump_format(AVFormatContext *ic,
1117
                 int index,
1118
                 const char *url,
1119
                 int is_output);
1120

    
1121
#if LIBAVFORMAT_VERSION_MAJOR < 53
1122
/**
1123
 * Parses width and height out of string str.
1124
 * @deprecated Use av_parse_video_frame_size instead.
1125
 */
1126
attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr,
1127
                                          const char *str);
1128

    
1129
/**
1130
 * Converts framerate from a string to a fraction.
1131
 * @deprecated Use av_parse_video_frame_rate instead.
1132
 */
1133
attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base,
1134
                                          const char *arg);
1135
#endif
1136

    
1137
/**
1138
 * Parses datestr and returns a corresponding number of microseconds.
1139
 * @param datestr String representing a date or a duration.
1140
 * - If a date the syntax is:
1141
 * @code
1142
 *  [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]}
1143
 * @endcode
1144
 * Time is local time unless Z is appended, in which case it is
1145
 * interpreted as UTC.
1146
 * If the year-month-day part is not specified it takes the current
1147
 * year-month-day.
1148
 * Returns the number of microseconds since 1st of January, 1970 up to
1149
 * the time of the parsed date or INT64_MIN if datestr cannot be
1150
 * successfully parsed.
1151
 * - If a duration the syntax is:
1152
 * @code
1153
 *  [-]HH[:MM[:SS[.m...]]]
1154
 *  [-]S+[.m...]
1155
 * @endcode
1156
 * Returns the number of microseconds contained in a time interval
1157
 * with the specified duration or INT64_MIN if datestr cannot be
1158
 * successfully parsed.
1159
 * @param duration Flag which tells how to interpret datestr, if
1160
 * not zero datestr is interpreted as a duration, otherwise as a
1161
 * date.
1162
 */
1163
int64_t parse_date(const char *datestr, int duration);
1164

    
1165
/** Gets the current time in microseconds. */
1166
int64_t av_gettime(void);
1167

    
1168
/* ffm-specific for ffserver */
1169
#define FFM_PACKET_SIZE 4096
1170
int64_t ffm_read_write_index(int fd);
1171
int ffm_write_write_index(int fd, int64_t pos);
1172
void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size);
1173

    
1174
/**
1175
 * Attempts to find a specific tag in a URL.
1176
 *
1177
 * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done.
1178
 * Return 1 if found.
1179
 */
1180
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info);
1181

    
1182
/**
1183
 * Returns in 'buf' the path with '%d' replaced by a number.
1184
 *
1185
 * Also handles the '%0nd' format where 'n' is the total number
1186
 * of digits and '%%'.
1187
 *
1188
 * @param buf destination buffer
1189
 * @param buf_size destination buffer size
1190
 * @param path numbered sequence string
1191
 * @param number frame number
1192
 * @return 0 if OK, -1 on format error
1193
 */
1194
int av_get_frame_filename(char *buf, int buf_size,
1195
                          const char *path, int number);
1196

    
1197
/**
1198
 * Checks whether filename actually is a numbered sequence generator.
1199
 *
1200
 * @param filename possible numbered sequence string
1201
 * @return 1 if a valid numbered sequence string, 0 otherwise
1202
 */
1203
int av_filename_number_test(const char *filename);
1204

    
1205
/**
1206
 * Generates an SDP for an RTP session.
1207
 *
1208
 * @param ac array of AVFormatContexts describing the RTP streams. If the
1209
 *           array is composed by only one context, such context can contain
1210
 *           multiple AVStreams (one AVStream per RTP stream). Otherwise,
1211
 *           all the contexts in the array (an AVCodecContext per RTP stream)
1212
 *           must contain only one AVStream.
1213
 * @param n_files number of AVCodecContexts contained in ac
1214
 * @param buff buffer where the SDP will be stored (must be allocated by
1215
 *             the caller)
1216
 * @param size the size of the buffer
1217
 * @return 0 if OK, AVERROR_xxx on error
1218
 */
1219
int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size);
1220

    
1221
#ifdef HAVE_AV_CONFIG_H
1222

    
1223
void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem);
1224

    
1225
#ifdef __GNUC__
1226
#define dynarray_add(tab, nb_ptr, elem)\
1227
do {\
1228
    __typeof__(tab) _tab = (tab);\
1229
    __typeof__(elem) _elem = (elem);\
1230
    (void)sizeof(**_tab == _elem); /* check that types are compatible */\
1231
    ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\
1232
} while(0)
1233
#else
1234
#define dynarray_add(tab, nb_ptr, elem)\
1235
do {\
1236
    ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\
1237
} while(0)
1238
#endif
1239

    
1240
time_t mktimegm(struct tm *tm);
1241
struct tm *brktimegm(time_t secs, struct tm *tm);
1242
const char *small_strptime(const char *p, const char *fmt,
1243
                           struct tm *dt);
1244

    
1245
struct in_addr;
1246
int resolve_host(struct in_addr *sin_addr, const char *hostname);
1247

    
1248
void url_split(char *proto, int proto_size,
1249
               char *authorization, int authorization_size,
1250
               char *hostname, int hostname_size,
1251
               int *port_ptr,
1252
               char *path, int path_size,
1253
               const char *url);
1254

    
1255
/**
1256
 * Returns a positive value if the given filename has one of the given
1257
 * extensions, 0 otherwise.
1258
 *
1259
 * @param extensions a comma-separated list of filename extensions
1260
 */
1261
int match_ext(const char *filename, const char *extensions);
1262

    
1263
#endif /* HAVE_AV_CONFIG_H */
1264

    
1265
#endif /* AVFORMAT_AVFORMAT_H */