]> git.sesse.net Git - vlc/blobdiff - modules/codec/cmml/intf.c
CMML: privatize callback lock
[vlc] / modules / codec / cmml / intf.c
index 4a13d427c53a5c33c4b514bc9b0e6442022a7712..31fadfdcc51b063248f02af0f149302efa968cbe 100644 (file)
@@ -31,7 +31,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include <stdio.h>
 
 #endif
 
 #include <vlc_codec.h>
-#include <vlc_input.h>
 #include <vlc_interface.h>
-#include <vlc_vout.h>
 #include <vlc_playlist.h>
 #include <vlc_osd.h>
 
-#include "vlc_keys.h"
+#include <vlc_keys.h>
 
 #include "browser_open.h"
 #include "history.h"
 #include "xstrcat.h"
 #include "xurl.h"
 
-#undef  CMML_INTF_USE_TIMED_URIS
+#undef CMML_INTF_USE_TIMED_URIS
 
 #undef  CMML_INTF_DEBUG
 #undef  CMML_INTF_HISTORY_DEBUG
@@ -63,6 +61,7 @@
  *****************************************************************************/
 struct intf_sys_t
 {
+    vlc_mutex_t         lock;
     decoder_t *         p_cmml_decoder;
     input_thread_t *    p_input;
 
@@ -100,8 +99,10 @@ static int   GoForwardCallback          ( vlc_object_t *, char const *,
                                           vlc_value_t, vlc_value_t, void * );
 
 static char *GetTimedURLFromPlaylistItem( intf_thread_t *, playlist_item_t * );
-static char *GetTimedURIFragmentForTime ( int );
+#ifdef CMML_INTF_USE_TIMED_URIS
 static int   GetCurrentTimeInSeconds    ( input_thread_t * );
+static char *GetTimedURIFragmentForTime ( int );
+#endif
 static int   DisplayAnchor              ( intf_thread_t *, vout_thread_t *,
                                           char *, char * );
 static int   DisplayPendingAnchor       ( intf_thread_t *, vout_thread_t * );
@@ -120,11 +121,10 @@ int OpenIntf ( vlc_object_t *p_this )
 
     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
-    {
-        return( 1 );
-    };
+        return VLC_ENOMEM;
 
     p_intf->pf_run = RunIntf;
+    vlc_mutex_init( &p_intf->p_sys->lock );
 
     var_AddCallback( p_intf->p_libvlc, "key-action", KeyEvent, p_intf );
     /* we also need to add the callback for "mouse-clicked", but do that later
@@ -140,7 +140,7 @@ int OpenIntf ( vlc_object_t *p_this )
     var_AddCallback( p_intf->p_libvlc, "browse-follow-anchor",
                      FollowAnchorCallback, p_intf );
 
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
@@ -168,6 +168,7 @@ void CloseIntf ( vlc_object_t *p_this )
 
     vlc_object_release( p_intf->p_sys->p_cmml_decoder );
 
+    vlc_mutex_destroy( &p_intf->p_sys->lock );
     free( p_intf->p_sys );
 }
 
@@ -177,6 +178,7 @@ void CloseIntf ( vlc_object_t *p_this )
  *****************************************************************************/
 static void RunIntf( intf_thread_t *p_intf )
 {
+    int canc = vlc_savecancel();
     vout_thread_t * p_vout = NULL;
 
     if( InitThread( p_intf ) < 0 )
@@ -189,10 +191,10 @@ static void RunIntf( intf_thread_t *p_intf )
 #endif
 
     /* Main loop */
-    while( !p_intf->b_die )
+    while( vlc_object_alive (p_intf) )
     {
         /* if video output is dying, disassociate ourselves from it */
-        if( p_vout && p_vout->b_die )
+        if( p_vout && !vlc_object_alive (p_vout) )
         {
             var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
             vlc_object_release( p_vout );
@@ -213,7 +215,7 @@ static void RunIntf( intf_thread_t *p_intf )
             }
         }
 
-        vlc_mutex_lock( &p_intf->change_lock );
+        vlc_mutex_lock( &p_intf->p_sys->lock );
 
         /*
          * keyboard event
@@ -233,7 +235,7 @@ static void RunIntf( intf_thread_t *p_intf )
                 break;
         }
         p_intf->p_sys->i_key_action = 0;
-        vlc_mutex_unlock( &p_intf->change_lock );
+        vlc_mutex_unlock( &p_intf->p_sys->lock );
 
         (void) DisplayPendingAnchor( p_intf, p_vout );
 
@@ -250,6 +252,7 @@ static void RunIntf( intf_thread_t *p_intf )
     }
 
     vlc_object_release( p_intf->p_sys->p_input );
+    vlc_restorecancel( canc );
 }
 
 /*****************************************************************************
@@ -285,25 +288,6 @@ static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout )
 
     if( p_vout != NULL )
     {
-        /* don't display anchor if main interface can display it */
-        p_primary_intf = vlc_object_find( p_intf->p_libvlc, VLC_OBJECT_INTF,
-                FIND_CHILD );
-
-        if( p_primary_intf )
-        {
-            if( var_Get( p_primary_intf, "intf-displays-cmml-description", &val )
-                    == VLC_SUCCESS )
-            {
-                if( val.b_bool == true )
-                {
-                    vlc_object_release( p_primary_intf );
-                    return true;
-                }
-            }
-
-            vlc_object_release( p_primary_intf );
-        }
-
         /* display anchor as subtitle on-screen */
         if( DisplayAnchor( p_intf, p_vout, psz_description, psz_url )
                 != VLC_SUCCESS )
@@ -334,7 +318,7 @@ static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout )
 static int InitThread( intf_thread_t * p_intf )
 {
     /* We might need some locking here */
-    if( !p_intf->b_die )
+    if( vlc_object_alive (p_intf) )
     {
         input_thread_t * p_input;
         decoder_t *p_cmml_decoder;
@@ -353,14 +337,14 @@ static int InitThread( intf_thread_t * p_intf )
             return VLC_EGENERIC;
         }
 
-        vlc_mutex_lock( &p_intf->change_lock );
+        vlc_mutex_lock( &p_intf->p_sys->lock );
 
         p_intf->p_sys->p_input = p_input;
         p_intf->p_sys->p_cmml_decoder = p_cmml_decoder;
 
         p_intf->p_sys->i_key_action = 0;
 
-        vlc_mutex_unlock( &p_intf->change_lock );
+        vlc_mutex_unlock( &p_intf->p_sys->lock );
 
         return VLC_SUCCESS;
     }
@@ -393,11 +377,13 @@ static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
     VLC_UNUSED(p_this); VLC_UNUSED(psz_var);
     VLC_UNUSED(oldval); VLC_UNUSED(newval);
     intf_thread_t *p_intf = (intf_thread_t *)p_data;
-    vlc_mutex_lock( &p_intf->change_lock );
 
+
+    vlc_mutex_lock( &p_intf->p_sys->lock );
+    /* FIXME: key presses might get lost here... */
     p_intf->p_sys->i_key_action = newval.i_int;
 
-    vlc_mutex_unlock( &p_intf->change_lock );
+    vlc_mutex_unlock( &p_intf->p_sys->lock );
 
     return VLC_SUCCESS;
 }
