From patchwork Thu Feb 24 11:48:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34513 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1750745nkx; Thu, 24 Feb 2022 03:49:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCucqhWWBgTaAJ0ru5//aRxS7x2cFDwJ9UHyrGtzLVOpfPaL9NstP324jReMWcB8B9paMo X-Received: by 2002:a05:6402:2750:b0:412:f7a6:6d52 with SMTP id z16-20020a056402275000b00412f7a66d52mr1940438edd.187.1645703374892; Thu, 24 Feb 2022 03:49:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645703374; cv=none; d=google.com; s=arc-20160816; b=NqL9XGy8SnHFBUuJqcPbaOwSsw0/hnNRQuq+5+h3rcOT0CQEU4hNMWW+Gx1qDsHoNu S8AcQtCjVmjjMVitRf7zMIHqR4uGbvxhB00P3LxDl1Lmr8l/i77LaXubMalezwLvyzK6 K6s5B5kfD1KFp5pF60mE06N6OGujNOP5LbnkmGCwzv/ZbR8U0gVGtiaRRz5KEmuAISBR qa0qRSh2LkgiWm4u2HGBPpqEbNtM4TfPqBxtRFU7zJXuHALguqbuY3kQfd+rR2k0zYgL uAOpKvPUnqs5yeW0CQbo7i4uBLRgzLIHpzz9yxKGoupK0bs3Dw0a4+dXQ1uNLKecuqK7 I3jQ== 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 :message-id:date:to:from:dkim-signature:delivered-to; bh=yZ0DrCiS7NbTYn22y3norhJVzM3anTlEGC4SYOgEFYE=; b=aLYlLW2jmScqWmq2y1XYsY3uayDCdHZfEQILnyoP9Dvs2oJmZhHYWl2YeL/z8uMIw+ cmecA7A2h0DEkeNddsEK6Sk/px+HPkiGzDdp4UkUUOsxO9DTY7EZsWdjjQ+8S0b/u3jG zEPDYK5j4DrzzPGHUQCbICn27iiWRPatBvue1qweIRbTnVwzf1bSXAEixpGuyljtxFsh KXfRoAutQWqD22JJTOLyzpI+bETiCnkK5IEyf6ktKSthetlg2DiadHvw3d2VljBL7jJs xYl9FlgdkFafrNXt4tBHMYsz0+bP1Kp2wdeWEgyfIlo5VaqVJRuSFgX3jmbHtOMrJ2HD qAQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=OH+zxMrP; 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=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b3si1298092eds.472.2022.02.24.03.49.34; Thu, 24 Feb 2022 03:49:34 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=OH+zxMrP; 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=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D07B068B32A; Thu, 24 Feb 2022 13:49:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 16E0D68B31E for ; Thu, 24 Feb 2022 13:49:12 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645703346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHcJ9E6Czagwq12x8X7Rivq/nVJEMd0c0ePANwkLqwc=; b=OH+zxMrPpdfstdhXcfKDXpwMjw2xvuW1GUibu788b2lE0ciysHSE4hOhGeAWW10S48Jncf qt1aLvLU7XULYD46QBlTdk7Xv38mwjw4lHxMPx75HD7PjQnqx5PZF308bt53M1INlX49+R HB3GbPDpFEztONHBWZQ8jB1/2IKl5Fo= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id d117249d; Thu, 24 Feb 2022 11:49:06 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 12:48:59 +0100 Message-Id: <20220224114903.251006-2-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224114903.251006-1-u@pkh.me> References: <20220224114903.251006-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/5] avformat/mov: prepare sbgp parsing for other grouping types 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6kCDY7RbL7gD --- libavformat/mov.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 5e26267810..aade052b7a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3137,6 +3137,8 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) unsigned int i, entries; uint8_t version; uint32_t grouping_type; + MOVSbgp *table, **tablep; + int *table_count; if (c->fc->nb_streams < 1) return 0; @@ -3146,28 +3148,34 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) version = avio_r8(pb); /* version */ avio_rb24(pb); /* flags */ grouping_type = avio_rl32(pb); - if (grouping_type != MKTAG( 'r','a','p',' ')) - return 0; /* only support 'rap ' grouping */ + + if (grouping_type == MKTAG('r','a','p',' ')) { + tablep = &sc->rap_group; + table_count = &sc->rap_group_count; + } else { + return 0; + } + if (version == 1) avio_rb32(pb); /* grouping_type_parameter */ entries = avio_rb32(pb); if (!entries) return 0; - if (sc->rap_group) - av_log(c->fc, AV_LOG_WARNING, "Duplicated SBGP atom\n"); - av_free(sc->rap_group); - sc->rap_group_count = 0; - sc->rap_group = av_malloc_array(entries, sizeof(*sc->rap_group)); - if (!sc->rap_group) + if (*tablep) + av_log(c->fc, AV_LOG_WARNING, "Duplicated SBGP %s atom\n", av_fourcc2str(grouping_type)); + av_freep(tablep); + table = av_malloc_array(entries, sizeof(*table)); + if (!table) return AVERROR(ENOMEM); + *tablep = table; for (i = 0; i < entries && !pb->eof_reached; i++) { - sc->rap_group[i].count = avio_rb32(pb); /* sample_count */ - sc->rap_group[i].index = avio_rb32(pb); /* group_description_index */ + table[i].count = avio_rb32(pb); /* sample_count */ + table[i].index = avio_rb32(pb); /* group_description_index */ } - sc->rap_group_count = i; + *table_count = i; if (pb->eof_reached) { av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SBGP atom\n"); From patchwork Thu Feb 24 11:49:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34514 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1750843nkx; Thu, 24 Feb 2022 03:49:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwMd4r0zBtofEBaba3s1NmjnixXXabWtQEtTX+WUdAoqKOOzcrb0Fd4dM9vPdlFewgygyS X-Received: by 2002:a17:906:40da:b0:6ce:51b:a593 with SMTP id a26-20020a17090640da00b006ce051ba593mr1988692ejk.604.1645703384368; Thu, 24 Feb 2022 03:49:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645703384; cv=none; d=google.com; s=arc-20160816; b=u1n0WOMuOAjdIkZgDNGca/XhR7VZwqU9eDObsMe/MBZuitRi/d2r+z5LNBUV8wUOZS Btlk4TajxdBSYfRYAB5xpWMebNCd2HBk4gxpimetu0BUnarAgv6Ha9R2I9Wq3RSLL2fZ VkBryDC90Neq10lUc3CO3jLI+yWAnY3Ub0AycTl31zAVlxF/Jj/qNUhSI0q1UAiJQFzy W/PaNjFz5s8K2Ox5tWDYyPkz1EzHVTAgifaPwW+tqUKEY7oPFQRBjt3SRLRia0R40qSQ ocEuuQQNoRJrRW3IRJZmUv65mLju8yDszN8NpAKvLNzFrxn1XrjVY6uAsnangNfqXDbI A/6w== 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 :message-id:date:to:from:dkim-signature:delivered-to; bh=nfsBPE4VyMJkJ1iEe2Io22SQ10odDfR+OYyEoRw7IL8=; b=auqzwtF4zO1LFeTC3e9KaD2FHS96/8ekTjnuCkFJINVDFs+75epTQhASo4fogIUxGA A5R7jKcRfToQbeAIEEPCzv4863Xyw3259CG61i9wUgOdVU+feW4s5cQ0XcOT91Khp+WM kF/97h2wXwm5XLKa6svexyRdKl/j/DEUpLGy+JB6njDv2iBLKEXP7m/ZzZ31Qk+uyCQn foFbYM36a7RonUVGQ+Nwv7RxiyW0jazKghD3Zof7F173MrnsY49by17P1Y1bofnbtGgy xcy7x/IsHd4mDzDgKUMSdnb75CLj1l6FZX+GTcesfAMhJCmwS761cEnfh0WI2Sehqz0O Xwxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=MKnCFJhL; 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=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t1si1472298edd.119.2022.02.24.03.49.44; Thu, 24 Feb 2022 03:49:44 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=MKnCFJhL; 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=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6EF5A68B334; Thu, 24 Feb 2022 13:49:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F419C68B324 for ; Thu, 24 Feb 2022 13:49:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645703347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2rFUjeAYkxRG68Z7RjVeRyq+gS2vrjL2QLJv8LT5wg8=; b=MKnCFJhLf7VTbqKpFm2HIfBFofW0W1JaTBFVg7kHBhRXb5fBm9XXEpDBWETInQ7ly3uv1j 2E/HnhGi6yUsslTn5eYluYYKoeOVHYJCGpj0sXF/E/n32m4hNF1f76NVsBvKiGozf1qkN1 jjWhuCWemPPiEU5QX68zSoM+ZiPxHYo= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id d7aa120a; Thu, 24 Feb 2022 11:49:07 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 12:49:00 +0100 Message-Id: <20220224114903.251006-3-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224114903.251006-1-u@pkh.me> References: <20220224114903.251006-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 2/5] avformat/mov: add support for sync group in sbgp box 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: a+kL5fMp+/pa --- libavformat/isom.h | 2 ++ libavformat/mov.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index 625dea8421..e326f4f27f 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -218,6 +218,8 @@ typedef struct MOVStreamContext { int start_pad; ///< amount of samples to skip due to enc-dec delay unsigned int rap_group_count; MOVSbgp *rap_group; + unsigned int sync_group_count; + MOVSbgp *sync_group; int nb_frames_for_fps; int64_t duration_for_fps; diff --git a/libavformat/mov.c b/libavformat/mov.c index aade052b7a..ebc397e573 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3152,6 +3152,9 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (grouping_type == MKTAG('r','a','p',' ')) { tablep = &sc->rap_group; table_count = &sc->rap_group_count; + } else if (grouping_type == MKTAG('s','y','n','c')) { + tablep = &sc->sync_group; + table_count = &sc->sync_group_count; } else { return 0; } @@ -4371,6 +4374,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_freep(&sc->stps_data); av_freep(&sc->elst_data); av_freep(&sc->rap_group); + av_freep(&sc->sync_group); return 0; } @@ -7708,6 +7712,7 @@ static int mov_read_close(AVFormatContext *s) av_freep(&sc->stps_data); av_freep(&sc->elst_data); av_freep(&sc->rap_group); + av_freep(&sc->sync_group); av_freep(&sc->display_matrix); av_freep(&sc->index_ranges); From patchwork Thu Feb 24 11:49:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34515 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1750973nkx; Thu, 24 Feb 2022 03:49:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5zb87G98sp8Oy4jx/Hj/JwRcRhF2PnZks9ZHa+pAEa9YHNn6C2OLEzPIQmfhRk8ORvFLy X-Received: by 2002:a17:907:6890:b0:6b4:88e2:aa24 with SMTP id qy16-20020a170907689000b006b488e2aa24mr1967326ejc.66.1645703395503; Thu, 24 Feb 2022 03:49:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645703395; cv=none; d=google.com; s=arc-20160816; b=SJwTnOnHQYUccjGsz64az4EuQvkjYyjpMcxbsBz15nhMWcGf4A3x3UPLyI5yBL4YGz sjbtFVJjfbBCLj6an5CAl/m1LHZq1jwnwWkSiufD/Vd0/OzcK5HQVwSWcKlFm+iVKWlZ gpDkZ1ReGilv6o1c0AY9PmLC5zh1Uz7FEi8PucUimK0kCj4/FzAfYiwzYVYM5Aw6cpik nCQHQV1W8CSwejAzlQ0oD/PEcpGFgmazwDZ5sHaHe5MXFFq3hiARJt88Hrum8zpMH1AU NGdIG2dj9VWd1u1gArBuVuy/annS73TWuvAbXhUhEPFdIGjiKQwQvpLt7tyAwenqz4pt 8MRw== 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 :message-id:date:to:from:dkim-signature:delivered-to; bh=TjNuiRlVBwlpTyMTLkDHajkfOkcmbb5pz9QkZh8jQsU=; b=wOfxhGUWnepEFAwmxu3Nje8fcSHaPRsCgWPK75kEoX4eFdmKFw+5wbJ9xLf3E/zZd9 y+43FO2uj/PytRDIhIgMXcJn5YGiD5N73hmaxN5LGkPGHtCXVC7iKIlYIvjE82ZD9V50 Y1QwG5j44chHEse7bvwr0wtDZXVcKTozl3qdbxn8PzRWUdq4cph+7oU/wh9gMa38VJUn AYWfh1N4N9L4jGLhmc7IZ8VN/AQG0fkieUBZNfNlC8PLaj70xvtduqx3X/vivHrvzBFa C9B+CuGFDhSByY7MoPFLzjmiEgJFO0tV2QXKrqrfL6yf0oHcbWl+nu9kMt1xanK6kw2A l01g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=DPIklLek; 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=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j10si1408062edt.555.2022.02.24.03.49.55; Thu, 24 Feb 2022 03:49:55 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=DPIklLek; 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=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7E01568B326; Thu, 24 Feb 2022 13:49:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE2826806E8 for ; Thu, 24 Feb 2022 13:49:16 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645703347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nl+4XVzTmTo77XAK67uh2ID1j6bvmH6Zc3NKIvrvxik=; b=DPIklLekFuhFfkCJzL3TNQaLnIRXm7mPtcOfHHRP9y6gjxrPpdmCDJ1pz24iEsldyOT9rl fMRqS0MM+OQUlWWASDxs2JxhB+joxLTMBFuwq/wT7dHiEw94PHsyAhVDhyyepbtqMWs8BC OTntkFJukTfdlfUfPn4yaLQbszjO9bo= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id e5041655; Thu, 24 Feb 2022 11:49:07 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 12:49:01 +0100 Message-Id: <20220224114903.251006-4-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224114903.251006-1-u@pkh.me> References: <20220224114903.251006-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 3/5] avformat/mov: add parsing for the sgpd sync box 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: A7UtSMfR6iG3 sgpd means Sample Group Description Box. For now, only the sync grouping type is parsed, but the function can easily be adjusted to support other flavours. The sbgp (Sample to Group Box) sync_group table built in previous commit contains references to this table through the group_description_index field. --- libavformat/isom.h | 2 ++ libavformat/mov.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index e326f4f27f..bbe395ee4b 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -220,6 +220,8 @@ typedef struct MOVStreamContext { MOVSbgp *rap_group; unsigned int sync_group_count; MOVSbgp *sync_group; + uint8_t *sgpd_sync; + uint32_t sgpd_sync_count; int nb_frames_for_fps; int64_t duration_for_fps; diff --git a/libavformat/mov.c b/libavformat/mov.c index ebc397e573..6b22d8c5f8 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3130,6 +3130,62 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_sgpd(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + MOVStreamContext *sc; + uint8_t version; + uint32_t grouping_type; + uint32_t default_length; + av_unused uint32_t default_group_description_index; + uint32_t entry_count; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams - 1]; + sc = st->priv_data; + + version = avio_r8(pb); /* version */ + avio_rb24(pb); /* flags */ + grouping_type = avio_rl32(pb); + + /* + * This function only supports "sync" boxes, but the code is able to parse + * other boxes (such as "tscl", "tsas" and "stsa") + */ + if (grouping_type != MKTAG('s','y','n','c')) + return 0; + + default_length = version >= 1 ? avio_rb32(pb) : 0; + default_group_description_index = version >= 2 ? avio_rb32(pb) : 0; + entry_count = avio_rb32(pb); + + av_freep(&sc->sgpd_sync); + sc->sgpd_sync_count = entry_count; + sc->sgpd_sync = av_calloc(entry_count, sizeof(*sc->sgpd_sync)); + if (!sc->sgpd_sync) + return AVERROR(ENOMEM); + + for (uint32_t i = 0; i < entry_count && !pb->eof_reached; i++) { + uint32_t description_length = default_length; + if (version >= 1 && default_length == 0) + description_length = avio_rb32(pb); + if (grouping_type == MKTAG('s','y','n','c')) { + const uint8_t nal_unit_type = avio_r8(pb) & 0x3f; + sc->sgpd_sync[i] = nal_unit_type; + description_length -= 1; + } + avio_skip(pb, description_length); + } + + if (pb->eof_reached) { + av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SGPD atom\n"); + return AVERROR_EOF; + } + + return 0; +} + static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -4375,6 +4431,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_freep(&sc->elst_data); av_freep(&sc->rap_group); av_freep(&sc->sync_group); + av_freep(&sc->sgpd_sync); return 0; } @@ -7253,6 +7310,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('c','m','o','v'), mov_read_cmov }, { MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */ { MKTAG('d','v','c','1'), mov_read_dvc1 }, +{ MKTAG('s','g','p','d'), mov_read_sgpd }, { MKTAG('s','b','g','p'), mov_read_sbgp }, { MKTAG('h','v','c','C'), mov_read_glbl }, { MKTAG('u','u','i','d'), mov_read_uuid }, @@ -7713,6 +7771,7 @@ static int mov_read_close(AVFormatContext *s) av_freep(&sc->elst_data); av_freep(&sc->rap_group); av_freep(&sc->sync_group); + av_freep(&sc->sgpd_sync); av_freep(&sc->display_matrix); av_freep(&sc->index_ranges); From patchwork Thu Feb 24 11:49:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34516 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1751089nkx; Thu, 24 Feb 2022 03:50:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGjrjYQwhPWIntzbsdJUg03PSvZobBFkmAZkUoTaCiDUAs3gY3rnpclVcs2EEEQLOI7IF9 X-Received: by 2002:a17:906:eb0f:b0:6af:738:3380 with SMTP id mb15-20020a170906eb0f00b006af07383380mr1924722ejb.398.1645703406853; Thu, 24 Feb 2022 03:50:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645703406; cv=none; d=google.com; s=arc-20160816; b=WNvsPwP4r5El/u68XNc/n8OJCV4PXaMoCluKeMOXTGCYtX6HJjnTkGKFv+lVlSC8ka /7S4XKHKZpMicrw5CGZPpsT9WvcfE11zQtVZq8NzLtODBrMF9HwcrxAeMAJBIk1APr2q VKS0ccVXaLsRrado8xevwfeyKyno0l74oBwU6WFj1PH7jQq9W1m5+J6SV9W7HOWD+kzq fcrTRaGjbTffuXksCjWdFtiL6+Z2wxnWj2FdWoBa6rNVCEDgYvDn96U53tXHsivwpvRa MJw0Q7M5yoeI4QgxIzLDcc20sWwTr3QOe4h04+WOru7e9pstSAryqnIe9Z5PMctBzx/N Pjdw== 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 :message-id:date:to:from:dkim-signature:delivered-to; bh=9KAP+PuFAbUvcj/spqt0YlD70Rvsz4pkhFkB5JvYMkE=; b=A7xykUDe8h8HmlDrgfGlfVKTmndFlogAuHe+aLwZ9GfhPNsfegn7DeO0Zv3v/LojVi ruSPJXku0arrQ+SSufS7USoj4japsaK3/mLDSkZt0TEYjsdx29JvKfr56pO7SKPat2q2 5C1+8NZarn4X1W3q4MiJ7n+Gu49Vv7FxY+tOe6IOgSvweSgP/nv0Dm6fLL6tLS4gUsjy DAAGdFT0bwjmBxz+Gyw57ATOmFsodg5VJPslrl4HzHkG5DG+cVHOxx1T/GCIKH1mDAx6 fBWN+z2cjiOGRx+abTHk0eM+BAGW8AMyWeyxO4fq9wmhDtN3EX7DvHk6R6y8L2e7AgzC oTkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=XS7D79ht; 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=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g3si1941689ejt.122.2022.02.24.03.50.06; Thu, 24 Feb 2022 03:50:06 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=XS7D79ht; 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=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9ECBC68B33C; Thu, 24 Feb 2022 13:49:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4589E68B333 for ; Thu, 24 Feb 2022 13:49:17 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645703347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dPAAPYpZOBhPZGyIoZhXU+/6k7pl2W1viI2sCbOCpbg=; b=XS7D79ht1mP1MFhwWUXHKGvhOCEAdyunK3MVJGwQEsdDmlJ02tzrceCuvK8jpKhWt0/Ooj j7kB2w0fHM7PBF5R8XLblGtuxQWpvzgtpk/RmRsGGObsWidd9FuNxungtkpM6mu9Jqss7Y cZkWIEvS4HteR5Raxf5sTzI5gr2R/m4= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 8529ccf9; Thu, 24 Feb 2022 11:49:07 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 12:49:02 +0100 Message-Id: <20220224114903.251006-5-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224114903.251006-1-u@pkh.me> References: <20220224114903.251006-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/5] avformat/mov: fix seeking with HEVC open GOP files 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: mOB4Wmzc+QyX This was tested with medias recorded from an iPhone XR and an iPhone 13. Here is how a typical stream looks like in coding order: ┌────────┬─────┬─────┬──────────┐ │ sample | PTS | DTS | keyframe | ├────────┼─────┼─────┼──────────┤ ┊ ┊ ┊ ┊ ┊ │ 53 │ 560 │ 510 │ No │ │ 54 │ 540 │ 520 │ No │ │ 55 │ 530 │ 530 │ No │ │ 56 │ 550 │ 540 │ No │ │ 57 │ 600 │ 550 │ Yes │ │ * 58 │ 580 │ 560 │ No │ │ * 59 │ 570 │ 570 │ No │ │ * 60 │ 590 │ 580 │ No │ │ 61 │ 640 │ 590 │ No │ │ 62 │ 620 │ 600 │ No │ ┊ ┊ ┊ ┊ ┊ In composition/display order: ┌────────┬─────┬─────┬──────────┐ │ sample | PTS | DTS | keyframe | ├────────┼─────┼─────┼──────────┤ ┊ ┊ ┊ ┊ ┊ │ 55 │ 530 │ 530 │ No │ │ 54 │ 540 │ 520 │ No │ │ 56 │ 550 │ 540 │ No │ │ 53 │ 560 │ 510 │ No │ │ * 59 │ 570 │ 570 │ No │ │ * 58 │ 580 │ 560 │ No │ │ * 60 │ 590 │ 580 │ No │ │ 57 │ 600 │ 550 │ Yes │ │ 63 │ 610 │ 610 │ No │ │ 62 │ 620 │ 600 │ No │ ┊ ┊ ┊ ┊ ┊ Sample/frame 58, 59 and 60 are B-frames which actually depends on the key frame (57). Here the key frame is not an IDR but a "CRA" (Clean Random Access). Initially, I thought I could rely on the sdtp box (independent and disposable samples), but unfortunately: sdtp[54] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[55] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[56] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[57] is_leading:0 sample_depends_on:2 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[58] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[59] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[60] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[61] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[62] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 The information that might have been useful here would have been is_leading, but all the samples are set to 0 so this was unusable. Instead, we need to rely on sgpd/sbgp tables. In my case the video track contained 3 sgpd tables with the following grouping types: tscl, sync and tsas. In the sync table we have the following 2 entries (only): sgpd.sync[1]: sync nal_unit_type:0x14 sgpd.sync[2]: sync nal_unit_type:0x15 (The count starts at 1 because 0 carries the undefined semantic, we'll see that later in the reference table). The NAL unit types presented here correspond to: libavcodec/hevc.h: HEVC_NAL_IDR_N_LP = 20, libavcodec/hevc.h: HEVC_NAL_CRA_NUT = 21, In parallel, the sbgp sync table contains the following: ┌────┬───────┬─────┐ │ id │ count │ gdi │ ├────┼───────┼─────┤ │ 0 │ 1 │ 1 │ │ 1 │ 56 │ 0 │ │ 2 │ 1 │ 2 │ │ 3 │ 59 │ 0 │ │ 4 │ 1 │ 2 │ │ 5 │ 59 │ 0 │ │ 6 │ 1 │ 2 │ │ 7 │ 59 │ 0 │ │ 8 │ 1 │ 2 │ │ 9 │ 59 │ 0 │ │ 10 │ 1 │ 2 │ │ 11 │ 11 │ 0 │ └────┴───────┴─────┘ The gdi column (group description index) directly refers to the index in the sgpd.sync table. This means the first frame is an IDR, then we have batches of undefined frames interlaced with CRA frames. No IDR ever appears again (tried on a 30+ seconds sample). With that information, we can build an heuristic using the presentation order. A few things needed to be introduced in this commit: 1. min_sample_duration is extracted from the stts: we need the minimal step between sample in order to PTS-step backward to a valid point 2. In order to avoid a loop over the ctts table systematically during a seek, we build an expanded list of sample offsets which will be used to translate from DTS to PTS 3. An open_key_samples index to keep track of all the non-IDR key frames; for now it only supports HEVC CRA frames. We should probably add BLA frames as well, but I don't have any sample so I prefered to leave that for later It is entirely possible I missed something obvious in my approach, but I couldn't come up with a better solution. Also, as mentioned in the diff, we could optimize is_open_key_sample(), but the linear scaling overhead should be fine for now since it only happens in seek events. Fixing this issue prevents sending broken packets to the decoder. With FFmpeg hevc decoder the frames are skipped, with VideoToolbox the frames are glitching. --- libavformat/isom.h | 5 ++ libavformat/mov.c | 120 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index bbe395ee4b..5caf42b15d 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -222,6 +222,11 @@ typedef struct MOVStreamContext { MOVSbgp *sync_group; uint8_t *sgpd_sync; uint32_t sgpd_sync_count; + int32_t *sample_offsets; + int sample_offsets_count; + int *open_key_samples; + int open_key_samples_count; + uint32_t min_sample_duration; int nb_frames_for_fps; int64_t duration_for_fps; diff --git a/libavformat/mov.c b/libavformat/mov.c index 6b22d8c5f8..573ee8bda3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -50,6 +50,7 @@ #include "libavutil/dovi_meta.h" #include "libavcodec/ac3tab.h" #include "libavcodec/flac.h" +#include "libavcodec/hevc.h" #include "libavcodec/mpegaudiodecheader.h" #include "libavcodec/mlp_parse.h" #include "avformat.h" @@ -3882,6 +3883,69 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) msc->current_index = msc->index_ranges[0].start; } +static uint32_t get_sgpd_sync_index(const MOVStreamContext *sc, int nal_unit_type) +{ + for (uint32_t i = 0; i < sc->sgpd_sync_count; i++) + if (sc->sgpd_sync[i] == HEVC_NAL_CRA_NUT) + return i + 1; + return 0; +} + +static int build_open_gop_key_points(AVStream *st) +{ + int k; + int sample_id = 0; + uint32_t cra_index; + MOVStreamContext *sc = st->priv_data; + + if (st->codecpar->codec_id != AV_CODEC_ID_HEVC || !sc->sync_group_count) + return 0; + + /* Build an unrolled index of the samples */ + sc->sample_offsets_count = 0; + for (uint32_t i = 0; i < sc->ctts_count; i++) + sc->sample_offsets_count += sc->ctts_data[i].count; + av_freep(&sc->sample_offsets); + sc->sample_offsets = av_calloc(sc->sample_offsets_count, sizeof(*sc->sample_offsets)); + if (!sc->sample_offsets) + return AVERROR(ENOMEM); + k = 0; + for (uint32_t i = 0; i < sc->ctts_count; i++) + for (int j = 0; j < sc->ctts_data[i].count; j++) + sc->sample_offsets[k++] = sc->ctts_data[i].duration; + + /* The following HEVC NAL type reveal the use of open GOP sync points + * (TODO: BLA types may also be concerned) */ + cra_index = get_sgpd_sync_index(sc, HEVC_NAL_CRA_NUT); /* Clean Random Access */ + if (!cra_index) + return 0; + + /* Build a list of open-GOP key samples */ + sc->open_key_samples_count = 0; + for (uint32_t i = 0; i < sc->sync_group_count; i++) + if (sc->sync_group[i].index == cra_index) + sc->open_key_samples_count += sc->sync_group[i].count; + av_freep(&sc->open_key_samples); + sc->open_key_samples = av_calloc(sc->open_key_samples_count, sizeof(*sc->open_key_samples)); + if (!sc->open_key_samples) + return AVERROR(ENOMEM); + k = 0; + for (uint32_t i = 0; i < sc->sync_group_count; i++) { + const MOVSbgp *sg = &sc->sync_group[i]; + if (sg->index == cra_index) + for (uint32_t j = 0; j < sg->count; j++) + sc->open_key_samples[k++] = sample_id; + sample_id += sg->count; + } + + /* Identify the minimal time step between samples */ + sc->min_sample_duration = UINT_MAX; + for (uint32_t i = 0; i < sc->stts_count; i++) + sc->min_sample_duration = FFMIN(sc->min_sample_duration, sc->stts_data[i].duration); + + return 0; +} + static void mov_build_index(MOVContext *mov, AVStream *st) { MOVStreamContext *sc = st->priv_data; @@ -3897,6 +3961,10 @@ static void mov_build_index(MOVContext *mov, AVStream *st) MOVCtts *ctts_data_old = sc->ctts_data; unsigned int ctts_count_old = sc->ctts_count; + int ret = build_open_gop_key_points(st); + if (ret < 0) + return; + if (sc->elst_count) { int i, edit_start_index = 0, multiple_edits = 0; int64_t empty_duration = 0; // empty duration of the first edit list entry @@ -7772,6 +7840,8 @@ static int mov_read_close(AVFormatContext *s) av_freep(&sc->rap_group); av_freep(&sc->sync_group); av_freep(&sc->sgpd_sync); + av_freep(&sc->sample_offsets); + av_freep(&sc->open_key_samples); av_freep(&sc->display_matrix); av_freep(&sc->index_ranges); @@ -8444,6 +8514,49 @@ static int mov_seek_fragment(AVFormatContext *s, AVStream *st, int64_t timestamp return 0; } +static int is_open_key_sample(const MOVStreamContext *sc, int sample) +{ + // TODO: a bisect search would scale much better + for (int i = 0; i < sc->open_key_samples_count; i++) { + const int oks = sc->open_key_samples[i]; + if (oks == sample) + return 1; + if (oks > sample) /* list is monotically increasing so we can stop early */ + break; + } + return 0; +} + +/* + * Some key sample may be key frames but not IDR frames, so a random access to + * them may not be allowed. + */ +static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pts) +{ + MOVStreamContext *sc = st->priv_data; + FFStream *const sti = ffstream(st); + int64_t key_sample_dts, key_sample_pts; + + if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) + return 1; + + if (sample >= sc->sample_offsets_count) + return 1; + + key_sample_dts = sti->index_entries[sample].timestamp; + key_sample_pts = key_sample_dts + sc->sample_offsets[sample] + sc->dts_shift; + + /* + * If the sample needs to be presented before an open key sample, they may + * not be decodable properly, even though they come after in decoding + * order. + */ + if (is_open_key_sample(sc, sample) && key_sample_pts > requested_pts) + return 0; + + return 1; +} + static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags) { MOVStreamContext *sc = st->priv_data; @@ -8459,12 +8572,19 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, if (ret < 0) return ret; + for (;;) { sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; + + if (!sample || can_seek_to_key_sample(st, sample, timestamp)) + break; + timestamp -= FFMAX(sc->min_sample_duration, 1); + } + mov_current_sample_set(sc, sample); av_log(s, AV_LOG_TRACE, "stream %d, found sample %d\n", st->index, sc->current_sample); /* adjust ctts index */ From patchwork Thu Feb 24 11:49:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34517 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1751189nkx; Thu, 24 Feb 2022 03:50:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRFQ9jTZGcm2QeHe7YIY5+VTa2eELm2fixNQb4fubb+lilkUVKoCMgwqX7i3I4CIJCusZX X-Received: by 2002:aa7:d453:0:b0:410:d407:da20 with SMTP id q19-20020aa7d453000000b00410d407da20mr1946402edr.351.1645703417284; Thu, 24 Feb 2022 03:50:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645703417; cv=none; d=google.com; s=arc-20160816; b=aURRljvSVQ9OxURo9k3m4FZbyH866n7ivnXLzVSyMdty02071Dp5A096i0i459UNMh zyH2PaM7tnYqtWsTEvU4jMMdrBgwo6RSqEiYonr/kQbH0WylE2vwIxgMcdSxJ6TgjWZg biesEWHaqh8UZHqCFw++g7TLXZiODtVOJZAR8gfiW4dINqZ6OHafjSadFAi0cSJkwplw MWyvqoUFGaD4i5M5UBsCjhBUL0WMUKof7VzVTGzWleab+Y6kmkGqsgxqE4jJajL9Y78W 9pmNDg22nr/sA6EFWOy33a2Hf1nzIbxZQ9fRIhu5tzWArrG1KuXq32N78nILE6jzO2E+ MQ6Q== 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 :message-id:date:to:from:dkim-signature:delivered-to; bh=EkAgDu1zT2utWUx74cCJEDkZuM1T7MjWrPK6B5kUWnM=; b=iPV096L/+COl2cBL5SRaZrBYlNHeRnD4pMurbDjYsED7VSdoWAx0pczMa41xI9lUv7 we5shwGJwOulN9bDV66gRLPzu0qn23AQf6sZdkPVYvfQKaPj2jGwN4IfaclFqygdsTFp B5aDgtLUbS/DmYqfgtGVB66BlpCU4Srg9UA0mtF2twjCRuqglOeN+LKcXEpwcIidWhUB 7kfm/zVZ+dmK5/QUg1u+6LgsblKXkJeRPkLvHIThBtZEERcA4Rce4nE4Q1zc+xRD6XNg 3Pu9Bo80s5zOQRAWLJidJYJtyvhKLw7S+rlC9g2UD/odeM6akc0apVWdsGsOB3f/OmJQ Fxzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=OTlntn3O; 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=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x6si1365220eds.594.2022.02.24.03.50.17; Thu, 24 Feb 2022 03:50:17 -0800 (PST) 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=@pkh.me header.s=selector1 header.b=OTlntn3O; 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=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F12C268B34A; Thu, 24 Feb 2022 13:49:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3000868B339 for ; Thu, 24 Feb 2022 13:49:20 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645703347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zd8SD2eHZYbwXGYvwZkVLjEoxzM4zuCDkHZrqWEK7GE=; b=OTlntn3OoFT7UocBwm0WxnAS4RRcA+IyCWuS7Z9Rui0c2pwq8UgISPF8tPUlYt5ZvswdLs N2Iwi8GIOGsi3Z0Umfs03X7bssxeQHSMHIT8b3CHIuOXrljK6jU+mBCJ1Z2nypJZZX3ZGX 4sGO5E1uc/qThmDqP/0h5HsX/2CBkTg= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id b034fe32; Thu, 24 Feb 2022 11:49:07 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Feb 2022 12:49:03 +0100 Message-Id: <20220224114903.251006-6-u@pkh.me> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220224114903.251006-1-u@pkh.me> References: <20220224114903.251006-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 5/5] avformat/mov: reindent after previous commit 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 7wCEksrvk73o --- libavformat/mov.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 573ee8bda3..86b0651697 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8573,12 +8573,12 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, return ret; for (;;) { - sample = av_index_search_timestamp(st, timestamp, flags); - av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); - if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) - sample = 0; - if (sample < 0) /* not sure what to do */ - return AVERROR_INVALIDDATA; + sample = av_index_search_timestamp(st, timestamp, flags); + av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); + if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) + sample = 0; + if (sample < 0) /* not sure what to do */ + return AVERROR_INVALIDDATA; if (!sample || can_seek_to_key_sample(st, sample, timestamp)) break;