]> git.sesse.net Git - vlc/blobdiff - modules/control/rc.c
Merge intf_Create() and intf_RunThread()
[vlc] / modules / control / rc.c
index 389a2f2706ebf9f0d157c299f5752ca297f0d667..843096d043dd0923b0fffdfc177f9571a45d421e 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * rc.c : remote control stdin/stdout module for vlc
  *****************************************************************************
- * Copyright (C) 2004-2007 the VideoLAN team
+ * Copyright (C) 2004-2009 the VideoLAN team
  * $Id$
  *
  * Author: Peter Surda <shurdeek@panorama.sth.ac.at>
@@ -25,6 +25,7 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -214,7 +215,7 @@ vlc_module_end ()
 static int Activate( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
-    char *psz_host, *psz_unix_path;
+    char *psz_host, *psz_unix_path = NULL;
     int  *pi_socket = NULL;
 
 #ifndef WIN32
@@ -552,25 +553,23 @@ static void Run( intf_thread_t *p_intf )
         {
             PL_LOCK;
             int status = playlist_Status( p_playlist );
-            if( (p_intf->p_sys->i_last_state != status) &&
-                (status == PLAYLIST_STOPPED) )
-            {
-                p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
-                msg_rc( STATUS_CHANGE "( stop state: 5 )" );
-            }
-            else if(
-                (p_intf->p_sys->i_last_state != status) &&
-                (status == PLAYLIST_RUNNING) )
+            if( p_intf->p_sys->i_last_state != status )
             {
-                p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
-                 msg_rc( STATUS_CHANGE "( play state: 3 )" );
-            }
-            else if(
-                (p_intf->p_sys->i_last_state != status) &&
-                (status == PLAYLIST_PAUSED) )
-            {
-                p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
-                msg_rc( STATUS_CHANGE "( pause state: 4 )" );
+                if( status == PLAYLIST_STOPPED )
+                {
+                    p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
+                    msg_rc( STATUS_CHANGE "( stop state: 5 )" );
+                }
+                else if( status == PLAYLIST_RUNNING )
+                {
+                    p_intf->p_sys->i_last_state = PLAYLIST_RUNNING;
+                    msg_rc( STATUS_CHANGE "( play state: 3 )" );
+                }
+                else if( status == PLAYLIST_PAUSED )
+                {
+                    p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
+                    msg_rc( STATUS_CHANGE "( pause state: 4 )" );
+                }
             }
             PL_UNLOCK;
         }
@@ -634,7 +633,7 @@ static void Run( intf_thread_t *p_intf )
 
                 if( psz_msg )
                 {
-                    msg_rc( psz_msg );
+                    msg_rc( "%s", psz_msg );
                     free( psz_msg );
                 }
             }
@@ -957,8 +956,8 @@ static int TimeOffsetChanged( vlc_object_t *p_this, char const *psz_cmd,
     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
     if( p_input )
     {
-        msg_rc( STATUS_CHANGE "( time-offset: %d )",
-                var_GetInteger( p_input, "time-offset" ) );
+        msg_rc( STATUS_CHANGE "( time-offset: %"PRId64"s )",
+                (var_GetTime( p_input, "time-offset" )/1000000) );
         vlc_object_release( p_input );
     }
     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
@@ -984,34 +983,32 @@ static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
     VLC_UNUSED(p_this); VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval);
     intf_thread_t *p_intf = (intf_thread_t*)p_data;
     playlist_t    *p_playlist = NULL;
-    input_thread_t *p_input = NULL;
+    char cmd[6];
 
     vlc_mutex_lock( &p_intf->p_sys->status_lock );
-    p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
-    if( p_input )
-    {
-        p_playlist = pl_Hold( p_input );
-        char cmd[6];
-        switch( playlist_Status( p_playlist ) )
-        {
-        case PLAYLIST_STOPPED:
-            strcpy( cmd, "stop" );
-            break;
-        case PLAYLIST_RUNNING:
-            strcpy( cmd, "play" );
-            break;
-        case PLAYLIST_PAUSED:
-            strcpy( cmd, "pause" );
-            break;
-        default:
-            cmd[0] = '\0';
-        } /* var_GetInteger( p_input, "state" )  */
-        msg_rc( STATUS_CHANGE "( %s state: %d ): %s",
-                              cmd, newval.i_int,
-                              ppsz_input_state[ newval.i_int ] );
-        vlc_object_release( p_playlist );
-        vlc_object_release( p_input );
-    }
+    p_playlist = pl_Hold( p_intf );
+    PL_LOCK;
+    int i_status = playlist_Status( p_playlist );
+    PL_UNLOCK;
+    pl_Release( p_intf );
+
+    switch( i_status )
+    {
+    case PLAYLIST_STOPPED:
+        strcpy( cmd, "stop" );
+        break;
+    case PLAYLIST_RUNNING:
+        strcpy( cmd, "play" );
+        break;
+    case PLAYLIST_PAUSED:
+        strcpy( cmd, "pause" );
+        break;
+    default:
+        cmd[0] = '\0';
+    } /* var_GetInteger( p_input, "state" )  */
+    msg_rc( STATUS_CHANGE "( %s state: %d ): %s", cmd, newval.i_int,
+            ppsz_input_state[ newval.i_int ] );
+
     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
     return VLC_SUCCESS;
 }
