From patchwork Sun Jul 9 09:34:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42553 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp22670pzb; Sun, 9 Jul 2023 02:35:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlFpv4WRw9/LMlxuzDPHG7msPAWXhSJ7gWVCsUJgEiWB0Qjr3jUCdAypsYcUNeScAt2Xy8xM X-Received: by 2002:a2e:9104:0:b0:2b6:f85a:20b0 with SMTP id m4-20020a2e9104000000b002b6f85a20b0mr6720488ljg.16.1688895300518; Sun, 09 Jul 2023 02:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688895300; cv=none; d=google.com; s=arc-20160816; b=RI8tbFhImjSmnsLZpwthKh4UZ6wsjPp5BLw3veL40ltMkOmTlNaY2/YV5jyD+cFCfL ZqZOCtCSsvoHVRNxgs8nEVReuurU9lckspWAePl6C2hpqBTljT8q2MF1gq0mB3DlidRE YmgvxBKBLO0oUP80JQAvRvs9kXz5HNM0UUFQJ3oDlSecblhhVXXbDZuhdjttFwpoZ4ow tlpS/MGIqGw0jVaI1xtP8MuNeF7QGv0bujfpufMK/LvlxJwh0/yglYCHLASuchHtpIls HKCmOlvHvMiTLn/hM/SP1J6Q2cREVhxnzl2s+yFn9qHS1X+Maqb3YkiMzDtm1WpTePHO c2YA== 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:message-id:date:to:from :delivered-to; bh=S89IgM7+kHfnmiy3A/PB1HLLPyXER4m4QXgVW1r85+w=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=VTGVeZOVsNYSTg1aCjxJE9of5bfrrPUN8ANxYv7GhDidsmR4OpolHXTWQ0TClajXI5 mqwZKUuMEIazQripl3z74B3tzNiIxgRsTUfMD1oRx6qZ7JmsLjWo7wrBZZ/WKYGxHjUz TddpZvtxD5/yOFSlw0kpiKmF0IAhyFtg1bRB40KAJ070eO58TIFFLuNoLtRsca3nY/Wi Wa5zOlNdOBLGiNgNebIipAQmnUdEV+60Y3x0XqAF47xaGGMZtip0iRvkuR3DPd26X1ii dXrs+tvLmZldaV9HPGs0id3lZ56N06ff16MsVB6akFwiXM6wssnuTo0PwMVZQlYsPJsj /qlQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n17-20020a056402515100b0051e1a5be137si5652641edd.482.2023.07.09.02.34.59; Sun, 09 Jul 2023 02:35:00 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CC37A68C56E; Sun, 9 Jul 2023 12:34:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6C7E768C33E for ; Sun, 9 Jul 2023 12:34:49 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1B0C92404EC for ; Sun, 9 Jul 2023 11:34:49 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id FbXkVUy07VGr for ; Sun, 9 Jul 2023 11:34:48 +0200 (CEST) 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 mail0.khirnov.net (Postfix) with ESMTPS id 78BC82404EA for ; Sun, 9 Jul 2023 11:34:48 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2EF263A0153 for ; Sun, 9 Jul 2023 11:34:42 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Jul 2023 11:34:30 +0200 Message-Id: <20230709093430.31673-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavfi/src_movie: stop using AV_CODEC_FLAG_COPY_OPAQUE 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: dHs3AvHLnCbC That feature is overkill for a constant pointer to AVFilterLink which can be stored in AVCodecContext.opaque (indirectly, because the link is not allocated yet at the time the codec is opened). This also avoid leaking non-NULL AVFrame.opaque to callers. --- libavfilter/src_movie.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c index f0d295d4bb..e50ebc99dc 100644 --- a/libavfilter/src_movie.c +++ b/libavfilter/src_movie.c @@ -51,6 +51,7 @@ #include "video.h" typedef struct MovieStream { + AVFilterLink *link; AVStream *st; AVCodecContext *codec_ctx; int64_t discontinuity_threshold; @@ -162,7 +163,8 @@ static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec) static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) { int linesize_align[AV_NUM_DATA_POINTERS]; - AVFilterLink *outlink = frame->opaque; + MovieStream *st = avctx->opaque; + AVFilterLink *outlink = st->link; int w, h, ow, oh, copy = 0; AVFrame *new; @@ -202,7 +204,6 @@ static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) av_frame_move_ref(frame, new); av_frame_free(&new); - frame->opaque = outlink; frame->width = ow; frame->height = oh; @@ -224,7 +225,7 @@ static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads) if (!st->codec_ctx) return AVERROR(ENOMEM); - st->codec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE; + st->codec_ctx->opaque = st; st->codec_ctx->get_buffer2 = get_buffer; ret = avcodec_parameters_to_context(st->codec_ctx, st->st->codecpar); if (ret < 0) @@ -469,6 +470,8 @@ static int movie_config_output_props(AVFilterLink *outlink) break; } + st->link = outlink; + return 0; } @@ -581,7 +584,6 @@ static int activate(AVFilterContext *ctx) movie->out_index[movie->pkt->stream_index]; if (pkt_out_id >= 0) { - movie->pkt->opaque = ctx->outputs[pkt_out_id]; ret = decode_packet(ctx, pkt_out_id); } av_packet_unref(movie->pkt);