Changeset 2d3be24e0f67e19dc29baced87af42481dafde21

Show
Ignore:
Timestamp:
21/10/06 15:33:06 (2 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1161437586 +0000
git-parent:

[0f382e7498b5285d73fd034d363e9aa5589289e1]

git-author:
Clément Stenac <zorglub@videolan.org> 1161437586 +0000
Message:

Don't loop continuously the playlist thread, use cond.
Not tested heavily yet ...

For interaction implementers: you need to call playlist_Signal after changing the status of a dialog. Please see the diff for qt4/dialogs/interaction.cpp

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_playlist.h

    r799b282 r2d3be24  
    138138    int                   i_sort; /**< Last sorting applied to the playlist */ 
    139139    int                   i_order; /**< Last ordering applied to the playlist */ 
    140     mtime_t               i_vout_destroyed_date; 
    141     mtime_t               i_sout_destroyed_date
     140    mtime_t               gc_date; 
     141    vlc_bool_t            b_cant_sleep
    142142    playlist_preparse_t  *p_preparse; /**< Preparser object */ 
    143143    playlist_secondary_preparse_t *p_secondary_preparse;/**< Preparser object */ 
     
    434434} 
    435435 
     436/** Ask the playlist to do some work */ 
     437static inline void playlist_Signal( playlist_t *p_playlist ) 
     438{ 
     439    PL_LOCK; 
     440    vlc_cond_signal( &p_playlist->object_wait ); 
     441    PL_UNLOCK; 
     442} 
     443 
    436444/** 
    437445 * @} 
  • modules/gui/qt4/dialogs/interaction.cpp

    r928454f r2d3be24  
    196196    hide(); 
    197197    vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); 
     198    playlist_Signal( THEPL ); 
    198199} 
  • src/input/input.c

    r6b5014a r2d3be24  
    381381    p_input->b_die = VLC_TRUE; 
    382382 
    383     /* We cannot touch p_input fields directly (we can from another thread), 
     383    /* We cannot touch p_input fields directly (we come from another thread), 
    384384     * so use the vlc_object_find way, it's perfectly safe */ 
    385385 
     
    443443        /* If we failed, wait before we are killed, and exit */ 
    444444        p_input->b_error = VLC_TRUE; 
     445        playlist_Signal( pl_Get( p_input ) ); 
    445446 
    446447        Error( p_input ); 
     
    469470        /* We have finished */ 
    470471        p_input->b_eof = VLC_TRUE; 
     472        playlist_Signal( pl_Get( p_input ) ); 
    471473    } 
    472474 
  • src/interface/interaction.c

    ra972b8b r2d3be24  
    103103            // Pretend we have hidden and destroyed it 
    104104            if( p_dialog->i_status == HIDDEN_DIALOG ) 
    105             { 
    106105                p_dialog->i_status = DESTROYED_DIALOG; 
    107             } 
    108106            else 
    109             { 
    110107                p_dialog->i_status = HIDING_DIALOG; 
    111             } 
    112108        } 
    113109    } 
    114110    else 
    115     { 
    116111        vlc_object_yield( p_interaction->p_intf ); 
    117     } 
    118112 
    119113    for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ ) 
     
    526520static void DialogDestroy( interaction_dialog_t *p_dialog ) 
    527521{ 
    528     FREENULL( p_dialog->psz_title ); 
    529     FREENULL( p_dialog->psz_description ); 
    530     FREENULL( p_dialog->psz_default_button ); 
    531     FREENULL( p_dialog->psz_alternate_button ); 
    532     FREENULL( p_dialog->psz_other_button ); 
     522    free( p_dialog->psz_title ); 
     523    free( p_dialog->psz_description ); 
     524    free( p_dialog->psz_default_button ); 
     525    free( p_dialog->psz_alternate_button ); 
     526    free( p_dialog->psz_other_button ); 
    533527    free( p_dialog ); 
    534528} 
     
    576570        if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY ) // Wait for answer 
    577571        { 
     572            playlist_Signal( pl_Get(p_this) ); 
    578573            while( p_dialog->i_status != ANSWERED_DIALOG && 
    579574                   p_dialog->i_status != HIDING_DIALOG && 
     
    592587            p_dialog->i_flags |= DIALOG_GOT_ANSWER; 
    593588            vlc_mutex_unlock( &p_interaction->object_lock ); 
     589            playlist_Signal( pl_Get(p_this) ); 
    594590            return p_dialog->i_return; 
    595591        } 
     
    599595            p_dialog->i_flags |=  DIALOG_GOT_ANSWER; 
    600596            vlc_mutex_unlock( &p_interaction->object_lock ); 
     597            playlist_Signal( pl_Get(p_this) ); 
    601598            return VLC_SUCCESS; 
    602599        } 
  • src/playlist/control.c

    r799b282 r2d3be24  
    180180        break; 
    181181    } 
     182    vlc_cond_signal( &p_playlist->object_wait ); 
    182183 
    183184    return VLC_SUCCESS; 
  • src/playlist/engine.c

    r799b282 r2d3be24  
    7171    p_playlist->p_input = NULL; 
    7272 
    73     p_playlist->i_vout_destroyed_date = 0; 
    74     p_playlist->i_sout_destroyed_date = 0
     73    p_playlist->gc_date = 0; 
     74    p_playlist->b_cant_sleep = VLC_FALSE
    7575 
    7676    ARRAY_INIT( p_playlist->items ); 
     
    195195 
    196196} 
     197 
    197198/* Destroy remaining objects */ 
    198 static mtime_t ObjectGarbageCollector( playlist_t *p_playlist, int i_type, 
    199                                        mtime_t destroy_date ) 
     199static void ObjectGarbageCollector( playlist_t *p_playlist ) 
    200200{ 
    201201    vlc_object_t *p_obj; 
    202202 
    203     if( destroy_date > mdate() ) return destroy_date; 
    204  
    205     if( destroy_date == 0 ) 
    206     { 
    207         /* give a little time */ 
    208         return mdate() + I64C(1000000); 
    209     } 
    210     else 
    211     { 
    212         vlc_mutex_lock( &p_playlist->gc_lock ); 
    213         while( ( p_obj = vlc_object_find( p_playlist, i_type, FIND_CHILD ) ) ) 
    214         { 
    215             if( p_obj->p_parent != (vlc_object_t*)p_playlist ) 
    216             { 
    217                 /* only first child (ie unused) */ 
    218                 vlc_object_release( p_obj ); 
    219                 break; 
    220             } 
    221             if( i_type == VLC_OBJECT_VOUT ) 
    222             { 
    223                 msg_Dbg( p_playlist, "garbage collector destroying 1 vout" ); 
    224                 vlc_object_detach( p_obj ); 
    225                 vlc_object_release( p_obj ); 
    226                 vout_Destroy( (vout_thread_t *)p_obj ); 
    227             } 
    228             else if( i_type == VLC_OBJECT_SOUT ) 
    229             { 
    230                 vlc_object_release( p_obj ); 
    231                 sout_DeleteInstance( (sout_instance_t*)p_obj ); 
    232             } 
    233         } 
    234         vlc_mutex_unlock( &p_playlist->gc_lock ); 
    235         return 0; 
    236     } 
     203    if( mdate() - p_playlist->gc_date < 1000000 ) 
     204    { 
     205        p_playlist->b_cant_sleep = VLC_TRUE; 
     206        return; 
     207    } 
     208    else if( p_playlist->gc_date == 0 ) 
     209        return; 
     210 
     211    vlc_mutex_lock( &p_playlist->gc_lock ); 
     212    while( ( p_obj = vlc_object_find( p_playlist, VLC_OBJECT_VOUT, 
     213                                                  FIND_CHILD ) ) ) 
     214    { 
     215        if( p_obj->p_parent != (vlc_object_t*)p_playlist ) 
     216        { 
     217            vlc_object_release( p_obj ); 
     218            break; 
     219        } 
     220        msg_Dbg( p_playlist, "garbage collector destroying 1 vout" ); 
     221        vlc_object_detach( p_obj ); 
     222        vlc_object_release( p_obj ); 
     223        vout_Destroy( (vout_thread_t *)p_obj ); 
     224    } 
     225    while( ( p_obj = vlc_object_find( p_playlist, VLC_OBJECT_SOUT, 
     226                                                  FIND_CHILD ) ) ) 
     227    { 
     228        if( p_obj->p_parent != (vlc_object_t*)p_playlist ) 
     229        { 
     230            vlc_object_release( p_obj ); 
     231            break; 
     232        } 
     233        vlc_object_release( p_obj ); 
     234        sout_DeleteInstance( (sout_instance_t*)p_obj ); 
     235    } 
     236    p_playlist->b_cant_sleep = VLC_FALSE; 
     237    vlc_mutex_unlock( &p_playlist->gc_lock ); 
    237238} 
    238239 
     
    245246 
    246247    /* First, check if we have something to do */ 
    247     /* FIXME : this can be called several times */ 
    248248    if( p_playlist->request.b_request ) 
    249249    { 
     
    255255        } 
    256256    } 
    257  
     257check_input: 
    258258    /* If there is an input, check that it doesn't need to die. */ 
    259259    if( p_playlist->p_input ) 
     
    283283            vlc_object_destroy( p_input ); 
    284284 
    285             p_playlist->i_vout_destroyed_date = 0; 
    286             p_playlist->i_sout_destroyed_date = 0; 
     285            PL_LOCK; 
     286 
     287            p_playlist->gc_date = mdate(); 
     288            p_playlist->b_cant_sleep = VLC_TRUE; 
    287289 
    288290            if( p_playlist->status.p_item->i_flags 
     
    300302            var_SetInteger( p_playlist, "activity", i_activity - 
    301303                            DEFAULT_INPUT_ACTIVITY ); 
    302  
    303             return; 
     304            goto check_input; 
    304305        } 
    305306        /* This input is dying, let it do */ 
     
    307308        { 
    308309            PL_DEBUG( "dying input" ); 
     310            msleep( 25000 ); // 25 ms 
     311            goto check_input; 
    309312        } 
    310313        /* This input has finished, ask it to die ! */ 
     
    314317            PL_DEBUG( "finished input" ); 
    315318            input_StopThread( p_playlist->p_input ); 
    316             /* Select the next playlist item */ 
    317             PL_UNLOCK 
    318             return; 
     319            /* No need to wait here, we'll wait in the p_input->b_die case */ 
     320            goto check_input; 
    319321        } 
    320322        else if( p_playlist->p_input->i_state != INIT_S ) 
    321323        { 
    322324            PL_UNLOCK; 
    323             p_playlist->i_vout_destroyed_date = 
    324                 ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, 
    325                                         p_playlist->i_vout_destroyed_date ); 
    326             p_playlist->i_sout_destroyed_date = 
    327                 ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, 
    328                                         p_playlist->i_sout_destroyed_date ); 
    329             PL_LOCK 
     325            ObjectGarbageCollector( p_playlist ); 
     326            PL_LOCK; 
    330327        } 
    331328    } 
     
    365362         else 
    366363         { 
    367              p_playlist->status.i_status = PLAYLIST_STOPPED; 
    368              if( p_playlist->status.p_item && 
    369                  p_playlist->status.p_item->i_flags & PLAYLIST_REMOVE_FLAG ) 
    370              { 
    371                  PL_DEBUG( "deleting item marked for deletion" ); 
    372                  playlist_ItemDelete( p_playlist->status.p_item ); 
    373                  p_playlist->status.p_item = NULL; 
    374              } 
    375  
    376              /* Collect garbage */ 
    377              PL_UNLOCK 
    378              p_playlist->i_sout_destroyed_date = 
    379              ObjectGarbageCollector( p_playlist, VLC_OBJECT_SOUT, mdate() ); 
    380              p_playlist->i_vout_destroyed_date = 
    381              ObjectGarbageCollector( p_playlist, VLC_OBJECT_VOUT, mdate() ); 
    382              PL_LOCK 
    383          } 
     364            p_playlist->status.i_status = PLAYLIST_STOPPED; 
     365            if( p_playlist->status.p_item && 
     366                p_playlist->status.p_item->i_flags & PLAYLIST_REMOVE_FLAG ) 
     367            { 
     368                PL_DEBUG( "deleting item marked for deletion" ); 
     369                playlist_ItemDelete( p_playlist->status.p_item ); 
     370                p_playlist->status.p_item = NULL; 
     371            } 
     372 
     373            /* Collect garbage */ 
     374            PL_UNLOCK; 
     375            ObjectGarbageCollector( p_playlist ); 
     376            PL_LOCK; 
     377        } 
    384378    } 
    385379    PL_UNLOCK 
  • src/playlist/item.c

    r799b282 r2d3be24  
    595595        p_playlist->request.p_item = p_toplay; 
    596596        if( p_playlist->p_input ) 
    597         { 
    598597            input_StopThread( p_playlist->p_input ); 
    599         } 
    600598        p_playlist->request.i_status = PLAYLIST_RUNNING; 
     599        vlc_cond_signal( &p_playlist->object_wait ); 
    601600    } 
    602601    if( i_mode & PLAYLIST_PREPARSE && 
     
    667666            p_playlist->request.p_item = NULL; 
    668667            msg_Info( p_playlist, "stopping playback" ); 
     668            vlc_cond_signal( &p_playlist->object_wait ); 
    669669        } 
    670670        b_flag = VLC_TRUE; 
  • src/playlist/thread.c

    r799b282 r2d3be24  
    143143{ 
    144144    p_playlist->b_die = VLC_TRUE; 
     145    playlist_Signal( p_playlist ); 
    145146    if( p_playlist->p_preparse ) 
    146147    { 
     
    176177        HandleInteraction( p_playlist ); 
    177178        HandlePlaylist( p_playlist ); 
    178  
    179         /* 100 ms is an acceptable delay for playlist operations */ 
    180         msleep( INTF_IDLE_SLEEP*2 ); 
     179        if( p_playlist->b_cant_sleep ) 
     180        { 
     181            /* 100 ms is an acceptable delay for playlist operations */ 
     182            msleep( INTF_IDLE_SLEEP*2 ); 
     183        } 
     184        else 
     185        { 
     186            PL_LOCK; 
     187            vlc_cond_wait( &p_playlist->object_wait, &p_playlist->object_lock ); 
     188            PL_UNLOCK; 
     189        } 
    181190    } 
    182191