From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 27/31] fftools/ffmpeg_dec: stop passing InputStream to dec_open()
Date: Wed, 24 Jan 2024 09:16:57 +0100
Message-ID: <20240124081702.4759-27-anton@khirnov.net> (raw)
In-Reply-To: <20240124081702.4759-1-anton@khirnov.net>
---
fftools/ffmpeg.h | 3 ++-
fftools/ffmpeg_dec.c | 50 +++++++++++++++++++++++++++---------------
fftools/ffmpeg_demux.c | 4 +++-
3 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 02c614d0ff..c8cba72006 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -296,6 +296,7 @@ typedef struct DecoderOpts {
int flags;
char *name;
+ void *log_parent;
const AVCodec *codec;
const AVCodecParameters *par;
@@ -756,7 +757,7 @@ AVBufferRef *hw_device_for_filter(void);
* @param dec_opts Dictionary filled with decoder options. Its ownership
* is transferred to the decoder.
*/
-int dec_open(InputStream *ist, Scheduler *sch, unsigned sch_idx,
+int dec_open(Decoder **pdec, Scheduler *sch, unsigned sch_idx,
AVDictionary **dec_opts, const DecoderOpts *o);
void dec_free(Decoder **pdec);
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 98cde0a040..3610256f31 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -110,7 +110,7 @@ void dec_free(Decoder **pdec)
av_freep(pdec);
}
-static int dec_alloc(Decoder **pdec)
+static int dec_alloc(DecoderPriv **pdec)
{
DecoderPriv *dp;
@@ -133,7 +133,7 @@ static int dec_alloc(Decoder **pdec)
dp->last_frame_tb = (AVRational){ 1, 1 };
dp->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
- *pdec = &dp->dec;
+ *pdec = dp;
return 0;
fail:
@@ -940,24 +940,25 @@ static const AVClass dec_class = {
.item_name = dec_item_name,
};
-int dec_open(InputStream *ist, Scheduler *sch, unsigned sch_idx,
+int dec_open(Decoder **pdec, Scheduler *sch, unsigned sch_idx,
AVDictionary **dec_opts, const DecoderOpts *o)
{
DecoderPriv *dp;
const AVCodec *codec = o->codec;
int ret;
- ret = dec_alloc(&ist->decoder);
+ *pdec = NULL;
+
+ ret = dec_alloc(&dp);
if (ret < 0)
return ret;
- dp = dp_from_dec(ist->decoder);
dp->sch = sch;
dp->sch_idx = sch_idx;
dp->flags = o->flags;
dp->dec.class = &dec_class;
- dp->log_parent = ist;
+ dp->log_parent = o->log_parent;
dp->framerate_in = o->framerate;
@@ -968,31 +969,39 @@ int dec_open(InputStream *ist, Scheduler *sch, unsigned sch_idx,
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)
- return AVERROR(ENOMEM);
+ if (!dp->parent_name) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
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])
- return AVERROR(ENOMEM);
+ if (!dp->sub_prev[i]) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
}
dp->sub_heartbeat = av_frame_alloc();
- if (!dp->sub_heartbeat)
- return AVERROR(ENOMEM);
+ if (!dp->sub_heartbeat) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
}
dp->sar_override = o->par->sample_aspect_ratio;
dp->dec_ctx = avcodec_alloc_context3(codec);
- if (!dp->dec_ctx)
- return AVERROR(ENOMEM);
+ if (!dp->dec_ctx) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
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");
- return ret;
+ goto fail;
}
dp->dec_ctx->opaque = dp;
@@ -1009,23 +1018,28 @@ int dec_open(InputStream *ist, Scheduler *sch, unsigned sch_idx,
av_log(dp, AV_LOG_ERROR,
"Hardware device setup failed for decoder: %s\n",
av_err2str(ret));
- return ret;
+ goto fail;
}
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));
- return ret;
+ goto fail;
}
ret = check_avoptions(*dec_opts);
if (ret < 0)
- return ret;
+ goto fail;
dp->dec.subtitle_header = dp->dec_ctx->subtitle_header;
dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size;
+ *pdec = &dp->dec;
+
return 0;
+fail:
+ dec_free((Decoder**)dp);
+ return ret;
}
int dec_add_filter(Decoder *dec, InputFilter *ifilter)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 6216b7c684..5178bcbce4 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -933,7 +933,9 @@ static int ist_use(InputStream *ist, int decoding_needed)
ds->dec_opts.codec = ist->dec;
ds->dec_opts.par = ist->par;
- ret = dec_open(ist, d->sch, ds->sch_idx_dec,
+ ds->dec_opts.log_parent = ist;
+
+ ret = dec_open(&ist->decoder, d->sch, ds->sch_idx_dec,
&ist->decoder_opts, &ds->dec_opts);
if (ret < 0)
return ret;
--
2.42.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-01-24 8:20 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 8:16 [FFmpeg-devel] [PATCH 01/31] fftools/ffmpeg_dec: split Decoder into a private and public part Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 02/31] fftools/ffmpeg_dec: export subtitle_header in Decoder Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 03/31] fftools/ffmpeg_filter: consolidate decoder/filter type checks Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 04/31] fftools/ffmpeg: make decoding AVCodecContext private to the decoder Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 05/31] fftools/ffmpeg_dec: add an AVClass to Decoder Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 06/31] fftools/ffmpeg_dec: pass decoder options as an argument to dec_open() Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 07/31] fftools/ffmpeg_dec: move decoding counters from InputStream to Decoder Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 08/31] fftools/ffmpeg_dec: drop useless and racy code Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 09/31] fftools/ffmpeg_dec: drop a useless log message Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 10/31] fftools/ffmpeg: move decoder existence check to a more appropriate place Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 11/31] fftools/ffmpeg_dec: override video SAR with AVCodecParameters value Anton Khirnov
2024-03-24 22:09 ` Michael Niedermayer
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 12/31] fftools/ffmpeg_dec: stop accesing InputStream.fix_sub_duration Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 13/31] fftools/ffmpeg: refactor disabling decoder threading for attached pictures Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 14/31] fftools/ffmpeg_dec: replace InputFile.format_nots with a decoder flag Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 15/31] fftools/ffmpeg: move hwaccel_retrieve_data() from ffmpeg_hw to ffmpeg_dec Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 16/31] fftools/ffmpeg_dec: pass hwaccel options to the decoder in a separate struct Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 17/31] fftools/ffmpeg_dec: move flags to DecoderOpts Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 18/31] fftools/ffmpeg_dec: pass forced/estimated framerate though DecoderOpts Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 19/31] fftools/ffmpeg_dec: move setting compute_edt to demuxer Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 20/31] fftools/ffmpeg_dec: pass input timebase through DecoderOpts Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 21/31] fftools/ffmpeg_dec: pass top_field_first " Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 22/31] fftools/ffmpeg_dec: pass decoder name " Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 23/31] fftools/ffmpeg_dec: eliminate InputStream use in hw_device_setup_for_decode() Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 24/31] fftools/ffmpeg_dec: pass AVCodec through DecoderOpts Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 25/31] fftools/ffmpeg_dec: pass AVCodecParameters " Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 26/31] fftools/ffmpeg_dec: remove unnecessary InputStream arguments Anton Khirnov
2024-01-24 8:16 ` Anton Khirnov [this message]
2024-01-25 1:19 ` [FFmpeg-devel] [PATCH 27/31] fftools/ffmpeg_dec: stop passing InputStream to dec_open() Michael Niedermayer
2024-01-28 9:40 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 28/31] fftools/ffmpeg_dec: eliminate all remaining InputStream uses Anton Khirnov
2024-01-24 8:16 ` [FFmpeg-devel] [PATCH 29/31] fftools/ffmpeg: make InputStream.decoding_needed private to demuxer Anton Khirnov
2024-01-24 8:17 ` [FFmpeg-devel] [PATCH 30/31] fftools/ffmpeg: make InputStream.decoder_opts " Anton Khirnov
2024-01-24 8:17 ` [FFmpeg-devel] [PATCH 31/31] fftools/ffmpeg: cosmetics, vertically align Input{File, Stream} Anton Khirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240124081702.4759-27-anton@khirnov.net \
--to=anton@khirnov.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git