]> git.sesse.net Git - vlc/blobdiff - src/input/vlmshell.c
decoder: remove BLOCK_FLAG_CORE_EOS
[vlc] / src / input / vlmshell.c
index a1eec6b2e64f920b37a5daf56d94870cf2694a12..9c254347f3454c925a53e89c59a43f56d0a5ed94 100644 (file)
@@ -1,26 +1,26 @@
 /*****************************************************************************
- * vlm.c: VLM interface plugin
+ * vlmshell.c: VLM interface plugin
  *****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
+ * Copyright (C) 2000-2005 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Simon Latapie <garf@videolan.org>
  *          Laurent Aimar <fenrir@videolan.org>
  *          Gildas Bazin <gbazin@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -49,6 +49,7 @@
 #include <vlc_charset.h>
 #include <vlc_fs.h>
 #include <vlc_sout.h>
+#include <vlc_url.h>
 #include "../stream_output/stream_output.h"
 #include "../libvlc.h"
 
@@ -79,7 +80,7 @@ static const char quotes[] = "\"'";
  */
 static const char *FindCommandEnd( const char *psz_sent )
 {
-    char c, quote = 0;
+    unsigned char c, quote = 0;
 
     while( (c = *psz_sent) != '\0' )
     {
@@ -126,7 +127,7 @@ static const char *FindCommandEnd( const char *psz_sent )
  */
 static int Unescape( char *out, const char *in )
 {
-    char c, quote = 0;
+    unsigned char c, quote = 0;
     bool param = false;
 
     while( (c = *in++) != '\0' )
@@ -134,7 +135,7 @@ static int Unescape( char *out, const char *in )
         // Don't escape the end of the string if we find a '#'
         // that's the begining of a vlc command
         // TODO: find a better solution
-        if( c == '#' || param )
+        if( ( c == '#' && !quote ) || param )
         {
             param = true;
             *out++ = c;
@@ -459,43 +460,6 @@ static int ExecuteControl( vlm_t *p_vlm, const char *psz_name, const int i_arg,
             i_result = VLC_EGENERIC;
         }
     }
-    else if( !strcmp( psz_control, "rewind" ) )
-    {
-        if( psz_argument )
-        {
-            const double d_scale = us_atof( psz_argument );
-            double d_position;
-
-            vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
-            d_position -= (d_scale / 1000.0);
-            if( d_position < 0.0 )
-                d_position = 0.0;
-            i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
-        }
-        else
-        {
-            i_result = VLC_EGENERIC;
-        }
-    }
-    else if( !strcmp( psz_control, "forward" ) )
-    {
-        if( psz_argument )
-        {
-            const double d_scale = us_atof( psz_argument );
-            double d_position;
-
-            vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );
-            d_position += (d_scale / 1000.0);
-            if( d_position > 1.0 )
-                d_position = 1.0;
-            i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );
-
-        }
-        else
-        {
-            i_result = VLC_EGENERIC;
-        }
-    }
     else if( !strcmp( psz_control, "stop" ) )
     {
         i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );
@@ -559,9 +523,11 @@ error:
     return VLC_EGENERIC;
 }
 
-static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
+static int ExecuteLoad( vlm_t *p_vlm, const char *psz_path, vlm_message_t **pp_status )
 {
+    char *psz_url = vlc_path2uri( psz_path, NULL );
     stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
+    free( psz_url );
     uint64_t i_size;
     char *psz_buffer;
 
@@ -636,7 +602,7 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
             if( ++i >= i_property )
                 break;
 
-            psz_line = strdup( ppsz_property[i] );
+            psz_line = xstrdup( ppsz_property[i] );
             for( j = i+1; j < i_property; j++ )
             {
                 psz_line = xrealloc( psz_line,
@@ -645,7 +611,9 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
                 strcat( psz_line, ppsz_property[j] );
             }
 
-            if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )
+            int val = vlm_ScheduleSetup( p_schedule, "append", psz_line );
+            free( psz_line );
+            if( val )
                 goto error;
             break;
         }
@@ -664,6 +632,12 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
         }
     }
     *pp_status = vlm_MessageSimpleNew( psz_cmd );
+
+    vlc_mutex_lock( &p_vlm->lock_manage );
+    p_vlm->input_state_changed = true;
+    vlc_cond_signal( &p_vlm->wait_manage );
+    vlc_mutex_unlock( &p_vlm->lock_manage );
+
     return VLC_SUCCESS;
 
 error:
@@ -730,13 +704,11 @@ static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,
         }
         else if( !strcmp( psz_option, "inputdeln" ) )
         {
-            int i_index;
-
             MISSING( "inputdeln" );
  
-            i_index = atoi( psz_value );
-            if( i_index > 0 && i_index <= p_cfg->i_input )
-                TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );
+            int idx = atoi( psz_value );
+            if( idx > 0 && idx <= p_cfg->i_input )
+                TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[idx-1] );
             i++;
         }
         else if( !strcmp( psz_option, "output" ) )
