FFmpeg
Loading...
Searching...
No Matches
dts_gen.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Zhao Zhili <quinkblack@foxmail.com>
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 AVCODEC_DTS_GEN_H
22#define AVCODEC_DTS_GEN_H
23
24#include <stdint.h>
25
26#include "libavutil/opt.h"
27
28#include "avcodec.h"
29
30// Special value for reorder delay.
31// Asks the encoder to pick a value itself.
32#define FF_DTS_GEN_DELAY_AUTO -1
33// Leaves pkt->dts unset.
34#define FF_DTS_GEN_DELAY_SKIP -2
35#define FF_DTS_GEN_DELAY_MAX 16
36
37/* AVOption entries for the reorder_delay option. The encoder resolves
38 * FF_DTS_GEN_DELAY_AUTO before passing the value to ff_dts_gen_init().
39 */
40#define FF_DTS_GEN_REORDER_DELAY_OPTION(offset, flags) \
41 { "reorder_delay", "Reorder delay in frames used to generate dts; a value below the real reorder depth makes dts non-monotonic", \
42 offset, AV_OPT_TYPE_INT, { .i64 = FF_DTS_GEN_DELAY_AUTO }, FF_DTS_GEN_DELAY_SKIP, FF_DTS_GEN_DELAY_MAX, flags, .unit = "reorder_delay" }, \
43 { "auto", "Derive the delay from the encoder configuration", \
44 0, AV_OPT_TYPE_CONST, { .i64 = FF_DTS_GEN_DELAY_AUTO }, 0, 0, flags, .unit = "reorder_delay" }, \
45 { "skip", "Leave dts unset for codecs that support reordering", \
46 0, AV_OPT_TYPE_CONST, { .i64 = FF_DTS_GEN_DELAY_SKIP }, 0, 0, flags, .unit = "reorder_delay" }
47
48/* Derives pkt->dts for packets emitted in decode order from their pts and
49 * the reorder delay. Packets are not reordered.
50 */
51typedef struct FFDTSGen {
52 /* Configuration, fixed by ff_dts_gen_init(). */
53 int delay;
54
55 /* Input side: the pts of input frames. */
58 /* First increasing interval between two input pts. */
60
61 /* Output side: the dts of output packets. */
62 /* pts values kept in ascending order; window[0] is the next dts. */
66 int warned;
67} FFDTSGen;
68
69/* Prepares g for packets emitted in decode order. delay is the reorder
70 * depth: the largest number of frames that precede a frame in decode
71 * order but follow it in display order. It is FF_DTS_GEN_DELAY_SKIP or a
72 * count in [0, FF_DTS_GEN_DELAY_MAX]; the caller resolves
73 * FF_DTS_GEN_DELAY_AUTO.
74 *
75 * Codecs without AV_CODEC_PROP_REORDER get dts == pts whatever delay is.
76 * g->delay holds the effective value, which a caller can publish as
77 * avctx->has_b_frames. A count above the real depth lowers every dts by
78 * the excess frames; a count below it produces dts values that do not
79 * increase, which is logged.
80 *
81 * Returns 0 on success or AVERROR(EINVAL) for any other delay.
82 */
84 int delay);
85
86/* Records the pts of an input frame, in display order. The first
87 * increasing interval spaces the dts values of the first packets, so it is
88 * latched. AV_NOPTS_VALUE is ignored.
89 */
91
92/* Sets pkt->dts. Call once per output packet, in output order, after
93 * setting pkt->pts. pkt->dts becomes AV_NOPTS_VALUE when g uses
94 * FF_DTS_GEN_DELAY_SKIP or pkt->pts is AV_NOPTS_VALUE.
95 *
96 * The first delay packets get dts values below the first input pts, or
97 * below the pts of the first packet when that is earlier, spaced by the
98 * interval recorded by ff_dts_gen_record_pts(), or by avctx->framerate, or
99 * by one tick when neither is known.
100 */
102
103/* Drops the buffered timestamps and the recorded input pts and interval,
104 * keeping the configured delay.
105 */
107
108#endif /* AVCODEC_DTS_GEN_H */
Libavcodec external API header.
long long int64_t
Definition coverity.c:34
static AVPacket * pkt
void ff_dts_gen_fill_pkt(AVCodecContext *avctx, FFDTSGen *g, AVPacket *pkt)
Definition dts_gen.c:79
#define FF_DTS_GEN_DELAY_MAX
Definition dts_gen.h:35
av_cold void ff_dts_gen_reset(FFDTSGen *g)
Definition dts_gen.c:130
void ff_dts_gen_record_pts(FFDTSGen *g, int64_t pts)
Definition dts_gen.c:51
av_cold int ff_dts_gen_init(const AVCodecContext *avctx, FFDTSGen *g, int delay)
Definition dts_gen.c:28
#define av_cold
Definition attributes.h:117
AVOptions.
main external API structure.
Definition avcodec.h:443
This structure stores compressed data.
Definition packet.h:587
int64_t prev_in_pts
Definition dts_gen.h:57
int delay
Definition dts_gen.h:53
int64_t first_in_pts
Definition dts_gen.h:56
int64_t window[FF_DTS_GEN_DELAY_MAX+1]
Definition dts_gen.h:63
int64_t prev_dts
Definition dts_gen.h:64
int started
Definition dts_gen.h:65
int64_t step
Definition dts_gen.h:59
int warned
Definition dts_gen.h:66
static int64_t pts
const char * g
Definition vf_curves.c:128