[vlc-devel] [PATCH 8/8] mp4: read and save ambisonics metadata from the Google specification

Adrien Maglo magsoft at videolan.org
Fri Feb 24 16:15:02 CET 2017


https://github.com/google/spatial-media/blob/master/docs/spatial-audio-rfc.md
---
 modules/demux/mp4/essetup.c |  5 +++++
 modules/demux/mp4/libmp4.c  | 27 +++++++++++++++++++++++++++
 modules/demux/mp4/libmp4.h  | 12 ++++++++++++
 3 files changed, 44 insertions(+)

diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index a75b83c..855ddc2 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -1160,6 +1160,11 @@ int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
             break;
     }
 
+    /* Ambisonics */
+    const MP4_Box_t *p_SA3D = MP4_BoxGet(p_sample, "SA3D");
+    if (p_SA3D && BOXDATA(p_SA3D))
+        p_track->fmt.audio.channel_type = AMBISONICS_CHANNELS;
+
     /* Late fixes */
     if ( p_soun->i_qt_version == 0 && p_track->fmt.i_codec == VLC_CODEC_QCELP )
     {
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index ebf3627..ba74d7e 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -4087,6 +4087,30 @@ static int MP4_ReadBox_pnot( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_EXIT( 1 );
 }
 
+static int MP4_ReadBox_SA3D( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_SA3D_t, NULL );
+
+    uint8_t i_version;
+    MP4_GET1BYTE( i_version );
+    if ( i_version != 0 )
+        MP4_READBOX_EXIT( 0 );
+
+    MP4_GET1BYTE( p_box->data.p_SA3D->i_ambisonic_type );
+    MP4_GET4BYTES( p_box->data.p_SA3D->i_ambisonic_order );
+    MP4_GET1BYTE( p_box->data.p_SA3D->i_ambisonic_channel_ordering );
+    MP4_GET1BYTE( p_box->data.p_SA3D->i_ambisonic_normalization );
+    MP4_GET4BYTES( p_box->data.p_SA3D->i_num_channels );
+    for (unsigned i = 0; i < p_box->data.p_SA3D->i_num_channels; i++)
+    {
+        uint8_t i_channel_map;
+        VLC_UNUSED( i_channel_map );
+        MP4_GET1BYTE( i_channel_map );
+    }
+
+    MP4_READBOX_EXIT( 1 );
+}
+
 /* For generic */
 static int MP4_ReadBox_default( stream_t *p_stream, MP4_Box_t *p_box )
 {
@@ -4522,6 +4546,9 @@ static const struct
     { ATOM_equi,    MP4_ReadBox_equi,        ATOM_proj },
     { ATOM_cbmp,    MP4_ReadBox_cbmp,        ATOM_proj },
 
+    /* Ambisonics */
+    { ATOM_SA3D,    MP4_ReadBox_SA3D,        0 },
+
     /* Last entry */
     { 0,              MP4_ReadBox_default,   0 }
 };
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 8bffc07..13f8e6b 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -377,6 +377,8 @@ typedef int64_t stime_t;
 #define ATOM_SDLN VLC_FOURCC( 'S', 'D', 'L', 'N' )
 #define ATOM_vndr VLC_FOURCC( 'v', 'n', 'd', 'r' )
 
+#define ATOM_SA3D VLC_FOURCC( 'S', 'A', '3', 'D' )
+
 #define HANDLER_mdta VLC_FOURCC('m', 'd', 't', 'a')
 #define HANDLER_mdir VLC_FOURCC('m', 'd', 'i', 'r')
 
@@ -1590,6 +1592,15 @@ typedef struct
     uint32_t i_padding;
 } MP4_Box_data_cbmp_t;
 
+typedef struct
+{
+    uint8_t i_ambisonic_type;
+    uint32_t i_ambisonic_order;
+    uint8_t i_ambisonic_channel_ordering;
+    uint8_t i_ambisonic_normalization;
+    uint32_t i_num_channels;
+} MP4_Box_data_SA3D_t;
+
 /*
 typedef struct MP4_Box_data__s
 {
@@ -1700,6 +1711,7 @@ typedef union MP4_Box_data_s
     MP4_Box_data_prhd_t *p_prhd;
     MP4_Box_data_equi_t *p_equi;
     MP4_Box_data_cbmp_t *p_cbmp;
+    MP4_Box_data_SA3D_t *p_SA3D;
 
     /* for generic handlers */
     MP4_Box_data_binary_t *p_binary;
-- 
2.9.3



More information about the vlc-devel mailing list