From patchwork Fri Jul 22 09:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wangyaqiang <1035567130@qq.com> X-Patchwork-Id: 36890 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp302790pzb; Fri, 22 Jul 2022 02:18:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tg+PEorEyL3h/2irizpu1wzwtSIktsHPF8SJ4ydESnscwkoAjbt/haDl6sF/FbaXAdfMwC X-Received: by 2002:a05:6402:2b88:b0:43a:6c58:6c64 with SMTP id fj8-20020a0564022b8800b0043a6c586c64mr2607780edb.348.1658481498609; Fri, 22 Jul 2022 02:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658481498; cv=none; d=google.com; s=arc-20160816; b=ZiDshUNnEC+It2h0WPbQ0t64na5E0LJGoyEx//o7+z5DOcxfp0H+nXVd9bKznzde1G 0ejTbeSTZW+h3HqTMKpS3+wLvCSvjlOLFxvYmy3AqrGL0K82TABIRTIUnL0h2l/+7LtD ACCiu0yTBiVlyeIBIosYhLq7epTsA1uAaBoX4y4p9VaJtZnd8HoBDpSGPY2HLsYWMGvn VorSq0LTeWSERBL2A6UgvFMQ1lIUTLS2M05Fj7jI8qP0/8LYhPkjPSynwvbo22dlahXH SUQohPrug66C0zdHvFTJaMC6sCCgftFBJe19z0cl/hF2iMPjRGmwA/3WgaztH6joriHE 3woA== 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:date:to:from:message-id :dkim-signature:delivered-to; bh=n6yWzKFnAySifPYS0IGo4rwKSuG33kvjQciza6zaOx4=; b=IcFNnt9Y9KdCqd+Xs4cbU+uSjxOAGRgIVj3uFlMmuXkDmXCAiVdvazSESnEM6sZea5 xPGNw1kFDSrhw1F33hi3uf+wDY55432Z1aDl49KACryNIPeKo4WVCafZvn9qes0MVnNS ZGwwYSMUktGaMkt9B1v0/5Bqbw8PhWvYFdlyVRhjT5yzpjknA5VxSjNDTSBN1n+DF8tk RM+/4txwxTfom+nSxpqT4SxaVPhUmYey9nO9rjUnI1vDAVypd1uaw6R18MC8UfexyoII cb6/QxnlDHcVVczmKjNBDf8OSEol6YE7Z7IZ7Q3Z4F5zLEl6RMr3tMbgtByrGEHoID2M IB0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@qq.com header.s=s201512 header.b=rCcTHnl0; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id jg39-20020a170907972700b0072b68ce3704si6173360ejc.655.2022.07.22.02.18.16; Fri, 22 Jul 2022 02:18:18 -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=@qq.com header.s=s201512 header.b=rCcTHnl0; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=qq.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5D84968B6CB; Fri, 22 Jul 2022 12:18:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out203-205-251-84.mail.qq.com (unknown [203.205.251.84]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C9CB68B021 for ; Fri, 22 Jul 2022 12:18:04 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1658481479; bh=OGHFX9HWe6Zc2T1rEBUuDpK/z05x1mcKAt/FKflbxVQ=; h=From:To:Cc:Subject:Date; b=rCcTHnl0lfC2sWQadRwPdwUePQh2iWvZL5lQ4uZGjyJneXDelZnCOiyb0S6q2c4Ch Zb6sBascWlb7/CqjyNrqTY0of5rPQvlkMJ7iCRpzFy/dO3U/bdHkljqSwHdbKI+rND 4IwsiM0gGfowYDpPfH5qwD/fK5gWowPbJCvBrYHw= Received: from localhost.localdomain ([103.107.216.232]) by newxmesmtplogicsvrsza9.qq.com (NewEsmtp) with SMTP id 478B4069; Fri, 22 Jul 2022 17:17:56 +0800 X-QQ-mid: xmsmtpt1658481476tu22918gn Message-ID: X-QQ-XMAILINFO: NkHKfw09D6j8eGx/BIGPqSZZmj/nK6DSxThpr8FZn3H6gToMzOp3CzwprtzlmR 5jzsQg4jCJzpFEorMlwYBohkdiZKKxXmI3mVvTx4YHsKVmqVU4iEZOCxDmQHDWTpUUhsbwEmTE2y 3sb1MILbTS5MH4fbXHy0O1Tdef+4Eal+aJUx6vP2ynVPN2SGr8yBQFeuXbkIWFp51N+yPv/QUzGE ylUhgFkmfVR6g0DFUY7zjJIU8FnRTzuAkHcab1zXX4x+8TQlOEen/RuJ8spDsouTmDmrP4v1hxsH 6UouD2GVT1xdT8xKfGyOb6HLz1SMT9hrMSIShDtY1ExK3YATJUNl5Hixl5QrTy/9PKhqJa2prfzb KIikxB7gcSFA+rAzrF85tkUUWt2AQ7GFL9GCSS7qbKMBAUlGNvw4YqtWyOlrhW1Lovf8xWd/7c0T dlHsWDneB/mnd+E5D5qFqUA6MVBBAVCwaXJ45TXQA1wHhc86yUKFWI8M8OrWRHZhCIiqPSFN9sx6 TbZtqLtksLA3TEnUuTj7hD+49Nky7/wgxWteNHjK8BPFwB5GgF1pI3sEEK9b1KsVWyM2bhpfpMbs xhD3Xv9wBnFsSVa/odGqKeHsx4IYNZrV/Uhm94J6DA/94/mUveVqt5AwERVMJ2nkiZzk4k/0n6b8 8cbRKzLjLdmfJXuUJzK5gezuY83zhbZeN4Ufnc9xs/LPNLHdaMUziIPjvkqF7B+0MTI2v3Wovaor xUcC3BVLD6HEJiSw/dfRcQzpF+D3xbfX29W0M7CPRi1nuW2KhyMlwt7R6pWt/rzqhC8EtLxDxDU0 KoWfxePXWmkozk90kgn6dIcjDxVrO4+hH4P1SkQc1f8NFsTUxJKycL00jAcYf0OSxoet6xtuiHGm RQ8SjrPTsVXa8YSI48CXXXvuhXBcDybujiHIo3ETOwhIsAUNl8grLvHOsu+3ZJHf4FyOraZ940ao OU1FwS16k6vDJkLzSGuKS0UGzb2z/awJtmxkH+QDuHs0uphw9MZg== From: 1035567130@qq.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Jul 2022 17:17:55 +0800 X-OQ-MSGID: <20220722091755.84000-1-1035567130@qq.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mov: get the correct fragment stream info when decrypting the sample 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: Wang Yaqiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BSXEJjoHvZ1J From: Wang Yaqiang When using mov_read_packet get a pkt, and the packet is encrypted, it will invoke the cenc_filter func for process the decryption. This function find the frag_stream_info according to frag_index.current, but the value of frag_index.current is equal to the last read index of moof box, this will cause pkt and frag_stream_info mismatch Signed-off-by: Wang Yaqiang --- libavformat/isom.h | 2 ++ libavformat/mov.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index f05c2d9c28..d90e16457b 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -137,6 +137,8 @@ typedef struct MOVFragmentStreamInfo { int64_t next_trun_dts; int index_entry; MOVEncryptionIndex *encryption_index; + int stsd_id; // current fragment stsd_id + int64_t max_pos; //current fragment max pos } MOVFragmentStreamInfo; typedef struct MOVFragmentIndexItem { diff --git a/libavformat/mov.c b/libavformat/mov.c index a09a762d91..c118072931 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1182,6 +1182,20 @@ static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; /* now go for mdat */ } +static int get_frag_index_with_pkt(MOVFragmentIndex *frag_index, AVPacket *pkt) +{ + if (!pkt) return -1; + for (int i = 0; i < frag_index->nb_items;i++) { + MOVFragmentStreamInfo *frag_stream_info = frag_index->item[i].stream_info; + if (frag_stream_info) { + if (pkt->pos + pkt->size <= frag_stream_info->max_pos) { + return i; + } + } + } + return -1; +} + static MOVFragmentStreamInfo * get_frag_stream_info( MOVFragmentIndex *frag_index, int index, @@ -4868,9 +4882,10 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "frag flags 0x%x\n", frag->flags); frag_stream_info = get_current_frag_stream_info(&c->frag_index); - if (frag_stream_info) + if (frag_stream_info) { frag_stream_info->next_trun_dts = AV_NOPTS_VALUE; - + frag_stream_info->stsd_id = frag->stsd_id; + } return 0; } @@ -5335,9 +5350,10 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) index = update_frag_index(c, offset); frag_stream_info = get_frag_stream_info(&c->frag_index, index, track_id); - if (frag_stream_info) + if (frag_stream_info) { frag_stream_info->sidx_pts = timestamp; - + frag_stream_info->max_pos = offset + size; + } if (av_sat_add64(offset, size) != offset + (uint64_t)size || av_sat_add64(pts, duration) != pts + (uint64_t)duration ) @@ -7101,13 +7117,16 @@ static int cenc_filter(MOVContext *mov, AVStream* st, MOVStreamContext *sc, AVPa MOVEncryptionIndex *encryption_index; AVEncryptionInfo *encrypted_sample; int encrypted_index, ret; - - frag_stream_info = get_frag_stream_info(&mov->frag_index, mov->frag_index.current, st->id); + int frag_index = get_frag_index_with_pkt(&mov->frag_index,pkt); + if (frag_index < 0) { + frag_index = mov->frag_index.current; + } + frag_stream_info = get_frag_stream_info(&mov->frag_index,frag_index, st->id); encrypted_index = current_index; encryption_index = NULL; if (frag_stream_info) { // Note this only supports encryption info in the first sample descriptor. - if (mov->fragment.stsd_id == 1) { + if (frag_stream_info->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;