[vlc-commits] demux: mp4: update from vp8/9/10 spec

Francois Cartegnie git at videolan.org
Mon Mar 5 17:30:09 CET 2018


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Mar  5 16:11:27 2018 +0100| [d9071d734a175a71bf9465937b5b01d2b146093e] | committer: Francois Cartegnie

demux: mp4: update from vp8/9/10 spec

(cherry picked from commit 2e6a72d2242ff3ffa81776ce2b542daeaf119444)

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

 NEWS                        |  1 +
 modules/demux/Makefile.am   |  1 +
 modules/demux/mp4/essetup.c | 48 +++++++++++++++++++++++++++++----------------
 modules/demux/mp4/libmp4.c  | 33 ++++++++++++++++++++++---------
 modules/demux/mp4/libmp4.h  |  4 +++-
 5 files changed, 60 insertions(+), 27 deletions(-)

diff --git a/NEWS b/NEWS
index b3b83594f1..fb460ce3ce 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Demux:
  * Fix wrong colors in some AVI files
  * Fix IFO files playback
  * Fix a crash with missing/invalid MPEG SDT
+ * Update VP8/9/10 ISOBMFF bindings
 
 Audio output:
  * Fix mmdevice default audio device handling
diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 1ccf8e976b..b36c9835ff 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -208,6 +208,7 @@ libmp4_plugin_la_SOURCES = demux/mp4/mp4.c demux/mp4/mp4.h \
                            demux/mp4/languages.h \
                            demux/asf/asfpacket.c demux/asf/asfpacket.h \
                            demux/mp4/avci.h \
+                           demux/mp4/color_specs.h \
                            demux/mp4/essetup.c demux/mp4/meta.c \
                            meta_engine/ID3Genres.h
 libmp4_plugin_la_LIBADD = $(LIBM)
diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index b501ae8735..b7a6ad9157 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -28,6 +28,7 @@
 #include "avci.h"
 #include "../xiph.h"
 #include "../../packetizer/dts_header.h"
+#include "color_config.h"
 
 #include <vlc_demux.h>
 #include <vlc_aout.h>
@@ -670,24 +671,37 @@ int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample )
                     p_track->fmt.i_codec = VLC_CODEC_VP8;
                 p_track->fmt.i_profile = p_data->i_profile;
                 p_track->fmt.i_level = p_data->i_level;
-                const uint8_t colorspacesmapping[] =
-                {
-                    COLOR_SPACE_UNDEF,
-                    COLOR_SPACE_BT601,
-                    COLOR_SPACE_BT709,
-                    COLOR_SPACE_SMPTE_170,
-                    COLOR_SPACE_SMPTE_240,
-                    COLOR_SPACE_BT2020,
-                    COLOR_SPACE_BT2020,
-                    COLOR_SPACE_SRGB,
-                };
-                if( p_data->i_color_space < ARRAY_SIZE(colorspacesmapping) )
-                    p_track->fmt.video.space = colorspacesmapping[p_data->i_color_space];
 
-                if( p_data->i_xfer_function == 0 )
-                    p_track->fmt.video.transfer = TRANSFER_FUNC_BT709;
-                else if ( p_data->i_xfer_function == 1 )
-                    p_track->fmt.video.transfer = TRANSFER_FUNC_SMPTE_ST2084;
+                if( p_data->i_version == 0 ) /* old deprecated */
+                {
+                    const uint8_t colorspacesmapping[] =
+                    {
+                        COLOR_SPACE_UNDEF,
+                        COLOR_SPACE_BT601,
+                        COLOR_SPACE_BT709,
+                        COLOR_SPACE_SMPTE_170,
+                        COLOR_SPACE_SMPTE_240,
+                        COLOR_SPACE_BT2020,
+                        COLOR_SPACE_BT2020,
+                        COLOR_SPACE_SRGB,
+                    };
+                    if( p_data->i_color_primaries < ARRAY_SIZE(colorspacesmapping) )
+                        p_track->fmt.video.space = colorspacesmapping[p_data->i_color_primaries];
+
+                    if( p_data->i_xfer_function == 0 )
+                        p_track->fmt.video.transfer = TRANSFER_FUNC_BT709;
+                    else if ( p_data->i_xfer_function == 1 )
+                        p_track->fmt.video.transfer = TRANSFER_FUNC_SMPTE_ST2084;
+                }
+                else
+                {
+                    p_track->fmt.video.primaries =
+                            iso_23001_8_cp_to_vlc_primaries( p_data->i_color_primaries );
+                    p_track->fmt.video.transfer =
+                            iso_23001_8_tc_to_vlc_xfer( p_data->i_xfer_function );
+                    p_track->fmt.video.space =
+                            iso_23001_8_mc_to_vlc_coeffs( p_data->i_matrix_coeffs );
+                }
 
                 p_track->fmt.video.b_color_range_full = p_data->i_fullrange;
                 p_track->fmt.video.i_bits_per_pixel = p_data->i_bit_depth;
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 7f2b843e2d..c88b7d2a9d 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1949,20 +1949,35 @@ static int MP4_ReadBox_vpcC( stream_t *p_stream, MP4_Box_t *p_box )
     if( p_box->i_size < 6 )
         MP4_READBOX_EXIT( 0 );
 
