Coverage Report

Created: 2026-10-28 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/internal.h
Line
Count
Source
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_INTERNAL_H
22
#define AVFORMAT_INTERNAL_H
23
24
#include <stdint.h>
25
26
#include "packet_internal.h"
27
28
#include "avformat.h"
29
30
#define MAX_URL_SIZE 4096
31
32
/** size of probe buffer, for guessing file type from file contents */
33
0
#define PROBE_BUF_MIN 2048
34
0
#define PROBE_BUF_MAX (1 << 20)
35
36
#ifdef DEBUG
37
#    define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size)
38
#else
39
#    define hex_dump_debug(class, buf, size) do { if (0) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size); } while(0)
40
#endif
41
42
typedef struct AVCodecTag {
43
    enum AVCodecID id;
44
    unsigned int tag;
45
} AVCodecTag;
46
47
typedef struct CodecMime{
48
    char str[32];
49
    enum AVCodecID id;
50
} CodecMime;
51
52
/*************************************************/
53
/* fractional numbers for exact pts handling */
54
55
/**
56
 * The exact value of the fractional number is: 'val + num / den'.
57
 * num is assumed to be 0 <= num < den.
58
 */
59
typedef struct FFFrac {
60
    int64_t val, num, den;
61
} FFFrac;
62
63
64
typedef struct FFFormatContext {
65
    /**
66
     * The public context.
67
     */
68
    AVFormatContext pub;
69
70
    /**
71
     * Whether the timestamp shift offset has already been determined.
72
     * -1: disabled, 0: not yet determined, 1: determined.
73
     */
74
    enum {
75
        AVOID_NEGATIVE_TS_DISABLED = -1,
76
        AVOID_NEGATIVE_TS_UNKNOWN  = 0,
77
        AVOID_NEGATIVE_TS_KNOWN    = 1,
78
    } avoid_negative_ts_status;
79
#define AVOID_NEGATIVE_TS_ENABLED(status) ((status) >= 0)
80
81
    /**
82
     * This buffer is only needed when packets were already buffered but
83
     * not decoded, for example to get the codec parameters in MPEG
84
     * streams.
85
     */
86
    PacketList packet_buffer;
87
88
    /* av_seek_frame() support */
89
    int64_t data_offset; /**< offset of the first packet */
90
91
    /**
92
     * The generic code uses this as a temporary packet
93
     * to parse packets or for muxing, especially flushing.
94
     * For demuxers, it may also be used for other means
95
     * for short periods that are guaranteed not to overlap
96
     * with calls to av_read_frame() (or ff_read_packet())
97
     * or with each other.
98
     * It may be used by demuxers as a replacement for
99
     * stack packets (unless they call one of the aforementioned
100
     * functions with their own AVFormatContext).
101
     * Every user has to ensure that this packet is blank
102
     * after using it.
103
     */
104
    AVPacket *parse_pkt;
105
106
    /**
107
     * Used to hold temporary packets for the generic demuxing code.
108
     * When muxing, it may be used by muxers to hold packets (even
109
     * permanent ones).
110
     */
111
    AVPacket *pkt;
112
113
    int avoid_negative_ts_use_pts;
114
115
    /**
116
     * ID3v2 tag useful for MP3 demuxing
117
     */
118
    AVDictionary *id3v2_meta;
119
120
    int missing_streams;
121
122
    /**
123
     * Set if program ids are strictly monotonic.
124
     */
125
    int program_ids_monotonic;
126
127
    /**
128
     * Shared libcurl event loop, created on demand on the first use. Freed on
129
     * context free. This allows to share libcurl state across URLContexts,
130
     * scoped to this context.
131
     */
132
    struct CurlLoop *curl_loop;
133
} FFFormatContext;
134
135
static av_always_inline FFFormatContext *ffformatcontext(AVFormatContext *s)
136
0
{
137
0
    return (FFFormatContext*)s;
138
0
}
Unexecuted instantiation: avformat.c:ffformatcontext
Unexecuted instantiation: demux.c:ffformatcontext
Unexecuted instantiation: demux_utils.c:ffformatcontext
Unexecuted instantiation: format.c:ffformatcontext
Unexecuted instantiation: id3v2.c:ffformatcontext
Unexecuted instantiation: options.c:ffformatcontext
Unexecuted instantiation: seek.c:ffformatcontext
Unexecuted instantiation: utils.c:ffformatcontext
Unexecuted instantiation: allformats.c:ffformatcontext
Unexecuted instantiation: avio.c:ffformatcontext
Unexecuted instantiation: aviobuf.c:ffformatcontext
139
140
typedef struct FFStream {
141
    /**
142
     * The public context.
143
     */
144
    AVStream pub;
145
146
    AVFormatContext *fmtctx;
147
    /**
148
     * Set to 1 if the codec allows reordering, so pts can be different
149
     * from dts.
150
     */
151
    int reorder;
152
153
    /**
154
     * bitstream filter to run on stream
155
     * - encoding: Set by muxer using ff_stream_add_bitstream_filter
156
     * - decoding: unused
157
     */
158
    struct AVBSFContext *bsfc;
159
160
    /**
161
     * Whether or not check_bitstream should still be run on each packet
162
     */
163
    int bitstream_checked;
164
165
    /**
166
     * The codec context used by avformat_find_stream_info, the parser, etc.
167
     */
168
    struct AVCodecContext *avctx;
169
    /**
170
     * 1 if avctx has been initialized with the values from the codec parameters
171
     */
172
    int avctx_inited;
173
174
    /* the context for extracting extradata in find_stream_info()
175
     * inited=1/bsf=NULL signals that extracting is not possible (codec not
176
     * supported) */
177
    struct {
178
        struct AVBSFContext *bsf;
179
        int inited;
180
    } extract_extradata;
181
182
    /**
183
     * Whether the internal avctx needs to be updated from codecpar (after a late change to codecpar)
184
     */
185
    int need_context_update;
186
187
    int is_intra_only;
188
189
    FFFrac priv_pts;
190
191
    /**
192
     * Stream information used internally by avformat_find_stream_info()
193
     */
194
    struct FFStreamInfo *info;
195
196
    AVIndexEntry *index_entries; /**< Only used if the format does not
197
                                    support seeking natively. */
198
    int nb_index_entries;
199
    unsigned int index_entries_allocated_size;
200
201
    int64_t interleaver_chunk_size;
202
    int64_t interleaver_chunk_duration;
203
204
    /**
205
     * stream probing state
206
     * -1   -> probing finished
207
     *  0   -> no probing requested
208
     * rest -> perform probing with request_probe being the minimum score to accept.
209
     */
210
    int request_probe;
211
    /**
212
     * Indicates that everything up to the next keyframe
213
     * should be discarded.
214
     */
215
    int skip_to_keyframe;
216
217
    /**
218
     * Number of samples to skip at the start of the frame decoded from the next packet.
219
     */
220
    int skip_samples;
221
222
    /**
223
     * If not 0, the number of samples that should be skipped from the start of
224
     * the stream (the samples are removed from packets with pts==0, which also
225
     * assumes negative timestamps do not happen).
226
     * Intended for use with formats such as mp3 with ad-hoc gapless audio
227
     * support.
228
     */
229
    int64_t start_skip_samples;
230
231
    /**
232
     * If not 0, the first audio sample that should be discarded from the stream.
233
     * This is broken by design (needs global sample count), but can't be
234
     * avoided for broken by design formats such as mp3 with ad-hoc gapless
235
     * audio support.
236
     */
237
    int64_t first_discard_sample;
238
239
    /**
240
     * The sample after last sample that is intended to be discarded after
241
     * first_discard_sample. Works on frame boundaries only. Used to prevent
242
     * early EOF if the gapless info is broken (considered concatenated mp3s).
243
     */
244
    int64_t last_discard_sample;
245
246
    /**
247
     * Set by a seek, cleared on the next packet of the stream, which gets in
248
     * skip_samples the rest of the priming if it is inside it, and unless it
249
     * is the first packet of the stream, at least the seek pre-roll of the
250
     * codec. After the priming, a seek to the start of the stream gets none.
251
     */
252
    int seek_discard;
253
254
    /**
255
     * Set with seek_discard when the target of the seek is at or before the
256
     * start of this stream.
257
     */
258
    int seek_to_start;
259
260
    /**
261
     * Number of internally decoded frames, used internally in libavformat, do not access
262
     * its lifetime differs from info which is why it is not in that structure.
263
     */
264
    int nb_decoded_frames;
265
266
    /**
267
     * Timestamp offset added to timestamps before muxing
268
     */
269
    int64_t mux_ts_offset;
270
271
    /**
272
     * This is the lowest ts allowed in this track; it may be set by the muxer
273
     * during init or write_header and influences the automatic timestamp
274
     * shifting code.
275
     */
276
    int64_t lowest_ts_allowed;
277
278
    /**
279
     * Internal data to check for wrapping of the time stamp
280
     */
281
    int64_t pts_wrap_reference;
282
283
    /**
284
     * Options for behavior, when a wrap is detected.
285
     *
286
     * Defined by AV_PTS_WRAP_ values.
287
     *
288
     * If correction is enabled, there are two possibilities:
289
     * If the first time stamp is near the wrap point, the wrap offset
290
     * will be subtracted, which will create negative time stamps.
291
     * Otherwise the offset will be added.
292
     */
293
    int pts_wrap_behavior;
294
295
    /**
296
     * Internal data to prevent doing update_initial_durations() twice
297
     */
298
    int update_initial_durations_done;
299
300
0
#define MAX_REORDER_DELAY 16
301
302
    /**
303
     * Internal data to generate dts from pts
304
     */
305
    int64_t pts_reorder_error[MAX_REORDER_DELAY+1];
306
    uint8_t pts_reorder_error_count[MAX_REORDER_DELAY+1];
307
308
    int64_t pts_buffer[MAX_REORDER_DELAY+1];
309
310
    /**
311
     * Internal data to analyze DTS and detect faulty mpeg streams
312
     */
313
    int64_t last_dts_for_order_check;
314
    uint8_t dts_ordered;
315
    uint8_t dts_misordered;
316
317
    /**
318
     * display aspect ratio (0 if unknown)
319
     * - encoding: unused
320
     * - decoding: Set by libavformat to calculate sample_aspect_ratio internally
321
     */
322
    AVRational display_aspect_ratio;
323
324
    AVProbeData probe_data;
325
326
    /**
327
     * last packet in packet_buffer for this stream when muxing.
328
     */
329
    PacketListEntry *last_in_packet_buffer;
330
331
    int64_t last_IP_pts;
332
    int last_IP_duration;
333
334
    /**
335
     * Number of packets to buffer for codec probing
336
     */
337
    int probe_packets;
338
339
    /* av_read_frame() support */
340
    enum AVStreamParseType need_parsing;
341
    struct AVCodecParserContext *parser;
342
343
    /**
344
     * The generic code uses this as a temporary packet
345
     * to parse packets or for muxing, especially flushing.
346
     * For demuxers, it may also be used for other means
347
     * for short periods that are guaranteed not to overlap
348
     * with calls to av_read_frame() (or ff_read_packet())
349
     * or with each other.
350
     * It may be used by demuxers as a replacement for
351
     * stack packets (unless they call one of the aforementioned
352
     * functions with their own AVFormatContext).
353
     * Every user has to ensure that this packet is blank
354
     * after using it.
355
     */
356
    AVPacket *parse_pkt;
357
358
    /**
359
     * Number of frames that have been demuxed during avformat_find_stream_info()
360
     */
361
    int codec_info_nb_frames;
362
363
    /**
364
     * Stream Identifier
365
     * This is the MPEG-TS stream identifier +1
366
     * 0 means unknown
367
     */
368
    int stream_identifier;
369
370
    // Timestamp generation support:
371
    /**
372
     * Timestamp corresponding to the last dts sync point.
373
     *
374
     * Initialized when AVCodecParserContext.dts_sync_point >= 0 and
375
     * a DTS is received from the underlying container. Otherwise set to
376
     * AV_NOPTS_VALUE by default.
377
     */
378
    int64_t first_dts;
379
    int64_t cur_dts;
380
381
    const struct AVCodecDescriptor *codec_desc;
382
} FFStream;
383
384
static av_always_inline FFStream *ffstream(AVStream *st)
385
0
{
386
0
    return (FFStream*)st;
387
0
}
Unexecuted instantiation: avformat.c:ffstream
Unexecuted instantiation: demux.c:ffstream
Unexecuted instantiation: demux_utils.c:ffstream
Unexecuted instantiation: format.c:ffstream
Unexecuted instantiation: id3v2.c:ffstream
Unexecuted instantiation: options.c:ffstream
Unexecuted instantiation: seek.c:ffstream
Unexecuted instantiation: utils.c:ffstream
Unexecuted instantiation: allformats.c:ffstream
Unexecuted instantiation: avio.c:ffstream
Unexecuted instantiation: aviobuf.c:ffstream
388
389
static av_always_inline const FFStream *cffstream(const AVStream *st)
390
0
{
391
0
    return (const FFStream*)st;
392
0
}
Unexecuted instantiation: avformat.c:cffstream
Unexecuted instantiation: demux.c:cffstream
Unexecuted instantiation: demux_utils.c:cffstream
Unexecuted instantiation: format.c:cffstream
Unexecuted instantiation: id3v2.c:cffstream
Unexecuted instantiation: options.c:cffstream
Unexecuted instantiation: seek.c:cffstream
Unexecuted instantiation: utils.c:cffstream
Unexecuted instantiation: allformats.c:cffstream
Unexecuted instantiation: avio.c:cffstream
Unexecuted instantiation: aviobuf.c:cffstream
393
394
#if defined (__GNUC__) || defined (__clang__)
395
#define dynarray_add(tab, nb_ptr, elem)\
396
do {\
397
    __typeof__(tab) _tab = (tab);\
398
    __typeof__(elem) _elem = (elem);\
399
    (void)sizeof(**_tab == _elem); /* check that types are compatible */\
400
    av_dynarray_add(_tab, nb_ptr, _elem);\
401
} while(0)
402
#else
403
#define dynarray_add(tab, nb_ptr, elem)\
404
do {\
405
    av_dynarray_add((tab), nb_ptr, (elem));\
406
} while(0)
407
#endif
408
409
/**
410
 * Automatically create sub-directories
411
 *
412
 * @param path will create sub-directories by path
413
 * @return 0, or < 0 on error
414
 */
