From patchwork Tue Jul 21 02:12:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21208 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 594CE44B6A8 for ; Tue, 21 Jul 2020 05:12:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26CE468BACC; Tue, 21 Jul 2020 05:12:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DB70968B834 for ; Tue, 21 Jul 2020 05:12:23 +0300 (EEST) Received: by mail-ej1-f46.google.com with SMTP id a21so20035411ejj.10 for ; Mon, 20 Jul 2020 19:12:23 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=+/HW60OumOlRNE82lxWX4uEDI5wtZGAV7lEc1+J+l0I=; b=UcBmZ2vdqKopxtFzShgj1zCFVxomzZ6GEaRObvRus/oaPOeP/80kkNetBE8LtKCEMY HtFmBbRWseDiOkNKikYjxKhgoY5lQRshf5pkr24uYrAZrQdiu40+gqO+nUjl9G7rgwOE a6KJTJt55KJ9ibsNM3xZh4K3pWVgegpjylF1rTsAgxVrhWd3b6t3KFDkRCka86j/Yl2l n1U2T2dZq4aPO0XrLuV4TLlzFfiCGV9J9qRcalIkuNQSHkNCyiF3Zznkcv2uxkc0OGe2 qYGdQX41Il15c0GmC00BTRqClCSWSZ9qrh3RzkVIz9bqneZg1osRsc+8qiZ/A6jDIFgK m3rA== 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:mime-version:content-transfer-encoding; bh=+/HW60OumOlRNE82lxWX4uEDI5wtZGAV7lEc1+J+l0I=; b=m4hXuDhrP+ILje4giXPrRE0bSIV1BQmUeunxF4vrJnU/sT6wKUpkz2BoEdpnbnTJUp GACuz2NDQiI5PSRlMSrFTwZJWeGf/dV4B+KsMSwQdEeS+CRRN0AkSL7gUlin3o9d5nAW 4OJ+AFtG8h1Umm7kgccUepucapxgRqjkro1GzyKdc4cP/yyVg0XRVByOJ0vJTEVAS1zc NqnTSq3jXKZiPd5aB/zy6FVk36RXqP7w+ttRRthDHlRq1/BuuYsjzYmzVr1IxgReiA9b 2eCl8R88dpFb+5M7xyZJvxmcpeUhKAALI5Yfe3SF4jRYf+ZsPtzzVpUroeRCBmxANZ3Q tWdQ== X-Gm-Message-State: AOAM533Mh1u/J9tTqu6vpnERWQfHXlvUc2vMvlf+cu/6YMG0kUwi6sAG 4iiJkCziSiCDqQjGJ1Ks0oG4Az2o X-Google-Smtp-Source: ABdhPJzLKB4vvP7ZQvkjUj7jGXl0vXnN+keaH4ytPUCGfVUM0NOQUOG3pmtoILbOYoMBXk23hKw/fQ== X-Received: by 2002:a17:906:35cd:: with SMTP id p13mr23107559ejb.172.1595297542799; Mon, 20 Jul 2020 19:12:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc10296.dynamic.kabel-deutschland.de. [188.193.2.150]) by smtp.gmail.com with ESMTPSA id p9sm15528563ejd.50.2020.07.20.19.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 19:12:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 21 Jul 2020 04:12:09 +0200 Message-Id: <20200721021215.32647-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200719204755.32269-1-andreas.rheinhardt@gmail.com> References: <20200719204755.32269-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/9] avformat/mxfdec: Simplify cleanup after read_header failure 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" by setting the AVFMT_HEADER_CLEANUP flag. Signed-off-by: Andreas Rheinhardt --- libavformat/mxfdec.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index 90546d42b3..06c6e0890b 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -302,8 +302,6 @@ typedef struct MXFMetadataReadTableEntry { enum MXFMetadataSetType type; } MXFMetadataReadTableEntry; -static int mxf_read_close(AVFormatContext *s); - /* partial keys to match */ static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 }; static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 }; @@ -3169,7 +3167,6 @@ static int mxf_read_header(AVFormatContext *s) if (!mxf_read_sync(s->pb, mxf_header_partition_pack_key, 14)) { av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n"); - //goto fail should not be needed as no metadata sets will have been parsed yet return AVERROR_INVALIDDATA; } avio_seek(s->pb, -14, SEEK_CUR); @@ -3200,8 +3197,7 @@ static int mxf_read_header(AVFormatContext *s) if (!mxf->current_partition) { av_log(mxf->fc, AV_LOG_ERROR, "found essence prior to first PartitionPack\n"); - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } if (!mxf->current_partition->first_essence_klv.offset) @@ -3226,7 +3222,7 @@ static int mxf_read_header(AVFormatContext *s) for (metadata = mxf_metadata_read_table; metadata->read; metadata++) { if (IS_KLV_KEY(klv.key, metadata->key)) { if ((ret = mxf_parse_klv(mxf, klv, metadata->read, metadata->ctx_size, metadata->type)) < 0) - goto fail; + return ret; break; } } @@ -3239,21 +3235,20 @@ static int mxf_read_header(AVFormatContext *s) /* FIXME avoid seek */ if (!essence_offset) { av_log(s, AV_LOG_ERROR, "no essence\n"); - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } avio_seek(s->pb, essence_offset, SEEK_SET); /* we need to do this before computing the index tables * to be able to fill in zero IndexDurations with st->duration */ if ((ret = mxf_parse_structural_metadata(mxf)) < 0) - goto fail; + return ret; for (int i = 0; i < s->nb_streams; i++) mxf_handle_missing_index_segment(mxf, s->streams[i]); if ((ret = mxf_compute_index_tables(mxf)) < 0) - goto fail; + return ret; if (mxf->nb_index_tables > 1) { /* TODO: look up which IndexSID to use via EssenceContainerData */ @@ -3261,8 +3256,7 @@ static int mxf_read_header(AVFormatContext *s) mxf->nb_index_tables, mxf->index_tables[0].index_sid); } else if (mxf->nb_index_tables == 0 && mxf->op == OPAtom && (s->error_recognition & AV_EF_EXPLODE)) { av_log(mxf->fc, AV_LOG_ERROR, "cannot demux OPAtom without an index\n"); - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } mxf_compute_essence_containers(s); @@ -3271,10 +3265,6 @@ static int mxf_read_header(AVFormatContext *s) mxf_compute_edit_units_per_packet(mxf, s->streams[i]); return 0; -fail: - mxf_read_close(s); - - return ret; } /* Get the edit unit of the next packet from current_offset in a track. The returned edit unit can be original_duration as well! */ @@ -3740,7 +3730,7 @@ static const AVClass demuxer_class = { AVInputFormat ff_mxf_demuxer = { .name = "mxf", .long_name = NULL_IF_CONFIG_SMALL("MXF (Material eXchange Format)"), - .flags = AVFMT_SEEK_TO_PTS, + .flags = AVFMT_SEEK_TO_PTS | AVFMT_HEADER_CLEANUP, .priv_data_size = sizeof(MXFContext), .read_probe = mxf_probe, .read_header = mxf_read_header,