[vlc-commits] Ogg: Parse chapters in comments

Jean-Baptiste Kempf git at videolan.org
Thu Nov 15 12:05:22 CET 2012


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Wed Oct 24 12:59:00 2012 +0200| [9f2442c933ed74173a2c8ff58e1e8c43816be455] | committer: Jean-Baptiste Kempf

Ogg: Parse chapters in comments

Ref #6895
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/demux/flac.c   |    2 +-
 modules/demux/ogg.c    |    6 +++++-
 modules/demux/ogg.h    |    3 ++-
 modules/demux/vorbis.h |   32 ++++++++++++++++++++++++++++++--
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/modules/demux/flac.c b/modules/demux/flac.c
index 11361c2..a0607f1 100644
--- a/modules/demux/flac.c
+++ b/modules/demux/flac.c
@@ -578,7 +578,7 @@ static void ParseComment( demux_t *p_demux, const uint8_t *p_data, int i_data )
     if( i_data < 4 )
         return;
 
-    vorbis_ParseComment( &p_sys->p_meta, &p_data[4], i_data - 4, NULL, NULL );
+    vorbis_ParseComment( &p_sys->p_meta, &p_data[4], i_data - 4, NULL, NULL, NULL, NULL );
 
 }
 
diff --git a/modules/demux/ogg.c b/modules/demux/ogg.c
index ded386e..ce66263 100644
--- a/modules/demux/ogg.c
+++ b/modules/demux/ogg.c
@@ -188,6 +188,7 @@ static int Open( vlc_object_t * p_this )
 
     /* */
     p_sys->p_meta = NULL;
+    TAB_INIT( p_sys->i_seekpoints, p_sys->pp_seekpoints );
 
     return VLC_SUCCESS;
 }
@@ -208,6 +209,8 @@ static void Close( vlc_object_t *p_this )
     if( p_sys->p_old_stream )
         Ogg_LogicalStreamDelete( p_demux, p_sys->p_old_stream );
 
+    TAB_CLEAN( p_sys->i_seekpoints, p_sys->pp_seekpoints );
+
     free( p_sys );
 }
 
@@ -1783,7 +1786,8 @@ static void Ogg_ExtractXiphMeta( demux_t *p_demux, const void *p_headers, unsign
     /* TODO how to handle multiple comments properly ? */
     if( i_count >= 2 && pi_size[1] > i_skip )
         vorbis_ParseComment( &p_ogg->p_meta, (uint8_t*)pp_data[1] + i_skip, pi_size[1] - i_skip,
-                             &p_ogg->i_attachments, &p_ogg->attachments );
+                             &p_ogg->i_attachments, &p_ogg->attachments,
+                             &p_ogg->i_seekpoints, &p_ogg->pp_seekpoints );
 
     for( unsigned i = 0; i < i_count; i++ )
         free( pp_data[i] );
diff --git a/modules/demux/ogg.h b/modules/demux/ogg.h
index be0f5ab..faff86a 100644
--- a/modules/demux/ogg.h
+++ b/modules/demux/ogg.h
@@ -133,9 +133,10 @@ struct demux_sys_t
 
     mtime_t i_st_pts;
 
-
     /* */
     vlc_meta_t *p_meta;
+    int                 i_seekpoints;
+    seekpoint_t         **pp_seekpoints;
 
     /* */
     int                i_attachments;
diff --git a/modules/demux/vorbis.h b/modules/demux/vorbis.h
index a643048..1fec373 100644
--- a/modules/demux/vorbis.h
+++ b/modules/demux/vorbis.h
@@ -23,6 +23,7 @@
 
 #include <vlc_charset.h>
 #include <vlc_strings.h>
+#include <vlc_input.h>
 
 static input_attachment_t* ParseFlacPicture( const uint8_t *p_data, int i_data, int i_attachments, int *i_type )
 {
@@ -70,8 +71,10 @@ error:
     return p_attachment;
 }
 
-static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_data, int i_data,
-        int *i_attachments, input_attachment_t ***attachments)
+static inline void vorbis_ParseComment( vlc_meta_t **pp_meta,
+        const uint8_t *p_data, int i_data,
+        int *i_attachments, input_attachment_t ***attachments,
+        int *i_seekpoint, seekpoint_t ***ppp_seekpoint )
 {
     int n;
     int i_comment;
@@ -185,6 +188,31 @@ static inline void vorbis_ParseComment( vlc_meta_t **pp_meta, const uint8_t *p_d
                     *i_attachments, *attachments, p_attachment );
             }
         }
+        else if( !strncasecmp(psz_comment, "chapter", strlen("chapter")) )
+        {
+            if( ppp_seekpoint == NULL )
+                continue;
+
+            int i_chapt;
+            if( strstr( psz_comment, "name") && sscanf( psz_comment, "chapter%i=", &i_chapt ) == 1 )
+            {
+                char *p = strchr( psz_comment, '=' );
+                *p++ = '\0';
+            }
+            else if( sscanf( psz_comment, "chapter %i=", &i_chapt ) == 1 )
+            {
+                int h, m, s, ms;
+                char *p = strchr( psz_comment, '=' );
+                *p++ = '\0';
+
+                if( sscanf( p, "%d:%d:%d.%d", &h, &m, &s, &ms ) == 4 )
+                {
+                    seekpoint_t *sk = vlc_seekpoint_New();
+                    sk->i_time_offset = ((h * 3600 + m * 60 + s) *1000 + ms) * 1000;
+                    TAB_APPEND_CAST( (seekpoint_t**), *i_seekpoint, *ppp_seekpoint, sk );
+                }
+            }
+        }
         else if( strchr( psz_comment, '=' ) )
         {
             /* generic (PERFORMER/LICENSE/ORGANIZATION/LOCATION/CONTACT/ISRC,



More information about the vlc-commits mailing list