@@ -875,16 +847,27 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
                            vlm_message_t **pp_message )
 {
     size_t i_command = 0;
-    char buf[strlen (psz_command) + 1], *psz_buf = buf;
-    char *ppsz_command[3+sizeof (buf) / 2];
+    size_t i_command_len = strlen( psz_command );
+    char *buf = malloc( i_command_len + 1 ), *psz_buf = buf;
+    size_t i_ppsz_command_len = (3 + (i_command_len + 1) / 2);
+    char **ppsz_command = malloc( i_ppsz_command_len * sizeof(char *) );
     vlm_message_t *p_message = NULL;
+    int i_ret = 0;
+
+    if( !psz_buf || !ppsz_command )
+    {
+        p_message = vlm_MessageNew( "Memory error",
+                        "allocation failed for command of length %zu",
+                        i_command_len );
+        goto error;
+    }
 
     /* First, parse the line and cut it */
     while( *psz_command != '\0' )
     {
         const char *psz_temp;
 
-        if(isspace (*psz_command))
+        if(isspace ((unsigned char)*psz_command))
         {
             psz_command++;
             continue;
@@ -905,7 +888,7 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
             goto error;
         }
 
-        assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));
+        assert (i_command < i_ppsz_command_len);
 
         ppsz_command[i_command] = psz_buf;
         memcpy (psz_buf, psz_command, psz_temp - psz_command);
@@ -917,7 +900,7 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
         psz_buf += psz_temp - psz_command + 1;
         psz_command = psz_temp;
 
-        assert (buf + sizeof (buf) >= psz_buf);
+        assert (buf + i_command_len + 1 >= psz_buf);
     }
 
     /*
@@ -941,20 +924,27 @@ int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,
     else IF_EXECUTE( "setup",   (i_command < 2),    ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )
     else
     {
-        p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );
+        p_message = vlm_MessageNew( ppsz_command[0], "Unknown VLM command" );
         goto error;
     }
 #undef IF_EXECUTE
 
 success:
     *pp_message = p_message;
+    free( buf );
+    free( ppsz_command );
     return VLC_SUCCESS;
 
 syntax_error:
-    return ExecuteSyntaxError( ppsz_command[0], pp_message );
+    i_ret = ExecuteSyntaxError( ppsz_command[0], pp_message );
+    free( buf );
+    free( ppsz_command );
+    return i_ret;
 
 error:
     *pp_message = p_message;
+    free( buf );
+    free( ppsz_command );
     return VLC_EGENERIC;
 }
 
@@ -996,28 +986,23 @@ static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name )
 
     TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );
 
-    vlc_mutex_lock( &vlm->lock_manage );
-    vlc_cond_signal( &vlm->wait_manage );
-    vlc_mutex_unlock( &vlm->lock_manage );
-
     return p_sched;
 }
 
 /* for now, simple delete. After, del with options (last arg) */
 void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched )
 {
+    int i;
     if( sched == NULL ) return;
 
     TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );
 
     if( vlm->i_schedule == 0 ) free( vlm->schedule );
     free( sched->psz_name );
-    while( sched->i_command )
-    {
-        char *psz_cmd = sched->command[0];
-        TAB_REMOVE( sched->i_command, sched->command, psz_cmd );
-        free( psz_cmd );
-    }
+
+    for ( i = 0; i < sched->i_command; i++ )
+        free( sched->command[i] );
+    free( sched->command );
     free( sched );
 }
 
@@ -1217,6 +1202,7 @@ static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,
     {
         return 1;
     }
+
     return 0;
 }
 
@@ -1339,7 +1325,6 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
         vlm_media_instance_sys_t *p_instance = p_media->instance[i];
         vlc_value_t val;
         vlm_message_t *p_msg_instance;
-        char *psz_tmp;
 
         val.i_int = END_S;
         if( p_instance->p_input )
@@ -1358,29 +1343,20 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
         /* FIXME should not do that this way */
         if( p_instance->p_input )
         {
-#define APPEND_INPUT_INFO( a, format, type ) \
-            if( asprintf( &psz_tmp, format, \
-                      var_Get ## type( p_instance->p_input, a ) ) != -1 ) \
-            { \
-                vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \
-                                "%s", psz_tmp ) ); \
-                free( psz_tmp ); \
-            }
+#define APPEND_INPUT_INFO( key, format, type ) \
+            vlm_MessageAdd( p_msg_instance, vlm_MessageNew( key, format, \
+                            var_Get ## type( p_instance->p_input, key ) ) )
             APPEND_INPUT_INFO( "position", "%f", Float );
             APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
             APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
             APPEND_INPUT_INFO( "rate", "%f", Float );
-            APPEND_INPUT_INFO( "title", "%d", Integer );
-            APPEND_INPUT_INFO( "chapter", "%d", Integer );
+            APPEND_INPUT_INFO( "title", "%"PRId64, Integer );
+            APPEND_INPUT_INFO( "chapter", "%"PRId64, Integer );
             APPEND_INPUT_INFO( "can-seek", "%d", Bool );
         }
 #undef APPEND_INPUT_INFO
-        if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )
-        {
-            vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
-                            "%s", psz_tmp ) );
-            free( psz_tmp );
-        }
+        vlm_MessageAdd( p_msg_instance, vlm_MessageNew( "playlistindex",
+                        "%d", p_instance->i_index + 1 ) );
     }
     return p_msg;
 }
