]> git.sesse.net Git - vlc/blobdiff - modules/codec/cmml/intf.c
Input access locking, part 3 (final).
[vlc] / modules / codec / cmml / intf.c
index 1907938a828b66dee79382076719994273751611..fa45e66d25d3ea5bca6b30a350b7e999f7848334 100644 (file)
@@ -3,7 +3,7 @@
  *****************************************************************************
  * Copyright (C) 2003-2004 Commonwealth Scientific and Industrial Research
  *                         Organisation (CSIRO) Australia
- * Copyright (C) 2004 VideoLAN
+ * Copyright (C) 2004 the VideoLAN team
  *
  * $Id$
  *
@@ -13,7 +13,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 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
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
-#include <unistd.h>
-
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/intf.h>
-#include <vlc/vout.h>
 
-#include <osd.h>
+#include <stdio.h>
+
+#ifdef HAVE_UNISTD_H
+#    include <unistd.h>
+#endif
 
-#include "stream_control.h"
-#include "input_ext-intf.h"
-#include "input_ext-dec.h"
+#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"
 
@@ -52,7 +52,6 @@
 #undef  CMML_INTF_USE_TIMED_URIS
 
 #undef  CMML_INTF_DEBUG
-#undef  CMML_INTF_SUBPICTURE_DEBUG
 #undef  CMML_INTF_HISTORY_DEBUG
 
 /*****************************************************************************
@@ -85,11 +84,19 @@ static void  FollowAnchor               ( intf_thread_t * );
 static void  GoBack                     ( intf_thread_t * );
 static void  GoForward                  ( intf_thread_t * );
 
+static int   FollowAnchorCallback       ( vlc_object_t *, char const *,
+                                          vlc_value_t, vlc_value_t, void * );
+static int   GoBackCallback             ( vlc_object_t *, char const *,
+                                          vlc_value_t, vlc_value_t, void * );
+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 );
 static int   GetCurrentTimeInSeconds    ( input_thread_t * );
 static int   DisplayAnchor              ( intf_thread_t *, vout_thread_t *,
                                           char *, char * );
+static int   DisplayPendingAnchor       ( intf_thread_t *, vout_thread_t * );
 static history_t * GetHistory           ( playlist_t * );
 static void  ReplacePlaylistItem        ( playlist_t *, char * );
 
@@ -110,11 +117,21 @@ int E_(OpenIntf) ( vlc_object_t *p_this )
     };
 
     p_intf->pf_run = RunIntf;
-    
-    var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
+
+    var_AddCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf );
     /* we also need to add the callback for "mouse-clicked", but do that later
      * when we've found a p_vout */
 
+    var_Create( p_intf->p_libvlc, "browse-go-back", VLC_VAR_VOID );
+    var_AddCallback( p_intf->p_libvlc, "browse-go-back",
+                     GoBackCallback, p_intf );
+    var_Create( p_intf->p_libvlc, "browse-go-forward", VLC_VAR_VOID );
+    var_AddCallback( p_intf->p_libvlc, "browse-go-forward",
+                     GoForwardCallback, p_intf );
+    var_Create( p_intf->p_libvlc, "browse-follow-anchor", VLC_VAR_VOID );
+    var_AddCallback( p_intf->p_libvlc, "browse-follow-anchor",
+                     FollowAnchorCallback, p_intf );
+
     return( 0 );
 }
 
@@ -130,31 +147,19 @@ void E_(CloseIntf) ( vlc_object_t *p_this )
     msg_Dbg( p_intf, "freeing CMML interface" );
 #endif
 
-    /* Erase the anchor text description from the video output if it exists */
+    /* erase the anchor text description from the video output if it exists */
     p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
