[vlc-commits] commit: MP4: support for trkn atom (Jean-Baptiste Kempf )

git at videolan.org git at videolan.org
Tue May 18 23:57:38 CEST 2010


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Tue May 18 23:46:40 2010 +0200| [1e7532bb4b94f24eaab5fdc4e3045a76137291f7] | committer: Jean-Baptiste Kempf 

MP4: support for trkn atom

Ref #3630

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

 modules/demux/mp4/libmp4.c |   36 ++++++++++++++++++++++++++++++++++++
 modules/demux/mp4/libmp4.h |    9 +++++++++
 modules/demux/mp4/mp4.c    |    9 ++++++++-
 3 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index e211966..f669e92 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -1179,6 +1179,41 @@ static int MP4_ReadBox_gnre( stream_t *p_stream, MP4_Box_t *p_box )
     MP4_READBOX_EXIT( 1 );
 }
 
+static int MP4_ReadBox_trkn( stream_t *p_stream, MP4_Box_t *p_box )
+{
+    MP4_Box_data_trkn_t *p_trkn;
+    MP4_READBOX_ENTER( MP4_Box_data_trkn_t );
+
+    p_trkn = p_box->data.p_trkn;
+
+    uint32_t i_data_len;
+    uint32_t i_data_tag;
+
+    MP4_GET4BYTES( i_data_len );
+    MP4_GETFOURCC( i_data_tag );
+    if( i_data_len < 12 || i_data_tag != VLC_FOURCC('d', 'a', 't', 'a') )
+        MP4_READBOX_EXIT( 0 );
+
+    uint32_t i_version;
+    uint32_t i_reserved;
+    MP4_GET4BYTES( i_version );
+    MP4_GET4BYTES( i_reserved );
+    MP4_GET4BYTES( p_trkn->i_track_number );
+#ifdef MP4_VERBOSE
+    msg_Dbg( p_stream, "read box: \"trkn\" number=%i", p_trkn->i_track_number );
+#endif
+    if( i_data_len > 15 )
+    {
+       MP4_GET4BYTES( p_trkn->i_track_total );
+#ifdef MP4_VERBOSE
+       msg_Dbg( p_stream, "read box: \"trkn\" total=%i", p_trkn->i_track_total );
+#endif
+    }
+
+    MP4_READBOX_EXIT( 1 );
+}
+
+
 static int MP4_ReadBox_sample_soun( stream_t *p_stream, MP4_Box_t *p_box )
 {
     unsigned int i;
@@ -2599,6 +2634,7 @@ static const struct
     { FOURCC_dac3,  MP4_ReadBox_dac3,       MP4_FreeBox_Common },
     { FOURCC_enda,  MP4_ReadBox_enda,       MP4_FreeBox_Common },
     { FOURCC_gnre,  MP4_ReadBox_gnre,       MP4_FreeBox_Common },
+    { FOURCC_trkn,  MP4_ReadBox_trkn,       MP4_FreeBox_Common },
 
     /* Nothing to do with this box */
     { FOURCC_mdat,  MP4_ReadBoxSkip,        MP4_FreeBox_Common },
diff --git a/modules/demux/mp4/libmp4.h b/modules/demux/mp4/libmp4.h
index a28d4c0..24263fc 100644
--- a/modules/demux/mp4/libmp4.h
+++ b/modules/demux/mp4/libmp4.h
@@ -122,6 +122,7 @@
 #define FOURCC_dec3 VLC_FOURCC( 'd', 'e', 'c', '3' )
 #define FOURCC_enda VLC_FOURCC( 'e', 'n', 'd', 'a' )
 #define FOURCC_gnre VLC_FOURCC( 'g', 'n', 'r', 'e' )
+#define FOURCC_trkn VLC_FOURCC( 't', 'r', 'k', 'n' )
 
 #define FOURCC_zlib VLC_FOURCC( 'z', 'l', 'i', 'b' )
 #define FOURCC_SVQ1 VLC_FOURCC( 'S', 'V', 'Q', '1' )
@@ -886,6 +887,13 @@ typedef struct
 
 } MP4_Box_data_gnre_t;
 
+typedef struct
+{
+    uint32_t i_track_number;
+    uint32_t i_track_total;
+
+} MP4_Box_data_trkn_t;
+
 /*
 typedef struct MP4_Box_data__s
 {
@@ -922,6 +930,7 @@ typedef union MP4_Box_data_s
         MP4_Box_data_dac3_t *p_dac3;
         MP4_Box_data_enda_t *p_enda;
         MP4_Box_data_gnre_t *p_gnre;
+        MP4_Box_data_trkn_t *p_trkn;
 
     MP4_Box_data_stsz_t *p_stsz;
     MP4_Box_data_stz2_t *p_stz2;
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 740736a..c7a30ee 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -916,7 +916,14 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 case FOURCC_0xa9trk: /* Track */
                     SET( vlc_meta_SetTrackNum );
                     break;
-
+                case FOURCC_trkn:
+                {
+                    char psz_trck[11];
+                    snprintf( psz_trck, sizeof( psz_trck ), "%i",
+                              p_0xa9xxx->data.p_trkn->i_track_number );
+                    vlc_meta_SetTrackNum( p_meta, psz_trck );
+                    break;
+                }
                 case FOURCC_0xa9cmt: /* Commment */
                     SET( vlc_meta_SetDescription );
                     break;



More information about the vlc-commits mailing list