415
int ff_mkdir_p(const char *path);
416
417
/**
418
 * Write hexadecimal string corresponding to given binary data. The string
419
 * is zero-terminated.
420
 *
421
 * @param buf       the output string is written here;
422
 *                  needs to be at least 2 * size + 1 bytes long.
423
 * @param src       the input data to be transformed.
424
 * @param size      the size (in byte) of src.
425
 * @param lowercase determines whether to use the range [0-9a-f] or [0-9A-F].
426
 * @return buf.
427
 */
428
char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
429
430
/**
431
 * Parse a string of hexadecimal strings. Any space between the hexadecimal
432
 * digits is ignored.
433
 *
434
 * @param data if non-null, the parsed data is written to this pointer
435
 * @param p the string to parse
436
 * @return the number of bytes written (or to be written, if data is null)
437
 */
438
int ff_hex_to_data(uint8_t *data, const char *p);
439
440
0
#define NTP_OFFSET 2208988800ULL
441
0
#define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL)
442
443
/** Get the current time since NTP epoch in microseconds. */
444
uint64_t ff_ntp_time(void);
445
446
/**
447
 * Get the NTP time stamp formatted as per the RFC-5905.
448
 *
449
 * @param ntp_time NTP time in microseconds (since NTP epoch)
450
 * @return the formatted NTP time stamp
451
 */
