From patchwork Fri Dec 25 15:47:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24653 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id B0C0B44B6ED for ; Fri, 25 Dec 2020 17:53:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9FBD368AE80; Fri, 25 Dec 2020 17:53:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F37468AE71 for ; Fri, 25 Dec 2020 17:53:03 +0200 (EET) Received: by mail-ej1-f51.google.com with SMTP id lt17so6638763ejb.3 for ; Fri, 25 Dec 2020 07:53:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=B+OpOm4tQ+SqlMrmIVwFhYfx8xtMxyhzQFBAQunaUj4=; b=KNXrr5DLV4pEVI4OwOsIAhH5CDmHly4JK4ADKwoy53wKaF6oEkhvaNY9Q1tAI11htx f40ejLng/I5tWk7Ursw64gL/aVyyscCG2Zap8ux+g2m5DvfRUcY50NfwdmvFLVN18FfY C1Y00Cd3AIvA2b7uEsCUHZYmCs3N12w8b5KqyAsQQ4duYUeu97sx9cf/fzxKmLEUL4ow +ZuLxDvt1X3kyGmh6xwHaWDuq0RDAcmPfT7I+iwbMHUDcstWf9Bths5EMOeKDGa3aEFK 4+OSd6aBJs/1Cew+R3rqhQoODixAanYfB7pIzznhpoL37zT5Vk3W6DsELJnhPlUShZrI D21A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=B+OpOm4tQ+SqlMrmIVwFhYfx8xtMxyhzQFBAQunaUj4=; b=ZUdxz15lSJL9HXgHo9X/WK9LwSp5JsO3hNlBJ8rACkNGH9Ee+CqUhUg/SSRG6A2Ud4 39aI/QKph0IrNlr7SWryeH2Fo0qeiDrMR9qs0+yu8no5bSlurCgmR7GIueRtxKCW0x5l iZfcukBhqeGeabZwErw+qu9gVMdy65lolFZg6uoA9yj0p1gZet7gWJ2mATuUiVmpoRvf ohUXw4qtISvm/0IyWSTn0vXHAVI4O9Js9GcXPiwc2q6usJPM9yAja6/O5AHrmWXW2FHD lY7qF4cWehB3468Qok1urvtXxkn47bpGRSitZr0AYEfB4N/B8wfXRxwBeXR4jQWjWzOV tqCw== X-Gm-Message-State: AOAM530zFyn+WiyDG/cLa3/iZPWbLz80xUaRrA0XHw67hehMbLtwP5sk baig2qYhBuDulh3vuD1eZNbJMaRxROE= X-Google-Smtp-Source: ABdhPJxBuGBH5TxpBl2GXGbLLEufaCTCstZwJ+v+b6z/doL/4S1MnKH4tQW3/u0iX8Hwxw9nQJ6C8A== X-Received: by 2002:a17:906:5293:: with SMTP id c19mr32487322ejm.72.1608911582421; Fri, 25 Dec 2020 07:53:02 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id ho12sm13733010ejc.45.2020.12.25.07.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Dec 2020 07:53:01 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 25 Dec 2020 16:47:24 +0100 Message-Id: <20201225154724.287465-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201225154724.287465-1-andreas.rheinhardt@gmail.com> References: <20201225154724.287465-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 7/7] avcodec/mpegvideo: Factor common freeing code out X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 3daccb816f..dd50c03306 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -455,6 +455,15 @@ static void free_duplicate_context(MpegEncContext *s) s->block = NULL; } +static void free_duplicate_contexts(MpegEncContext *s) +{ + for (int i = 1; i < s->slice_context_count; i++) { + free_duplicate_context(s->thread_context[i]); + av_freep(&s->thread_context[i]); + } + free_duplicate_context(s); +} + static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src) { #define COPY(a) bak->a = src->a @@ -1049,16 +1058,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) if (!s->context_initialized) return AVERROR(EINVAL); - if (s->slice_context_count > 1) { - for (i = 0; i < s->slice_context_count; i++) { - free_duplicate_context(s->thread_context[i]); - } - for (i = 1; i < s->slice_context_count; i++) { - av_freep(&s->thread_context[i]); - } - } else - free_duplicate_context(s); - + free_duplicate_contexts(s); free_context_frame(s); if (s->picture) @@ -1106,15 +1106,9 @@ void ff_mpv_common_end(MpegEncContext *s) if (!s) return; - if (s->slice_context_count > 1) { - for (i = 0; i < s->slice_context_count; i++) { - free_duplicate_context(s->thread_context[i]); - } - for (i = 1; i < s->slice_context_count; i++) { - av_freep(&s->thread_context[i]); - } + free_duplicate_contexts(s); + if (s->slice_context_count > 1) s->slice_context_count = 1; - } else free_duplicate_context(s); av_freep(&s->parse_context.buffer); s->parse_context.buffer_size = 0;