Changeset 36d1d663db8961cbb85e578f43f90ecfde11016e

Show
Ignore:
Timestamp:
19/07/08 13:19:16 (5 months ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1216466356 +0200
git-parent:

[ab131d8bfb68e02a952567e93c5a891ce8d6322c]

git-author:
Laurent Aimar <fenrir@videolan.org> 1216466356 +0200
Message:

Fixed a segfault in aout_EnableFilter.
Fixed missing lock in aout callbacks !
Factorized duplicated code.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/audio_output/aout_internal.h

    r95e3bb2 r36d1d66  
    139139int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate ); 
    140140 
     141/* Helpers */ 
     142 
     143/** 
     144 * This function will safely mark aout input to be restarted as soon as 
     145 * possible to take configuration changes into account */ 
     146static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout ) 
     147{ 
     148    int i; 
     149    vlc_mutex_lock( &p_aout->mixer_lock ); 
     150    for( i = 0; i < p_aout->i_nb_inputs; i++ ) 
     151        p_aout->pp_inputs[i]->b_restart = true; 
     152    vlc_mutex_unlock( &p_aout->mixer_lock ); 
     153} 
     154 
     155/* This function will add or remove a a module from a string list (comma 
     156 * separated). It will return true if there is a modification 
     157 * In case p_aout is NULL, we will use configuration instead of variable */ 
     158static inline bool AoutChangeFilterString( vlc_object_t *p_obj, aout_instance_t * p_aout, 
     159                                           const char* psz_variable, 
     160                                           const char *psz_name, bool b_add ) 
     161{ 
     162    vlc_value_t val; 
     163    char *psz_parser; 
     164 
     165    if( *psz_name == '\0' ) 
     166        return false; 
     167 
     168    if( p_aout ) 
     169        var_Get( p_aout, psz_variable, &val ); 
     170    else 
     171        val.psz_string = config_GetPsz( p_obj, "audio-filter" ); 
     172 
     173    if( !val.psz_string ) 
     174        val.psz_string = strdup(""); 
     175 
     176    psz_parser = strstr( val.psz_string, psz_name ); 
     177 
     178    if( ( b_add && psz_parser ) || ( !b_add && !psz_parser ) ) 
     179    { 
     180        /* Nothing to do */ 
     181        free( val.psz_string ); 
     182        return false; 
     183    } 
     184 
     185    if( b_add ) 
     186    { 
     187        char *psz_old = val.psz_string; 
     188        if( *psz_old ) 
     189            asprintf( &val.psz_string, "%s:%s", psz_old, psz_name ); 
     190        else 
     191            val.psz_string = strdup( psz_name ); 
     192        free( psz_old ); 
     193    } 
     194    else 
     195    { 
     196        const int i_name = strlen( psz_name ); 
     197        const char *psz_next; 
     198 
     199        psz_next = &psz_parser[i_name]; 
     200        if( *psz_next == ':' ) 
     201            psz_next++; 
     202 
     203        memmove( psz_parser, psz_next, strlen(psz_next)+1 ); 
     204    } 
     205 
     206    if( p_aout ) 
     207        var_Set( p_aout, psz_variable, val ); 
     208    else 
     209        config_PutPsz( p_obj, psz_variable, val.psz_string ); 
     210    free( val.psz_string ); 
     211    return true; 
     212} 
     213 
    141214#endif /* !__LIBVLC_AOUT_INTERNAL_H */ 
  • src/audio_output/input.c

    r1fe2080 r36d1d66  
    767767                                 const char *psz_name, bool b_add ) 
    768768{ 
    769     vlc_value_t val; 
    770     char *psz_parser; 
    771  
    772     var_Get( p_aout, psz_variable, &val ); 
    773  
    774     if( !val.psz_string ) val.psz_string = strdup(""); 
    775  
    776     psz_parser = strstr( val.psz_string, psz_name ); 
    777  
    778     if( b_add ) 
    779     { 
    780         if( !psz_parser ) 
    781         { 
    782             psz_parser = val.psz_string; 
    783             asprintf( &val.psz_string, (*val.psz_string) ? "%s:%s" : "%s%s", 
    784                       val.psz_string, psz_name ); 
    785             free( psz_parser ); 
    786         } 
    787         else 
    788         { 
    789             return 0; 
    790         } 
    791     } 
    792     else 
    793     { 
    794         if( psz_parser ) 
    795         { 
    796             memmove( psz_parser, psz_parser + strlen(psz_name) + 
    797                      (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ), 
    798                      strlen(psz_parser + strlen(psz_name)) + 1 ); 
    799         } 
    800         else 
    801         { 
    802             free( val.psz_string ); 
    803             return 0; 
    804         } 
    805     } 
    806  
    807     var_Set( p_aout, psz_variable, val ); 
    808     free( val.psz_string ); 
    809     return 1; 
     769    return AoutChangeFilterString( VLC_OBJECT(p_aout), p_aout, 
     770                                   psz_variable, psz_name, b_add ) ? 1 : 0; 
    810771} 
    811772 
     
    816777    char *psz_mode = newval.psz_string; 
    817778    vlc_value_t val; 
    818     int i; 
    819779    (void)psz_cmd; (void)oldval; (void)p_data; 
    820780 
     
    852812 
    853813    /* That sucks */ 
    854     for( i = 0; i < p_aout->i_nb_inputs; i++ ) 
    855     { 
    856         p_aout->pp_inputs[i]->b_restart = true; 
    857     } 
     814    AoutInputsMarkToRestart( p_aout ); 
    858815 
    859816    return VLC_SUCCESS; 
     
    866823    char *psz_mode = newval.psz_string; 
    867824    vlc_value_t val; 
    868     int i; 
    869825    int i_ret; 
    870826    (void)psz_cmd; (void)oldval; (void)p_data; 
     
    887843    /* That sucks */ 
    888844    if( i_ret == 1 ) 
    889     { 
    890         for( i = 0; i < p_aout->i_nb_inputs; i++ ) 
    891         { 
    892             p_aout->pp_inputs[i]->b_restart = true; 
    893         } 
    894     } 
    895  
     845        AoutInputsMarkToRestart( p_aout ); 
    896846    return VLC_SUCCESS; 
    897847} 
  • src/audio_output/intf.c

    rd666030 r36d1d66  
    490490                        bool b_add ) 
    491491{ 
    492     char *psz_parser, *psz_string; 
    493     aout_instance_t * p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, 
    494                                                 FIND_ANYWHERE ); 
     492    aout_instance_t *p_aout = vlc_object_find( p_this, VLC_OBJECT_AOUT, 
     493                                               FIND_ANYWHERE ); 
     494 
     495    if( AoutChangeFilterString( p_this, p_aout, "audio-filter", psz_name, b_add ) ) 
     496    { 
     497        if( p_aout ) 
     498            AoutInputsMarkToRestart( p_aout ); 
     499    } 
    495500 
    496501    if( p_aout ) 
    497         psz_string = var_GetNonEmptyString( p_aout, "audio-filter" ); 
    498     else 
    499         psz_string = config_GetPsz( p_this, "audio-filter" ); 
    500  
    501     if( !psz_string ) psz_string = strdup(""); 
    502  
    503     psz_parser = strstr( psz_string, psz_name ); 
    504  
    505     if( b_add ) 
    506     { 
    507         if( !psz_parser ) 
    508         { 
    509             psz_parser = psz_string; 
    510             asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s", 
    511                             psz_string, psz_name ); 
    512             free( psz_parser ); 
    513         } 
    514         else 
    515         { 
    516             vlc_object_release( p_aout ); 
    517             return; 
    518         } 
    519     } 
    520     else 
    521     { 
    522         if( psz_parser ) 
    523         { 
    524             memmove( psz_parser, psz_parser + strlen(psz_name) + 
    525                             (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ), 
    526                             strlen(psz_parser + strlen(psz_name)) + 1 ); 
    527  
    528             if( *(psz_string+strlen(psz_string ) -1 ) == ':' ) 
    529             { 
    530                 *(psz_string+strlen(psz_string ) -1 ) = '\0'; 
    531             } 
    532          } 
    533          else 
    534          { 
    535              free( psz_string ); 
    536              return; 
    537          } 
    538     } 
    539  
    540     if( p_aout == NULL ) 
    541         config_PutPsz( p_this, "audio-filter", psz_string ); 
    542     else 
    543     { 
    544         var_SetString( p_aout, "audio-filter", psz_string ); 
    545         for( int i = 0; i < p_aout->i_nb_inputs; i++ ) 
    546             p_aout->pp_inputs[i]->b_restart = true; 
    547502        vlc_object_release( p_aout ); 
    548     } 
    549     free( psz_string ); 
    550503} 
    551504