From patchwork Thu May 11 18:19:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 41586 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp4833792pzb; Thu, 11 May 2023 11:20:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5XmeAQeqkPODwP+w5eKi8sMXR2Uu/EablL8qJEuNTFlAZ9GWvtFNVEZn+Ze2T5hkJYszH/ X-Received: by 2002:a17:907:5c5:b0:95f:56e8:1c3c with SMTP id wg5-20020a17090705c500b0095f56e81c3cmr20348858ejb.17.1683829229356; Thu, 11 May 2023 11:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683829229; cv=none; d=google.com; s=arc-20160816; b=BeJuyqfDPjpAZwGNObfOdRwfREMQX8SeDp0yLhswx762IN9c9PIac4ddLXxh591el8 6CD8WsuvUr7mOFyEbS6lVDzubQpMH7PIGE9RR2sPyH2NWXCqnAu9GQ9dSJeJfzOWm8u8 AYgL1XyZQzH3Nacj2+POX3xhtkK6SmsdCTOqWYYPR55AbgNPgL+7qjx6DSySj1LWXuhl yPukbNWZCyaMpT2r4D487F46MF0pZLLL2KKRfVwsWukIPzTnqUGPFfJLWAez9IJ5/TfL BB3FFjtky5V+xrXOzFXrIOK9d8NSx+sNyfiAbD1mZFg1PwsZG2sULGqKXV5ycOtV2g5Q zsZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=dR5k4gDLJfJQHmoMkV6x3hLfvU0UsCaSoJacGN4/OdE=; b=if8cl5IbBhP/zc4RF2bfuUuG17aeBOpsl7DH/kHmJDsC7leQ85p9EYXf9EuE1cQ1/s t3KpPlNfIePyA/SoVNqWliQLjnJukfDHYgRwLT3dVo7KnUMigskPqnYHkn1RICvVIyQM 60kzJYqn1ROVheGs5uPteSdeGOGZXaFtV6ikfiRmfBgCuVmReE+d2fsdy93jT3q7uJ7O TbQXf65l9LHeMupjBCmGZnbQxyIuoNtsi58STDqp1mtH/TWzpROM5eBTrfMZLKqu+ETy zdpR7k8NjTXn7Ix5Hhuab6XwHoWEzT70UiEgc0baFpZt6p/fq3D19NgHcuYqtbU0u5AJ T7Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=HKSjkKjf; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qb27-20020a1709077e9b00b00965a8995e33si8185012ejc.2.2023.05.11.11.20.28; Thu, 11 May 2023 11:20:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=HKSjkKjf; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8A53B68BE49; Thu, 11 May 2023 21:20:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7A5E568044A for ; Thu, 11 May 2023 21:20:19 +0300 (EEST) Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6ab1f0b6abeso2690235a34.1 for ; Thu, 11 May 2023 11:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683829218; x=1686421218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=IBXQFyNAVzvut2fsbbSUYRVr0fRlHC3ui/2sh9yrp1c=; b=HKSjkKjfkd3BrGhuDc5W18F+OQPCHvvFUQPe05Ton0wWGHqMhNvY+H51BDBXx/bxXp NNL4FlGzkJjMs8BNjlbTh82eC0whijJ0FR0rBi1L13eiQ3oiR7bjBfIFQEZL/hw3vQDE VpGpEvhstWoyBoB98xkBoq3LlrJ2WJJGMvbYchUza6yogxjH5MqQsic5Q3Lkxj795GeL puRJr4FvdlaYpJzJoEl4UxP4T52lDPM1x/nFkMUa7xteG/z/rRaiZLJ7IRfdOefmHQ3E ByamWwO9jdyv4NJmTTgRfaGeM4QsHJRU26E/9FqQs1MBu7pqMps1YsYT/PWdzaf6Dc7m CQqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683829218; x=1686421218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IBXQFyNAVzvut2fsbbSUYRVr0fRlHC3ui/2sh9yrp1c=; b=NxWS9bkeYmT7bjJuO8kcWZyt9ZNp/ssLnFmkkOXGGToMCIbbAg8W1QI+Njskr41Ywj FtLvde4Mwngd5qKWmyjnJKVjcTcw962y3BI7HUJexi3uIhKyLQxPrfWLjoGvsF3zBQeh Mw5drqHN9GTvqjZN51sy8JYR2uoiQJW8qJww48eddYhTWqDINx9EGmF3H8w7RUX0SYGV bPXhycnHZ/CFwfFTT4diyutXUI01UBmu9KHt3a86WCy7Lg2d5g/wJeX8YtEyaGQnzEqB Irga4WTGHmpr2sQdbxLleXMY83zzVhvGahODO1iu3zvOZHL4wuC6uLadsclR1ExGNdj9 QNOQ== X-Gm-Message-State: AC+VfDwQcFE5ZEMY2grK8WcklX/GFqcgXamDTYpz1TaVYObm/7zdKtlW Fu891w5lVkf/GvdCt49zxmpb89EuwpQ= X-Received: by 2002:a9d:6a14:0:b0:6a5:dae7:9c74 with SMTP id g20-20020a9d6a14000000b006a5dae79c74mr5227197otn.30.1683829217557; Thu, 11 May 2023 11:20:17 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id dj8-20020a0568303a8800b006ab2af64f34sm2150227otb.13.2023.05.11.11.20.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 11:20:17 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 May 2023 15:19:53 -0300 Message-Id: <20230511181953.15199-1-jamrial@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avfilter/ccfifo: remove unnecessary context allocations 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jFIvILRmgTtE This is not public API, no it has no need for an alloc() and free() functions. The struct can reside on stack. Signed-off-by: James Almer --- libavfilter/ccfifo.c | 49 ++++++++++++------------------------- libavfilter/ccfifo.h | 42 ++++++++++++++++++------------- libavfilter/tinterlace.h | 2 +- libavfilter/vf_bwdif.c | 8 +++--- libavfilter/vf_ccrepack.c | 13 +++++----- libavfilter/vf_fps.c | 13 +++++----- libavfilter/vf_tinterlace.c | 18 +++++++------- libavfilter/vf_yadif.c | 8 +++--- libavfilter/vf_yadif_cuda.c | 6 ++--- libavfilter/yadif.h | 2 +- libavfilter/yadif_common.c | 6 ++--- 11 files changed, 81 insertions(+), 86 deletions(-) diff --git a/libavfilter/ccfifo.c b/libavfilter/ccfifo.c index 5fb68ce04c..f39dbc1740 100644 --- a/libavfilter/ccfifo.c +++ b/libavfilter/ccfifo.c @@ -23,18 +23,6 @@ #include "ccfifo.h" -struct AVCCFifo { - AVFifo *cc_608_fifo; - AVFifo *cc_708_fifo; - AVRational framerate; - int expected_cc_count; - int expected_608; - int cc_detected; - int passthrough; - int passthrough_warning; - void *log_ctx; -}; - #define MAX_CC_ELEMENTS 128 #define CC_BYTES_PER_ENTRY 3 @@ -55,25 +43,18 @@ const static struct cc_lookup cc_lookup_vals[] = { { 60000, 1001, 10, 1}, }; -void ff_ccfifo_freep(AVCCFifo **ccf) +void ff_ccfifo_uninit(CCFifo *ccf) { - AVCCFifo *tmp = *ccf; - if (tmp) { - av_fifo_freep2(&tmp->cc_608_fifo); - av_fifo_freep2(&tmp->cc_708_fifo); - } - av_freep(ccf); + av_fifo_freep2(&ccf->cc_608_fifo); + av_fifo_freep2(&ccf->cc_708_fifo); + memset(ccf, 0, sizeof(*ccf)); } -AVCCFifo *ff_ccfifo_alloc(AVRational framerate, void *log_ctx) +int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx) { - AVCCFifo *ccf; int i; - ccf = av_mallocz(sizeof(*ccf)); - if (!ccf) - return NULL; - + memset(ccf, 0, sizeof(*ccf)); ccf->log_ctx = log_ctx; ccf->framerate = framerate; @@ -101,24 +82,24 @@ AVCCFifo *ff_ccfifo_alloc(AVRational framerate, void *log_ctx) ccf->passthrough = 1; } - return ccf; + return 0; error: - ff_ccfifo_freep(&ccf); - return NULL; + ff_ccfifo_uninit(ccf); + return AVERROR(ENOMEM); } -int ff_ccfifo_getoutputsize(AVCCFifo *ccf) +int ff_ccfifo_getoutputsize(CCFifo *ccf) { return ccf->expected_cc_count * CC_BYTES_PER_ENTRY; } -int ff_ccfifo_ccdetected(AVCCFifo *ccf) +int ff_ccfifo_ccdetected(CCFifo *ccf) { return ccf->cc_detected; } -int ff_ccfifo_injectbytes(AVCCFifo *ccf, uint8_t *cc_data, size_t len) +int ff_ccfifo_injectbytes(CCFifo *ccf, uint8_t *cc_data, size_t len) { int cc_608_tuples = 0; int cc_708_tuples = 0; @@ -159,7 +140,7 @@ int ff_ccfifo_injectbytes(AVCCFifo *ccf, uint8_t *cc_data, size_t len) return 0; } -int ff_ccfifo_inject(AVCCFifo *ccf, AVFrame *frame) +int ff_ccfifo_inject(CCFifo *ccf, AVFrame *frame) { AVFrameSideData *sd; int ret; @@ -180,7 +161,7 @@ int ff_ccfifo_inject(AVCCFifo *ccf, AVFrame *frame) return 0; } -int ff_ccfifo_extractbytes(AVCCFifo *ccf, uint8_t *cc_bytes, size_t len) +int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *cc_bytes, size_t len) { int cc_count = len / CC_BYTES_PER_ENTRY; @@ -209,7 +190,7 @@ int ff_ccfifo_extractbytes(AVCCFifo *ccf, uint8_t *cc_bytes, size_t len) /* Read the A53 side data, discard padding, and put 608/708 into queues so we can ensure they get into the output frames at the correct rate... */ -int ff_ccfifo_extract(AVCCFifo *ccf, AVFrame *frame) +int ff_ccfifo_extract(CCFifo *ccf, AVFrame *frame) { AVFrameSideData *side_data = av_frame_get_side_data(frame, AV_FRAME_DATA_A53_CC); if (side_data) { diff --git a/libavfilter/ccfifo.h b/libavfilter/ccfifo.h index 44c924593c..a380f67b52 100644 --- a/libavfilter/ccfifo.h +++ b/libavfilter/ccfifo.h @@ -33,25 +33,33 @@ #include "libavutil/frame.h" #include "libavutil/fifo.h" -typedef struct AVCCFifo AVCCFifo; +typedef struct CCFifo { + AVFifo *cc_608_fifo; + AVFifo *cc_708_fifo; + AVRational framerate; + int expected_cc_count; + int expected_608; + int cc_detected; + int passthrough; + int passthrough_warning; + void *log_ctx; +} CCFifo; /** - * Allocate an AVCCFifo. + * Initialize a CCFifo. * * @param framerate output framerate * @param log_ctx used for any av_log() calls - * @return newly allocated AVCCFifo, or NULL on error + * @return Zero on success, or negative AVERROR code on failure. */ -AVCCFifo *ff_ccfifo_alloc(AVRational framerate, void *log_ctx); +int ff_ccfifo_init(CCFifo *ccf, AVRational framerate, void *log_ctx); /** - * Free an AVCCFifo + * Free all memory allocated in a CCFifo and clear the context. * - * @param ccf Pointer to the pointer to the AVCCFifo which should be freed - * @note `*ptr = NULL` is safe and leads to no action. + * @param ccf Pointer to the CCFifo which should be uninitialized */ -void ff_ccfifo_freep(AVCCFifo **ccf); - +void ff_ccfifo_uninit(CCFifo *ccf); /** * Extract CC data from an AVFrame @@ -61,17 +69,17 @@ void ff_ccfifo_freep(AVCCFifo **ccf); * as it will be re-inserted at the appropriate rate later in the * filter. * - * @param af AVCCFifo to write to + * @param af CCFifo to write to * @param frame AVFrame with the video frame to operate on * @return Zero on success, or negative AVERROR * code on failure. */ -int ff_ccfifo_extract(AVCCFifo *ccf, AVFrame *frame); +int ff_ccfifo_extract(CCFifo *ccf, AVFrame *frame); /** *Just like ff_ccfifo_extract(), but takes the raw bytes instead of an AVFrame */ -int ff_ccfifo_extractbytes(AVCCFifo *ccf, uint8_t *data, size_t len); +int ff_ccfifo_extractbytes(CCFifo *ccf, uint8_t *data, size_t len); /** * Provide the size in bytes of an output buffer to allocate @@ -80,7 +88,7 @@ int ff_ccfifo_extractbytes(AVCCFifo *ccf, uint8_t *data, size_t len); * an appropriately sized buffer and pass it to ff_ccfifo_injectbytes() * */ -int ff_ccfifo_getoutputsize(AVCCFifo *ccf); +int ff_ccfifo_getoutputsize(CCFifo *ccf); /** * Insert CC data from the FIFO into an AVFrame (as side data) @@ -88,23 +96,23 @@ int ff_ccfifo_getoutputsize(AVCCFifo *ccf); * Dequeue the appropriate number of CC tuples based on the * frame rate, and insert them into the AVFrame * - * @param af AVCCFifo to read from + * @param af CCFifo to read from * @param frame AVFrame with the video frame to operate on * @return Zero on success, or negative AVERROR * code on failure. */ -int ff_ccfifo_inject(AVCCFifo *ccf, AVFrame *frame); +int ff_ccfifo_inject(CCFifo *ccf, AVFrame *frame); /** * Just like ff_ccfifo_inject(), but takes the raw bytes to insert the CC data * int rather than an AVFrame */ -int ff_ccfifo_injectbytes(AVCCFifo *ccf, uint8_t *data, size_t len); +int ff_ccfifo_injectbytes(CCFifo *ccf, uint8_t *data, size_t len); /** * Returns 1 if captions have been found as a prior call * to ff_ccfifo_extract() or ff_ccfifo_extractbytes() */ -int ff_ccfifo_ccdetected(AVCCFifo *ccf); +int ff_ccfifo_ccdetected(CCFifo *ccf); #endif /* AVFILTER_CCFIFO_H */ diff --git a/libavfilter/tinterlace.h b/libavfilter/tinterlace.h index 9f5ce7e65b..f9b3e630b8 100644 --- a/libavfilter/tinterlace.h +++ b/libavfilter/tinterlace.h @@ -78,7 +78,7 @@ typedef struct TInterlaceContext { const AVPixFmtDescriptor *csp; void (*lowpass_line)(uint8_t *dstp, ptrdiff_t width, const uint8_t *srcp, ptrdiff_t mref, ptrdiff_t pref, int clip_max); - AVCCFifo *cc_fifo; + CCFifo cc_fifo; } TInterlaceContext; void ff_tinterlace_init_x86(TInterlaceContext *interlace); diff --git a/libavfilter/vf_bwdif.c b/libavfilter/vf_bwdif.c index 51e1e02503..e278cf1217 100644 --- a/libavfilter/vf_bwdif.c +++ b/libavfilter/vf_bwdif.c @@ -297,7 +297,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_frame_free(&yadif->prev); av_frame_free(&yadif->cur ); av_frame_free(&yadif->next); - ff_ccfifo_freep(&yadif->cc_fifo); + ff_ccfifo_uninit(&yadif->cc_fifo); } static const enum AVPixelFormat pix_fmts[] = { @@ -326,6 +326,7 @@ static int config_props(AVFilterLink *link) AVFilterContext *ctx = link->src; BWDIFContext *s = link->src->priv; YADIFContext *yadif = &s->yadif; + int ret; link->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); link->w = link->src->inputs[0]->w; @@ -336,9 +337,10 @@ static int config_props(AVFilterLink *link) else link->frame_rate = ctx->inputs[0]->frame_rate; - if (!(yadif->cc_fifo = ff_ccfifo_alloc(link->frame_rate, ctx))) { + ret = ff_ccfifo_init(&yadif->cc_fifo, link->frame_rate, ctx); + if (ret < 0 ) { av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return AVERROR(ENOMEM); + return ret; } if (link->w < 3 || link->h < 4) { diff --git a/libavfilter/vf_ccrepack.c b/libavfilter/vf_ccrepack.c index e3fd67f1b5..61eb2128ae 100644 --- a/libavfilter/vf_ccrepack.c +++ b/libavfilter/vf_ccrepack.c @@ -37,7 +37,7 @@ typedef struct CCRepackContext { const AVClass *class; - AVCCFifo *cc_fifo; + CCFifo cc_fifo; } CCRepackContext; static const AVOption ccrepack_options[] = { @@ -50,9 +50,10 @@ static int config_input(AVFilterLink *link) { CCRepackContext *ctx = link->dst->priv; - if (!(ctx->cc_fifo = ff_ccfifo_alloc(link->frame_rate, ctx))) { + int ret = ff_ccfifo_init(&ctx->cc_fifo, link->frame_rate, ctx); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return AVERROR(ENOMEM); + return ret; } return 0; @@ -63,8 +64,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) CCRepackContext *ctx = inlink->dst->priv; AVFilterLink *outlink = inlink->dst->outputs[0]; - ff_ccfifo_extract(ctx->cc_fifo, frame); - ff_ccfifo_inject(ctx->cc_fifo, frame); + ff_ccfifo_extract(&ctx->cc_fifo, frame); + ff_ccfifo_inject(&ctx->cc_fifo, frame); return ff_filter_frame(outlink, frame); } @@ -72,7 +73,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) static av_cold void uninit(AVFilterContext *ctx) { CCRepackContext *s = ctx->priv; - ff_ccfifo_freep(&s->cc_fifo); + ff_ccfifo_uninit(&s->cc_fifo); } static const AVFilterPad avfilter_vf_ccrepack_inputs[] = { diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c index 824e7a128d..2bfb6d29e7 100644 --- a/libavfilter/vf_fps.c +++ b/libavfilter/vf_fps.c @@ -86,7 +86,7 @@ typedef struct FPSContext { AVFrame *frames[2]; ///< buffered frames int frames_count; ///< number of buffered frames - AVCCFifo *cc_fifo; ///< closed captions + CCFifo cc_fifo; ///< closed captions int64_t next_pts; ///< pts of the next frame to output @@ -167,7 +167,7 @@ static av_cold void uninit(AVFilterContext *ctx) frame = shift_frame(ctx, s); av_frame_free(&frame); } - ff_ccfifo_freep(&s->cc_fifo); + ff_ccfifo_uninit(&s->cc_fifo); av_log(ctx, AV_LOG_VERBOSE, "%d frames in, %d frames out; %d frames dropped, " "%d frames duplicated.\n", s->frames_in, s->frames_out, s->drop, s->dup); @@ -213,9 +213,10 @@ static int config_props(AVFilterLink* outlink) s->in_pts_off, s->out_pts_off, s->start_time); } - if (!(s->cc_fifo = ff_ccfifo_alloc(outlink->frame_rate, ctx))) { + ret = ff_ccfifo_init(&s->cc_fifo, outlink->frame_rate, ctx); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return AVERROR(ENOMEM); + return ret; } av_log(ctx, AV_LOG_VERBOSE, "fps=%d/%d\n", outlink->frame_rate.num, outlink->frame_rate.den); @@ -250,7 +251,7 @@ static int read_frame(AVFilterContext *ctx, FPSContext *s, AVFilterLink *inlink, av_log(ctx, AV_LOG_DEBUG, "Read frame with in pts %"PRId64", out pts %"PRId64"\n", in_pts, frame->pts); - ff_ccfifo_extract(s->cc_fifo, frame); + ff_ccfifo_extract(&s->cc_fifo, frame); s->frames[s->frames_count++] = frame; s->frames_in++; @@ -298,7 +299,7 @@ static int write_frame(AVFilterContext *ctx, FPSContext *s, AVFilterLink *outlin if (!frame) return AVERROR(ENOMEM); // Make sure Closed Captions will not be duplicated - ff_ccfifo_inject(s->cc_fifo, frame); + ff_ccfifo_inject(&s->cc_fifo, frame); frame->pts = s->next_pts++; frame->duration = 1; diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c index e1057ffc8e..63f1fc72f2 100644 --- a/libavfilter/vf_tinterlace.c +++ b/libavfilter/vf_tinterlace.c @@ -203,7 +203,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_frame_free(&tinterlace->next); av_freep(&tinterlace->black_data[0][0]); av_freep(&tinterlace->black_data[1][0]); - ff_ccfifo_freep(&tinterlace->cc_fifo); + ff_ccfifo_uninit(&tinterlace->cc_fifo); } static int config_out_props(AVFilterLink *outlink) @@ -212,7 +212,7 @@ static int config_out_props(AVFilterLink *outlink) AVFilterLink *inlink = outlink->src->inputs[0]; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format); TInterlaceContext *tinterlace = ctx->priv; - int i; + int ret, i; tinterlace->vsub = desc->log2_chroma_h; outlink->w = inlink->w; @@ -224,7 +224,6 @@ static int config_out_props(AVFilterLink *outlink) if (tinterlace->mode == MODE_PAD) { uint8_t black[4] = { 0, 0, 0, 16 }; - int ret; ff_draw_init(&tinterlace->draw, outlink->format, 0); ff_draw_color(&tinterlace->draw, &tinterlace->color, black); /* limited range */ @@ -292,9 +291,10 @@ static int config_out_props(AVFilterLink *outlink) #endif } - if (!(tinterlace->cc_fifo = ff_ccfifo_alloc(outlink->frame_rate, ctx))) { + ret = ff_ccfifo_init(&tinterlace->cc_fifo, outlink->frame_rate, ctx); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return AVERROR(ENOMEM); + return ret; } av_log(ctx, AV_LOG_VERBOSE, "mode:%d filter:%s h:%d -> h:%d\n", tinterlace->mode, @@ -381,7 +381,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) tinterlace->cur = tinterlace->next; tinterlace->next = picref; - ff_ccfifo_extract(tinterlace->cc_fifo, picref); + ff_ccfifo_extract(&tinterlace->cc_fifo, picref); cur = tinterlace->cur; next = tinterlace->next; @@ -464,7 +464,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (!out) return AVERROR(ENOMEM); out->pts /= 2; // adjust pts to new framerate - ff_ccfifo_inject(tinterlace->cc_fifo, out); + ff_ccfifo_inject(&tinterlace->cc_fifo, out); ret = ff_filter_frame(outlink, out); return ret; } @@ -514,7 +514,7 @@ FF_ENABLE_DEPRECATION_WARNINGS out->pts = cur->pts*2; out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base); - ff_ccfifo_inject(tinterlace->cc_fifo, out); + ff_ccfifo_inject(&tinterlace->cc_fifo, out); if ((ret = ff_filter_frame(outlink, out)) < 0) return ret; @@ -559,7 +559,7 @@ FF_ENABLE_DEPRECATION_WARNINGS out->pts = av_rescale_q(out->pts, tinterlace->preout_time_base, outlink->time_base); out->duration = av_rescale_q(1, av_inv_q(outlink->frame_rate), outlink->time_base); - ff_ccfifo_inject(tinterlace->cc_fifo, out); + ff_ccfifo_inject(&tinterlace->cc_fifo, out); ret = ff_filter_frame(outlink, out); return ret; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index f77f8113ca..d6fe24a386 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -261,7 +261,7 @@ static av_cold void uninit(AVFilterContext *ctx) av_frame_free(&yadif->prev); av_frame_free(&yadif->cur ); av_frame_free(&yadif->next); - ff_ccfifo_freep(&yadif->cc_fifo); + ff_ccfifo_uninit(&yadif->cc_fifo); } static const enum AVPixelFormat pix_fmts[] = { @@ -286,6 +286,7 @@ static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; YADIFContext *s = ctx->priv; + int ret; outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2}); outlink->w = ctx->inputs[0]->w; @@ -297,9 +298,10 @@ static int config_output(AVFilterLink *outlink) else outlink->frame_rate = ctx->inputs[0]->frame_rate; - if (!(s->cc_fifo = ff_ccfifo_alloc(outlink->frame_rate, ctx))) { + ret = ff_ccfifo_init(&s->cc_fifo, outlink->frame_rate, ctx); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - return AVERROR(ENOMEM); + return ret; } if (outlink->w < 3 || outlink->h < 3) { diff --git a/libavfilter/vf_yadif_cuda.c b/libavfilter/vf_yadif_cuda.c index 73f04126c5..b5ff84e11a 100644 --- a/libavfilter/vf_yadif_cuda.c +++ b/libavfilter/vf_yadif_cuda.c @@ -205,7 +205,7 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx) av_frame_free(&y->prev); av_frame_free(&y->cur); av_frame_free(&y->next); - ff_ccfifo_freep(&y->cc_fifo); + ff_ccfifo_uninit(&y->cc_fifo); av_buffer_unref(&s->device_ref); s->hwctx = NULL; @@ -295,9 +295,9 @@ static int config_output(AVFilterLink *link) else link->frame_rate = ctx->inputs[0]->frame_rate; - if (!(y->cc_fifo = ff_ccfifo_alloc(link->frame_rate, ctx))) { + ret = ff_ccfifo_init(&y->cc_fifo, link->frame_rate, ctx); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Failure to setup CC FIFO queue\n"); - ret = AVERROR(ENOMEM); goto exit; } diff --git a/libavfilter/yadif.h b/libavfilter/yadif.h index 10775767e9..fbb99fd46e 100644 --- a/libavfilter/yadif.h +++ b/libavfilter/yadif.h @@ -77,7 +77,7 @@ typedef struct YADIFContext { int eof; uint8_t *temp_line; int temp_line_size; - AVCCFifo *cc_fifo; + CCFifo cc_fifo; /* * An algorithm that treats first and/or last fields in a sequence diff --git a/libavfilter/yadif_common.c b/libavfilter/yadif_common.c index 49ea7cfce4..05474a5ba9 100644 --- a/libavfilter/yadif_common.c +++ b/libavfilter/yadif_common.c @@ -66,7 +66,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } } - ff_ccfifo_inject(yadif->cc_fifo, yadif->out); + ff_ccfifo_inject(&yadif->cc_fifo, yadif->out); ret = ff_filter_frame(ctx->outputs[0], yadif->out); yadif->frame_pending = (yadif->mode&1) && !is_second; @@ -103,7 +103,7 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame) av_assert0(frame); - ff_ccfifo_extract(yadif->cc_fifo, frame); + ff_ccfifo_extract(&yadif->cc_fifo, frame); if (yadif->frame_pending) return_frame(ctx, 1); @@ -146,7 +146,7 @@ int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame) if (!yadif->out) return AVERROR(ENOMEM); - ff_ccfifo_inject(yadif->cc_fifo, yadif->out); + ff_ccfifo_inject(&yadif->cc_fifo, yadif->out); av_frame_free(&yadif->prev); if (yadif->out->pts != AV_NOPTS_VALUE) yadif->out->pts *= 2;