-    if( p_vout != NULL && p_vout->p_subpicture != NULL )
+    if( p_vout )
     {
-        subpicture_t *p_subpic;
-        int          i_subpic;
-
-        for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
-        {
-            p_subpic = &p_vout->p_subpicture[i_subpic];
-
-            if( p_subpic != NULL &&
-              ( p_subpic->i_status == RESERVED_SUBPICTURE
-                || p_subpic->i_status == READY_SUBPICTURE ) )
-            {
-                vout_DestroySubPicture( p_vout, p_subpic );
-            }
-        }
+        /* enable CMML as a subtitle track */
+        spu_Control( p_vout->p_spu, SPU_CHANNEL_CLEAR, DEFAULT_CHAN );
+        vlc_object_release( p_vout );
     }
-    if( p_vout ) vlc_object_release( p_vout );
 
-    var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
+    var_DelCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf );
 
     vlc_object_release( p_intf->p_sys->p_cmml_decoder );
-   
+
     free( p_intf->p_sys );
 }
 
@@ -186,9 +191,7 @@ static void RunIntf( intf_thread_t *p_intf )
     /* Main loop */
     while( !p_intf->b_die )
     {
-        vlc_value_t val;
-        decoder_t *p_cmml_decoder;
-        
+
         /* find a video output if we currently don't have one */
         if( p_vout == NULL )
         {
@@ -212,10 +215,10 @@ static void RunIntf( intf_thread_t *p_intf )
         {
             vlc_value_t val;
             int i, i_action = -1;
-            struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
+            struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
 
             /* Find action triggered by hotkey (if any) */
-            var_Get( p_intf->p_vlc, "key-pressed", &val );
+            var_Get( p_intf->p_libvlc, "key-pressed", &val );
 
             /* Acknowledge that we've handled the b_key_pressed event */
             p_intf->p_sys->b_key_pressed = VLC_FALSE;
@@ -223,7 +226,7 @@ static void RunIntf( intf_thread_t *p_intf )
 #ifdef CMML_INTF_DEBUG
             msg_Dbg( p_intf, "Got a keypress: %d", val.i_int );
 #endif
-            
+
             for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
             {
                 if( p_hotkeys[i].i_key == val.i_int )
@@ -248,55 +251,11 @@ static void RunIntf( intf_thread_t *p_intf )
                         break;
                 }
             }
-        }       
+        }
 
         vlc_mutex_unlock( &p_intf->change_lock );
 
-        /*
-         * Get a pending anchor description/URL from the CMML decoder
-         * and display it on screen
-         */
-        p_cmml_decoder = p_intf->p_sys->p_cmml_decoder;
-        if( var_Get( p_cmml_decoder, "psz-current-anchor-description", &val )
-                == VLC_SUCCESS )
-        {
-            if( val.p_address )
-            {
-                char *psz_description = NULL;
-                char *psz_url = NULL;
-
-                psz_description = val.p_address;
-
-                if( var_Get( p_cmml_decoder, "psz-current-anchor-url", &val )
-                        == VLC_SUCCESS )
-                {
-                    psz_url = val.p_address;
-                }
-
-                if( p_vout != NULL )
-                {
-                    if( DisplayAnchor( p_intf, p_vout, psz_description,
-                                psz_url ) != VLC_SUCCESS )
-                    {
-                        /* text render unsuccessful: do nothing */
-                    }
-                    else
-                    {
-                        /* text render successful: clear description */
-                        val.p_address = NULL;
-                        if( var_Set( p_cmml_decoder,
-                                    "psz-current-anchor-description", val ) !=
-                                VLC_SUCCESS )
-                        {
-                            msg_Dbg( p_intf, "reset of "
-                                    "psz-current-anchor-description failed" );
-                        }
-                        free( psz_description );
-                        psz_url = NULL;
-                    }
-                }
-            }
-        }
+        (void) DisplayPendingAnchor( p_intf, p_vout );
 
         /* Wait a bit */
         msleep( INTF_IDLE_SLEEP );
