From patchwork Sat Jul 30 17:14:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 37045 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp1564869pzb; Sat, 30 Jul 2022 10:15:53 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tcPRxTFbSV+Q9+4m7nVgBeYpuVz26eIUZA28BvL8leY4DN7wYTjHg5MNcXeAZJoLfEHyGA X-Received: by 2002:a17:907:724d:b0:72f:2366:be86 with SMTP id ds13-20020a170907724d00b0072f2366be86mr7052307ejc.146.1659201353483; Sat, 30 Jul 2022 10:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659201353; cv=none; d=google.com; s=arc-20160816; b=VUFpMqz0ZTzoqUiF6ur9fXp/3l8fFlbXAaLMyJ3diSV/sPL0B8lruVU5016nYrWEFg Zza/AWM1hB3miQIUgxBfd6qRCXKJmxWYErIR6kK8U+Xoql+k0D7fJsCafRFXydSS9mUk CRfSxCja39Gu6cwOaaf1qjh8NFRQlCYoyNvJyTkfdpPSwO+eedEhfwaqlGOAxYkwHRtr EY8Rv87QMepsvrUrcrvut1BoBBKQyVwdOH1sbdvbWnpN0ZVn588nKdChCI/oInmlWXUi q9i3LaNWLJriPjM8KBe3nIqapM2Hbq7xRHORPTk3gmmtpvvLUbwL6VH/LH05PjV8ttU5 FeDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to:date :to:from:message-id:dkim-signature:delivered-to; bh=FT7AjPjVaqETM68sDIHklpuFLkvPEiqvd05AUZCfPz0=; b=KsVTlQxbxl/0IgbUok7UfiGq/sULixgVTEo8EatDESbObQ/4jP3BWhb0Icba1RKzgl wYOJ01cs4veschZSuvZjz3453Z1WurVOqo/voSf2tNsmH4yyrUzRlHm2zfaAvGFS/8bo 38CePPTigg8XNbcA31tm1BpM6fgXeP/Uw5QJQNPjWN3m7m7DdSxTmE+Q7oeCn2ODJ1mc ZgsCLbJbKLPdiKIMImJpdGYyE6MF3uofo4ZUepqncqsK5pih6rFlzE0qLbehk9IOUUVQ ntrCH7BBIOEhg0gpzBj5sEjEM4caSAgVc0A4ROzSDcV4udfkYgSRH5j49RVieDpr25+Q Wn/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b="UkHh/OtT"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e20-20020a17090681d400b007235473b2fbsi1505445ejx.680.2022.07.30.10.15.50; Sat, 30 Jul 2022 10:15:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b="UkHh/OtT"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B1F3C68B95E; Sat, 30 Jul 2022 20:15:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com [162.62.57.210]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 218CE68B8B3 for ; Sat, 30 Jul 2022 20:15:30 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1659201328; bh=eEU0u+HPW6SP8oxEwoPYW+u94h2F2M+L75oljb0n950=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UkHh/OtTuitvZC5YvJlPlv+04ISk2jRIsdbzsjl0+h1QZFSNxkYrI014xslQWNdhW UzaVyWW4Lfd2RMKmc5fSeKvsGfde26KhPvVIfWMs3ybndQRUfxBrgdms5QjCsBoSB+ 2Y+uV6soeb92ebg9GasNv+6IzuzNuBEMmRMkE6qI= Received: from black.localdomain ([113.116.29.125]) by newxmesmtplogicsvrszc10.qq.com (NewEsmtp) with SMTP id 39003A85; Sun, 31 Jul 2022 01:14:16 +0800 X-QQ-mid: xmsmtpt1659201257t0g3sgwdr Message-ID: X-QQ-XMAILINFO: M0PjjqbLT90w5K6yXZBuviwqzEfDHM3RDAE+V6oBmOsK97ZWLWT4wS2X41k9Hr 1pYNFYJ74T3Zfp2XkmKBIstvVFC8PlxpaoEoHX58TfEIp7PcE7ER4szfOZ4g7X/nTi+YPSnHXG8+ ICeZ/TAVdQ10fAeToGtO/Tzcq7SueZeFEgoaxyrFERpNbE6swH2g3GXwfRYxgEHQMV66cjKO9+KU +8ACSyQ8I7ETODIUhzBD55yfltGrI4OW+Zn9QAM1NmOlDZM+b7dqGMelVcHSBCgEWrJ6pVJqeJxw SR6BJsuNvmxbitrkyQDKo5ON1bQeYwmQqqVtm9fMTZURIMN1upIYkGPibZzFqJlP2U1Yd8Qy7TG9 Q0yvITOmMKvqFNOXYEGYvr4I07ljOemhqMHkoAVn5xChAOk3IuJP5fusKFUjTQjBrLb3ZzPbPe56 cENHLVx8eHC4nvKh3+wXqAb/zl4G3hnuRM/CLCT4tmLDErzFPGInt/X51SdveT7SNmK73s8Tdeu5 RxjQEadw/49gehVeBGJUoOrxa+oKoxjq+yNpGTcqRyvwwKWtnWG/nPqdAbuNYZbvli/NO25uOKwY tdsk5rn0cfvvBBwM862iCFGoUNyAuxjlNJYdrK05tgGF1W/CO2QdvRC+BoXigDsrRNQM9u8mDjj2 WMbs/GuLKyvL2oLmkMbQQlYGLZy3wGeemzLHeSRS7nco0V9eLaMY95UkVEqcIC/KY5J0HDCPnjUl RmSj+w4Trbg1Se+ssU3qQ65wq3vwgt0K7BAIQZbGXgaqwS+jkXGRPPsewmxMdYmnrxZNo/2hk5N6 lzOhc7ZFXFs3Gu0CFwEpPMyOrb0bBcu0NNAe3Ceawa59eHuHtRrGLW06VTCLqNkZjwJK450kDBSe SoTEmy6EaAgJZqvn+l9kUj9UiFnxJIvO6JCoti8jKa/IVaVTVXUJGS0QW2ngVQBT9hm0nRiSbx From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Sun, 31 Jul 2022 01:14:12 +0800 X-OQ-MSGID: <20220730171412.600-2-quinkblack@foxmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220730171412.600-1-quinkblack@foxmail.com> References: <20220730171412.600-1-quinkblack@foxmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avformat/mov: fix encryption index in the case of multiple trun X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 1T9fffSIbVkj From: Zhao Zhili frag_stream_info->index_entry isn't the first sample/trun index. cenc.frag_index_entry_base failed to catch the case since current_index > 0. Fix ticket #9807. --- libavformat/isom.h | 3 ++- libavformat/mov.c | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index f05c2d9c28..c6365f2f48 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -135,6 +135,8 @@ typedef struct MOVFragmentStreamInfo { int64_t first_tfra_pts; int64_t tfdt_dts; int64_t next_trun_dts; + // Index of the first sample/trun in the fragment. + int index_base; int index_entry; MOVEncryptionIndex *encryption_index; } MOVFragmentStreamInfo; @@ -253,7 +255,6 @@ typedef struct MOVStreamContext { struct { struct AVAESCTR* aes_ctr; struct AVAES *aes_ctx; - unsigned int frag_index_entry_base; unsigned int per_sample_iv_size; // Either 0, 8, or 16. AVEncryptionInfo *default_encrypted_sample; MOVEncryptionIndex *encryption_index; diff --git a/libavformat/mov.c b/libavformat/mov.c index ce12a9e4f1..23d9bb4af1 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1369,6 +1369,7 @@ static int update_frag_index(MOVContext *c, int64_t offset) frag_stream_info[i].tfdt_dts = AV_NOPTS_VALUE; frag_stream_info[i].next_trun_dts = AV_NOPTS_VALUE; frag_stream_info[i].first_tfra_pts = AV_NOPTS_VALUE; + frag_stream_info[i].index_base = -1; frag_stream_info[i].index_entry = -1; frag_stream_info[i].encryption_index = NULL; } @@ -5125,8 +5126,11 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->ctts_count = sti->nb_index_entries; // Record the index_entry position in frag_index of this fragment - if (frag_stream_info) + if (frag_stream_info) { frag_stream_info->index_entry = index_entry_pos; + if (frag_stream_info->index_base < 0) + frag_stream_info->index_base = index_entry_pos; + } if (index_entry_pos > 0) prev_dts = sti->index_entries[index_entry_pos-1].timestamp; @@ -7134,9 +7138,7 @@ static int cenc_filter(MOVContext *mov, AVStream* st, MOVStreamContext *sc, AVPa // Note this only supports encryption info in the first sample descriptor. if (mov->fragment.stsd_id == 1) { if (frag_stream_info->encryption_index) { - if (!current_index && frag_stream_info->index_entry) - sc->cenc.frag_index_entry_base = frag_stream_info->index_entry; - encrypted_index = current_index - (frag_stream_info->index_entry - sc->cenc.frag_index_entry_base); + encrypted_index = current_index - frag_stream_info->index_base; encryption_index = frag_stream_info->encryption_index; } else { encryption_index = sc->cenc.encryption_index;