From patchwork Wed Jul 8 01:29:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 20867 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 BB17644BEB7 for ; Wed, 8 Jul 2020 04:52:29 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A35368AB1D; Wed, 8 Jul 2020 04:52:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 064D368A965 for ; Wed, 8 Jul 2020 04:52:23 +0300 (EEST) Received: by mail-qt1-f195.google.com with SMTP id w34so13323071qte.1 for ; Tue, 07 Jul 2020 18:52:22 -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=uDluu0G4gZbsBUFJ+BH9pR36F50fvpNA3FOILEcIqOM=; b=DWM851Y48JlUX8bpy+jr8PrVunsgncYddEW8gyVZmVtXlAcmLcCQci9HI4HAD/Q6LD /MsTw606I6A+CliQALr4ZiHLywYVMWgNll1oEkslKhJHo0IHbYruesfuiZa0ydlLGAM1 Jk67gYv0ibuHHJ7BAK+ulTiNmvZJv62T/5LnWHgD8T4zzP1HujS9540aoW3sp/toV8VK /CeDbe0SMFUraApdcXN/+n6zV4r9TmR+/7ok8o1ZOVpIVMCDGEcAIbqvuyoMhpSmzsXn 8bDwL3rs6qWIvM+8ZOhTdmuGPUNFM+ATb/It/yCSL6DK1JQJNiKLbkIto9aZuwnpusLo CRuQ== 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=uDluu0G4gZbsBUFJ+BH9pR36F50fvpNA3FOILEcIqOM=; b=lLk4WlU9QoiSHajVMQqeCEwMQ3H4F5oIw+XFjPBl9aUd0G0FGLgDg/EhL4QG7FS04b fnx7R5Dj/Oh3OsRx81mghQCKdKpBBQaUmCjcTqFDLdLgP00RSf7GSnjGxTltp5nC20yF NEZJVdkuV9iv0Bvx4VhkrkLnOPU+8F/drugaMrtVg9VYdDJkSqgXd8ubvmLjZXrFdIkV oMdfwPqBAL6d3+gNb/QDhjlK2cO8mpK/3WjZAHjgyLSohz1CfyqV+3eWhrtSoUMfAbLl vpp8FMF/7by5zZnQsd6xv30mRBWoweKfpRegNsgH+aNE6+t/Q53JvoymbbiLyKxppNWq DTHQ== X-Gm-Message-State: AOAM532homRJH61w4Dcniuj6Z8/+BIiJCGofMNReq9Jyb42F2IdzickP cmFCBx0RFcsmjYEm1NK0TCL2D045wMg= X-Google-Smtp-Source: ABdhPJxGyf5eUDo/T8L9aUEbT48IHizIlrq5LS3q9jwefqwsXGjZxFmY1rOwwo+6dvpIlaHaOMmbBw== X-Received: by 2002:a37:448:: with SMTP id 69mr54464289qke.130.1594171821881; Tue, 07 Jul 2020 18:30:21 -0700 (PDT) Received: from localhost.localdomain ([191.84.244.216]) by smtp.gmail.com with ESMTPSA id y40sm29275177qtc.29.2020.07.07.18.30.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 18:30:21 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Jul 2020 22:29:48 -0300 Message-Id: <20200708012949.13522-3-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200708012949.13522-1-jamrial@gmail.com> References: <20200708012949.13522-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/filter_units_bsf: Use separate contexts for reading/writing 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" Based on code from 235a5734e0 Signed-off-by: James Almer --- libavcodec/filter_units_bsf.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c index 354594ac50..14960761d2 100644 --- a/libavcodec/filter_units_bsf.c +++ b/libavcodec/filter_units_bsf.c @@ -29,7 +29,8 @@ typedef struct FilterUnitsContext { const AVClass *class; - CodedBitstreamContext *cbc; + CodedBitstreamContext *input; + CodedBitstreamContext *output; CodedBitstreamFragment fragment; const char *pass_types; @@ -112,7 +113,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) if (ctx->mode == NOOP) return 0; - err = ff_cbs_read_packet(ctx->cbc, frag, pkt); + err = ff_cbs_read_packet(ctx->input, frag, pkt); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read packet.\n"); goto fail; @@ -134,7 +135,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *pkt) goto fail; } - err = ff_cbs_write_packet(ctx->cbc, pkt, frag); + err = ff_cbs_write_packet(ctx->output, pkt, frag); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to write packet.\n"); goto fail; @@ -179,22 +180,25 @@ static int filter_units_init(AVBSFContext *bsf) return 0; } - err = ff_cbs_init(&ctx->cbc, bsf->par_in->codec_id, bsf); + err = ff_cbs_init(&ctx->input, bsf->par_in->codec_id, bsf); + if (err < 0) + return err; + err = ff_cbs_init(&ctx->output, bsf->par_in->codec_id, bsf); if (err < 0) return err; // Don't actually decompose anything, we only want the unit data. - ctx->cbc->decompose_unit_types = ctx->type_list; - ctx->cbc->nb_decompose_unit_types = 0; + ctx->input->decompose_unit_types = ctx->type_list; + ctx->input->nb_decompose_unit_types = 0; if (bsf->par_in->extradata) { CodedBitstreamFragment *frag = &ctx->fragment; - err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in); + err = ff_cbs_read_extradata(ctx->input, frag, bsf->par_in); if (err < 0) { av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n"); } else { - err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag); + err = ff_cbs_write_extradata(ctx->output, bsf->par_out, frag); if (err < 0) av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n"); } @@ -212,7 +216,8 @@ static void filter_units_close(AVBSFContext *bsf) av_freep(&ctx->type_list); ff_cbs_fragment_free(&ctx->fragment); - ff_cbs_close(&ctx->cbc); + ff_cbs_close(&ctx->input); + ff_cbs_close(&ctx->output); } #define OFFSET(x) offsetof(FilterUnitsContext, x)