fftools/ffmpeg_dec: factor opening the decoder out of dec_open()

Rename dec_open to dec_init(), as it is more descriptive of its new
purpose.

Will be useful in following commits, which will add a new path for
opening decoders.
This commit is contained in:
Anton Khirnov 2024-02-19 12:11:33 +01:00
parent 48c39a9c71
commit c4de5778bc
3 changed files with 34 additions and 31 deletions

View File

@ -740,7 +740,7 @@ AVBufferRef *hw_device_for_filter(void);
* @retval ">=0" non-negative scheduler index on success
* @retval "<0" an error code on failure
*/
int dec_open(Decoder **pdec, Scheduler *sch,
int dec_init(Decoder **pdec, Scheduler *sch,
AVDictionary **dec_opts, const DecoderOpts *o);
void dec_free(Decoder **pdec);

View File

@ -1066,19 +1066,11 @@ static int hw_device_setup_for_decode(DecoderPriv *dp,
return 0;
}
int dec_open(Decoder **pdec, Scheduler *sch,
AVDictionary **dec_opts, const DecoderOpts *o)
static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o)
{
DecoderPriv *dp;
const AVCodec *codec = o->codec;
int ret;
*pdec = NULL;
ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
if (ret < 0)
return ret;
dp->flags = o->flags;
dp->log_parent = o->log_parent;
@ -1091,39 +1083,31 @@ int dec_open(Decoder **pdec, Scheduler *sch,
snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name);
dp->parent_name = av_strdup(o->name ? o->name : "");
if (!dp->parent_name) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (!dp->parent_name)
return AVERROR(ENOMEM);
if (codec->type == AVMEDIA_TYPE_SUBTITLE &&
(dp->flags & DECODER_FLAG_FIX_SUB_DURATION)) {
for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) {
dp->sub_prev[i] = av_frame_alloc();
if (!dp->sub_prev[i]) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (!dp->sub_prev[i])
return AVERROR(ENOMEM);
}
dp->sub_heartbeat = av_frame_alloc();
if (!dp->sub_heartbeat) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (!dp->sub_heartbeat)
return AVERROR(ENOMEM);
}
dp->sar_override = o->par->sample_aspect_ratio;
dp->dec_ctx = avcodec_alloc_context3(codec);
if (!dp->dec_ctx) {
ret = AVERROR(ENOMEM);
goto fail;
}
if (!dp->dec_ctx)
return AVERROR(ENOMEM);
ret = avcodec_parameters_to_context(dp->dec_ctx, o->par);
if (ret < 0) {
av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n");
goto fail;
return ret;
}
dp->dec_ctx->opaque = dp;
@ -1140,22 +1124,41 @@ int dec_open(Decoder **pdec, Scheduler *sch,
av_log(dp, AV_LOG_ERROR,
"Hardware device setup failed for decoder: %s\n",
av_err2str(ret));
goto fail;
return ret;
}
if ((ret = avcodec_open2(dp->dec_ctx, codec, dec_opts)) < 0) {
av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
av_err2str(ret));
goto fail;
return ret;
}
ret = check_avoptions(*dec_opts);
if (ret < 0)
goto fail;
return ret;
dp->dec.subtitle_header = dp->dec_ctx->subtitle_header;
dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size;
return 0;
}
int dec_init(Decoder **pdec, Scheduler *sch,
AVDictionary **dec_opts, const DecoderOpts *o)
{
DecoderPriv *dp;
int ret;
*pdec = NULL;
ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS));
if (ret < 0)
return ret;
ret = dec_open(dp, dec_opts, o);
if (ret < 0)
goto fail;
*pdec = &dp->dec;
return dp->sch_idx;

View File

@ -935,7 +935,7 @@ static int ist_use(InputStream *ist, int decoding_needed)
ds->dec_opts.log_parent = ist;
ret = dec_open(&ist->decoder, d->sch,
ret = dec_init(&ist->decoder, d->sch,
&ds->decoder_opts, &ds->dec_opts);
if (ret < 0)
return ret;