[vlc-devel] [PATCH 3/3] stream_demux: add stream_DemuxGetStatus

Francois Cartegnie fcvlcdev at free.fr
Mon Sep 14 14:11:20 CEST 2015


Forwards at least EOF signal from demux.
(allows polling stream_demux for completeness/failure)
---
 include/vlc_stream.h     |  2 ++
 src/input/stream_demux.c | 31 +++++++++++++++++++++++++++++--
 src/libvlccore.sym       |  1 +
 3 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index cbdd2fa..5fd7a4f 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -201,6 +201,8 @@ VLC_API stream_t * stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_
  */
 VLC_API void stream_DemuxSend( stream_t *s, block_t *p_block );
 
+VLC_API int stream_DemuxGetStatus( stream_t *s );
+
 /**
  * Perform a <b>demux</b> (i.e. DEMUX_...) control request on a stream handle
  * created by stream_DemuxNew().
diff --git a/src/input/stream_demux.c b/src/input/stream_demux.c
index a7629b4..02afd1d 100644
--- a/src/input/stream_demux.c
+++ b/src/input/stream_demux.c
@@ -54,6 +54,7 @@ struct stream_sys_t
         int64_t length;
         int64_t time;
     } stats;
+    bool b_eof;
     mtime_t i_next_demux_time;
 };
 
@@ -90,6 +91,7 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
     p_sys->stats.length = 0;
     p_sys->stats.time = 0;
     p_sys->i_next_demux_time = VLC_TS_0 + CLOCK_FREQ / 4;
+    p_sys->b_eof = false;
 
     /* decoder fifo */
     if( ( p_sys->p_fifo = block_FifoNew() ) == NULL )
@@ -116,6 +118,17 @@ error:
     return NULL;
 }
 
+int stream_DemuxGetStatus( stream_t *s )
+{
+    stream_sys_t *p_sys = s->p_sys;
+    int i_status = VLC_DEMUXER_SUCCESS;
+    vlc_mutex_lock( &p_sys->lock );
+    if ( p_sys->b_eof )
+        i_status = VLC_DEMUXER_EOF;
+    vlc_mutex_unlock( &p_sys->lock );
+    return i_status;
+}
+
 void stream_DemuxSend( stream_t *s, block_t *p_block )
 {
     stream_sys_t *p_sys = s->p_sys;
@@ -289,15 +302,29 @@ static void* DStreamThread( void *obj )
             p_demux->info.i_update = 0;
             next_update = mdate() + (CLOCK_FREQ / 4);
         }
+        vlc_mutex_lock( &p_sys->lock );
+        demux_Control( p_demux, DEMUX_SET_NEXT_DEMUX_TIME, p_sys->i_next_demux_time );
+        p_sys->i_next_demux_time += CLOCK_FREQ / 4;
+        vlc_mutex_unlock( &p_sys->lock );
 
-        if( demux_Demux( p_demux ) <= 0 )
+        const int i_ret = demux_Demux( p_demux );
+        if( i_ret != VLC_DEMUXER_SUCCESS )
         {
+            if( i_ret == VLC_DEMUXER_EOF )
+            {
+                vlc_mutex_lock( &p_sys->lock );
+                p_sys->b_eof = true;
+                vlc_mutex_unlock( &p_sys->lock );
+            }
             break;
         }
+
         vlc_mutex_lock( &p_sys->lock );
-        demux_Control( p_demux, DEMUX_SET_NEXT_DEMUX_TIME, p_sys->i_next_demux_time );
+        const mtime_t i_next_demux_time = p_sys->i_next_demux_time;
         p_sys->i_next_demux_time += CLOCK_FREQ / 4;
         vlc_mutex_unlock( &p_sys->lock );
+        demux_Control( p_demux, DEMUX_SET_NEXT_DEMUX_TIME, i_next_demux_time );
+
     }
 
     /* Explicit kludge: the stream is destroyed by the owner of the
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 372b312..b9b8587 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -395,6 +395,7 @@ spu_ClearChannel
 stream_Block
 stream_Control
 stream_Delete
+stream_DemuxGetStatus
 stream_DemuxNew
 stream_DemuxSend
 stream_DemuxControlVa
-- 
2.4.3



More information about the vlc-devel mailing list