[vlc-commits] dshow: remove redundant loop and vlc_object_alive() call

Rémi Denis-Courmont git at videolan.org
Thu Jun 4 19:08:12 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jun  4 20:04:12 2015 +0300| [d08a9136c6c12a44b2ad52f0f5143a44faa29dc1] | committer: Rémi Denis-Courmont

dshow: remove redundant loop and vlc_object_alive() call

The caller (i.e. the buffer stream_t) will call the function again if
NULL is returned (assuming !b_error and !b_eof).

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

 modules/access/dshow/dshow.cpp |   70 +++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 40 deletions(-)

diff --git a/modules/access/dshow/dshow.cpp b/modules/access/dshow/dshow.cpp
index eb181c7..195669d 100644
--- a/modules/access/dshow/dshow.cpp
+++ b/modules/access/dshow/dshow.cpp
@@ -1777,55 +1777,45 @@ static size_t EnumDeviceCaps( vlc_object_t *p_this, IBaseFilter *p_filter,
 static block_t *ReadCompressed( access_t *p_access )
 {
     access_sys_t   *p_sys = p_access->p_sys;
-    dshow_stream_t *p_stream = NULL;
-    VLCMediaSample sample;
-
-    /* Read 1 DV/MPEG frame (they contain the video and audio data) */
-
     /* There must be only 1 elementary stream to produce a valid stream
      * of MPEG or DV data */
-    p_stream = p_sys->pp_streams[0];
+    dshow_stream_t *p_stream = p_sys->pp_streams[0];
+    VLCMediaSample sample;
 
-    while( 1 )
-    {
-        if( !vlc_object_alive (p_access) ) return NULL;
+    /* Read 1 DV/MPEG frame (they contain the video and audio data) */
 
-        /* Get new sample/frame from the elementary stream (blocking). */
-        vlc_mutex_lock( &p_sys->lock );
+    /* Get new sample/frame from the elementary stream (blocking). */
+    vlc_mutex_lock( &p_sys->lock );
 
-        if( p_stream->p_capture_filter->CustomGetPin()
-              ->CustomGetSample( &sample ) != S_OK )
-        {
-            /* No data available. Wait until some data has arrived */
-            vlc_cond_wait( &p_sys->wait, &p_sys->lock );
-            vlc_mutex_unlock( &p_sys->lock );
-            continue;
-        }
+    CaptureFilter *p_filter = p_stream->p_capture_filter;
 
+    if( p_filter->CustomGetPin()->CustomGetSample(&sample) != S_OK )
+    {   /* No data available. Wait until some data has arrived */
+        vlc_cond_wait( &p_sys->wait, &p_sys->lock );
         vlc_mutex_unlock( &p_sys->lock );
-
-        /*
-         * We got our sample
-         */
-        block_t *p_block;
-        uint8_t *p_data;
-        int i_data_size = sample.p_sample->GetActualDataLength();
-
-        if( !i_data_size || !(p_block = block_Alloc( i_data_size )) )
-        {
-            sample.p_sample->Release();
-            continue;
-        }
-
-        sample.p_sample->GetPointer( &p_data );
-        memcpy( p_block->p_buffer, p_data, i_data_size );
-        sample.p_sample->Release();
-
-        /* The caller got what he wanted */
-        return p_block;
+        return NULL;
     }
+    vlc_mutex_unlock( &p_sys->lock );
 
-    return NULL; /* never reached */
+    /*
+     * We got our sample
+     */
+    block_t *p_block = NULL;
+    uint8_t *p_data;
+    int i_data_size = sample.p_sample->GetActualDataLength();
+    if( i_data_size == 0 )
+        goto out;
+
+    p_block = block_Alloc( i_data_size );
+    if( unlikely(p_block == NULL) )
+        goto out;
+
+    sample.p_sample->GetPointer( &p_data );
+    memcpy( p_block->p_buffer, p_data, i_data_size );
+    /* The caller got what he wanted */
+out:
+    sample.p_sample->Release();
+    return p_block;
 }
 
 /****************************************************************************



More information about the vlc-commits mailing list