]> git.sesse.net Git - vlc/blobdiff - modules/control/rc.c
playlist: Move more members as private.
[vlc] / modules / control / rc.c
index 5e45c61a6272ef15f651812a5e85d39c30ae68a5..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 );
 }
 
@@ -449,13 +446,14 @@ static void Run( intf_thread_t *p_intf )
     input_thread_t * p_input;
     playlist_t *     p_playlist;
 
-    char       p_buffer[ MAX_LINE_LENGTH + 1 ];
+    char p_buffer[ MAX_LINE_LENGTH + 1 ];
     bool b_showpos = config_GetInt( p_intf, "rc-show-pos" );
     bool b_longhelp = false;
 
-    int        i_size = 0;
-    int        i_oldpos = 0;
-    int        i_newpos;
+    int  i_size = 0;
+    int  i_oldpos = 0;
+    int  i_newpos;
+    int  canc = vlc_savecancel();
 
     p_buffer[0] = 0;
     p_input = NULL;
@@ -478,7 +476,7 @@ static void Run( intf_thread_t *p_intf )
     }
 #endif
 
-    while( !intf_ShouldDie( p_intf ) )
+    while( vlc_object_alive( p_intf ) )
     {
         char *psz_cmd, *psz_arg;
         bool b_complete;
@@ -508,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 */
@@ -544,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 )
@@ -846,6 +845,7 @@ static void Run( intf_thread_t *p_intf )
     }
 
     var_DelCallback( p_intf->p_libvlc, "volume-change", VolumeChanged, p_intf );
+    vlc_restorecancel( canc );
 }
 
 static void Help( intf_thread_t *p_intf, bool b_longhelp)
@@ -992,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" );
@@ -1304,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" ) )
@@ -1477,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 )" );
@@ -1504,6 +1505,7 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
                     break;
             }
             PL_UNLOCK;
+            vlc_object_release( p_input );
         }
     }
 
@@ -1515,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;
 }
 
@@ -1526,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 );
     
@@ -1913,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 )
@@ -2048,7 +2053,7 @@ bool ReadWin32( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
     while( WaitForSingleObject( p_intf->p_sys->hConsoleIn,
                                 INTF_IDLE_SLEEP/1000 ) == WAIT_OBJECT_0 )
     {
-        while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
+        while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
                ReadConsoleInput( p_intf->p_sys->hConsoleIn, &input_record,
                                  1, &i_dw ) )
         {
@@ -2118,7 +2123,7 @@ bool ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
     }
 #endif
 
-    while( !intf_ShouldDie( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
+    while( vlc_object_alive( p_intf ) && *pi_size < MAX_LINE_LENGTH &&
            (i_read = net_Read( p_intf, p_intf->p_sys->i_socket == -1 ?
                        0 /*STDIN_FILENO*/ : p_intf->p_sys->i_socket, NULL,
                   (uint8_t *)p_buffer + *pi_size, 1, false ) ) > 0 )