]> git.sesse.net Git - vlc/blobdiff - src/input/stream_demux.c
decoder: remove decoder_DeleteSubpicture() and fix a leak
[vlc] / src / input / stream_demux.c
index 5f0521728f858687b50f107ae657f2a787b877b0..3516d799482dafd08f2278a32d64c9e8fbcbb207 100644 (file)
@@ -29,6 +29,7 @@
 #include "demux.h"
 #include <libvlc.h>
 #include <vlc_codec.h>
+#include <vlc_atomic.h>
 
 /****************************************************************************
  * stream_Demux*: create a demuxer for an outpout stream (allow demuxer chain)
@@ -45,6 +46,7 @@ struct stream_sys_t
     char        *psz_name;
     es_out_t    *out;
 
+    atomic_bool  active;
     vlc_thread_t thread;
     vlc_mutex_t  lock;
     struct
@@ -103,6 +105,7 @@ stream_t *stream_DemuxNew( demux_t *p_demux, const char *psz_demux, es_out_t *ou
         return NULL;
     }
 
+    atomic_init( &p_sys->active, true );
     vlc_mutex_init( &p_sys->lock );
 
     if( vlc_clone( &p_sys->thread, DStreamThread, s, VLC_THREAD_PRIORITY_INPUT ) )
@@ -156,7 +159,7 @@ static void DStreamDelete( stream_t *s )
     stream_sys_t *p_sys = s->p_sys;
     block_t *p_empty;
 
-    vlc_object_kill( s );
+    atomic_store( &p_sys->active, false );
     p_empty = block_Alloc( 0 );
     block_FifoPut( p_sys->p_fifo, p_empty );
     vlc_join( p_sys->thread, NULL );
@@ -180,7 +183,7 @@ static int DStreamRead( stream_t *s, void *p_read, unsigned int i_read )
 
     //msg_Dbg( s, "DStreamRead: wanted %d bytes", i_read );
 
-    while( vlc_object_alive( s ) && !s->b_error && i_read )
+    while( atomic_load( &p_sys->active ) && !s->b_error && i_read )
     {
         block_t *p_block = p_sys->p_block;
         int i_copy;
@@ -223,7 +226,7 @@ static int DStreamPeek( stream_t *s, const uint8_t **pp_peek, unsigned int i_pee
 
     //msg_Dbg( s, "DStreamPeek: wanted %d bytes", i_peek );
 
-    while( vlc_object_alive( s ) && !s->b_error && i_peek )
+    while( atomic_load( &p_sys->active ) && !s->b_error && i_peek )
     {
         int i_copy;
 
@@ -256,7 +259,6 @@ static int DStreamControl( stream_t *s, int i_query, va_list args )
 {
     stream_sys_t *p_sys = s->p_sys;
     uint64_t    *p_i64;
-    bool *p_b;
 
     switch( i_query )
     {
@@ -266,13 +268,10 @@ static int DStreamControl( stream_t *s, int i_query, va_list args )
             return VLC_SUCCESS;
 
         case STREAM_CAN_SEEK:
-            p_b = (bool*) va_arg( args, bool * );
-            *p_b = false;
-            return VLC_SUCCESS;
-
         case STREAM_CAN_FASTSEEK:
-            p_b = (bool*) va_arg( args, bool * );
-            *p_b = false;
+        case STREAM_CAN_PAUSE:
+        case STREAM_CAN_CONTROL_PACE:
+            *va_arg( args, bool * ) = false;
             return VLC_SUCCESS;
 
         case STREAM_GET_POSITION:
@@ -297,9 +296,23 @@ static int DStreamControl( stream_t *s, int i_query, va_list args )
             return VLC_SUCCESS;
         }
 
-        case STREAM_CONTROL_ACCESS:
+        case STREAM_GET_PTS_DELAY:
+            *va_arg( args, int64_t * ) = DEFAULT_PTS_DELAY;
+            return VLC_SUCCESS;
+
+        case STREAM_GET_TITLE_INFO:
+        case STREAM_GET_TITLE:
+        case STREAM_GET_SEEKPOINT:
+        case STREAM_GET_META:
         case STREAM_GET_CONTENT_TYPE:
+        case STREAM_GET_SIGNAL:
+        case STREAM_SET_PAUSE_STATE:
+        case STREAM_SET_TITLE:
+        case STREAM_SET_SEEKPOINT:
         case STREAM_SET_RECORD_STATE:
+        case STREAM_SET_PRIVATE_ID_STATE:
+        case STREAM_SET_PRIVATE_ID_CA:
+        case STREAM_GET_PRIVATE_ID_STATE:
             return VLC_EGENERIC;
 
         default:
@@ -326,7 +339,7 @@ static void* DStreamThread( void *obj )
 
     /* Main loop */
     mtime_t next_update = 0;
-    while( vlc_object_alive( s ) )
+    while( atomic_load( &p_sys->active ) )
     {
         if( p_demux->info.i_update || mdate() >= next_update )
         {
@@ -354,6 +367,9 @@ static void* DStreamThread( void *obj )
             break;
     }
 
+    /* Explicit kludge: the stream is destroyed by the owner of the
+     * streamDemux, not here. */
+    p_demux->s = NULL;
     demux_Delete( p_demux );
 
     return NULL;