fftools/ffmpeg_dec: replace InputFile.format_nots with a decoder flag

Reduces the need to access InputFile from decoding.

This is a step towards decoupling Decoder and InputStream.
This commit is contained in:
Anton Khirnov 2024-01-17 11:00:26 +01:00
parent a938f47916
commit ebb8a58c8f
3 changed files with 8 additions and 10 deletions

View File

@ -282,6 +282,8 @@ typedef struct FilterGraph {
enum DecoderFlags {
DECODER_FLAG_FIX_SUB_DURATION = (1 << 0),
// input timestamps are unreliable (guessed by demuxer)
DECODER_FLAG_TS_UNRELIABLE = (1 << 1),
};
typedef struct Decoder {
@ -362,9 +364,6 @@ typedef struct InputFile {
int index;
// input format has no timestamps
int format_nots;
AVFormatContext *ctx;
int64_t input_ts_offset;
int input_sync_ref;

View File

@ -216,7 +216,7 @@ static void audio_ts_process(DecoderPriv *dp, AVFrame *frame)
static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame)
{
const DecoderPriv *dp = dp_from_dec(ist->decoder);
const InputFile *ifile = ist->file;
const int ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
int64_t codec_duration = 0;
// XXX lavf currently makes up frame durations when they are not provided by
@ -226,7 +226,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
// durations, then this should be simplified.
// prefer frame duration for containers with timestamps
if (frame->duration > 0 && (!ifile->format_nots || ist->framerate.num))
if (frame->duration > 0 && (!ts_unreliable || ist->framerate.num))
return frame->duration;
if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
@ -238,7 +238,7 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
}
// prefer codec-layer duration for containers without timestamps
if (codec_duration > 0 && ifile->format_nots)
if (codec_duration > 0 && ts_unreliable)
return codec_duration;
// when timestamps are available, repeat last frame's actual duration
@ -466,7 +466,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
if (pkt && pkt->size == 0)
return 0;
if (pkt && ifile->format_nots) {
if (pkt && (dp->flags & DECODER_FLAG_TS_UNRELIABLE)) {
pkt->pts = AV_NOPTS_VALUE;
pkt->dts = AV_NOPTS_VALUE;
}

View File

@ -891,7 +891,8 @@ static int ist_use(InputStream *ist, int decoding_needed)
if (decoding_needed && ds->sch_idx_dec < 0) {
int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
int dec_flags = !!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION;
int dec_flags = (!!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION) |
(!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE);
ret = sch_add_dec(d->sch, decoder_thread, ist, d->loop && is_audio);
if (ret < 0)
@ -1698,8 +1699,6 @@ int ifile_open(const OptionsContext *o, const char *filename, Scheduler *sch)
d->min_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
d->max_pts = (Timestamp){ .ts = AV_NOPTS_VALUE, .tb = (AVRational){ 1, 1 } };
f->format_nots = !!(ic->iformat->flags & AVFMT_NOTIMESTAMPS);
d->readrate = o->readrate ? o->readrate : 0.0;
if (d->readrate < 0.0f) {
av_log(d, AV_LOG_ERROR, "Option -readrate is %0.3f; it must be non-negative.\n", d->readrate);