[vlc-commits] demux: mp4: add support for AV1

Francois Cartegnie git at videolan.org
Thu Oct 11 22:45:19 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Aug  9 11:34:54 2018 +0200| [cff945c9fbdf5388847839cfbcdec49d83832b44] | committer: Francois Cartegnie

demux: mp4: add support for AV1

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=cff945c9fbdf5388847839cfbcdec49d83832b44
---

 modules/demux/mp4/essetup.c | 17 +++++++++++------
 modules/demux/mp4/libmp4.c  | 44 +++++++++++++++++++++++++++++++++++++++++++-
 modules/demux/mp4/libmp4.h  | 12 ++++++++++++
 3 files changed, 66 insertions(+), 7 deletions(-)

diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index 177acb76b8..0af20f89e1 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -605,14 +605,19 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
         {
             static_assert(ATOM_av01 == VLC_CODEC_AV1, "VLC_CODEC_AV1 != ATOM_av01");
             MP4_Box_t *p_av1C = MP4_BoxGet( p_sample, "av1C" );
-            if( p_av1C && p_av1C->data.p_binary && p_av1C->data.p_binary->i_blob )
+            if( p_av1C && BOXDATA(p_av1C) )
             {
-                p_track->fmt.p_extra = malloc( p_av1C->data.p_binary->i_blob );
-                if( p_track->fmt.p_extra )
+                p_track->fmt.i_profile = BOXDATA(p_av1C)->i_profile;
+                p_track->fmt.i_level = BOXDATA(p_av1C)->i_level;
+                if( BOXDATA(p_av1C)->i_av1C )
                 {
-                    p_track->fmt.i_extra = p_av1C->data.p_binary->i_blob;
-                    memcpy( p_track->fmt.p_extra, p_av1C->data.p_binary->p_blob,
-                            p_av1C->data.p_binary->i_blob );
+                    p_track->fmt.p_extra = malloc( BOXDATA(p_av1C)->i_av1C );
+                    if( p_track->fmt.p_extra )
+                    {
+                        memcpy( p_track->fmt.p_extra, BOXDATA(p_av1C)->p_av1C,
+                                BOXDATA(p_av1C)->i_av1C );
+                        p_track->fmt.i_extra = BOXDATA(p_av1C)->i_av1C;
+                    }
                 }
             }
             break;
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index f9280783e5..dda4555858 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1820,6 +1820,48 @@ static int MP4_ReadBox_esds( stream_t *p_stream, MP4_Box_t *p_box )
 #undef es_descriptor
 }
 
+static void MP4_FreeBox_av1C( MP4_Box_t *p_box )
+{
+    MP4_Box_data_av1C_t *p_av1C = p_box->data.p_av1C;
+    free( p_av1C->p_av1C );
+}
+
+static int MP4_ReadBox_av1C( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_Box_data_av1C_t *p_av1C;
+
+    MP4_READBOX_ENTER( MP4_Box_data_av1C_t, MP4_FreeBox_av1C );
+    p_av1C = p_box->data.p_av1C;
+
+    if( i_read < 4 ||
+       p_peek[0] != 0x81 ) /* marker / version */
+        MP4_READBOX_EXIT( 0 );
+
+    p_av1C->p_av1C = malloc( i_read );
+    if( p_av1C->p_av1C )
+    {
+        memcpy( p_av1C->p_av1C, p_peek, i_read );
+        p_av1C->i_av1C = i_read;
+    }
+
+    uint8_t i_8b;
+    MP4_GET1BYTE( i_8b ); /* marker / version */
+
+    MP4_GET1BYTE( i_8b );
+    p_av1C->i_profile = i_8b >> 5;
+    p_av1C->i_level = i_8b & 0x1F;
+
+    MP4_GET1BYTE( i_8b );
+    MP4_GET1BYTE( i_8b );
+
+    if( i_8b & 0x10 ) /* delay flag */
+        p_av1C->i_presentation_delay = 1 + (i_8b & 0x0F);
+    else
+        p_av1C->i_presentation_delay = 0;
+
+    MP4_READBOX_EXIT( 1 );
+}
+
 static void MP4_FreeBox_avcC( MP4_Box_t *p_box )
 {
     MP4_Box_data_avcC_t *p_avcC = p_box->data.p_avcC;
@@ -4763,7 +4805,7 @@ static const struct
     { ATOM_dcom,    MP4_ReadBox_dcom,         0 },
     { ATOM_dfLa,    MP4_ReadBox_Binary,       ATOM_fLaC },
     { ATOM_cmvd,    MP4_ReadBox_cmvd,         0 },
-    { ATOM_av1C,    MP4_ReadBox_Binary,       ATOM_av01 },
+    { ATOM_av1C,    MP4_ReadBox_av1C,         ATOM_av01 },
     { ATOM_avcC,    MP4_ReadBox_avcC,         ATOM_avc1 },
     { ATOM_avcC,    MP4_ReadBox_avcC,         ATOM_avc3 },
     { ATOM_hvcC,    MP4_ReadBox_Binary,       0 },
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 5a8fc87083..bb21efe785 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1280,6 +1280,17 @@ typedef struct
 
 typedef struct
 {
+    uint8_t i_profile;
+    uint8_t i_level;
+    uint8_t i_presentation_delay;
+
+    size_t   i_av1C;
+    uint8_t *p_av1C;
+
+} MP4_Box_data_av1C_t;
+
+typedef struct
+{
     uint8_t i_version;
     uint8_t i_profile;
     uint8_t i_level;
@@ -1772,6 +1783,7 @@ typedef union MP4_Box_data_s
     MP4_Box_data_sample_hint_t *p_sample_hint;
 
     MP4_Box_data_esds_t *p_esds;
+    MP4_Box_data_av1C_t *p_av1C;
     MP4_Box_data_avcC_t *p_avcC;
     MP4_Box_data_dac3_t *p_dac3;
     MP4_Box_data_dec3_t *p_dec3;



More information about the vlc-commits mailing list