[vlc-commits] demux: mp4: handle sample rate box

Francois Cartegnie git at videolan.org
Mon Apr 27 21:36:28 CEST 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Apr 17 16:30:00 2020 +0200| [d1ee25b96494cd0191afd65c8913322bf651a54c] | committer: Francois Cartegnie

demux: mp4: handle sample rate box

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

 modules/demux/mp4/essetup.c |  4 ++++
 modules/demux/mp4/libmp4.c  | 16 ++++++++++++++++
 modules/demux/mp4/libmp4.h  |  7 +++++++
 3 files changed, 27 insertions(+)

diff --git a/modules/demux/mp4/essetup.c b/modules/demux/mp4/essetup.c
index 43662a53eb..12d1703c22 100644
--- a/modules/demux/mp4/essetup.c
+++ b/modules/demux/mp4/essetup.c
@@ -1154,6 +1154,10 @@ int SetupAudioES( demux_t *p_demux, const mp4_track_t *p_track,
         }
     }
 
+    const MP4_Box_t *p_srat = MP4_BoxGet( p_sample, "srat" );
+    if ( p_srat )
+        p_fmt->audio.i_rate = BOXDATA(p_srat)->i_sample_rate;
+
     SetupGlobalExtensions( p_sample, p_fmt );
 
     /* now see if esds is present and if so create a data packet
diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 091a6b2df6..d7d8b6c426 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -2338,6 +2338,21 @@ static int MP4_ReadBox_stsdext_chan( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_EXIT( 1 );
 }
 
+static int MP4_ReadBox_stsdext_srat( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_READBOX_ENTER( MP4_Box_data_srat_t, NULL );
+    MP4_Box_data_srat_t *p_srat = p_box->data.p_srat;
+    if ( i_read != 8 )
+        MP4_READBOX_EXIT( 0 );
+
+    uint32_t i_dummy;
+    VLC_UNUSED( i_dummy );
+    MP4_GET4BYTES( i_dummy ); /* version flags */
+    MP4_GET4BYTES( p_srat->i_sample_rate );
+
+    MP4_READBOX_EXIT( 1 );
+}
+
 static int MP4_ReadBox_dec3( stream_t *p_stream, MP4_Box_t *p_box )
 {
     MP4_READBOX_ENTER( MP4_Box_data_dec3_t, NULL );
@@ -4916,6 +4931,7 @@ static const struct
 
     /* Sound extensions */
     { ATOM_chan,    MP4_ReadBox_stsdext_chan, 0 },
+    { ATOM_srat,    MP4_ReadBox_stsdext_srat, 0 },
     { ATOM_WMA2,    MP4_ReadBox_WMA2,         ATOM_wave }, /* flip4mac */
     { ATOM_dOps,    MP4_ReadBox_Binary,       ATOM_Opus },
     { ATOM_wfex,    MP4_ReadBox_WMA2,         ATOM_wma  }, /* ismv formatex */
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index 7318ee8898..9cb4ddb149 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -211,6 +211,7 @@ typedef int64_t stime_t;
 #define ATOM_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
 #define ATOM_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
 #define ATOM_chan VLC_FOURCC( 'c', 'h', 'a', 'n' )
+#define ATOM_srat VLC_FOURCC( 's', 'r', 'a', 't' )
 #define ATOM_in24 VLC_FOURCC( 'i', 'n', '2', '4' )
 #define ATOM_in32 VLC_FOURCC( 'i', 'n', '3', '2' )
 #define ATOM_fl32 VLC_FOURCC( 'f', 'l', '3', '2' )
@@ -1386,6 +1387,11 @@ typedef struct
     struct CoreAudio_layout_s layout;
 } MP4_Box_data_chan_t;
 
+typedef struct
+{
+    uint32_t i_sample_rate;
+} MP4_Box_data_srat_t;
+
 typedef struct
 {
     uint16_t i_data_rate;
@@ -1741,6 +1747,7 @@ typedef union MP4_Box_data_s
     MP4_Box_data_dvc1_t *p_dvc1;
     MP4_Box_data_fiel_t *p_fiel;
     MP4_Box_data_chan_t *p_chan;
+    MP4_Box_data_srat_t *p_srat;
     MP4_Box_data_enda_t *p_enda;
     MP4_Box_data_keys_t *p_keys;
     MP4_Box_data_iods_t *p_iods;



More information about the vlc-commits mailing list