]> git.sesse.net Git - vlc/blobdiff - modules/control/rc.c
playlist: Move more members as private.
[vlc] / modules / control / rc.c
index 448ebf46ffd510c519248fa95968ae0efb54682d..b8f4e68fd2dcabd4bf533f0d11caeb0e9b3e8f6f 100644 (file)
@@ -149,18 +149,15 @@ struct intf_sys_t
 static void __msg_rc( intf_thread_t *p_intf, const char *psz_fmt, ... )
 {
     va_list args;
+    char fmt_eol[strlen (psz_fmt) + 3];
+
+    snprintf (fmt_eol, sizeof (fmt_eol), "%s\r\n", psz_fmt);
     va_start( args, psz_fmt );
 
     if( p_intf->p_sys->i_socket == -1 )
-    {
-        utf8_vfprintf( stdout, psz_fmt, args );
-        printf( "\r\n" );
-    }
+        utf8_vfprintf( stdout, fmt_eol, args );
     else
-    {
-        net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, psz_fmt, args );
-        net_Write( p_intf, p_intf->p_sys->i_socket, NULL, (uint8_t*)"\r\n", 2 );
-    }
+        net_vaPrintf( p_intf, p_intf->p_sys->i_socket, NULL, fmt_eol, args );
     va_end( args );
 }
 
@@ -509,7 +506,7 @@ static void Run( intf_thread_t *p_intf )
                                                    FIND_ANYWHERE );
                 if( p_input )
                 {
-                    p_playlist = pl_Yield( p_input );
+                    p_playlist = pl_Hold( p_input );
                 }
             }
             /* New input has been registered */
@@ -545,38 +542,39 @@ static void Run( intf_thread_t *p_intf )
 
             if( p_playlist )
             {
-                vlc_object_lock( p_playlist );
+                PL_LOCK;
                 p_intf->p_sys->i_last_state = (int) PLAYLIST_STOPPED;
                 msg_rc( STATUS_CHANGE "( stop state: 0 )" );
-                vlc_object_unlock( p_playlist );
+                PL_UNLOCK;
             }
         }
 
         if( (p_input != NULL) && !p_input->b_dead && vlc_object_alive (p_input) &&
             (p_playlist != NULL) )
         {
-            vlc_object_lock( p_playlist );
-            if( (p_intf->p_sys->i_last_state != p_playlist->status.i_status) &&
-                (p_playlist->status.i_status == PLAYLIST_STOPPED) )
+            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 != p_playlist->status.i_status) &&
-                (p_playlist->status.i_status == PLAYLIST_RUNNING) )
+                (p_intf->p_sys->i_last_state != status) &&
+                (status == PLAYLIST_RUNNING) )
             {
-                p_intf->p_sys->i_last_state = p_playlist->status.i_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 != p_playlist->status.i_status) &&
-                (p_playlist->status.i_status == PLAYLIST_PAUSED) )
+                (p_intf->p_sys->i_last_state != status) &&
+                (status == PLAYLIST_PAUSED) )
             {
-                p_intf->p_sys->i_last_state = p_playlist->status.i_status;
+                p_intf->p_sys->i_last_state = PLAYLIST_PAUSED;
                 msg_rc( STATUS_CHANGE "( pause state: 4 )" );
             }
-            vlc_object_unlock( p_playlist );
+            PL_UNLOCK;
         }
 
         if( p_input && b_showpos )
@@ -994,9 +992,9 @@ static int StateChanged( vlc_object_t *p_this, char const *psz_cmd,
     p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
     if( p_input )
     {
-        p_playlist = pl_Yield( p_input );
+        p_playlist = pl_Hold( p_input );
         char cmd[6];
-        switch( p_playlist->status.i_status )
+        switch( playlist_Status( p_playlist ) )
         {
         case PLAYLIST_STOPPED:
             strcpy( cmd, "stop" );
@@ -1306,21 +1304,21 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
     vlc_value_t val;
 
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
-    playlist_t *p_playlist = pl_Yield( p_this );
+    playlist_t *p_playlist = pl_Hold( p_this );
+    input_thread_t * p_input = playlist_CurrentInput( p_playlist );
 
-    PL_LOCK;
-    if( p_playlist->p_input )
+    if( p_input )
     {
-        var_Get( p_playlist->p_input, "state", &val );
+        var_Get( p_input, "state", &val );
+        vlc_object_release( p_input );
+
         if( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) )
         {
             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
-            vlc_object_release( p_playlist );
-            PL_UNLOCK;
+            pl_Release( p_this );
             return VLC_EGENERIC;
         }
     }
-    PL_UNLOCK;
 
     /* Parse commands that require a playlist */
     if( !strcmp( psz_cmd, "prev" ) )
@@ -1479,18 +1477,19 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
     }
     else if( !strcmp( psz_cmd, "status" ) )
     {
-        if( p_playlist->p_input )
+        input_thread_t * p_input = playlist_CurrentInput( p_playlist );
+        if( p_input )
         {
             /* Replay the current state of the system. */
             char *psz_uri =
-                    input_item_GetURI( input_GetItem( p_playlist->p_input ) );
+                    input_item_GetURI( input_GetItem( p_input ) );
             msg_rc( STATUS_CHANGE "( new input: %s )", psz_uri );
             free( psz_uri );
             msg_rc( STATUS_CHANGE "( audio volume: %d )",
                     config_GetInt( p_intf, "volume" ));
 
             PL_LOCK;
-            switch( p_playlist->status.i_status )
+            switch( playlist_Status(p_playlist) )
             {
                 case PLAYLIST_STOPPED:
                     msg_rc( STATUS_CHANGE "( stop state: 5 )" );
@@ -1506,6 +1505,7 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
                     break;
             }
             PL_UNLOCK;
+            vlc_object_release( p_input );
         }
     }
 
@@ -1517,7 +1517,7 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
         msg_rc( "unknown command!" );
     }
 
-    vlc_object_release( p_playlist );
+    pl_Release( p_this );
     return VLC_SUCCESS;
 }
 
@@ -1528,7 +1528,7 @@ static int Quit( vlc_object_t *p_this, char const *psz_cmd,
     VLC_UNUSED(oldval); VLC_UNUSED(newval);
     playlist_t *p_playlist;
 
-    p_playlist = pl_Yield( p_this );
+    p_playlist = pl_Hold( p_this );
     playlist_Stop( p_playlist );
     vlc_object_release( p_playlist );
     
@@ -1915,20 +1915,23 @@ static int Menu( vlc_object_t *p_this, char const *psz_cmd,
         return VLC_EGENERIC;
     }
 
-    p_playlist = pl_Yield( p_this );
+    p_playlist = pl_Hold( p_this );
+    input_thread_t * p_input = playlist_CurrentInput( p_playlist );
 
-    if( p_playlist->p_input )
+    if( p_input )
     {
-        var_Get( p_playlist->p_input, "state", &val );
+        var_Get( p_input, "state", &val );
+        vlc_object_release( p_input );
+
         if( ( ( val.i_int == PAUSE_S ) || ( val.i_int == PLAYLIST_PAUSED ) ) &&
             ( strcmp( newval.psz_string, "select" ) != 0 ) )
         {
             msg_rc( _("Type 'menu select' or 'pause' to continue.") );
-            vlc_object_release( p_playlist );
+            pl_Release( p_this );
             return VLC_EGENERIC;
         }
     }
-    vlc_object_release( p_playlist );
+    pl_Release( p_this );
 
     val.psz_string = strdup( newval.psz_string );
     if( !val.psz_string )