@@ -313,6 +272,82 @@ static void RunIntf( intf_thread_t *p_intf )
     vlc_object_release( p_intf->p_sys->p_input );
 }
 
+/*****************************************************************************
+ * DisplayPendingAnchor: get a pending anchor description/URL from the CMML
+ * decoder and display it on screen
+ *****************************************************************************/
+static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout )
+{
+    decoder_t *p_cmml_decoder;
+    char *psz_description = NULL;
+    char *psz_url = NULL;
+
+    intf_thread_t *p_primary_intf;
+    vlc_value_t val;
+
+    p_cmml_decoder = p_intf->p_sys->p_cmml_decoder;
+    if( var_Get( p_cmml_decoder, "psz-current-anchor-description", &val )
+            != VLC_SUCCESS )
+    {
+        return VLC_TRUE;
+    }
+
+    if( !val.p_address )
+        return VLC_TRUE;
+
+    psz_description = val.p_address;
+
+    if( var_Get( p_cmml_decoder, "psz-current-anchor-url", &val )
+            == VLC_SUCCESS )
+    {
+        psz_url = val.p_address;
+    }
+
+    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 == VLC_TRUE )
+                {
+                    vlc_object_release( p_primary_intf );
+                    return VLC_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 )
+        {
+            /* text render unsuccessful: do nothing */
+            return VLC_FALSE;
+        }
+
+        /* text render successful: clear description */
+        val.p_address = NULL;
+        if( var_Set( p_cmml_decoder, "psz-current-anchor-description", val )
+                != VLC_SUCCESS )
+        {
+            msg_Dbg( p_intf,
+                     "reset of psz-current-anchor-description failed" );
+        }
+        free( psz_description );
+        psz_url = NULL;
+    }
+
+    return VLC_TRUE;
+}
+
+
 /*****************************************************************************
  * InitThread:
  *****************************************************************************/
@@ -376,7 +411,7 @@ static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
     vlc_mutex_lock( &p_intf->change_lock );
 
     p_intf->p_sys->b_key_pressed = VLC_TRUE;
-    
+
     vlc_mutex_unlock( &p_intf->change_lock );
 
     return VLC_SUCCESS;
@@ -412,8 +447,10 @@ static void FollowAnchor ( intf_thread_t *p_intf )
         playlist_t *p_playlist;
         playlist_item_t *p_current_item;
         char *psz_uri_to_load;
+        mtime_t i_seconds;
+        vlc_value_t time;
 
