]> git.sesse.net Git - vlc/blobdiff - modules/access_output/rtmp.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / access_output / rtmp.c
index 8c8b7993e04a4941094df430c2a6350c8740c707..ab9d159531ee38392a2428c83de0433bed363a89 100644 (file)
@@ -68,7 +68,7 @@ vlc_module_end ()
  *****************************************************************************/
 static ssize_t Write( sout_access_out_t *, block_t * );
 static int     Seek ( sout_access_out_t *, off_t  );
-static void* ThreadControl( vlc_object_t * );
+static void* ThreadControl( void * );
 
 struct sout_access_out_sys_t
 {
@@ -143,7 +143,6 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* Initialize thread variables */
-    p_sys->p_thread->b_die = 0;
     p_sys->p_thread->b_error= 0;
     p_sys->p_thread->p_fifo_input = block_FifoNew();
     p_sys->p_thread->p_empty_blocks = block_FifoNew();
@@ -219,8 +218,8 @@ static int Open( vlc_object_t *p_this )
         }
     }
 
-    if( vlc_thread_create( p_sys->p_thread, "rtmp control thread", ThreadControl,
-                           VLC_THREAD_PRIORITY_INPUT ) )
+    if( vlc_clone( &p_sys->p_thread->thread, ThreadControl, p_sys->p_thread,
+                   VLC_THREAD_PRIORITY_INPUT ) )
     {
         msg_Err( p_access, "cannot spawn rtmp control thread" );
         goto error2;
@@ -231,6 +230,8 @@ static int Open( vlc_object_t *p_this )
         if( rtmp_connect_passive( p_sys->p_thread ) < 0 )
         {
             msg_Err( p_access, "connect passive failed");
+            vlc_cancel( p_sys->p_thread->thread );
+            vlc_join( p_sys->p_thread->thread, NULL );
             goto error2;
         }
     }
@@ -251,7 +252,6 @@ error2:
         net_Close( p_sys->p_thread->fd );
 error:
     vlc_UrlClean( &p_sys->p_thread->url );
-    vlc_object_detach( p_sys->p_thread );
     vlc_object_release( p_sys->p_thread );
     free( p_sys );
 
@@ -267,11 +267,8 @@ static void Close( vlc_object_t * p_this )
     sout_access_out_sys_t *p_sys = p_access->p_sys;
     int i;
 
-//    p_sys->p_thread->b_die = true;
-    vlc_object_kill( p_sys->p_thread );
-    block_FifoWake( p_sys->p_thread->p_fifo_input );
-
-    vlc_thread_join( p_sys->p_thread );
+    vlc_cancel( p_sys->p_thread->thread );
+    vlc_join( p_sys->p_thread->thread, NULL );
 
     vlc_cond_destroy( &p_sys->p_thread->wait );
     vlc_mutex_destroy( &p_sys->p_thread->lock );
@@ -290,7 +287,6 @@ static void Close( vlc_object_t * p_this )
 
     net_Close( p_sys->p_thread->fd );
 
-    vlc_object_detach( p_sys->p_thread );
     vlc_object_release( p_sys->p_thread );
 
     vlc_UrlClean( &p_sys->p_thread->url );
@@ -376,17 +372,19 @@ static int Seek( sout_access_out_t *p_access, off_t i_pos )
 /*****************************************************************************
  * ThreadControl: manage control messages and pipe media to Read
  *****************************************************************************/
-static void* ThreadControl( vlc_object_t *p_this )
+static void* ThreadControl( void *p_this )
 {
-    rtmp_control_thread_t *p_thread = (rtmp_control_thread_t *) p_this;
+    rtmp_control_thread_t *p_thread = p_this;
     rtmp_packet_t *rtmp_packet;
     int canc = vlc_savecancel ();
 
     rtmp_init_handler( p_thread->rtmp_handler );
 
-    while( vlc_object_alive (p_thread) )
+    for( ;; )
     {
+        vlc_restorecancel( canc );
         rtmp_packet = rtmp_read_net_packet( p_thread );
+        canc = vlc_savecancel( );
         if( rtmp_packet != NULL )
         {
             if( rtmp_packet->content_type < 0x01 /* RTMP_CONTENT_TYPE_CHUNK_SIZE */
@@ -411,8 +409,7 @@ static void* ThreadControl( vlc_object_t *p_this )
                 vlc_cond_signal( &p_thread->wait );
                 vlc_mutex_unlock( &p_thread->lock );
             }
-
-            p_thread->b_die = 1;
+            break;
         }
     }
     vlc_restorecancel (canc);