[vlc-devel] [PATCH 1/4] stream_output: query the stream output to know when the decoder is really empty

Steve Lhomme robux4 at videolabs.io
Fri Dec 18 12:51:38 CET 2015


similar to vout_IsEmpty() for stream output
--
it will be need by the Chromecast as we must not skip to the next file until it
has read all its internal buffer
---
 include/vlc_sout.h                | 19 +++++++++++++++++++
 src/input/decoder.c               |  4 +++-
 src/stream_output/stream_output.c | 13 +++++++++++++
 src/stream_output/stream_output.h |  1 +
 4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/include/vlc_sout.h b/include/vlc_sout.h
index d18be89..8147131 100644
--- a/include/vlc_sout.h
+++ b/include/vlc_sout.h
@@ -189,6 +189,10 @@ static inline int sout_MuxControl( sout_mux_t *p_mux, int i_query, ... )
 
 /** @} */
 
+enum sout_stream_query_e {
+    SOUT_STREAM_EMPTY,    /* arg1=bool *,       res=can fail (assume true) */
+};
+
 struct sout_stream_t
 {
     VLC_COMMON_MEMBERS
@@ -205,6 +209,7 @@ struct sout_stream_t
     void              (*pf_del)( sout_stream_t *, sout_stream_id_sys_t * );
     /* manage a packet */
     int               (*pf_send)( sout_stream_t *, sout_stream_id_sys_t *, block_t* );
+    int               (*pf_control)( sout_stream_t *, int, va_list );
 
     sout_stream_sys_t *p_sys;
     bool pace_nocontrol;
@@ -232,6 +237,20 @@ static inline int sout_StreamIdSend( sout_stream_t *s,
     return s->pf_send( s, id, b );
 }
 
+static inline int sout_StreamControl( sout_stream_t *s, int i_query, ... )
+{
+    va_list args;
+    int     i_result;
+
+    va_start( args, i_query );
+    if ( !s->pf_control )
+        i_result = VLC_EGENERIC;
+    else
+        i_result = s->pf_control( s, i_query, args );
+    va_end( args );
+    return i_result;
+}
+
 /****************************************************************************
  * Encoder
  ****************************************************************************/
diff --git a/src/input/decoder.c b/src/input/decoder.c
index 91f1b51..af1df41 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -1932,7 +1932,9 @@ bool input_DecoderIsEmpty( decoder_t * p_dec )
     bool b_empty;
 
     vlc_mutex_lock( &p_owner->lock );
-    if( p_owner->fmt.i_cat == VIDEO_ES && p_owner->p_vout != NULL )
+    if (p_owner->p_sout_input != NULL)
+        b_empty = sout_InputIsEmpty( p_owner->p_sout_input );
+    else if( p_owner->fmt.i_cat == VIDEO_ES && p_owner->p_vout != NULL )
         b_empty = vout_IsEmpty( p_owner->p_vout );
     else if( p_owner->fmt.i_cat == AUDIO_ES )
         b_empty = atomic_load( &p_owner->drained );
diff --git a/src/stream_output/stream_output.c b/src/stream_output/stream_output.c
index 113fce2..20448a1 100644
--- a/src/stream_output/stream_output.c
+++ b/src/stream_output/stream_output.c
@@ -211,6 +211,18 @@ int sout_InputDelete( sout_packetizer_input_t *p_input )
     return( VLC_SUCCESS);
 }
 
+bool sout_InputIsEmpty(sout_packetizer_input_t *p_input)
+{
+    sout_instance_t *p_sout = p_input->p_sout;
+    bool b;
+
+    vlc_mutex_lock( &p_sout->lock );
+    if (sout_StreamControl( p_sout->p_stream, SOUT_STREAM_EMPTY, &b ) != VLC_SUCCESS)
+        b = true;
+    vlc_mutex_unlock( &p_sout->lock );
+    return b;
+}
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -777,6 +789,7 @@ static sout_stream_t *sout_StreamNew( sout_instance_t *p_sout, char *psz_name,
     p_stream->psz_name = psz_name;
     p_stream->p_cfg    = p_cfg;
     p_stream->p_next   = p_next;
+    p_stream->pf_control = NULL;
     p_stream->pace_nocontrol = false;
     p_stream->p_sys = NULL;
 
diff --git a/src/stream_output/stream_output.h b/src/stream_output/stream_output.h
index 1e48151..1429584 100644
--- a/src/stream_output/stream_output.h
+++ b/src/stream_output/stream_output.h
@@ -49,5 +49,6 @@ void sout_DeleteInstance( sout_instance_t * );
 sout_packetizer_input_t *sout_InputNew( sout_instance_t *, es_format_t * );
 int sout_InputDelete( sout_packetizer_input_t * );
 int sout_InputSendBuffer( sout_packetizer_input_t *, block_t* );
+bool sout_InputIsEmpty(sout_packetizer_input_t *);
 
 #endif
-- 
2.6.3



More information about the vlc-devel mailing list