@@ -435,16 +421,10 @@ static void FollowAnchor ( intf_thread_t *p_intf )
         mtime_t i_seconds;
         vlc_value_t time;
 
-        p_playlist = (playlist_t *) vlc_object_find( p_intf,
-                VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-        if ( !p_playlist )
-        {
-            msg_Warn( p_intf, "can't find playlist" );
-            return;
-        }
+        p_playlist = pl_Hold( p_intf );
 
         /* Get new URL */
-        p_current_item = p_playlist->status.p_item;
+        p_current_item = playlist_CurrentPlayingItem( p_playlist );
         char *psz_uri = input_item_GetURI( p_current_item->p_input );
 #ifdef CMML_INTF_DEBUG
         msg_Dbg( p_intf, "Current playlist item URL is \"%s\"", psz_uri );
@@ -516,7 +496,7 @@ static void FollowAnchor ( intf_thread_t *p_intf )
             msg_Dbg( p_intf, "calling browser_Open with \"%s\"", psz_url );
 #endif
             (void) browser_Open( psz_url );
-            playlist_Control( p_playlist, PLAYLIST_PAUSE, true, 0 );
+            playlist_Control( p_playlist, PLAYLIST_PAUSE, pl_Unlocked, 0 );
         }
 
         free( psz_uri_to_load );
@@ -558,17 +538,14 @@ char *GetTimedURLFromPlaylistItem( intf_thread_t *p_intf,
     return psz_return_value;
 #else
     VLC_UNUSED(p_intf);
-    void *p;
-
-    /* Suppress warning messages about unused functions */
-    p = GetTimedURIFragmentForTime; /* unused */
-    p = GetCurrentTimeInSeconds;    /* unused */
 
     return input_item_GetURI( p_current_item->p_input );
 #endif
 }
 
 
+
+#ifdef CMML_INTF_USE_TIMED_URIS
 /*
  * Get the current time, rounded down to the nearest second
  *
@@ -590,9 +567,11 @@ char *GetTimedURIFragmentForTime( int seconds )
 {
     char *psz_time;
 
-    asprintf( &psz_time, "%d", seconds );
+    if( asprintf( &psz_time, "%d", seconds ) == -1 )
+        return NULL;
     return psz_time;
 }
+#endif
 
 static
 int GoBackCallback( vlc_object_t *p_this, char const *psz_var,
@@ -644,13 +623,7 @@ void GoBack( intf_thread_t *p_intf )
 #endif
 
     /* Find the playlist */
-    p_playlist = (playlist_t *) vlc_object_find( p_intf,
-            VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if ( !p_playlist )
-    {
-        msg_Warn( p_intf, "can't find playlist" );
-        return;
-    }
+    p_playlist = pl_Hold( p_intf );
 
     /* Retrieve navigation history from playlist */
     if( var_Get( p_playlist, "navigation-history", &history ) != VLC_SUCCESS ||
@@ -677,7 +650,7 @@ void GoBack( intf_thread_t *p_intf )
         return;
     }
 
-    p_current_item = p_playlist->status.p_item;
+    p_current_item = playlist_CurrentPlayingItem( p_playlist );
 
     /* Save the currently-playing media in a new history item */
     psz_timed_url = GetTimedURLFromPlaylistItem( p_intf, p_current_item );
@@ -722,13 +695,7 @@ void GoForward( intf_thread_t *p_intf )
 #endif
 
     /* Find the playlist */
-    p_playlist = (playlist_t *) vlc_object_find( p_intf,
-            VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if ( !p_playlist )
-    {
-        msg_Warn( p_intf, "can't find playlist" );
-        return;
-    }
+    p_playlist = pl_Hold( p_intf );
 
     /* Retrieve navigation history from playlist */
     if( var_Get( p_playlist, "navigation-history", &history ) != VLC_SUCCESS ||
@@ -765,7 +732,7 @@ void GoForward( intf_thread_t *p_intf )
         vlc_object_release( p_playlist );
         return;
     }
-    p_current_item = p_playlist->status.p_item;
+    p_current_item = playlist_CurrentPlayingItem( p_playlist );
     p_new_history_item->psz_uri = GetTimedURLFromPlaylistItem( p_intf,
             p_current_item );
     p_new_history_item->psz_name = p_new_history_item->psz_uri;