@@ -1419,17 +1395,13 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
         {
             struct tm date;
             time_t i_time = (time_t)( schedule->i_date / 1000000 );
-            char *psz_date;
 
             localtime_r( &i_time, &date);
-            if( asprintf( &psz_date, "%d/%d/%d-%d:%d:%d",
-                          date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,
-                          date.tm_hour, date.tm_min, date.tm_sec ) != -1 )
-            {
-                 vlm_MessageAdd( msg_schedule,
-                                 vlm_MessageNew( "date", "%s", psz_date ) );
-                 free( psz_date );
-            }
+            vlm_MessageAdd( msg_schedule,
+                            vlm_MessageNew( "date", "%d/%d/%d-%d:%d:%d",
+                                            date.tm_year + 1900, date.tm_mon + 1,
+                                            date.tm_mday, date.tm_hour, date.tm_min,
+                                            date.tm_sec ) );
         }
         else
             vlm_MessageAdd( msg_schedule, vlm_MessageNew("date", "now") );
@@ -1481,10 +1453,8 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
         vlm_message_t *p_msg;
         vlm_message_t *p_msg_child;
         int i_vod = 0, i_broadcast = 0;
-        int i;
-        char *psz_count;
 
-        for( i = 0; i < vlm->i_media; i++ )
+        for( int i = 0; i < vlm->i_media; i++ )
         {
             if( vlm->media[i]->cfg.b_vod )
                 i_vod++;
@@ -1492,15 +1462,12 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
                 i_broadcast++;
         }
 
-        if( asprintf( &psz_count, "( %d broadcast - %d vod )", i_broadcast,
-                      i_vod) == -1 )
-            return NULL;
         p_msg = vlm_MessageSimpleNew( "show" );
-        p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media", "%s",
-                                                             psz_count ) );
-        free( psz_count );
+        p_msg_child = vlm_MessageAdd( p_msg, vlm_MessageNew( "media",
+                                      "( %d broadcast - %d vod )", i_broadcast,
+                                      i_vod ) );
 
-        for( i = 0; i < vlm->i_media; i++ )
+        for( int i = 0; i < vlm->i_media; i++ )
             vlm_MessageAdd( p_msg_child, vlm_ShowMedia( vlm->media[i] ) );
 
         return p_msg;
@@ -1546,18 +1513,13 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_sys_t *media,
             if( i_next_date > i_time )
             {
                 time_t i_date = (time_t) (i_next_date / 1000000) ;
+                struct tm tm;
+                char psz_date[32];
 
-#if !defined( UNDER_CE )
-#ifdef HAVE_CTIME_R
-                char psz_date[500];
-                ctime_r( &i_date, psz_date );
-#else
-                char *psz_date = ctime( &i_date );
-#endif
-
+                strftime( psz_date, sizeof(psz_date), "%Y-%m-%d %H:%M:%S (%a)",
+                          localtime_r( &i_date, &tm ) );
                 vlm_MessageAdd( msg_schedule,
                                 vlm_MessageNew( "next launch", "%s", psz_date ) );
-#endif
             }
         }
 
@@ -1650,12 +1612,12 @@ static char *Save( vlm_t *vlm )
         else
             i_length += strlen( "new * broadcast " ) + strlen(p_cfg->psz_name);
 
-        if( p_cfg->b_enabled == true )
+        if( p_cfg->b_enabled )
             i_length += strlen( "enabled" );
         else
             i_length += strlen( "disabled" );
 
-        if( !p_cfg->b_vod && p_cfg->broadcast.b_loop == true )
+        if( !p_cfg->b_vod && p_cfg->broadcast.b_loop )
             i_length += strlen( " loop\n" );
         else
             i_length += strlen( "\n" );
@@ -1679,7 +1641,7 @@ static char *Save( vlm_t *vlm )
 
         i_length += strlen( "new  schedule " ) + strlen( schedule->psz_name );
 
-        if( schedule->b_enabled == true )
+        if( schedule->b_enabled )
         {
             i_length += strlen( "date //-:: enabled\n" ) + 14;
         }
@@ -1770,7 +1732,7 @@ static char *Save( vlm_t *vlm )
         localtime_r( &i_time, &date);
         p += sprintf( p, "new %s schedule ", schedule->psz_name);
 
-        if( schedule->b_enabled == true )
+        if( schedule->b_enabled )
         {
             p += sprintf( p, "date %d/%d/%d-%d:%d:%d enabled\n",
                           date.tm_year + 1900, date.tm_mon + 1, date.tm_mday,