From: Felix Paul Kühne Date: Fri, 13 Jun 2008 07:48:13 +0000 (+0200) Subject: Replaced a certain amount of vlc_object_find by pl_Yield X-Git-Tag: 0.9.0-test0~171 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=fd6294273ec43243abac97dd11b4fca1cd4f0257;p=vlc Replaced a certain amount of vlc_object_find by pl_Yield Great news: there is no need to check for the existance of the playlist! --- diff --git a/modules/codec/cmml/intf.c b/modules/codec/cmml/intf.c index 1ecfbf0a40..ac908726e0 100644 --- a/modules/codec/cmml/intf.c +++ b/modules/codec/cmml/intf.c @@ -435,13 +435,7 @@ 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->status.p_item; @@ -644,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 || @@ -722,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 || diff --git a/modules/control/gestures.c b/modules/control/gestures.c index d2d02dfafc..282aaf6a00 100644 --- a/modules/control/gestures.c +++ b/modules/control/gestures.c @@ -226,11 +226,7 @@ static void RunIntf( intf_thread_t *p_intf ) case GESTURE(RIGHT,LEFT,NONE,NONE): { input_thread_t * p_input; - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - - if( !p_playlist ) - break; + p_playlist = pl_Yield( p_intf ); p_input = input_from_playlist( p_playlist ); vlc_object_release( p_playlist ); @@ -257,23 +253,13 @@ static void RunIntf( intf_thread_t *p_intf ) } break; case GESTURE(LEFT,DOWN,NONE,NONE): - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist == NULL ) - { - break; - } + p_playlist = pl_Yield( p_intf ); playlist_Prev( p_playlist ); vlc_object_release( p_playlist ); break; case GESTURE(RIGHT,DOWN,NONE,NONE): - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist == NULL ) - { - break; - } + p_playlist = pl_Yield( p_intf ); playlist_Next( p_playlist ); vlc_object_release( p_playlist ); @@ -306,11 +292,7 @@ static void RunIntf( intf_thread_t *p_intf ) vlc_value_t val, list, list2; int i_count, i; - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - - if( !p_playlist ) - break; + p_playlist = pl_Yield( p_intf ); p_input = input_from_playlist( p_playlist ); @@ -365,11 +347,7 @@ static void RunIntf( intf_thread_t *p_intf ) vlc_value_t val, list, list2; int i_count, i; - p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - - if( !p_playlist ) - break; + p_playlist = pl_Yield( p_intf ); p_input = input_from_playlist( p_playlist ); vlc_object_release( p_playlist ); diff --git a/modules/control/rc.c b/modules/control/rc.c index 5df1f3f35f..5d7744caf1 100644 --- a/modules/control/rc.c +++ b/modules/control/rc.c @@ -499,8 +499,7 @@ static void Run( intf_thread_t *p_intf ) FIND_ANYWHERE ); if( p_input ) { - p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, - FIND_PARENT ); + p_playlist = pl_Yield( p_input ); } } /* New input has been registered */ @@ -984,29 +983,26 @@ 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 = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT ); - if( p_playlist ) + p_playlist = pl_Yield( p_input ); + char cmd[6]; + switch( p_playlist->status.i_status ) { - char cmd[6]; - switch( p_playlist->status.i_status ) - { - case PLAYLIST_STOPPED: - strcpy( cmd, "stop" ); - break; - case PLAYLIST_RUNNING: - strcpy( cmd, "play" ); - break; - case PLAYLIST_PAUSED: - strcpy( cmd, "pause" ); - break; - default: - cmd[0] = '\0'; - } /* var_GetInteger( p_input, "state" ) */ - msg_rc( STATUS_CHANGE "( %s state: %d ): %s", - &cmd[0], newval.i_int, - ppsz_input_state[ newval.i_int ] ); - vlc_object_release( p_playlist ); - } + case PLAYLIST_STOPPED: + strcpy( cmd, "stop" ); + break; + case PLAYLIST_RUNNING: + strcpy( cmd, "play" ); + break; + case PLAYLIST_PAUSED: + strcpy( cmd, "pause" ); + break; + default: + cmd[0] = '\0'; + } /* var_GetInteger( p_input, "state" ) */ + msg_rc( STATUS_CHANGE "( %s state: %d ): %s", + &cmd[0], newval.i_int, + ppsz_input_state[ newval.i_int ] ); + vlc_object_release( p_playlist ); vlc_object_release( p_input ); } vlc_mutex_unlock( &p_intf->p_sys->status_lock ); @@ -1521,12 +1517,10 @@ static int Quit( vlc_object_t *p_this, char const *psz_cmd, VLC_UNUSED(oldval); VLC_UNUSED(newval); playlist_t *p_playlist; - p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); - if( p_playlist ) - { - playlist_Stop( p_playlist ); - vlc_object_release( p_playlist ); - } + p_playlist = pl_Yield( p_this ); + playlist_Stop( p_playlist ); + vlc_object_release( p_playlist ); + vlc_object_kill( p_this->p_libvlc ); return VLC_SUCCESS; } @@ -1910,9 +1904,7 @@ static int Menu( vlc_object_t *p_this, char const *psz_cmd, return VLC_EGENERIC; } - p_playlist = vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); - if( !p_playlist ) - return VLC_ENOOBJ; + p_playlist = pl_Yield( p_this ); if( p_playlist->p_input ) { diff --git a/modules/gui/macosx/applescript.m b/modules/gui/macosx/applescript.m index 232d7e53d4..f860af6e32 100644 --- a/modules/gui/macosx/applescript.m +++ b/modules/gui/macosx/applescript.m @@ -1,7 +1,7 @@ /***************************************************************************** * applescript.m: MacOS X AppleScript support ***************************************************************************** - * Copyright (C) 2002-2003, 2005, 2007 the VideoLAN team + * Copyright (C) 2002-2003, 2005, 2007-2008 the VideoLAN team * $Id$ * * Authors: Derk-Jan Hartman @@ -41,8 +41,7 @@ if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] ) { intf_thread_t * p_intf = VLCIntf; - playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + playlist_t * p_playlist = pl_Yield( p_intf ); if( p_playlist == NULL ) { return nil; @@ -91,8 +90,7 @@ NSString *o_command = [[self commandDescription] commandName]; intf_thread_t * p_intf = VLCIntf; - playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + playlist_t * p_playlist = pl_Yield( p_intf ); if( p_playlist == NULL ) { return nil; diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m index 762e8d929c..b9927dd096 100644 --- a/modules/gui/macosx/playlist.m +++ b/modules/gui/macosx/playlist.m @@ -274,7 +274,7 @@ else { char *psz_name = input_item_GetName( p_item->p_input ); - if( psz_name != NULL ) + if( !EMPTY_STR( psz_name ) ) { o_value = [NSString stringWithUTF8String: psz_name]; } @@ -372,7 +372,7 @@ @"VLCPlaylistItemPboardType", nil]]; [o_outline_view setIntercellSpacing: NSMakeSize (0.0, 1.0)]; - /* This uses private Apple API which works fine until 10.4. + /* This uses private Apple API which works fine until 10.5. * We need to keep checking in the future! * These methods are being added artificially to NSOutlineView's interface above */ o_ascendingSortingImage = [[NSOutlineView class] _defaultTableHeaderSortImage]; @@ -1110,9 +1110,9 @@ } else if( b_selected_item_met == YES && ( [o_current_name rangeOfString:[o_search_field - stringValue] options:NSCaseInsensitiveSearch ].length || + stringValue] options:NSCaseInsensitiveSearch].length || [o_current_author rangeOfString:[o_search_field - stringValue] options:NSCaseInsensitiveSearch ].length ) ) + stringValue] options:NSCaseInsensitiveSearch].length ) ) { vlc_object_release( p_playlist ); /*Adds the parent items in the result array as well, so that we can diff --git a/modules/gui/macosx/vout.m b/modules/gui/macosx/vout.m index e6465b5c7a..4fde1d1078 100644 --- a/modules/gui/macosx/vout.m +++ b/modules/gui/macosx/vout.m @@ -1208,8 +1208,7 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, - (BOOL)windowShouldClose:(id)sender { - playlist_t * p_playlist = vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); + playlist_t * p_playlist = pl_Yield( p_vout ); if( p_playlist == NULL ) { return NO; diff --git a/modules/gui/qt4/input_manager.cpp b/modules/gui/qt4/input_manager.cpp index 1280485f4e..40c4e66edc 100644 --- a/modules/gui/qt4/input_manager.cpp +++ b/modules/gui/qt4/input_manager.cpp @@ -545,13 +545,9 @@ void MainInputManager::customEvent( QEvent *event ) else { /* we are working as a dialogs provider */ - playlist_t *p_playlist = (playlist_t *) vlc_object_find( p_intf, - VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); - if( p_playlist ) - { - p_input = p_playlist->p_input; - emit inputChanged( p_input ); - } + playlist_t *p_playlist = pl_Yield( p_intf ); + p_input = p_playlist->p_input; + emit inputChanged( p_input ); } } diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp index 2784db7abf..cbc8a64b36 100644 --- a/modules/gui/skins2/src/skin_main.cpp +++ b/modules/gui/skins2/src/skin_main.cpp @@ -98,14 +98,7 @@ static int Open( vlc_object_t *p_this ) p_intf->p_sys->p_sub = msg_Subscribe( p_intf ); p_intf->p_sys->p_input = NULL; - p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf, - VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); - if( p_intf->p_sys->p_playlist == NULL ) - { - msg_Err( p_intf, "No playlist object found" ); - msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub ); - return VLC_EGENERIC; - } + p_intf->p_sys->p_playlist = pl_Yield( p_intf ); // Initialize "singleton" objects p_intf->p_sys->p_logger = NULL; @@ -290,16 +283,11 @@ static int DemuxOpen( vlc_object_t *p_this ) // Do nothing is skins2 is not the main interface if( var_Type( p_intf, "skin-to-load" ) == VLC_VAR_STRING ) { - playlist_t *p_playlist = - (playlist_t *) vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist != NULL ) - { - // Make sure the item is deleted afterwards - /// \bug does not always work - p_playlist->status.p_item->i_flags |= PLAYLIST_REMOVE_FLAG; - vlc_object_release( p_playlist ); - } + playlist_t *p_playlist = pl_Yield( p_this ); + // Make sure the item is deleted afterwards + /// \bug does not always work + p_playlist->status.p_item->i_flags |= PLAYLIST_REMOVE_FLAG; + vlc_object_release( p_playlist ); vlc_value_t val; val.psz_string = p_demux->psz_path; diff --git a/modules/misc/dummy/input.c b/modules/misc/dummy/input.c index 81e24b0722..64ba12dde3 100644 --- a/modules/misc/dummy/input.c +++ b/modules/misc/dummy/input.c @@ -206,13 +206,7 @@ static int Demux( demux_t *p_demux ) playlist_t *p_playlist; bool b_eof = false; - p_playlist = vlc_object_find( p_demux, VLC_OBJECT_PLAYLIST, FIND_PARENT ); - - if( p_playlist == NULL ) - { - msg_Err( p_demux, "we are not attached to a playlist" ); - return -1; - } + p_playlist = pl_Yield( p_demux ); switch( p_sys->i_command ) { diff --git a/modules/video_filter/atmo/atmo.cpp b/modules/video_filter/atmo/atmo.cpp index 38a6696849..84b3cd94bc 100644 --- a/modules/video_filter/atmo/atmo.cpp +++ b/modules/video_filter/atmo/atmo.cpp @@ -1926,18 +1926,13 @@ static int StateCallback( vlc_object_t *p_this, char const *psz_cmd, *****************************************************************************/ static void AddStateVariableCallback(filter_t *p_filter) { - playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_filter, - VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) + playlist_t *p_playlist = pl_Yield( p_filter ); + input_thread_t *p_input = p_playlist->p_input; + if(p_input) { - input_thread_t *p_input = p_playlist->p_input; - if(p_input) - { - var_AddCallback( p_input, "state", StateCallback, p_filter ); - } - vlc_object_release( p_playlist ); + var_AddCallback( p_input, "state", StateCallback, p_filter ); } + vlc_object_release( p_playlist ); } /***************************************************************************** @@ -1949,18 +1944,13 @@ static void AddStateVariableCallback(filter_t *p_filter) *****************************************************************************/ static void DelStateVariableCallback( filter_t *p_filter ) { - playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_filter, - VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist ) + playlist_t *p_playlist = pl_Yield( p_filter ); + input_thread_t *p_input = p_playlist->p_input; + if(p_input) { - input_thread_t *p_input = p_playlist->p_input; - if(p_input) - { - var_DelCallback( p_input, "state", StateCallback, p_filter ); - } - vlc_object_release( p_playlist ); + var_DelCallback( p_input, "state", StateCallback, p_filter ); } + vlc_object_release( p_playlist ); } diff --git a/modules/video_output/caca.c b/modules/video_output/caca.c index 41292b4b47..54d7cfc7ab 100644 --- a/modules/video_output/caca.c +++ b/modules/video_output/caca.c @@ -371,13 +371,9 @@ static int Manage( vout_thread_t *p_vout ) break; case CACA_EVENT_QUIT: { - p_playlist = vlc_object_find( p_vout, - VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); - if( p_playlist ) - { - playlist_Stop( p_playlist ); - vlc_object_release( p_playlist ); - } + p_playlist = pl_Yield( p_vout ); + playlist_Stop( p_playlist ); + vlc_object_release( p_playlist ); vlc_object_kill( p_vout->p_libvlc ); break; } diff --git a/modules/video_output/msw/directx.c b/modules/video_output/msw/directx.c index 56aade1f8b..084968d7b4 100644 --- a/modules/video_output/msw/directx.c +++ b/modules/video_output/msw/directx.c @@ -2125,18 +2125,12 @@ static int WallpaperCallback( vlc_object_t *p_this, char const *psz_cmd, { playlist_t *p_playlist; - p_playlist = - (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST, - FIND_PARENT ); - if( p_playlist ) - { - /* Modify playlist as well because the vout might have to be - * restarted */ - var_Create( p_playlist, "directx-wallpaper", VLC_VAR_BOOL ); - var_Set( p_playlist, "directx-wallpaper", newval ); - - vlc_object_release( p_playlist ); - } + p_playlist = pl_Yield( p_this ); + /* Modify playlist as well because the vout might have to be + * restarted */ + var_Create( p_playlist, "directx-wallpaper", VLC_VAR_BOOL ); + var_Set( p_playlist, "directx-wallpaper", newval ); + vlc_object_release( p_playlist ); p_vout->p_sys->i_changes |= DX_WALLPAPER_CHANGE; } diff --git a/modules/video_output/msw/events.c b/modules/video_output/msw/events.c index 7987ab283f..8ee36bf5a4 100644 --- a/modules/video_output/msw/events.c +++ b/modules/video_output/msw/events.c @@ -77,15 +77,11 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args ); static void DirectXPopupMenu( event_thread_t *p_event, bool b_open ) { - playlist_t *p_playlist = - vlc_object_find( p_event, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); - if( p_playlist != NULL ) - { - vlc_value_t val; - val.b_bool = b_open; - var_Set( p_playlist, "intf-popupmenu", val ); - vlc_object_release( p_playlist ); - } + playlist_t *p_playlist = pl_Yield( p_event ); + vlc_value_t val; + val.b_bool = b_open; + var_Set( p_playlist, "intf-popupmenu", val ); + vlc_object_release( p_playlist ); } static int DirectXConvertKey( int i_key ); @@ -870,14 +866,7 @@ static long FAR PASCAL DirectXEventProc( HWND hwnd, UINT message, /* the user wants to close the window */ case WM_CLOSE: { - playlist_t * p_playlist = - (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST, - FIND_ANYWHERE ); - if( p_playlist == NULL ) - { - return 0; - } - + playlist_t * p_playlist = pl_Yield( p_vout ); playlist_Stop( p_playlist ); vlc_object_release( p_playlist ); return 0;