-    uint8_t i_version;
-    MP4_GET1BYTE( i_version );
-    if( i_version != 0 )
+    MP4_GET1BYTE( p_vpcC->i_version );
+    if( p_vpcC->i_version > 1 )
         MP4_READBOX_EXIT( 0 );
 
     MP4_GET1BYTE( p_vpcC->i_profile );
     MP4_GET1BYTE( p_vpcC->i_level );
     MP4_GET1BYTE( p_vpcC->i_bit_depth );
-    p_vpcC->i_color_space = p_vpcC->i_bit_depth & 0x0F;
-    p_vpcC->i_bit_depth >>= 4;
-    MP4_GET1BYTE( p_vpcC->i_chroma_subsampling );
-    p_vpcC->i_xfer_function = ( p_vpcC->i_chroma_subsampling & 0x0F ) >> 1;
-    p_vpcC->i_fullrange = p_vpcC->i_chroma_subsampling & 0x01;
-    p_vpcC->i_chroma_subsampling >>= 4;
+
+    /* Deprecated one
+       https://github.com/webmproject/vp9-dash/blob/master/archive/VPCodecISOMediaFileFormatBinding-v0.docx */
+    if( p_vpcC->i_version == 0 )
+    {
+        p_vpcC->i_color_primaries = p_vpcC->i_bit_depth & 0x0F;
+        p_vpcC->i_bit_depth >>= 4;
+        MP4_GET1BYTE( p_vpcC->i_chroma_subsampling );
+        p_vpcC->i_xfer_function = ( p_vpcC->i_chroma_subsampling & 0x0F ) >> 1;
+        p_vpcC->i_fullrange = p_vpcC->i_chroma_subsampling & 0x01;
+        p_vpcC->i_chroma_subsampling >>= 4;
+    }
+    else
+    {
+        p_vpcC->i_chroma_subsampling = ( p_vpcC->i_bit_depth & 0x0F ) >> 1;
+        p_vpcC->i_fullrange = p_vpcC->i_bit_depth & 0x01;
+        p_vpcC->i_bit_depth >>= 4;
+        MP4_GET1BYTE( p_vpcC->i_color_primaries );
+        MP4_GET1BYTE( p_vpcC->i_xfer_function );
+        MP4_GET1BYTE( p_vpcC->i_matrix_coeffs );
+    }
+
     MP4_GET2BYTES( p_vpcC->i_codec_init_datasize );
     if( p_vpcC->i_codec_init_datasize > i_read )
         p_vpcC->i_codec_init_datasize = i_read;
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index ae48098dd7..f129e1d166 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -1270,12 +1270,14 @@ typedef struct
 
 typedef struct
 {
+    uint8_t i_version;
     uint8_t i_profile;
     uint8_t i_level;
     uint8_t i_bit_depth;
-    uint8_t i_color_space;
     uint8_t i_chroma_subsampling;
+    uint8_t i_color_primaries;
     uint8_t i_xfer_function;
+    uint8_t i_matrix_coeffs;
     uint8_t i_fullrange;
     uint16_t i_codec_init_datasize;
     uint8_t *p_codec_init_data;



More information about the vlc-commits mailing list