[vlc-commits] demux: ttml: fix duplicated blocks

Francois Cartegnie git at videolan.org
Tue Jan 10 14:33:57 CET 2017


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jan 10 13:56:34 2017 +0100| [56c6d349a152add526234ca9454f41c398ab68bc] | committer: Francois Cartegnie

demux: ttml: fix duplicated blocks

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

 modules/codec/ttml/ttml.c | 9 +++++++--
 modules/codec/ttml/ttml.h | 2 +-
 modules/demux/ttml.c      | 5 +++--
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/modules/codec/ttml/ttml.c b/modules/codec/ttml/ttml.c
index 3958c01..1874530 100644
--- a/modules/codec/ttml/ttml.c
+++ b/modules/codec/ttml/ttml.c
@@ -337,7 +337,7 @@ static int tt_bsearch_searchkey_Compare( const void *key, const void *other )
     return ( p_key->i_time >= i_time ) ? p_key->i_time - i_time : -1;
 }
 
-size_t tt_timings_FindLowerIndex( const int64_t *p_times, size_t i_times, int64_t i_time )
+size_t tt_timings_FindLowerIndex( const int64_t *p_times, size_t i_times, int64_t i_time, bool *pb_found )
 {
     size_t i_index = 0;
     if( p_times )
@@ -350,18 +350,23 @@ size_t tt_timings_FindLowerIndex( const int64_t *p_times, size_t i_times, int64_
                                    sizeof(int64_t), tt_bsearch_searchkey_Compare );
         if( lookup )
             key.p_last = lookup;
+        *pb_found = !!lookup;
 
         /* Compute index from last visited */
         i_index = (key.p_last - p_times);
         if( p_times[i_index] < i_time )
             i_index++;
     }
+    else *pb_found = false;
     return i_index;
 }
 
 static void tt_bsearch_Insert( int64_t **pp_times, size_t *pi_times, int64_t i_time )
 {
-    size_t i_index = tt_timings_FindLowerIndex( *pp_times, *pi_times, i_time );
+    bool b_exists;
+    size_t i_index = tt_timings_FindLowerIndex( *pp_times, *pi_times, i_time, &b_exists );
+    if( b_exists )
+        return;
 
     if( SIZE_MAX / sizeof(int64_t) < (*pi_times + 1) )
         return;
diff --git a/modules/codec/ttml/ttml.h b/modules/codec/ttml/ttml.h
index 4787878..f842d2e 100644
--- a/modules/codec/ttml/ttml.h
+++ b/modules/codec/ttml/ttml.h
@@ -89,7 +89,7 @@ int tt_nodes_Read( xml_reader_t *p_reader, tt_node_t *p_root_node );
 void tt_timings_Resolve( tt_basenode_t *p_child, const tt_timings_t *p_container_timings,
                          int64_t **pp_array, size_t *pi_count );
 bool tt_timings_Contains( const tt_timings_t *p_range, int64_t i_time );
-size_t tt_timings_FindLowerIndex( const int64_t *p_times, size_t i_times, int64_t i_time );
+size_t tt_timings_FindLowerIndex( const int64_t *p_times, size_t i_times, int64_t i_time, bool *pb_found );
 
 
 
diff --git a/modules/demux/ttml.c b/modules/demux/ttml.c
index 1274142..53eea2d 100644
--- a/modules/demux/ttml.c
+++ b/modules/demux/ttml.c
@@ -214,6 +214,7 @@ static int Control( demux_t* p_demux, int i_query, va_list args )
     demux_sys_t *p_sys = p_demux->p_sys;
     int64_t *pi64, i64;
     double *pf, f;
+    bool b;
 
     switch( i_query )
     {
@@ -234,7 +235,7 @@ static int Control( demux_t* p_demux, int i_query, va_list args )
             if( p_sys->times.i_count )
             {
                 size_t i_index = tt_timings_FindLowerIndex( p_sys->times.p_array,
-                                                            p_sys->times.i_count, i64 );
+                                                            p_sys->times.i_count, i64, &b );
                 p_sys->times.i_current = i_index;
                 p_sys->b_first_time = true;
                 return VLC_SUCCESS;
@@ -276,7 +277,7 @@ static int Control( demux_t* p_demux, int i_query, va_list args )
             {
                 i64 = f * p_sys->times.p_array[p_sys->times.i_count - 1];
                 size_t i_index = tt_timings_FindLowerIndex( p_sys->times.p_array,
-                                                            p_sys->times.i_count, i64 );
+                                                            p_sys->times.i_count, i64, &b );
                 p_sys->times.i_current = i_index;
                 p_sys->b_first_time = true;
                 return VLC_SUCCESS;



More information about the vlc-commits mailing list