452
uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us);
453
454
/**
455
 * Parse the NTP time in microseconds (since NTP epoch).
456
 *
457
 * @param ntp_ts NTP time stamp formatted as per the RFC-5905.
458
 * @return the time in microseconds (since NTP epoch)
459
 */
460
uint64_t ff_parse_ntp_time(uint64_t ntp_ts);
461
462
/**
463
 * Append the media-specific SDP fragment for the media stream c
464
 * to the buffer buff.
465
 *
466
 * Note, the buffer needs to be initialized, since it is appended to
467
 * existing content.
468
 *
469
 * @param buff the buffer to append the SDP fragment to
470
 * @param size the size of the buff buffer
471
 * @param st the AVStream of the media to describe
472
 * @param idx the global stream index
473
 * @param dest_addr the destination address of the media stream, may be NULL
474
 * @param dest_type the destination address type, may be NULL
475
 * @param port the destination port of the media stream, 0 if unknown
476
 * @param ttl the time to live of the stream, 0 if not multicast
477
 * @param fmt the AVFormatContext, which might contain options modifying
478
 *            the generated SDP
479
 * @return 0 on success, a negative error code on failure
480
 */
481
int ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx,
482
                       const char *dest_addr, const char *dest_type,
483
                       int port, int ttl, AVFormatContext *fmt);
