]> git.sesse.net Git - vlc/blobdiff - modules/access/rtmp/access.c
Trailing ;
[vlc] / modules / access / rtmp / access.c
index 1df9f62b531436349e1f27dedc201e055c3912a1..57e9238dd95b0e2f8b5df44e0b5a363f4f14da35 100644 (file)
@@ -27,7 +27,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_access.h>
 
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( N_("RTMP input") );
-    set_shortname( N_("RTMP") );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_ACCESS );
+vlc_module_begin ()
+    set_description( N_("RTMP input") )
+    set_shortname( N_("RTMP") )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_ACCESS )
 
     add_integer( "rtmp-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
-                 CACHING_LONGTEXT, true );
+                 CACHING_LONGTEXT, true )
 
-    set_capability( "access", 10 );
-    set_callbacks( Open, Close );
-    add_shortcut( "rtmp" );
-vlc_module_end();
+    set_capability( "access", 0 )
+    set_callbacks( Open, Close )
+    add_shortcut( "rtmp" )
+vlc_module_end ()
 
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int Read( access_t *, uint8_t *, size_t ); /*DOWN: last parameter int */
+static ssize_t  Read( access_t *, uint8_t *, size_t );
 static int Seek( access_t *, int64_t );
 static int Control( access_t *, int, va_list );
 
-static void ThreadControl( vlc_object_t * );
+static void* ThreadControl( vlc_object_t * );
 
 /*****************************************************************************
  * Open: open the rtmp connection
@@ -88,10 +88,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->p_thread =
         vlc_object_create( p_access, sizeof( rtmp_control_thread_t ) );
     if( !p_sys->p_thread )
-    {
-        msg_Err( p_access, "out of memory" );
         return VLC_ENOMEM;
-    }
     vlc_object_attach( p_sys->p_thread, p_access );
 
     /* Parse URI - remove spaces */
@@ -118,7 +115,10 @@ static int Open( vlc_object_t *p_this )
     }
 
     length_path = strlen( p_sys->p_thread->url.psz_path );
-    length_media_name = strlen( strrchr( p_sys->p_thread->url.psz_path, '/' ) ) - 1;
+    char* psz_tmp = strrchr( p_sys->p_thread->url.psz_path, '/' );
+    if( !psz_tmp )
+        goto error;
+    length_media_name = strlen( psz_tmp ) - 1;
 
     p_sys->p_thread->psz_application = strndup( p_sys->p_thread->url.psz_path + 1, length_path - length_media_name - 2 );
     p_sys->p_thread->psz_media = strdup( p_sys->p_thread->url.psz_path + ( length_path - length_media_name ) );
@@ -160,7 +160,7 @@ static int Open( vlc_object_t *p_this )
 
     p_sys->p_thread->p_base_object = p_this;
 
-    vlc_cond_init( p_sys->p_thread, &p_sys->p_thread->wait );
+    vlc_cond_init( &p_sys->p_thread->wait );
 
     vlc_mutex_init( &p_sys->p_thread->lock );
 
@@ -212,7 +212,7 @@ static int Open( vlc_object_t *p_this )
     }
 
     if( vlc_thread_create( p_sys->p_thread, "rtmp control thread", ThreadControl,
-                           VLC_THREAD_PRIORITY_INPUT, false ) )
+                           VLC_THREAD_PRIORITY_INPUT ) )
     {
         msg_Err( p_access, "cannot spawn rtmp control thread" );
         goto error2;
@@ -245,10 +245,11 @@ 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 );
 
-    vlc_UrlClean( &p_sys->p_thread->url );
     free( p_sys );
 
     return VLC_EGENERIC;
@@ -266,7 +267,6 @@ static void Close( vlc_object_t * p_this )
 /*    p_sys->p_thread->b_die = true;*/
     vlc_object_kill( p_sys->p_thread );
     block_FifoWake( p_sys->p_thread->p_fifo_input );
-    block_FifoWake( p_sys->p_thread->p_empty_blocks );
 
     vlc_thread_join( p_sys->p_thread );
 
@@ -289,19 +289,19 @@ static void Close( vlc_object_t * p_this )
 
     var_Destroy( p_access, "rtmp-caching" );
 
-    vlc_object_detach( p_sys->p_thread );
-    vlc_object_release( p_sys->p_thread );
-
     vlc_UrlClean( &p_sys->p_thread->url );
     free( p_sys->p_thread->psz_application );
     free( p_sys->p_thread->psz_media );
+
+    vlc_object_detach( p_sys->p_thread );
+    vlc_object_release( p_sys->p_thread );
     free( p_sys );
 }
 
 /*****************************************************************************
  * Read: standard read on a file descriptor.
  *****************************************************************************/
-static int Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
+static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 {
     access_sys_t *p_sys = p_access->p_sys;
     rtmp_packet_t *rtmp_packet;
@@ -313,7 +313,7 @@ static int Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 
     while( i_len_tmp < i_len )
     {
-        if( p_sys->p_thread->result_stop || p_access->info.b_eof || p_access->b_die )
+        if( p_sys->p_thread->result_stop || p_access->info.b_eof || !vlc_object_alive (p_access) )
         {
             p_access->info.b_eof = true;
             return 0;
@@ -448,7 +448,6 @@ static int Seek( access_t *p_access, int64_t i_pos )
 static int Control( access_t *p_access, int i_query, va_list args )
 {
     bool    *pb_bool;
-    int     *pi_int;
     int64_t *pi_64;
 
     switch( i_query )
@@ -471,11 +470,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
             break;
 
         /* */
-        case ACCESS_GET_MTU:
-            pi_int = (int*) va_arg( args, int * );
-            *pi_int = 0;
-            break;
-
         case ACCESS_GET_PTS_DELAY:
             pi_64 = (int64_t*) va_arg( args, int64_t * );
             *pi_64 = var_GetInteger( p_access, "rtmp-caching" ) * INT64_C(1000);
@@ -505,14 +499,15 @@ static int Control( access_t *p_access, int i_query, va_list args )
 /*****************************************************************************
  * ThreadControl: manage control messages and pipe media to Read
  *****************************************************************************/
-static void ThreadControl( vlc_object_t *p_this )
+static void* ThreadControl( vlc_object_t *p_this )
 {
     rtmp_control_thread_t *p_thread = (rtmp_control_thread_t *) p_this;
     rtmp_packet_t *rtmp_packet;
+    int canc = vlc_savecancel ();
 
     rtmp_init_handler( p_thread->rtmp_handler );
 
-    while( !p_thread->b_die )
+    while( vlc_object_alive (p_thread) )
     {
         rtmp_packet = rtmp_read_net_packet( p_thread );
         if( rtmp_packet != NULL )
@@ -545,4 +540,6 @@ static void ThreadControl( vlc_object_t *p_this )
             block_FifoWake( p_thread->p_fifo_input );
         }
     }
+    vlc_restorecancel (canc);
+    return NULL;
 }