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);