[vlc-commits] demux: mp4: support the 360 spherical video box

Adrien Maglo git at videolan.org
Thu Nov 10 10:34:36 CET 2016


vlc | branch: master | Adrien Maglo <magsoft at videolan.org> | Wed May 25 14:47:59 2016 +0200| [c3d173385bf0e5ad915328e4b91939c1ae367106] | committer: Thomas Guillem

demux: mp4: support the 360 spherical video box

It is defined by the Spherical Video specification v1 from Google.
https://github.com/google/spatial-media/blob/master/docs/spherical-video-rfc.md

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/demux/mp4/essetup.c | 10 ++++++++++
 modules/demux/mp4/libmp4.c  | 34 ++++++++++++++++++++++++++++++++++
 modules/demux/mp4/libmp4.h  | 11 +++++++++++
 3 files changed, 55 insertions(+)

diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index b1ddaf4..d85bd8b 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -345,6 +345,16 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
             break;
     }
 
+    /* Set 360 video mode */
+    const MP4_Box_t *p_uuid = MP4_BoxGet( p_track->p_track, "uuid" );
+    for( ; p_uuid; p_uuid = p_uuid->p_next)
+    {
+        if( p_uuid->i_type == ATOM_uuid
+            && !CmpUUID( &p_uuid->i_uuid, &XML360BoxUUID )
+            && p_uuid->data.p_360 )
+            p_track->fmt.video.projection_mode = p_uuid->data.p_360->i_projection_mode;
+    }
+
     /* It's a little ugly but .. there are special cases */
     switch( p_sample->i_type )
     {
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 34ecb1a..e121dfe 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -26,6 +26,7 @@
 
 #include <vlc_common.h>
 #include <vlc_stream.h>                               /* vlc_stream_Peek*/
+#include <vlc_strings.h>                              /* vlc_ascii_tolower */
 
 #ifdef HAVE_ZLIB_H
 #   include <zlib.h>                                  /* for compressed moov */
@@ -712,12 +713,45 @@ static int MP4_ReadBox_tfrf(  stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_EXIT( 1 );
 }
 
+static int MP4_ReadBox_XML360( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_360_t, NULL );
+
+    MP4_Box_data_360_t *p_360_data = p_box->data.p_360;
+
+    /* Copy the string for pattern matching as it does not end
+    with a '\0' in the stream. */
+    char *psz_rdf = strndup((char *)p_peek, i_read);
+
+    if ( unlikely( !psz_rdf ) )
+        MP4_READBOX_EXIT( 0 );
+
+    /* Try to find the string "GSpherical:Spherical" because the v1
+    spherical video spec says the tag must be there. */
+
+    if ( strcasestr( psz_rdf, "Gspherical:Spherical" ) )
+        p_360_data->i_projection_mode = PROJECTION_MODE_EQUIRECTANGULAR;
+
+    /* Try to find the stero mode. */
+    if ( strcasestr( psz_rdf, "left-right" ) )
+        msg_Dbg( p_stream, "Left-right stereo mode" );
+
+    if ( strcasestr( psz_rdf, "top-bottom" ) )
+        msg_Dbg( p_stream, "Top-bottom stereo mode" );
+
+    free( psz_rdf );
+
+    MP4_READBOX_EXIT( 1 );
+}
+
 static int MP4_ReadBox_uuid( stream_t *p_stream, MP4_Box_t *p_box )
 {
     if( !CmpUUID( &p_box->i_uuid, &TfrfBoxUUID ) )
         return MP4_ReadBox_tfrf( p_stream, p_box );
     if( !CmpUUID( &p_box->i_uuid, &TfxdBoxUUID ) )
         return MP4_ReadBox_tfxd( p_stream, p_box );
+    if( !CmpUUID( &p_box->i_uuid, &XML360BoxUUID ) )
+        return MP4_ReadBox_XML360( p_stream, p_box );
 
 #ifdef MP4_VERBOSE
     msg_Warn( p_stream, "Unknown uuid type box: "
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index b2ba084..c72f85a 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1538,6 +1538,11 @@ typedef struct
     uint32_t i_blob;
 } MP4_Box_data_data_t;
 
+typedef struct
+{
+    uint32_t i_projection_mode;
+} MP4_Box_data_360_t;
+
 /*
 typedef struct MP4_Box_data__s
 {
@@ -1643,6 +1648,8 @@ typedef union MP4_Box_data_s
     MP4_Box_data_strf_t *p_strf; /* flip4mac Little endian video config */
     MP4_Box_data_ASF_t  *p_asf;  /* flip4mac asf streams indicator */
 
+    MP4_Box_data_360_t  *p_360;
+
     /* for generic handlers */
     MP4_Box_data_string_t *p_string;
     MP4_Box_data_binary_t *p_binary;
@@ -1801,6 +1808,10 @@ static const UUID_t TfxdBoxUUID = {
                 { 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6,
                   0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2 } };
 
+static const UUID_t XML360BoxUUID = {
+                { 0xff, 0xcc, 0x82, 0x63, 0xf8, 0x55, 0x4a, 0x93,
+                  0x88, 0x14, 0x58, 0x7a, 0x02, 0x52, 0x1f, 0xdd } };
+
 /*****************************************************************************
  * MP4_BoxGetNextChunk : Parse the entire moof box.
  *****************************************************************************



More information about the vlc-commits mailing list