Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: "Clément Bœsch" <u@pkh.me>
To: ffmpeg-devel@ffmpeg.org
Cc: "Clément Bœsch" <u@pkh.me>
Subject: [FFmpeg-devel] [PATCH 3/5] avformat/mov: add parsing for the sgpd sync box
Date: Sat, 19 Feb 2022 00:19:59 +0100
Message-ID: <20220218232001.345826-4-u@pkh.me> (raw)
In-Reply-To: <20220218232001.345826-1-u@pkh.me>

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

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-02-18 23:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 23:19 [FFmpeg-devel] HEVC open GOP support in MOV/MP4 Clément Bœsch
2022-02-18 23:19 ` [FFmpeg-devel] [PATCH 1/5] avformat/mov: prepare sbgp parsing for other grouping types Clément Bœsch
2022-02-18 23:19 ` [FFmpeg-devel] [PATCH 2/5] avformat/mov: add support for sync group in sbgp box Clément Bœsch
2022-02-18 23:19 ` Clément Bœsch [this message]
2022-02-18 23:20 ` [FFmpeg-devel] [PATCH 4/5] avformat/mov: fix seeking with HEVC open GOP files Clément Bœsch
2022-02-18 23:20 ` [FFmpeg-devel] [PATCH 5/5] avformat/mov: reindent after previous commit Clément Bœsch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220218232001.345826-4-u@pkh.me \
    --to=u@pkh.me \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git