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

Francois Cartegnie git at videolan.org
Wed Oct 17 15:22:20 CEST 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Aug  9 11:34:54 2018 +0200| [72e011943665382ff2fb6be2b265f4b676a38957] | committer: Tristan Matthews

demux: mp4: add support for AV1

(cherry picked from commit cff945c9fbdf5388847839cfbcdec49d83832b44)

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

 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 58c68b5f47..6bb527d3dd 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -598,14 +598,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 c760018225..f069541f9a 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1813,6 +1813,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;
@@ -4473,7 +4515,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 b8a7a87a1e..3b14b5dfb3 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1275,6 +1275,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;
@@ -1684,6 +1695,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