484
485
/**
486
 * Read a whole line of text from AVIOContext. Stop reading after reaching
487
 * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
488
 * and may be truncated if the buffer is too small.
489
 *
490
 * @param s the read-only AVIOContext
491
 * @param buf buffer to store the read line
492
 * @param maxlen size of the buffer
493
 * @return the length of the string written in the buffer, not including the
494
 *         final \\0
495
 */
496
int ff_get_line(AVIOContext *s, char *buf, int maxlen);
497
498
/**
499
 * Same as ff_get_line but strip the white-space characters in the text tail
500
 *
501
 * @param s the read-only AVIOContext
502
 * @param buf buffer to store the read line
503
 * @param maxlen size of the buffer
504
 * @return the length of the string written in the buffer
505
 */
506
int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen);
507
508
0
#define SPACE_CHARS " \t\r\n"
509
510
/**
511
 * Callback function type for ff_parse_key_value.
512
 *
513
 * @param key a pointer to the key
514
 * @param key_len the number of bytes that belong to the key, including the '='
515
 *                char
516
 * @param dest return the destination pointer for the value in *dest, may
517
 *             be null to ignore the value
518
 * @param dest_len the length of the *dest buffer
519
 */
520
typedef void (*ff_parse_key_val_cb)(void *context, const char *key,
521
                                    int key_len, char **dest, int *dest_len);