@@ -1148,28 +1145,17 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
             }
             else
             {
-                vlc_value_t val_list;
-
                 /* Get. */
                 var_Get( p_input, "chapter", &val );
-                var_Change( p_input, "chapter", VLC_VAR_GETCHOICES,
-                            &val_list, NULL );
-                msg_rc( "Currently playing chapter %d/%d.",
-                        val.i_int, val_list.p_list->i_count );
-                var_Change( p_this, "chapter", VLC_VAR_FREELIST,
-                            &val_list, NULL );
+                int i_chapter_count = var_CountChoices( p_input, "chapter" );
+                msg_rc( "Currently playing chapter %d/%d.", val.i_int,
+                        i_chapter_count );
             }
         }
         else if( !strcmp( psz_cmd, "chapter_n" ) )
-        {
-            val.b_bool = true;
-            var_Set( p_input, "next-chapter", val );
-        }
+            var_SetVoid( p_input, "next-chapter" );
         else if( !strcmp( psz_cmd, "chapter_p" ) )
-        {
-            val.b_bool = true;
-            var_Set( p_input, "prev-chapter", val );
-        }
+            var_SetVoid( p_input, "prev-chapter" );
         vlc_object_release( p_input );
         return VLC_SUCCESS;
     }
@@ -1187,28 +1173,17 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
             }
             else
             {
-                vlc_value_t val_list;
-
                 /* Get. */
                 var_Get( p_input, "title", &val );
-                var_Change( p_input, "title", VLC_VAR_GETCHOICES,
-                            &val_list, NULL );
-                msg_rc( "Currently playing title %d/%d.",
-                        val.i_int, val_list.p_list->i_count );
-                var_Change( p_this, "title", VLC_VAR_FREELIST,
-                            &val_list, NULL );
+                int i_title_count = var_CountChoices( p_input, "title" );
+                msg_rc( "Currently playing title %d/%d.", val.i_int,
+                        i_title_count );
             }
         }
         else if( !strcmp( psz_cmd, "title_n" ) )
-        {
-            val.b_bool = true;
-            var_Set( p_input, "next-title", val );
-        }
+            var_SetVoid( p_input, "next-title" );
         else if( !strcmp( psz_cmd, "title_p" ) )
-        {
-            val.b_bool = true;
-            var_Set( p_input, "prev-title", val );
-        }
+            var_SetVoid( p_input, "prev-title" );
 
         vlc_object_release( p_input );
         return VLC_SUCCESS;
@@ -1277,8 +1252,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                     msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
                             text.p_list->p_values[i].psz_string );
             }
-            var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
-                        &val, &text );
+            var_FreeList( &val, &text );
             msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
             free( val_name.psz_string );
@@ -1551,19 +1525,8 @@ static int Intf( vlc_object_t *p_this, char const *psz_cmd,
                  vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_data);
-    intf_thread_t *p_newintf = NULL;
-
-    p_newintf = intf_Create( p_this->p_libvlc, newval.psz_string );
-    if( p_newintf )
-    {
-        if( intf_RunThread( p_newintf ) )
-        {
-            vlc_object_detach( p_newintf );
-            vlc_object_release( p_newintf );
-        }
-    }
 
-    return VLC_SUCCESS;
+    return intf_Create( p_this->p_libvlc, newval.psz_string );
 }
 
 static int Volume( vlc_object_t *p_this, char const *psz_cmd,
@@ -1807,8 +1770,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
             }
             free( psz_value );
         }
-        var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
-                    &val, &text );
+        var_FreeList( &val, &text );
         msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
         free( val_name.psz_string );
@@ -1895,8 +1857,7 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
                 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
                         text.p_list->p_values[i].psz_string );
         }
-        var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
-                    &val, &text );
+        var_FreeList( &val, &text );
         msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
         free( val_name.psz_string );