[vlc-commits] mkv: simplify Demux() by using vlc_mutex_locker

Steve Lhomme git at videolan.org
Wed Mar 16 07:04:40 CET 2016


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Tue Mar 15 15:45:54 2016 +0100| [9eb0571bb2a73f84cad96df2f5d2e47711bd0dd8] | committer: Jean-Baptiste Kempf

mkv: simplify Demux() by using vlc_mutex_locker

also the loop was not necessary

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

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

 modules/demux/mkv/mkv.cpp |  137 +++++++++++++++++++--------------------------
 1 file changed, 58 insertions(+), 79 deletions(-)

diff --git a/modules/demux/mkv/mkv.cpp b/modules/demux/mkv/mkv.cpp
index 93ad241..4d7b6b4 100644
--- a/modules/demux/mkv/mkv.cpp
+++ b/modules/demux/mkv/mkv.cpp
@@ -710,109 +710,88 @@ static int Demux( demux_t *p_demux)
 {
     demux_sys_t        *p_sys = p_demux->p_sys;
 
-    vlc_mutex_lock( &p_sys->lock_demuxer );
+    vlc_mutex_locker( &p_sys->lock_demuxer );
 
     virtual_segment_c  *p_vsegment = p_sys->p_current_segment;
     matroska_segment_c *p_segment = p_vsegment->CurrentSegment();
     if ( p_segment == NULL )
-    {
-        vlc_mutex_unlock( &p_sys->lock_demuxer );
         return 0;
-    }
-    int i_return = 0;
 
-    do
-    {
-        if( p_sys->i_pts >= p_sys->i_start_pts  )
-            if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) )
-            {
-                i_return = 1;
-                break;
-            }
+    if( p_sys->i_pts >= p_sys->i_start_pts  )
+        if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) )
+            return 1;
 
-        if ( p_vsegment->CurrentEdition() &&
-             p_vsegment->CurrentEdition()->b_ordered &&
-             p_vsegment->CurrentChapter() == NULL )
-            /* nothing left to read in this ordered edition */
-            break;
+    if ( p_vsegment->CurrentEdition() &&
+         p_vsegment->CurrentEdition()->b_ordered &&
+         p_vsegment->CurrentChapter() == NULL )
+        /* nothing left to read in this ordered edition */
+        return 0;
 
-        KaxBlock *block;
-        KaxSimpleBlock *simpleblock;
-        int64_t i_block_duration = 0;
-        bool b_key_picture;
-        bool b_discardable_picture;
-        if( p_segment->BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
+    KaxBlock *block;
+    KaxSimpleBlock *simpleblock;
+    int64_t i_block_duration = 0;
+    bool b_key_picture;
+    bool b_discardable_picture;
+    if( p_segment->BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
+    {
+        if ( p_vsegment->CurrentEdition() && p_vsegment->CurrentEdition()->b_ordered )
         {
-            if ( p_vsegment->CurrentEdition() && p_vsegment->CurrentEdition()->b_ordered )
+            const virtual_chapter_c *p_chap = p_vsegment->CurrentChapter();
+            // check if there are more chapters to read
+            if ( p_chap != NULL )
             {
-                const virtual_chapter_c *p_chap = p_vsegment->CurrentChapter();
-                // check if there are more chapters to read
-                if ( p_chap != NULL )
-                {
-                    /* TODO handle successive chapters with the same user_start_time/user_end_time
-                    */
-                    p_sys->i_pts = p_chap->i_mk_virtual_stop_time + VLC_TS_0;
-                    p_sys->i_pts++; // trick to avoid staying on segments with no duration and no content
+                /* TODO handle successive chapters with the same user_start_time/user_end_time
+                */
+                p_sys->i_pts = p_chap->i_mk_virtual_stop_time + VLC_TS_0;
+                p_sys->i_pts++; // trick to avoid staying on segments with no duration and no content
 
-                    i_return = 1;
-                }
-
-                break;
-            }
-            else
-            {
-                msg_Warn( p_demux, "cannot get block EOF?" );
-                break;
+                return 1;
             }
         }
 
-        if( simpleblock != NULL )
-            p_sys->i_pts = (mtime_t)simpleblock->GlobalTimecode() / INT64_C(1000);
-        else
-            p_sys->i_pts = (mtime_t)block->GlobalTimecode() / INT64_C(1000);
-        p_sys->i_pts += p_sys->i_mk_chapter_time + VLC_TS_0;
+        msg_Warn( p_demux, "cannot get block EOF?" );
+        return 0;
+    }
 
-        mtime_t i_pcr = VLC_TS_INVALID;
-        for( size_t i = 0; i < p_segment->tracks.size(); i++)
-            if( p_segment->tracks[i]->i_last_dts > VLC_TS_INVALID &&
-                ( p_segment->tracks[i]->i_last_dts < i_pcr || i_pcr == VLC_TS_INVALID ))
-                i_pcr = p_segment->tracks[i]->i_last_dts;
+    if( simpleblock != NULL )
+        p_sys->i_pts = (mtime_t)simpleblock->GlobalTimecode() / INT64_C(1000);
+    else
+        p_sys->i_pts = (mtime_t)block->GlobalTimecode() / INT64_C(1000);
+    p_sys->i_pts += p_sys->i_mk_chapter_time + VLC_TS_0;
 
-        if( i_pcr > p_sys->i_pcr + 300000 )
-        {
-            es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
-            p_sys->i_pcr = i_pcr;
-        }
+    mtime_t i_pcr = VLC_TS_INVALID;
+    for( size_t i = 0; i < p_segment->tracks.size(); i++)
+        if( p_segment->tracks[i]->i_last_dts > VLC_TS_INVALID &&
+            ( p_segment->tracks[i]->i_last_dts < i_pcr || i_pcr == VLC_TS_INVALID ))
+            i_pcr = p_segment->tracks[i]->i_last_dts;
 
-        if( p_sys->i_pts >= p_sys->i_start_pts  )
-        {
-            if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) )
-            {
-                i_return = 1;
-                delete block;
-                break;
-            }
-        }
+    if( i_pcr > p_sys->i_pcr + 300000 )
+    {
+        es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pcr );
+        p_sys->i_pcr = i_pcr;
+    }
 
-        if ( p_vsegment->CurrentEdition() &&
-             p_vsegment->CurrentEdition()->b_ordered &&
-             p_vsegment->CurrentChapter() == NULL )
+    if( p_sys->i_pts >= p_sys->i_start_pts  )
+    {
+        if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) )
         {
-            /* nothing left to read in this ordered edition */
             delete block;
-            break;
+            return 1;
         }
+    }
 
-        BlockDecode( p_demux, block, simpleblock, p_sys->i_pts, i_block_duration, b_key_picture, b_discardable_picture );
-
+    if ( p_vsegment->CurrentEdition() &&
+         p_vsegment->CurrentEdition()->b_ordered &&
+         p_vsegment->CurrentChapter() == NULL )
+    {
+        /* nothing left to read in this ordered edition */
         delete block;
-
-        vlc_mutex_unlock( &p_sys->lock_demuxer );
-        return 1;
+        return 0;
     }
-    while (0);
 
-    vlc_mutex_unlock( &p_sys->lock_demuxer );
+    BlockDecode( p_demux, block, simpleblock, p_sys->i_pts, i_block_duration, b_key_picture, b_discardable_picture );
+
+    delete block;
 
-    return i_return;
+    return 1;
 }



More information about the vlc-commits mailing list