From patchwork Fri Mar 8 09:26:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 12250 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 B723B44903F for ; Fri, 8 Mar 2019 11:27:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A234E68A7B4; Fri, 8 Mar 2019 11:27:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1529C68A773 for ; Fri, 8 Mar 2019 11:27:28 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id z84so11778306wmg.4 for ; Fri, 08 Mar 2019 01:27:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S4IZnZZuHFsjhE1qr6l7sWfaxr6YWAhvjdK0+ptHpTw=; b=NaV8gJwDD7/cUcQBfAKTWg6e1xim8W0yTrSx+qbw0KVCH9WLgBwgIsZZiVc8T9Qxev 8hYrQKa2c6GNAqWeDoFdBPK1vupzxI0SzDdNzIDJjvMdG+uWeJoV7aF3TP9AIN48CxUz Z8oE8UrN9C3COiifa5+KRxGmMORDxjoBGTAK8wr6lqN4s3DOKiIXdQLm9pVuHs756vnD TBBWWlw70oY8Pe5QlYx/Ead2DMhvCTA4tXBtNbMosXKn0KZ8WKuXsC8WkxguIuqZsfPp onXErL1RsxWCQLPQsBVUcRe+uRL8MMBrEjwxnCNE8z7OiWbOjHBmgYJ3iYGyAhL2wp3o kJUw== 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=S4IZnZZuHFsjhE1qr6l7sWfaxr6YWAhvjdK0+ptHpTw=; b=kk1Q5vkXebCUyt4aTNQENOMVuAhEhm35c04z2HGRUbAojCaub0Bfn7G7XEirkWZ6Kk qo+KULa3oxpUyT678ICcb9vU43GSbZPoSUkZEj9ts2CEhXk/4VdCGcnhsSHB57pt3nuW Z0ZaDl2tzNUl4wVD1KQX6pvdG/UmS39t5XCSySdlVZz8OLQnlJQdvtOuRHFSUat2rAaC cVt9umpccwJwPYPLxTRshOdA4flGy1FX2OIGVkTROKWCFrOmTZeBkFiVrAARFE/wlztE yXVLbewrID2Os+wWi5PnlKKPCwjyTm25WO068DOF2qs5q/kaxjNIOQZiaA3eCY2IXcHC 7oKA== X-Gm-Message-State: APjAAAUimbiWESi/Gr2y4+DlYdb5nPyj+W3s8F6EHwvhsz1cU88iGATS 9AUGOsYQiryDHw+K5HfCN9FWURjDsHA= X-Google-Smtp-Source: APXvYqytY77bWRL6yo1evHygaT5zZeu+3nSpcA8ZqE95V9Nkf/Rk6iRgVuFVV4g6/zJ14XGmkscnFA== X-Received: by 2002:a7b:c08d:: with SMTP id r13mr8544226wmh.55.1552037247370; Fri, 08 Mar 2019 01:27:27 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id v20sm12179825wmj.2.2019.03.08.01.27.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Mar 2019 01:27:26 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Mar 2019 10:26:00 +0100 Message-Id: <20190308092604.3752-7-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190308092604.3752-1-andreas.rheinhardt@googlemail.com> References: <20190308092604.3752-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/10] avformat/matroskadec: Don't keep old blocks 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" Before this commit, the Matroska muxer would read a block when required to do so, parse the block, create and return the necessary AVPackets and yet keep the blocks (in a dynamically allocated list), although they aren't used at all any more. This has been changed. There is no list any more and the block is immediately discarded after parsing. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 76 +++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 6ab9ef7a3e..e7f84d545c 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -304,9 +304,19 @@ typedef struct MatroskaLevel { uint64_t length; } MatroskaLevel; +typedef struct MatroskaBlock { + uint64_t duration; + int64_t reference; + uint64_t non_simple; + EbmlBin bin; + uint64_t additional_id; + EbmlBin additional; + int64_t discard_padding; +} MatroskaBlock; + typedef struct MatroskaCluster { + MatroskaBlock block; uint64_t timecode; - EbmlList blocks; } MatroskaCluster; typedef struct MatroskaLevel1Element { @@ -356,7 +366,6 @@ typedef struct MatroskaDemuxContext { MatroskaLevel1Element level1_elems[64]; int num_level1_elems; - int current_cluster_num_blocks; int64_t current_cluster_pos; MatroskaCluster current_cluster; @@ -367,16 +376,6 @@ typedef struct MatroskaDemuxContext { int bandwidth; } MatroskaDemuxContext; -typedef struct MatroskaBlock { - uint64_t duration; - int64_t reference; - uint64_t non_simple; - EbmlBin bin; - uint64_t additional_id; - EbmlBin additional; - int64_t discard_padding; -} MatroskaBlock; - static const EbmlSyntax ebml_header[] = { { EBML_ID_EBMLREADVERSION, EBML_UINT, 0, offsetof(Ebml, version), { .u = EBML_VERSION } }, { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml, max_size), { .u = 8 } }, @@ -705,9 +704,9 @@ static const EbmlSyntax matroska_blockgroup[] = { }; static const EbmlSyntax matroska_cluster_parsing[] = { - { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, - { MATROSKA_ID_BLOCKGROUP, EBML_NEST, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, - { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, sizeof(MatroskaBlock), offsetof(MatroskaCluster, blocks), { .n = matroska_blockgroup } }, + { MATROSKA_ID_CLUSTERTIMECODE, EBML_UINT, 0, offsetof(MatroskaCluster, timecode) }, + { MATROSKA_ID_BLOCKGROUP, EBML_NEST, 0, 0, { .n = matroska_blockgroup } }, + { MATROSKA_ID_SIMPLEBLOCK, EBML_PASS, 0, 0, { .n = matroska_blockgroup } }, { MATROSKA_ID_CLUSTERPOSITION, EBML_NONE }, { MATROSKA_ID_CLUSTERPREVSIZE, EBML_NONE }, { MATROSKA_ID_INFO, EBML_NONE }, @@ -3429,9 +3428,8 @@ end: static int matroska_parse_cluster(MatroskaDemuxContext *matroska) { - EbmlList *blocks_list; - MatroskaBlock *blocks; - int i, res; + MatroskaBlock *block = &matroska->current_cluster.block; + int res; res = ebml_parse(matroska, matroska_cluster_parsing, &matroska->current_cluster); @@ -3439,10 +3437,7 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) /* New Cluster */ if (matroska->current_cluster_pos) ebml_level_end(matroska); - ebml_free(matroska_cluster_parsing, &matroska->current_cluster); - memset(&matroska->current_cluster, 0, sizeof(MatroskaCluster)); - matroska->current_cluster_num_blocks = 0; - matroska->current_cluster_pos = avio_tell(matroska->ctx->pb); + matroska->current_cluster_pos = avio_tell(matroska->ctx->pb); /* sizeof the ID which was already read */ if (matroska->current_id) matroska->current_cluster_pos -= 4; @@ -3456,31 +3451,25 @@ static int matroska_parse_cluster(MatroskaDemuxContext *matroska) &matroska->current_cluster); } - if (!res && - matroska->current_cluster_num_blocks < - matroska->current_cluster.blocks.nb_elem) { - blocks_list = &matroska->current_cluster.blocks; - blocks = blocks_list->elem; - - matroska->current_cluster_num_blocks = blocks_list->nb_elem; - i = blocks_list->nb_elem - 1; - if (blocks[i].bin.size > 0 && blocks[i].bin.data) { - int is_keyframe = blocks[i].non_simple ? blocks[i].reference == INT64_MIN : -1; - uint8_t* additional = blocks[i].additional.size > 0 ? - blocks[i].additional.data : NULL; - if (!blocks[i].non_simple) - blocks[i].duration = 0; - res = matroska_parse_block(matroska, blocks[i].bin.buf, blocks[i].bin.data, - blocks[i].bin.size, blocks[i].bin.pos, + if (!res && block->bin.size > 0) { + int is_keyframe = block->non_simple ? block->reference == INT64_MIN : -1; + uint8_t* additional = block->additional.size > 0 ? + block->additional.data : NULL; + if (!block->non_simple) + block->duration = 0; + res = matroska_parse_block(matroska, block->bin.buf, block->bin.data, + block->bin.size, block->bin.pos, matroska->current_cluster.timecode, - blocks[i].duration, is_keyframe, - additional, blocks[i].additional_id, - blocks[i].additional.size, + block->duration, is_keyframe, + additional, block->additional_id, + block->additional.size, matroska->current_cluster_pos, - blocks[i].discard_padding); - } + block->discard_padding); } + ebml_free(matroska_blockgroup, block); + memset(block, 0, sizeof(*block)); + return res; } @@ -3579,7 +3568,6 @@ static int matroska_read_close(AVFormatContext *s) for (n = 0; n < matroska->tracks.nb_elem; n++) if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO) av_freep(&tracks[n].audio.buf); - ebml_free(matroska_cluster_parsing, &matroska->current_cluster); ebml_free(matroska_segment, matroska); return 0;