-        p_playlist = (playlist_t *) vlc_object_find( p_intf, 
+        p_playlist = (playlist_t *) vlc_object_find( p_intf,
                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
         if ( !p_playlist )
         {
@@ -422,21 +459,19 @@ static void FollowAnchor ( intf_thread_t *p_intf )
         }
 
         /* Get new URL */
-        p_current_item = p_playlist->pp_items[p_playlist->i_index];
+        p_current_item = p_playlist->status.p_item;
+        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\"",
-                p_current_item->psz_uri );
+        msg_Dbg( p_intf, "Current playlist item URL is \"%s\"", psz_uri );
 #endif
 
-        psz_uri_to_load = XURL_Concat( p_current_item->input.psz_uri,
-                                       psz_url );
+        psz_uri_to_load = XURL_Concat( psz_uri, psz_url );
+        free( psz_uri );
 
 #ifdef CMML_INTF_DEBUG
         msg_Dbg( p_intf, "URL to load is \"%s\"", psz_uri_to_load );
 #endif
 
-        mtime_t i_seconds;
-        vlc_value_t time;
         if( var_Get( p_intf->p_sys->p_input, "time", &time ) )
         {
             msg_Dbg( p_intf, "couldn't get time from current clip" );
@@ -454,7 +489,7 @@ static void FollowAnchor ( intf_thread_t *p_intf )
             history_t *p_history = NULL;
             history_item_t *p_history_item = NULL;
             char *psz_timed_url;
-            
+
             p_history = GetHistory( p_playlist );
 
             /* create history item */
@@ -492,8 +527,11 @@ static void FollowAnchor ( intf_thread_t *p_intf )
         }
         else
         {
+#ifdef CMML_INTF_DEBUG
+            msg_Dbg( p_intf, "calling browser_Open with \"%s\"", psz_url );
+#endif
             (void) browser_Open( psz_url );
-            playlist_Command( p_playlist, PLAYLIST_PAUSE, 0 );
+            playlist_Control( p_playlist, PLAYLIST_PAUSE, VLC_TRUE, 0 );
         }
 
         free( psz_uri_to_load );
@@ -511,8 +549,10 @@ char *GetTimedURLFromPlaylistItem( intf_thread_t *p_intf,
     char *psz_return_value = NULL;
     char *psz_seconds = NULL;
     int i_seconds;
-    
-    psz_url = XURL_GetWithoutFragment( p_current_item->input->psz_uri );
+
+    char *psz_uri = input_item_GetURI( p_current_item->p_input );
+    psz_url = XURL_GetWithoutFragment( psz_uri );
+    free( psz_uri );
 
     /* Get current time as a string */
     if( XURL_IsFileURL( psz_url ) == VLC_TRUE )
@@ -538,7 +578,7 @@ char *GetTimedURLFromPlaylistItem( intf_thread_t *p_intf,
     p = GetTimedURIFragmentForTime; /* unused */
     p = GetCurrentTimeInSeconds;    /* unused */
 
-    return strdup( p_current_item->input.psz_uri );
+    return input_item_GetURI( p_current_item->p_input );
 #endif
 }
 
@@ -556,7 +596,6 @@ int GetCurrentTimeInSeconds( input_thread_t *p_input )
 
     var_Get( p_input, "time", &time );
     i_seconds = time.i_time / 1000000;
-
     return i_seconds;
 }
 
@@ -566,10 +605,37 @@ char *GetTimedURIFragmentForTime( int seconds )
     char *psz_time;
 
     asprintf( &psz_time, "%d", seconds );
-
     return psz_time;
 }
 
+static
+int GoBackCallback( vlc_object_t *p_this, char const *psz_var,
+                    vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    intf_thread_t *p_intf = (intf_thread_t *) p_data;
+    GoBack( p_intf );
+    return VLC_SUCCESS;
+}
+
+static
+int GoForwardCallback( vlc_object_t *p_this, char const *psz_var,
+                       vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+    intf_thread_t *p_intf = (intf_thread_t *) p_data;
+    GoForward( p_intf );
+    return VLC_SUCCESS;
+}
+
+static
+int FollowAnchorCallback( vlc_object_t *p_this, char const *psz_var,
+                          vlc_value_t oldval, vlc_value_t newval,
+                          void *p_data )
+{
+    intf_thread_t *p_intf = (intf_thread_t *) p_data;
+    FollowAnchor( p_intf );
+    return VLC_SUCCESS;
+}
+
 static
 void GoBack( intf_thread_t *p_intf )
 {
@@ -579,13 +645,14 @@ void GoBack( intf_thread_t *p_intf )
     history_item_t *p_new_history_item = NULL;
     playlist_t *p_playlist = NULL;
     char *psz_timed_url = NULL;
+    playlist_item_t *p_current_item;
 
 #ifdef CMML_INTF_DEBUG
     msg_Dbg( p_intf, "Going back in navigation history" );
 #endif
 
     /* Find the playlist */
-    p_playlist = (playlist_t *) vlc_object_find( p_intf, 
+    p_playlist = (playlist_t *) vlc_object_find( p_intf,
             VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
     if ( !p_playlist )
     {
@@ -618,8 +685,7 @@ void GoBack( intf_thread_t *p_intf )
         return;
     }
 
-    playlist_item_t *p_current_item;
-    p_current_item = p_playlist->pp_items[p_playlist->i_index];
+    p_current_item = p_playlist->status.p_item;
 
     /* Save the currently-playing media in a new history item */
     psz_timed_url = GetTimedURLFromPlaylistItem( p_intf, p_current_item );
@@ -657,13 +723,14 @@ void GoForward( intf_thread_t *p_intf )
     history_item_t *p_history_item = NULL;
     history_item_t *p_new_history_item = NULL;
     playlist_t *p_playlist = NULL;
+    playlist_item_t *p_current_item;
 
 #ifdef CMML_INTF_DEBUG
     msg_Dbg( p_intf, "Going forward in navigation history" );
 #endif
 
     /* Find the playlist */
-    p_playlist = (playlist_t *) vlc_object_find( p_intf, 
+    p_playlist = (playlist_t *) vlc_object_find( p_intf,
             VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
     if ( !p_playlist )
     {
@@ -706,9 +773,8 @@ void GoForward( intf_thread_t *p_intf )
         vlc_object_release( p_playlist );
         return;
     }
-    playlist_item_t *p_current_item;
-    p_current_item = p_playlist->pp_items[p_playlist->i_index];
-    p_new_history_item->psz_uri = GetTimedURLFromPlaylistItem( p_intf, 
+    p_current_item = p_playlist->status.p_item;
+    p_new_history_item->psz_uri = GetTimedURLFromPlaylistItem( p_intf,
             p_current_item );
     p_new_history_item->psz_name = p_new_history_item->psz_uri;
 
@@ -730,8 +796,8 @@ static void ReplacePlaylistItem( playlist_t *p_playlist, char *psz_uri )
 {
     playlist_Stop( p_playlist );
     (void) playlist_Add( p_playlist, psz_uri, psz_uri,
-                         PLAYLIST_REPLACE, p_playlist->i_index );
-    playlist_Goto( p_playlist, p_playlist->i_index );
+                         PLAYLIST_INSERT /* FIXME: used to be PLAYLIST_REPLACE */, PLAYLIST_END|PLAYLIST_GO, VLC_TRUE /* FIXME: p_playlist->status.i_index */,
+                         VLC_FALSE);
 }
 
 /****************************************************************************
@@ -752,40 +818,27 @@ static int DisplayAnchor( intf_thread_t *p_intf,
 
     if( p_vout )
     {
-        text_style_t *p_style = NULL;
-
-        text_style_t blue_with_underline = default_text_style;
-        blue_with_underline.b_underline = VLC_TRUE;
-        blue_with_underline.i_color = 0x22ff22;
-
         if( psz_anchor_url )
         {
-            /* Should display subtitle underlined and in blue,
-             * but it looks like VLC doesn't implement any
-             * text styles yet.  D'oh! */
-            p_style = &blue_with_underline;
+            /* Should display subtitle underlined and in blue, but it looks
+             * like VLC doesn't implement any text styles yet.  D'oh! */
+            // p_style = &blue_with_underline;
 
         }
 
         /* TODO: p_subpicture doesn't have the proper i_x and i_y
          * coordinates.  Need to look at the subpicture display system to
          * work out why. */
-        if ( vout_ShowTextAbsolute( p_vout,
-                psz_anchor_description, p_style, OSD_ALIGN_BOTTOM, 
+        if ( vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN,
+                psz_anchor_description, NULL, OSD_ALIGN_BOTTOM,
                 i_margin_h, i_margin_v, i_now, 0 ) == VLC_SUCCESS )
         {
             /* Displayed successfully */
-#ifdef CMML_INTF_SUBPICTURE_DEBUG
-            msg_Dbg( p_intf, "subpicture created at (%d, %d) (%d, %d)",
-                     p_subpicture->i_x, p_subpicture->i_y,
-                     p_subpicture->i_width, p_subpicture->i_height );
-#endif
         }
         else
         {
             return VLC_EGENERIC;
         }
-
     }
     else
     {