522
/**
523
 * Parse a string with comma-separated key=value pairs. The value strings
524
 * may be quoted and may contain escaped characters within quoted strings.
525
 *
526
 * @param str the string to parse
527
 * @param callback_get_buf function that returns where to store the
528
 *                         unescaped value string.
529
 * @param context the opaque context pointer to pass to callback_get_buf
530
 */
531
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
532
                        void *context);
533
534
enum AVCodecID ff_guess_image2_codec(const char *filename);
535
536
/**
537
 * Set the time base and wrapping info for a given stream. This will be used
538
 * to interpret the stream's timestamps. If the new time base is invalid
539
 * (numerator or denominator are non-positive), it leaves the stream
540
 * unchanged.
541
 *
542
 * @param st stream
543
 * @param pts_wrap_bits number of bits effectively used by the pts
544
 *        (used for wrap control)
545
 * @param pts_num time base numerator
546
 * @param pts_den time base denominator
547
 */
548
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
549
                         unsigned int pts_num, unsigned int pts_den);
550
551
/**
552
 * Set the timebase for each stream from the corresponding codec timebase and
553
 * print it.
554
 */
555
int ff_framehash_write_header(AVFormatContext *s);
556
557
/**
558
 * Remove a stream from its AVFormatContext and free it.
559
 * The stream must be the last stream of the AVFormatContext.
560
 */
