]> git.sesse.net Git - vlc/blobdiff - modules/access/rtsp/access.c
Trailing ;
[vlc] / modules / access / rtsp / access.c
index 25e9361d332c5b5de50bd4989e8e0734427ce6b3..94232b24d713d9f94f72a583f9534532892e2422 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
-#include "network.h"
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_access.h>
+#include <vlc_interface.h>
+
+#include <vlc_network.h>
 #include "rtsp.h"
 #include "real.h"
 
@@ -39,21 +45,22 @@ static void Close( vlc_object_t * );
 
 #define CACHING_TEXT N_("Caching value (ms)")
 #define CACHING_LONGTEXT N_( \
-    "Allows you to modify the default caching value for RTSP streams. This " \
-    "value should be set in millisecond units." )
-
-vlc_module_begin();
-    set_description( _("Real RTSP") );
-    set_shortname( _("Real RTSP") );
-    set_category( CAT_INPUT );
-    set_subcategory( SUBCAT_INPUT_ACCESS );
+    "Caching value for RTSP streams. This " \
+    "value should be set in milliseconds." )
+
+vlc_module_begin ()
+    set_description( N_("Real RTSP") )
+    set_shortname( N_("Real RTSP") )
+    set_category( CAT_INPUT )
+    set_subcategory( SUBCAT_INPUT_ACCESS )
     add_integer( "realrtsp-caching", 3000, NULL,
-                 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
-    set_capability( "access2", 10 );
-    set_callbacks( Open, Close );
-    add_shortcut( "realrtsp" );
-    add_shortcut( "rtsp" );
-vlc_module_end();
+                 CACHING_TEXT, CACHING_LONGTEXT, true )
+    set_capability( "access", 10 )
+    set_callbacks( Open, Close )
+    add_shortcut( "realrtsp" )
+    add_shortcut( "rtsp" )
+    add_shortcut( "pnm" )
+vlc_module_end ()
 
 
 /*****************************************************************************
@@ -65,8 +72,8 @@ static int     Control( access_t *, int, va_list );
 
 struct access_sys_t
 {
-    vlc_bool_t b_seekable;
-    vlc_bool_t b_pace_control;
+    bool b_seekable;
+    bool b_pace_control;
 
     rtsp_client_t *p_rtsp;
 
@@ -88,6 +95,8 @@ static int RtspConnect( void *p_userdata, char *psz_server, int i_port )
     if( p_sys->fd < 0 )
     {
         msg_Err( p_access, "cannot connect to %s:%d", psz_server, i_port );
+        intf_UserFatal( p_access, false, _("Connection failed"),
+                        _("VLC could not connect to \"%s:%d\"."), psz_server, i_port );
         return VLC_EGENERIC;
     }
 
@@ -108,7 +117,7 @@ static int RtspRead( void *p_userdata, uint8_t *p_buffer, int i_buffer )
     access_t *p_access = (access_t *)p_userdata;
     access_sys_t *p_sys = p_access->p_sys;
 
-    return net_Read( p_access, p_sys->fd, 0, p_buffer, i_buffer, VLC_TRUE );
+    return net_Read( p_access, p_sys->fd, 0, p_buffer, i_buffer, true );
 }
 
 static int RtspReadLine( void *p_userdata, uint8_t *p_buffer, int i_buffer )
@@ -123,7 +132,7 @@ static int RtspReadLine( void *p_userdata, uint8_t *p_buffer, int i_buffer )
     if( psz ) strncpy( (char *)p_buffer, psz, i_buffer );
     else *p_buffer = 0;
 
-    if( psz ) free( psz );
+    free( psz );
     return 0;
 }
 
@@ -146,10 +155,16 @@ static int Open( vlc_object_t *p_this )
 {
     access_t *p_access = (access_t *)p_this;
     access_sys_t *p_sys;
-    char *psz_server = 0;
+    char* psz_server = NULL;
     int i_result;
 
-    if( !p_access->b_force ) return VLC_EGENERIC;
+    if( !p_access->psz_access || (
+        strncmp( p_access->psz_access, "rtsp", 4 ) &&
+        strncmp( p_access->psz_access, "pnm", 3 )  &&
+        strncmp( p_access->psz_access, "realrtsp", 8 ) ))
+    {
+            return VLC_EGENERIC;
+    }
 
     p_access->pf_read = NULL;
     p_access->pf_block = BlockRead;
@@ -158,13 +173,20 @@ static int Open( vlc_object_t *p_this )
     p_access->info.i_update = 0;
     p_access->info.i_size = 0;
     p_access->info.i_pos = 0;
-    p_access->info.b_eof = VLC_FALSE;
+    p_access->info.b_eof = false;
     p_access->info.i_title = 0;
     p_access->info.i_seekpoint = 0;
     p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
+    if( !p_sys )
+        return VLC_ENOMEM;
     p_sys->p_rtsp = malloc( sizeof( rtsp_client_t) );
+    if( !p_sys->p_rtsp )
+    {
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
 
-    p_sys->p_header = 0;
+    p_sys->p_header = NULL;
     p_sys->p_rtsp->p_userdata = p_access;
     p_sys->p_rtsp->pf_connect = RtspConnect;
     p_sys->p_rtsp->pf_disconnect = RtspDisconnect;
@@ -177,7 +199,7 @@ static int Open( vlc_object_t *p_this )
     {
         msg_Dbg( p_access, "could not connect to: %s", p_access->psz_path );
         free( p_sys->p_rtsp );
-        p_sys->p_rtsp = 0;
+        p_sys->p_rtsp = NULL;
         goto error;
     }
 
@@ -214,17 +236,19 @@ static int Open( vlc_object_t *p_this )
 
 
             msg_Err( p_access, "rtsp session can not be established" );
+            intf_UserFatal( p_access, false, _("Session failed"),
+                    _("The requested RTSP session could not be established.") );
             goto error;
         }
 
         p_sys->p_header = block_New( p_access, 4096 );
         p_sys->p_header->i_buffer =
-            rmff_dump_header( h, p_sys->p_header->p_buffer, 1024 );
+            rmff_dump_header( h, (char *)p_sys->p_header->p_buffer, 1024 );
         rmff_free_header( h );
     }
     else
     {
-        msg_Dbg( p_access, "only real/helix rtsp servers supported for now" );
+        msg_Warn( p_access, "only real/helix rtsp servers supported for now" );
         goto error;
     }
 
@@ -232,11 +256,11 @@ static int Open( vlc_object_t *p_this )
     var_Create( p_access, "realrtsp-caching",
                 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
 
-    if( psz_server ) free( psz_server );
+    free( psz_server );
     return VLC_SUCCESS;
 
  error:
-    if( psz_server ) free( psz_server );
+    free( psz_server );
     Close( p_this );
     return VLC_EGENERIC;
 }
@@ -250,7 +274,7 @@ static void Close( vlc_object_t * p_this )
     access_sys_t *p_sys = p_access->p_sys;
 
     if( p_sys->p_rtsp ) rtsp_close( p_sys->p_rtsp );
-    if( p_sys->p_rtsp ) free( p_sys->p_rtsp );
+    free( p_sys->p_rtsp );
     free( p_sys );
 }
 
@@ -267,12 +291,12 @@ static block_t *BlockRead( access_t *p_access )
     if( p_sys->p_header )
     {
         p_block = p_sys->p_header;
-        p_sys->p_header = 0;
+        p_sys->p_header = NULL;
         return p_block;
     }
 
     i_size = real_get_rdt_chunk_header( p_access->p_sys->p_rtsp, &pheader );
-    if( i_size <= 0 ) return 0;
+    if( i_size <= 0 ) return NULL;
 
     p_block = block_New( p_access, i_size );
     p_block->i_buffer = real_get_rdt_chunk( p_access->p_sys->p_rtsp, &pheader,
@@ -294,7 +318,7 @@ static int Seek( access_t *p_access, int64_t i_pos )
  *****************************************************************************/
 static int Control( access_t *p_access, int i_query, va_list args )
 {
-    vlc_bool_t   *pb_bool;
+    bool   *pb_bool;
     int          *pi_int;
     int64_t      *pi_64;
 
@@ -303,24 +327,18 @@ static int Control( access_t *p_access, int i_query, va_list args )
         /* */
         case ACCESS_CAN_SEEK:
         case ACCESS_CAN_FASTSEEK:
-            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-            *pb_bool = VLC_FALSE;//p_sys->b_seekable;
+            pb_bool = (bool*)va_arg( args, bool* );
+            *pb_bool = false;//p_sys->b_seekable;
             break;
 
         case ACCESS_CAN_PAUSE:
-            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-            *pb_bool = VLC_FALSE;
+            pb_bool = (bool*)va_arg( args, bool* );
+            *pb_bool = false;
             break;
 
         case ACCESS_CAN_CONTROL_PACE:
-            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
-            *pb_bool = VLC_TRUE;//p_sys->b_pace_control;
-            break;
-
-        /* */
-        case ACCESS_GET_MTU:
-            pi_int = (int*)va_arg( args, int * );
-            *pi_int = 0;
+            pb_bool = (bool*)va_arg( args, bool* );
+            *pb_bool = true;//p_sys->b_pace_control;
             break;
 
         case ACCESS_GET_PTS_DELAY:
@@ -338,6 +356,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
         case ACCESS_SET_SEEKPOINT:
         case ACCESS_SET_PRIVATE_ID_STATE:
         case ACCESS_GET_META:
+        case ACCESS_GET_CONTENT_TYPE:
             return VLC_EGENERIC;
 
         default: