X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fcmml%2Fintf.c;h=b57cd668a6b6084f3b8c5494974f8a6c302c424a;hb=6cc9595de6e94e5f56242a7b605fc30fa3369081;hp=a0a1d8a5333989ee68bd4e01405274276dcd11a3;hpb=cd444ff97500960dd583255934f99d38dcd77ada;p=vlc diff --git a/modules/codec/cmml/intf.c b/modules/codec/cmml/intf.c index a0a1d8a533..b57cd668a6 100644 --- a/modules/codec/cmml/intf.c +++ b/modules/codec/cmml/intf.c @@ -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 @@ -21,27 +21,30 @@ * * 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 /* malloc(), free() */ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include +#include + +#include #ifdef HAVE_UNISTD_H # include #endif -#include -#include -#include -#include - -#include +#include +#include +#include +#include +#include +#include #include "vlc_keys.h" @@ -53,7 +56,6 @@ #undef CMML_INTF_USE_TIMED_URIS #undef CMML_INTF_DEBUG -#undef CMML_INTF_SUBPICTURE_DEBUG #undef CMML_INTF_HISTORY_DEBUG /***************************************************************************** @@ -64,7 +66,7 @@ struct intf_sys_t decoder_t * p_cmml_decoder; input_thread_t * p_input; - vlc_bool_t b_key_pressed; + int i_key_action; }; struct navigation_history_t @@ -76,6 +78,10 @@ struct navigation_history_t /***************************************************************************** * Local prototypes. *****************************************************************************/ + +int OpenIntf ( vlc_object_t * ); +void CloseIntf ( vlc_object_t * ); + static int InitThread ( intf_thread_t * ); static int MouseEvent ( vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void * ); @@ -108,7 +114,7 @@ static void RunIntf ( intf_thread_t *p_intf ); /***************************************************************************** * OpenIntf: initialize CMML interface *****************************************************************************/ -int E_(OpenIntf) ( vlc_object_t *p_this ) +int OpenIntf ( vlc_object_t *p_this ) { intf_thread_t *p_intf = (intf_thread_t *)p_this; @@ -120,18 +126,18 @@ 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-action", 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_vlc, "browse-go-back", VLC_VAR_VOID ); - var_AddCallback( p_intf->p_vlc, "browse-go-back", + 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_vlc, "browse-go-forward", VLC_VAR_VOID ); - var_AddCallback( p_intf->p_vlc, "browse-go-forward", + 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_vlc, "browse-follow-anchor", VLC_VAR_VOID ); - var_AddCallback( p_intf->p_vlc, "browse-follow-anchor", + 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 ); @@ -140,7 +146,7 @@ int E_(OpenIntf) ( vlc_object_t *p_this ) /***************************************************************************** * CloseIntf: destroy dummy interface *****************************************************************************/ -void E_(CloseIntf) ( vlc_object_t *p_this ) +void CloseIntf ( vlc_object_t *p_this ) { intf_thread_t * p_intf = (intf_thread_t *)p_this; vout_thread_t * p_vout; @@ -149,31 +155,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-action", KeyEvent, p_intf ); vlc_object_release( p_intf->p_sys->p_cmml_decoder ); - + free( p_intf->p_sys ); } @@ -194,18 +188,17 @@ static void RunIntf( intf_thread_t *p_intf ) msg_Dbg( p_intf, "CMML intf initialized" ); #endif - /* if video output is dying, disassociate ourselves from it */ - if( p_vout && p_vout->b_die ) - { - var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf ); - vlc_object_release( p_vout ); - p_vout = NULL; - } - /* 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 && !vlc_object_alive (p_vout) ) + { + var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf ); + vlc_object_release( p_vout ); + p_vout = NULL; + } + /* find a video output if we currently don't have one */ if( p_vout == NULL ) { @@ -225,48 +218,21 @@ static void RunIntf( intf_thread_t *p_intf ) /* * keyboard event */ - if( p_intf->p_sys->b_key_pressed ) + switch( p_intf->p_sys->i_key_action ) { - vlc_value_t val; - int i, i_action = -1; - struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys; - - /* Find action triggered by hotkey (if any) */ - var_Get( p_intf->p_vlc, "key-pressed", &val ); - - /* Acknowledge that we've handled the b_key_pressed event */ - p_intf->p_sys->b_key_pressed = VLC_FALSE; - -#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 ) - i_action = p_hotkeys[i].i_action; - } - - /* What did the user do? */ - if( i_action != -1 ) - { - switch( i_action ) - { - case ACTIONID_NAV_ACTIVATE: - FollowAnchor( p_intf ); - break; - case ACTIONID_HISTORY_BACK: - GoBack( p_intf ); - break; - case ACTIONID_HISTORY_FORWARD: - GoForward( p_intf ); - break; - default: - break; - } - } + case ACTIONID_NAV_ACTIVATE: + FollowAnchor( p_intf ); + break; + case ACTIONID_HISTORY_BACK: + GoBack( p_intf ); + break; + case ACTIONID_HISTORY_FORWARD: + GoForward( p_intf ); + break; + default: + break; } - + p_intf->p_sys->i_key_action = 0; vlc_mutex_unlock( &p_intf->change_lock ); (void) DisplayPendingAnchor( p_intf, p_vout ); @@ -303,11 +269,11 @@ static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout ) if( var_Get( p_cmml_decoder, "psz-current-anchor-description", &val ) != VLC_SUCCESS ) { - return VLC_TRUE; + return true; } if( !val.p_address ) - return VLC_TRUE; + return true; psz_description = val.p_address; @@ -320,7 +286,7 @@ 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_vlc, VLC_OBJECT_INTF, + p_primary_intf = vlc_object_find( p_intf->p_libvlc, VLC_OBJECT_INTF, FIND_CHILD ); if( p_primary_intf ) @@ -328,8 +294,14 @@ static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout ) if( var_Get( p_primary_intf, "intf-displays-cmml-description", &val ) == VLC_SUCCESS ) { - if( val.b_bool == VLC_TRUE ) return VLC_TRUE; + 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 */ @@ -337,7 +309,7 @@ static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout ) != VLC_SUCCESS ) { /* text render unsuccessful: do nothing */ - return VLC_FALSE; + return false; } /* text render successful: clear description */ @@ -352,7 +324,7 @@ static int DisplayPendingAnchor( intf_thread_t *p_intf, vout_thread_t *p_vout ) psz_url = NULL; } - return VLC_TRUE; + return true; } @@ -362,7 +334,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; @@ -386,7 +358,7 @@ static int InitThread( intf_thread_t * p_intf ) p_intf->p_sys->p_input = p_input; p_intf->p_sys->p_cmml_decoder = p_cmml_decoder; - p_intf->p_sys->b_key_pressed = VLC_FALSE; + p_intf->p_sys->i_key_action = 0; vlc_mutex_unlock( &p_intf->change_lock ); @@ -404,6 +376,9 @@ static int InitThread( intf_thread_t * p_intf ) static int MouseEvent( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(psz_var); + VLC_UNUSED(oldval); VLC_UNUSED(newval); + VLC_UNUSED(p_data); /* TODO: handle mouse clicks on the anchor text */ return VLC_SUCCESS; @@ -415,11 +390,13 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var, static int KeyEvent( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + 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 ); - p_intf->p_sys->b_key_pressed = VLC_TRUE; - + p_intf->p_sys->i_key_action = newval.i_int; + vlc_mutex_unlock( &p_intf->change_lock ); return VLC_SUCCESS; @@ -458,23 +435,17 @@ 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_Yield( 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->input.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 ); @@ -497,7 +468,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 */ @@ -539,7 +510,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_Command( p_playlist, PLAYLIST_PAUSE, 0 ); + playlist_Control( p_playlist, PLAYLIST_PAUSE, false, 0 ); } free( psz_uri_to_load ); @@ -557,11 +528,13 @@ 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 ) + if( XURL_IsFileURL( psz_url ) == true ) psz_url = xstrcat( psz_url, "#" ); else psz_url = xstrcat( psz_url, "?" ); @@ -578,13 +551,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 strdup( p_current_item->input.psz_uri ); + return input_item_GetURI( p_current_item->p_input ); #endif } @@ -602,7 +576,6 @@ int GetCurrentTimeInSeconds( input_thread_t *p_input ) var_Get( p_input, "time", &time ); i_seconds = time.i_time / 1000000; - return i_seconds; } @@ -612,7 +585,6 @@ char *GetTimedURIFragmentForTime( int seconds ) char *psz_time; asprintf( &psz_time, "%d", seconds ); - return psz_time; } @@ -620,6 +592,8 @@ static int GoBackCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(psz_var); + VLC_UNUSED(oldval); VLC_UNUSED(newval); intf_thread_t *p_intf = (intf_thread_t *) p_data; GoBack( p_intf ); return VLC_SUCCESS; @@ -629,6 +603,8 @@ static int GoForwardCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(psz_var); + VLC_UNUSED(oldval); VLC_UNUSED(newval); intf_thread_t *p_intf = (intf_thread_t *) p_data; GoForward( p_intf ); return VLC_SUCCESS; @@ -639,6 +615,8 @@ int FollowAnchorCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(psz_var); + VLC_UNUSED(oldval); VLC_UNUSED(newval); intf_thread_t *p_intf = (intf_thread_t *) p_data; FollowAnchor( p_intf ); return VLC_SUCCESS; @@ -660,13 +638,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_Yield( p_intf ); /* Retrieve navigation history from playlist */ if( var_Get( p_playlist, "navigation-history", &history ) != VLC_SUCCESS || @@ -686,14 +658,14 @@ void GoBack( intf_thread_t *p_intf ) #endif /* Check whether we can go back in the history */ - if( history_CanGoBack( p_history ) == VLC_FALSE ) + if( history_CanGoBack( p_history ) == false ) { msg_Warn( p_intf, "can't go back: already at beginning of history" ); vlc_object_release( p_playlist ); return; } - 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 ); @@ -738,13 +710,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_Yield( p_intf ); /* Retrieve navigation history from playlist */ if( var_Get( p_playlist, "navigation-history", &history ) != VLC_SUCCESS || @@ -764,7 +730,7 @@ void GoForward( intf_thread_t *p_intf ) #endif /* Check whether we can go forward in the history */ - if( history_CanGoForward( p_history ) == VLC_FALSE ) + if( history_CanGoForward( p_history ) == false ) { msg_Warn( p_intf, "can't go forward: already at end of history" ); vlc_object_release( p_playlist ); @@ -781,8 +747,8 @@ void GoForward( intf_thread_t *p_intf ) vlc_object_release( p_playlist ); return; } - 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; @@ -804,8 +770,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, true /* FIXME: p_playlist->status.i_index */, + false); } /**************************************************************************** @@ -826,18 +792,11 @@ 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; } @@ -845,21 +804,15 @@ static int DisplayAnchor( intf_thread_t *p_intf, * coordinates. Need to look at the subpicture display system to * work out why. */ if ( vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, - psz_anchor_description, p_style, OSD_ALIGN_BOTTOM, + 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 {