From patchwork Sat Jul 6 14:18: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: 13834 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 EAF81449D3B for ; Sat, 6 Jul 2019 17:25:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D543768ACE8; Sat, 6 Jul 2019 17:25:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E54C68ACBB for ; Sat, 6 Jul 2019 17:25:34 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id v19so12250517wmj.5 for ; Sat, 06 Jul 2019 07:25:34 -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=UjnHH/HP9KPcCFktvt9WaHhSvb5DpGy2GLnPtdyznu8=; b=iIISewkz2HBlAolPdAvLo1Xe0p0saBuE7ujh3Pfzfj06XitY7pehPEHFFCdzgGBt9Q uBz4hDwJR7p9ZgRhsAzwYIZyLvXBhs3mKCJae7KyEZQOGAg84cmjQFG6gHSGsA9A6FvK YmEAzyiY2BlyW0sOeQm1KAjMpyRqUZhxExI3U2ib366Wrh1sP35aOyEBKdwizpNpLLMw oMfzqy2AGfLx+NWdUc/0UmgFpAU1RZE+1t8kXSYUvbPWw0fyU2PcSIuKTZif1sx6TYys gh43dkNR+cLjXtjmnOZ+tVY9NTCLgqj+OJ47IYDMI7/F6FLwTjldJkpGLVmXs4DKSas3 W2fg== 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=UjnHH/HP9KPcCFktvt9WaHhSvb5DpGy2GLnPtdyznu8=; b=DHHpsnYIppTJSFMc251Kyr04Pq2jzFOU8xMKwrooHugOAnb5MpcMRE5aFp8lDvextB FlSHU+l7JwlYNIpVQaPBPR/IG4BNd2h6MGAIVv5iNCGNZfrar8bo7mj2QT7ojD9663Jw tTSbk57YIARehT+PRjy/T6ntH4Ex70yZvOt3PH+Ivp5Q+sOcR1eJSLeRj9IfqHMzAuGe KtEuZUPY7Fc5PkNSgb7WEo+Y5aMbf9/4tUJ/0sKHABLXrKKRpDOt+tX6bNCZlhrCrrII eRF8NLm8pl5mGt4sh+XfR13wkKY8sbZehYFa9/Bs0FtB6TNhVWOe/00LEPajMgv4wn2w BQRQ== X-Gm-Message-State: APjAAAVVGRm0+6dFcvVuwoTKPK4Z0KnNsVIzY2W5wtys1NMPonmLHCaU XRKWdXDR5ZOGYqN3Eig8gZQmlFUEC8E= X-Google-Smtp-Source: APXvYqwzsk7f0KxnOB7ACQXCfQphR5E92jZIjzcCPNe3/OCowCs3oDAg+gotRckR9fxlUTWl5yknNg== X-Received: by 2002:a1c:c188:: with SMTP id r130mr7067720wmf.73.1562422699691; Sat, 06 Jul 2019 07:18:19 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b8f.dynamic.kabel-deutschland.de. [188.192.139.143]) by smtp.gmail.com with ESMTPSA id z7sm1331566wrh.67.2019.07.06.07.18.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 06 Jul 2019 07:18:19 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 6 Jul 2019 16:18:00 +0200 Message-Id: <20190706141804.12034-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190706135911.11986-1-andreas.rheinhardt@gmail.com> References: <20190706135911.11986-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/6] truehd_core: Correct output size 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" If truehd_core strips Atmos data away, three parts of the output differ in size compared to the input access unit: a) The major_sync_info block if the extra_channel_meaning_data is present, as the newly written output never contains said block; b) the substream_directory (because entries relating to discarded substreams are discarded, too); and c) the actual substream data. b) and c) have already been taken into account when choosing the size of the output packet, but a) has been forgotten. This is also the reason behind the end of the output buffer having been uninitialized until 801d78f0. The workaround added in said commit has been removed, too. Signed-off-by: Andreas Rheinhardt --- The extra_channel stuff can be 32 bytes at most, so the workaround might have initialized too few bytes for some files. libavcodec/truehd_core_bsf.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c index 757d26a10d..83f2b16e3d 100644 --- a/libavcodec/truehd_core_bsf.c +++ b/libavcodec/truehd_core_bsf.c @@ -46,7 +46,7 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) int in_size, out_size; int have_header = 0; int substream_bits = 0; - int start, end; + int end; uint16_t dts; ret = ff_bsf_get_packet(ctx, &in); @@ -81,7 +81,6 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) if (s->hdr.num_substreams > MAX_SUBSTREAMS) goto fail; - start = get_bits_count(&gbc); for (i = 0; i < s->hdr.num_substreams; i++) { for (int j = 0; j < 4; j++) units[i].bits[j] = get_bits1(&gbc); @@ -104,7 +103,7 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) if (size >= 0 && size <= in->size) out_size = size; if (out_size < in_size) { - int bpos = 0, reduce = (end - start - substream_bits) >> 4; + int bpos = 0, reduce = (end - have_header * 28 * 8 - substream_bits) >> 4; uint16_t parity_nibble = 0; uint16_t auheader; @@ -117,8 +116,6 @@ static int truehd_core_filter(AVBSFContext *ctx, AVPacket *out) out->size -= reduce * 2; parity_nibble ^= out->size / 2; - if (out_size > 8) - AV_WN64(out->data + out_size - 8, 0); if (have_header) { memcpy(out->data + 4, in->data + 4, 28); out->data[16 + 4] = (out->data[16 + 4] & 0x0c) | (FFMIN(s->hdr.num_substreams, 3) << 4);