From patchwork Thu May 16 22:29:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13175 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 505C7449B3C for ; Fri, 17 May 2019 01:51:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3DED668A5FA; Fri, 17 May 2019 01:51:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E3D2868A04B for ; Fri, 17 May 2019 01:51:03 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id f204so5155060wme.0 for ; Thu, 16 May 2019 15:51:03 -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=msXDgbB51Ursgc/mAuijGvYlsIKLjUJR5xtVdXqug1k=; b=EZYA9EcuId+Vi7IgpKKBPhSDKxDPsPndarC/A8GJuNpBccC3uBtVkvB+SttzyBazi1 XYAgXRgbDqAy/wKXMfKv63EBIlUXKpnkU4EE2CD2RYYHU+l65UMTG/AlFew15wlH618J hPQLRodg/O0IuknnVBVro/NFDfWhd9y1Wo3lh8DmOwaYICIaPvbfFvA85GZM4AG5l+cx D7RkG+kBVAa5hjFANvU1qGJq5qho/kqJtCZE7QUbEaQ6wmmc8RwsXaBvWmfORtrBmdCC BrXNV4FwKjW3DFD2/CJWgJYvzAzeMJTVCSxCVZKr4PuXWYd4ulv74x50wWQu/ppfRIYP 1JNA== 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=msXDgbB51Ursgc/mAuijGvYlsIKLjUJR5xtVdXqug1k=; b=sTPqT3Ia9n4RyEnkscwQZjzACLxyhZzb7IyZ1U8fciIuI3hVsqcQayspvbuRzpdqkS WBTsyjjyKl0LTJ+cLTUKA+gkVMB7F7m+Z5C2BgH4JZt5k1W2QGXwtg7SS2JstSQUAYH/ dBzR67ZvxHAl2wZfAaqRgBwC9lFeUAczDniblgQ87gHLQMEbbQhFItweRKpNHQKeBzuH Qylt0Ww15FSc7LywyyJ8peU6SMkS6Qkn06aR6Vi8XKNkmjRWz6QL8lQIpt3YZ+Es6ou3 oVouZTVjRuSypM4QQB8pnXOd2xnvfIhaXcjlPrjmVpJgy29sDrQGYEIA/TQ5wToJf+uJ 0lbQ== X-Gm-Message-State: APjAAAU/pAwJ3Y4u/+NRw4PfWfJCTs0YZphiXQpeG6WLRJHC4Xei11VP gZlLwrBQJPF3ejTo3V/Cl7Sp0Kg6 X-Google-Smtp-Source: APXvYqwbtzoaPl3tAgJCBODl3wF+2e5txs+ejdG9+qirJ9EPVn8R+b1uSc5jjm3Qqyi8IqBrjZ3wnw== X-Received: by 2002:a1c:6a0e:: with SMTP id f14mr107755wmc.28.1558046594320; Thu, 16 May 2019 15:43:14 -0700 (PDT) Received: from localhost.localdomain (ipbcc18715.dynamic.kabel-deutschland.de. [188.193.135.21]) by smtp.gmail.com with ESMTPSA id i185sm11168725wmg.32.2019.05.16.15.43.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 15:43:13 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2019 00:29:59 +0200 Message-Id: <20190516223018.30827-16-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190516223018.30827-1-andreas.rheinhardt@gmail.com> References: <20190516223018.30827-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/37] 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 | 87 +++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 49 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index c0767c3529..380db55340 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -306,9 +306,20 @@ 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; + int64_t pos; } MatroskaCluster; typedef struct MatroskaLevel1Element { @@ -358,8 +369,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; /* WebM DASH Manifest live flag */ @@ -369,16 +378,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 } }, @@ -707,9 +706,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 }, @@ -3499,57 +3498,48 @@ end: static int matroska_parse_cluster(MatroskaDemuxContext *matroska) { - EbmlList *blocks_list; - MatroskaBlock *blocks; - int i, res; + MatroskaCluster *cluster = &matroska->current_cluster; + MatroskaBlock *block = &cluster->block; + int res; res = ebml_parse(matroska, matroska_cluster_parsing, - &matroska->current_cluster); + cluster); if (res == 1) { /* New Cluster */ - if (matroska->current_cluster_pos) + if (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); + cluster->pos = avio_tell(matroska->ctx->pb); /* sizeof the ID which was already read */ if (matroska->current_id) - matroska->current_cluster_pos -= 4; + cluster->pos -= 4; res = ebml_parse(matroska, matroska_clusters, - &matroska->current_cluster); + cluster); /* Try parsing the block again. */ if (res == 1) res = ebml_parse(matroska, matroska_cluster_parsing, - &matroska->current_cluster); + cluster); } - if (!res && - matroska->current_cluster_num_blocks < - matroska->current_cluster.blocks.nb_elem) { - blocks_list = &matroska->current_cluster.blocks; - blocks = blocks_list->elem; + 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; - 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; - - res = matroska_parse_block(matroska, blocks[i].bin.buf, blocks[i].bin.data, - blocks[i].bin.size, blocks[i].bin.pos, + 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, - matroska->current_cluster_pos, - blocks[i].discard_padding); - } + block->duration, is_keyframe, + additional, block->additional_id, + block->additional.size, + cluster->pos, + block->discard_padding); } + ebml_free(matroska_blockgroup, block); + memset(block, 0, sizeof(*block)); + return res; } @@ -3647,7 +3637,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;