From patchwork Mon Aug 10 18:06:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 21592 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 A1B8A44AD49 for ; Mon, 10 Aug 2020 21:07:09 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B97B68ABC2; Mon, 10 Aug 2020 21:07:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A6D0B68AAEC for ; Mon, 10 Aug 2020 21:07:01 +0300 (EEST) Received: by mail-qt1-f196.google.com with SMTP id 6so7489467qtt.0 for ; Mon, 10 Aug 2020 11:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GCdH8/O3Ukt2gt7OHJZxzNhFSOUCcDNrYMtmV9Yi2fc=; b=pk1G3ryOFrRKf0hz2ArVvTACz3rW84mXeT4T/C+tdbjInO3soi6/1CCnUhbbeLpyh4 ynmaUUaP/gyOMCi4oBVzvGcNd9eMNtxYWfARqStU2/oc3M7GY52StH+ckwHH6BRVE0Xc ikiYL0cFxB0v7wPqg9Vw58eBUkTHdKtOerl8h7N4JdGtcY8ba1ivG6/aTj+UrYLlpeQ4 QVx0CapAM3lKNjpy4WyaNL6ijlHHT/FaNYsT34EkJkMzFfpyNFyw06F9F5zAH7r42Jiw OMZ7BaSJh0rq1vXVNyhnb1bOtvfwvhbnE8bfUgQrtmaKhRirHMMZIplmY+TTyrcg1NhU MUOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GCdH8/O3Ukt2gt7OHJZxzNhFSOUCcDNrYMtmV9Yi2fc=; b=JPEPeL4DAmclQ16/jHoAyTeC8nWa9Y+ncHQHrYHcvnrGYFQYiSGo/qCQLMPsjnaM6f bvJhzQmKbSLKwcIzc9Jznx/jR9RBJhSJ1hSTcAGuDaPymcJXBBq/M6RXr6Jb8RbZoxBa jzwxev3Q3VjtJfV6e2RyWBi7jGMLLj8K8TaLzbyJcbh8YcJrqtZWeFnFRuPF5uinGahE eCEvWu815h/midZfTgk8h8MquWGFCB0mK1HRj6wfvrAgqyPVM6RCtf2K1FNbHbIN2ZYs AfNB16/Bf9/6OuJc2I5rHDYevLvg8lzlmgDLwMX96Zsu9aRU0vRIantnx0fLM67LZqdp QX9g== X-Gm-Message-State: AOAM531aHaEDpPbjdT1ALJoUmRYER7AvWHNP7CDMoCpPD2bPm9TqW/ul /C9q6suAdulXjorxeAzIwuQFvsJy X-Google-Smtp-Source: ABdhPJx+P+AkgRr/LRSw3rlwF0RJSp5qljCh3kfLz30eRj0zUC5emxWgTkCkoPNIHUMEvq0l4kzkRg== X-Received: by 2002:aed:33a5:: with SMTP id v34mr28602279qtd.262.1597082820129; Mon, 10 Aug 2020 11:07:00 -0700 (PDT) Received: from localhost.localdomain ([181.23.72.45]) by smtp.gmail.com with ESMTPSA id t12sm14568707qkt.56.2020.08.10.11.06.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 11:06:59 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Aug 2020 15:06:15 -0300 Message-Id: <20200810180615.5222-3-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200810180615.5222-1-jamrial@gmail.com> References: <20200810180615.5222-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/bsf: add av_bsf_close() 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This function lets the API user reuse an AVBSFContext in case of stream parameter changes. Signed-off-by: James Almer --- Missing version bump and APIChanges entry. libavcodec/bsf.c | 21 +++++++++++++++++++++ libavcodec/bsf.h | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c index d71bc32584..667c40863d 100644 --- a/libavcodec/bsf.c +++ b/libavcodec/bsf.c @@ -29,6 +29,7 @@ #include "bsf_internal.h" #include "codec_desc.h" #include "codec_par.h" +#include "internal.h" #define IS_EMPTY(pkt) (!(pkt)->data && !(pkt)->side_data_elems) @@ -197,6 +198,26 @@ void av_bsf_flush(AVBSFContext *ctx) ctx->filter->flush(ctx); } +void av_bsf_close(AVBSFContext *ctx) +{ + AVBSFInternal *bsfi = ctx->internal; + + if (ctx->filter->close) + ctx->filter->close(ctx); + if (ctx->filter->priv_class && ctx->priv_data) { + av_opt_free(ctx->priv_data); + av_opt_set_defaults(ctx->priv_data); + } + + bsfi->eof = 0; + av_packet_unref(bsfi->buffer_pkt); + + ctx->time_base_out = ctx->time_base_in = (AVRational){ 0, 0 }; + + ff_codec_parameters_reset(ctx->par_in); + ff_codec_parameters_reset(ctx->par_out); +} + int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt) { AVBSFInternal *bsfi = ctx->internal; diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h index 3b5faa85cb..f72c45f7e5 100644 --- a/libavcodec/bsf.h +++ b/libavcodec/bsf.h @@ -216,12 +216,26 @@ int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt); /** * Reset the internal bitstream filter state. Should be called e.g. when seeking. + * + * @see av_bsf_close(). */ void av_bsf_flush(AVBSFContext *ctx); +/** + * Close a bitstream filter context, leaving it in the same state as when it was + * freshly allocated. May be called e.g. to reuse the context in case of stream + * parameter changes. + * + * @see av_bsf_flush(). + * @see av_bsf_free(). + */ +void av_bsf_close(AVBSFContext *ctx); + /** * Free a bitstream filter context and everything associated with it; write NULL * into the supplied pointer. + * + * @see av_bsf_close(). */ void av_bsf_free(AVBSFContext **ctx);