561
void ff_remove_stream(AVFormatContext *s, AVStream *st);
562
563
/**
564
 * Remove a stream group from its AVFormatContext and free it.
565
 * The stream group must be the last stream group of the AVFormatContext.
566
 */
567
void ff_remove_stream_group(AVFormatContext *s, AVStreamGroup *stg);
568
569
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
570
571
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag);
572
573
/**
574
 * Select a PCM codec based on the given parameters.
575
 *
576
 * @param bps     bits-per-sample
577
 * @param flt     floating-point
578
 * @param be      big-endian
579
 * @param sflags  signed flags. each bit corresponds to one byte of bit depth.
580
 *                e.g. the 1st bit indicates if 8-bit should be signed or
581
 *                unsigned, the 2nd bit indicates if 16-bit should be signed or
582
 *                unsigned, etc... This is useful for formats such as WAVE where
583
 *                only 8-bit is unsigned and all other bit depths are signed.
584
 * @return        a PCM codec id or AV_CODEC_ID_NONE
585
 */
586
enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
587
588
/**
589
 * Create a new stream and copy to it all parameters from a source stream, with
590
 * the exception of the index field, which is set when the new stream is
591
 * created.
592
 *
593
 * @param dst_ctx pointer to the context in which the new stream is created
594
 * @param src pointer to source AVStream
595
 * @return pointer to the new stream or NULL on error
596
 */
597
AVStream *ff_stream_clone(AVFormatContext *dst_ctx, const AVStream *src);
598
599
/**
600
 * Wrap ffurl_move() and log if error happens.
601
 *
602
 * @param url_src source path
603
 * @param url_dst destination path
604
 * @return        0 or AVERROR on failure
605
 */
606
int ff_rename(const char *url_src, const char *url_dst, void *logctx);
607
608
/**
609
 * Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end
610
 * which is always set to 0.
611
 *
612
 * Previously allocated extradata in par will be freed.
613
 *
614
 * @param size size of extradata
615
 * @return 0 if OK, AVERROR_xxx on error
616
 */
617
int ff_alloc_extradata(AVCodecParameters *par, int size);
618
619
/**
620
 * Copies the whilelists from one context to the other
621
 */
622
int ff_copy_whiteblacklists(AVFormatContext *dst, const AVFormatContext *src);
623
624
/*
625
 * A wrapper around AVFormatContext.io_close that should be used
626
 * instead of calling the pointer directly.
627
 *
628
 * @param s AVFormatContext
629
 * @param *pb the AVIOContext to be closed and freed. Can be NULL.
630
 * @return >=0 on success, negative AVERROR in case of failure
631
 */
632
int ff_format_io_close(AVFormatContext *s, AVIOContext **pb);
633
634
/**
635
 * Release a libcurl event loop and set *loop to NULL.
636
 * No-op when @p loop or *loop is NULL.
637
 */
638
void ff_curl_loop_free(struct CurlLoop **loop);
639
640
/**
641
 * Utility function to check if the file uses http or https protocol
642
 *
643
 * @param s AVFormatContext
644
 * @param filename URL or file name to open for writing
645
 */
646
int ff_is_http_proto(const char *filename);
647
648
struct AVBPrint;
649
/**
650
 * Finalize buf into extradata and set its size appropriately.
651
 */
