From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id AA46A48CAE for ; Wed, 24 Jan 2024 08:19:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B056E68D0D3; Wed, 24 Jan 2024 10:17:43 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6851468D111 for ; Wed, 24 Jan 2024 10:17:27 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=sVtws9sb; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id A90FA1C05 for ; Wed, 24 Jan 2024 09:17:25 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id muujN7lAoZJw for ; Wed, 24 Jan 2024 09:17:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1706084240; bh=AqTMsKGhRnfTykDdNeeG1szTwpxtKBt68/hzFrM+Zp0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sVtws9sbyELkigVWlEQfpPkes6RQ9ymsZ2zrixB+TN9N2ElfhRHWprwJuYNefkbm7 YSIFNbJFRMntX/2F1jPXW5m/nIaypbtNshk0Rcwo8iulTiuhg8WurpK8olU0PSOVRl c31efRK1BQM+pnx3i/arI2Yyk/e7Aue8kjzkhoLTk3e7nDSlYiNrmMg+EqUbYCQxYx QKbpS5GYT2O8znu9yqwbF38TI4c9Yn7btdXQveLtWqA7SBCj8vXgOzoyoUU/aJhEI7 oEoPtp2dcu1wEMS4CxmnLni4jw2pKw6miqEQIMYN3kQ/UCgVe0jrmwXRFsQL/0QDXW tXVfey9n3KZNg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 715811C09 for ; Wed, 24 Jan 2024 09:17:20 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 651243A054A for ; Wed, 24 Jan 2024 09:17:20 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Jan 2024 09:16:58 +0100 Message-ID: <20240124081702.4759-28-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240124081702.4759-1-anton@khirnov.net> References: <20240124081702.4759-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 28/31] fftools/ffmpeg_dec: eliminate all remaining InputStream uses X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Previously, the demuxer would register decoder with the scheduler, using InputStream as opaque, and pass the scheduling index to the decoder. Now the registration is done by the decoder itself, using DecoderPriv as opaque, and the scheduling index is returned to demuxer from dec_open(). decoder_thread() then no longer needs to be accessed from outside of ffmpeg_dec and can be made static. --- fftools/ffmpeg.h | 7 +++++-- fftools/ffmpeg_dec.c | 16 +++++++++------- fftools/ffmpeg_demux.c | 21 +++++++++------------ 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index c8cba72006..4881174632 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -290,6 +290,7 @@ enum DecoderFlags { #if FFMPEG_OPT_TOP DECODER_FLAG_TOP_FIELD_FIRST = (1 << 3), #endif + DECODER_FLAG_SEND_END_TS = (1 << 4), }; typedef struct DecoderOpts { @@ -756,8 +757,11 @@ AVBufferRef *hw_device_for_filter(void); /** * @param dec_opts Dictionary filled with decoder options. Its ownership * is transferred to the decoder. + * + * @retval ">=0" non-negative scheduler index on success + * @retval "<0" an error code on failure */ -int dec_open(Decoder **pdec, Scheduler *sch, unsigned sch_idx, +int dec_open(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o); void dec_free(Decoder **pdec); @@ -847,7 +851,6 @@ const char *opt_match_per_type_str(const SpecifierOptList *sol, char mediatype); void *muxer_thread(void *arg); -void *decoder_thread(void *arg); void *encoder_thread(void *arg); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 3610256f31..57017faa59 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -645,10 +645,9 @@ fail: return AVERROR(ENOMEM); } -void *decoder_thread(void *arg) +static void *decoder_thread(void *arg) { - InputStream *ist = arg; - DecoderPriv *dp = dp_from_dec(ist->decoder); + DecoderPriv *dp = arg; DecThreadContext dt; int ret = 0, input_status = 0; @@ -692,7 +691,7 @@ void *decoder_thread(void *arg) break; /* report last frame duration to the scheduler */ - if (ist->dec->type == AVMEDIA_TYPE_AUDIO) { + if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { dt.pkt->pts = dp->last_frame_pts + dp->last_frame_duration_est; dt.pkt->time_base = dp->last_frame_tb; } @@ -940,7 +939,7 @@ static const AVClass dec_class = { .item_name = dec_item_name, }; -int dec_open(Decoder **pdec, Scheduler *sch, unsigned sch_idx, +int dec_open(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o) { DecoderPriv *dp; @@ -953,8 +952,11 @@ int dec_open(Decoder **pdec, Scheduler *sch, unsigned sch_idx, if (ret < 0) return ret; + ret = sch_add_dec(sch, decoder_thread, dp, o->flags & DECODER_FLAG_SEND_END_TS); + if (ret < 0) + return ret; dp->sch = sch; - dp->sch_idx = sch_idx; + dp->sch_idx = ret; dp->flags = o->flags; dp->dec.class = &dec_class; @@ -1036,7 +1038,7 @@ int dec_open(Decoder **pdec, Scheduler *sch, unsigned sch_idx, *pdec = &dp->dec; - return 0; + return dp->sch_idx; fail: dec_free((Decoder**)dp); return ret; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 5178bcbce4..0ccb05b1d0 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -895,18 +895,9 @@ 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; - ret = sch_add_dec(d->sch, decoder_thread, ist, d->loop && is_audio); - if (ret < 0) - return ret; - ds->sch_idx_dec = ret; - - ret = sch_connect(d->sch, SCH_DSTREAM(d->f.index, ds->sch_idx_stream), - SCH_DEC(ds->sch_idx_dec)); - if (ret < 0) - return ret; - ds->dec_opts.flags = (!!ist->fix_sub_duration * DECODER_FLAG_FIX_SUB_DURATION) | - (!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE) + (!!(d->f.ctx->iformat->flags & AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE) | + (!!(d->loop && is_audio) * DECODER_FLAG_SEND_END_TS) #if FFMPEG_OPT_TOP | ((ist->top_field_first >= 0) * DECODER_FLAG_TOP_FIELD_FIRST) #endif @@ -935,10 +926,16 @@ static int ist_use(InputStream *ist, int decoding_needed) ds->dec_opts.log_parent = ist; - ret = dec_open(&ist->decoder, d->sch, ds->sch_idx_dec, + ret = dec_open(&ist->decoder, d->sch, &ist->decoder_opts, &ds->dec_opts); if (ret < 0) return ret; + ds->sch_idx_dec = ret; + + ret = sch_connect(d->sch, SCH_DSTREAM(d->f.index, ds->sch_idx_stream), + SCH_DEC(ds->sch_idx_dec)); + if (ret < 0) + return ret; d->have_audio_dec |= is_audio; } -- 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".