652
int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf);
653
654
/**
655
 * Set AVFormatContext url field to the provided pointer. The pointer must
656
 * point to a valid string. The existing url field is freed if necessary. Also
657
 * set the legacy filename field to the same string which was provided in url.
658
 */
659
void ff_format_set_url(AVFormatContext *s, char *url);
660
661
/**
662
 * Set AVFormatContext url field to a av_strdup of the provided pointer. The pointer must
663
 * point to a valid string. The existing url field is freed if necessary.
664
 *
665
 * Checks protocol_whitelist/blacklist
666
 *
667
 * @returns a AVERROR code or non negative on success
668
 */
669
int ff_format_check_set_url(AVFormatContext *s, const char *url);
670
671
/**
672
 * Return a positive value if the given url has one of the given
673
 * extensions, negative AVERROR on error, 0 otherwise.
674
 *
675
 * @param url        url to check against the given extensions
676
 * @param extensions a comma-separated list of filename extensions
677
 */
678
int ff_match_url_ext(const char *url, const char *extensions);
679
680
/**
681
 * Return in 'buf' the path with '%d' replaced by a number.
682
 *
683
 * Also handles the '%0nd' format where 'n' is the total number
684
 * of digits and '%%'.
685
 *
686
 * @param buf destination buffer
687
 * @param path path with substitution template
688
 * @param number the number to substitute
689
 * @param flags AV_FRAME_FILENAME_FLAGS_*
690
 * @return 0 if OK, <0 on error.
691
 */
692
int ff_bprint_get_frame_filename(struct AVBPrint *buf, const char *path, int64_t number, int flags);
693
694
/**
695
 * Set a dictionary value to an ISO-8601 compliant timestamp string.
696
 *
697
 * @param dict pointer to a pointer to a dictionary struct. If *dict is NULL
698
 *             a dictionary struct is allocated and put in *dict.
699
 * @param key metadata key
700
 * @param timestamp unix timestamp in microseconds
701
 * @return <0 on error
702
 */
703
int ff_dict_set_timestamp(AVDictionary **dict, const char *key, int64_t timestamp);
704
705
/**
706
 * Set a list of query string options on an object. Only the objects own
707
 * options will be set.
708
 *
709
 * @param obj the object to set options on
710
 * @param str the query string
711
 * @param allow_unknown ignore unknown query string options. This can be OK if
712
 *                      nested protocols are used.
713
 * @return <0 on error
714
 */
715
int ff_parse_opts_from_query_string(void *obj, const char *str, int allow_unknown);
716
717
/**
718
 * Make a RFC 4281/6381 like string describing a codec.
719
 *
720
 * @param logctx a context for potential log messages; if NULL, nothing is
721
 *               logged
722
 * @param par pointer to an AVCodecParameters struct describing the codec
723
 * @param frame_rate an optional pointer to AVRational for the frame rate,
724
 *                   for deciding the right profile for video codecs
725
 * @param out the AVBPrint to write the output to
726
 * @return <0 on error
727
 */
728
int ff_make_codec_str(void *logctx, const AVCodecParameters *par,
729
                      const AVRational *frame_rate, struct AVBPrint *out);
730
731
/**
732
 * Allocate copy of a structure and copy contents of an AVBPrint buffer to the
733
 * flexible array member of the copied struct. AVBPrint buffer is freed.
734
 *
735
 * @param bp pointer to an AVBprint struct
736
 * @param struct_ptr pointer to the struct to be copied
737
 * @param fam_offset must be offsetof(StructType, flexible_array_member)
738
 * @return pointer to the newly allocated struct, NULL on allocation error or
739
 *         if the AVBPrint buffer is not complete
740
 */
741
void *ff_bprint_finalize_as_fam(struct AVBPrint *bp, const void *struct_ptr, size_t fam_offset);
742
743
#endif /* AVFORMAT_INTERNAL_H */