Changeset 6df62cf5a6d007f180968eeba2e2f1922f4a0025

Show
Ignore:
Timestamp:
02/09/07 23:24:02 (1 year ago)
Author:
Antoine Cellerier <dionoea@videolan.org>
git-committer:
Antoine Cellerier <dionoea@videolan.org> 1188768242 +0000
git-parent:

[027b8eabd3d40ec522e0e19cb9db0e73b51ddd25]

git-author:
Antoine Cellerier <dionoea@videolan.org> 1188768242 +0000
Message:

Rewrite parts of the podcast service discovery module and make it handle additions to the url list at runtime. (deletions are not supported, without a module restart)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/services_discovery/podcast.c

    rfe92f9c r6df62cf  
    4848 
    4949/* Callbacks */ 
    50     static int  Open ( vlc_object_t * ); 
    51     static void Close( vlc_object_t * ); 
     50static int  Open ( vlc_object_t * ); 
     51static void Close( vlc_object_t * ); 
    5252 
    5353#define URLS_TEXT N_("Podcast URLs list") 
     
    7979    /* playlist node */ 
    8080    input_thread_t **pp_input; 
     81    int i_input; 
    8182 
    8283    char **ppsz_urls; 
    8384    int i_urls; 
     85 
     86    vlc_bool_t b_update; 
    8487}; 
    8588 
     
    8790 * Local prototypes 
    8891 *****************************************************************************/ 
    89  
    90 /* Main functions */ 
    91     static void Run    ( services_discovery_t *p_intf ); 
     92static void Run( services_discovery_t *p_intf ); 
     93static int UrlsChange( vlc_object_t *, char const *, vlc_value_t, 
     94                       vlc_value_t, void * ); 
     95static void ParseUrls( services_discovery_t *p_sd, char *psz_urls ); 
    9296 
    9397/***************************************************************************** 
     
    99103    services_discovery_sys_t *p_sys  = malloc( 
    100104                                    sizeof( services_discovery_sys_t ) ); 
    101      
     105 
    102106    p_sys->i_urls = 0; 
    103107    p_sys->ppsz_urls = NULL; 
     108    p_sys->i_input = 0; 
    104109    p_sys->pp_input = NULL; 
    105      
     110    p_sys->b_update = VLC_TRUE; 
     111 
    106112    p_sd->pf_run = Run; 
    107113    p_sd->p_sys  = p_sys; 
     
    121127    services_discovery_sys_t *p_sys  = p_sd->p_sys; 
    122128    int i; 
    123     for( i = 0; i < p_sys->i_urls; i++ ) 
     129    for( i = 0; i < p_sys->i_input; i++ ) 
    124130    { 
    125131        if( p_sd->p_sys->pp_input[i] ) 
     
    143149    services_discovery_sys_t *p_sys  = p_sd->p_sys; 
    144150 
    145     int i, j; 
    146     char *psz_buf; 
    147     char *psz_tmp = psz_buf = var_CreateGetString( p_sd, "podcast-urls" ); 
    148  
    149     i = 0; 
    150     p_sys->i_urls = psz_buf[0] ? 1 : 0; 
    151     while( psz_buf[i] != 0 ) 
    152         if( psz_buf[i++] == '|' ) 
    153             p_sys->i_urls++; 
    154  
    155     p_sys->ppsz_urls = (char **)malloc( p_sys->i_urls * sizeof( char * ) ); 
    156  
    157     i = 0; 
    158     j = 0; 
    159     while( psz_buf[i] != 0 ) 
    160     { 
    161         if( psz_buf[i] == '|' ) 
    162         { 
    163             psz_buf[i] = 0; 
    164             p_sys->ppsz_urls[j] = strdup( psz_tmp ); 
    165             i++; 
    166             j++; 
    167             psz_tmp = psz_buf+i; 
    168         } 
    169         else 
    170             i++; 
    171     } 
    172     p_sys->ppsz_urls[j] = strdup( psz_tmp ); 
    173     free( psz_buf ); 
    174  
    175     p_sys->pp_input = malloc( p_sys->i_urls * sizeof( input_thread_t * ) ); 
    176     for( i = 0; i < p_sys->i_urls; i++ ) 
    177     { 
    178         input_item_t *p_input; 
    179         asprintf( &psz_buf, "%s", p_sys->ppsz_urls[i] ); 
    180         p_input = input_ItemNewExt( p_sd, psz_buf, 
    181                                     p_sys->ppsz_urls[i], 0, NULL, -1 ); 
    182         input_ItemAddOption( p_input, "demux=podcast" ); 
    183         services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ ); 
    184         p_sys->pp_input[i] = input_CreateThread( p_sd, p_input ); 
    185     } 
     151    char *psz_urls = var_CreateGetString( p_sd, "podcast-urls" ); 
     152    free( psz_urls ); /* Gruik ? */ 
     153    var_AddCallback( p_sd, "podcast-urls", UrlsChange, p_sys ); 
    186154 
    187155    while( !p_sd->b_die ) 
    188156    { 
    189157        int i; 
    190         for( i = 0; i < p_sd->p_sys->i_urls; i++ ) 
    191         { 
    192             if( p_sd->p_sys->pp_input[i] && 
    193                 ( p_sd->p_sys->pp_input[i]->b_eof 
    194                   || p_sd->p_sys->pp_input[i]->b_error ) ) 
     158        if( p_sys->b_update == VLC_TRUE ) 
     159        { 
     160            msg_Dbg( p_sd, "Update required" ); 
     161            psz_urls = var_GetString( p_sd, "podcast-urls" ); 
     162            ParseUrls( p_sd, psz_urls ); 
     163            free( psz_urls ); 
     164            p_sys->b_update = VLC_FALSE; 
     165        } 
     166 
     167        for( i = 0; i < p_sd->p_sys->i_input; i++ ) 
     168        { 
     169            if( p_sd->p_sys->pp_input[i]->b_eof 
     170                || p_sd->p_sys->pp_input[i]->b_error ) 
    195171            { 
    196172                input_StopThread( p_sd->p_sys->pp_input[i] ); 
    197173                input_DestroyThread( p_sd->p_sys->pp_input[i] ); 
    198174                p_sd->p_sys->pp_input[i] = NULL; 
     175                REMOVE_ELEM( p_sys->pp_input, p_sys->i_input, i ); 
     176                i--; 
    199177            } 
    200178        } 
    201         msleep( 100000 ); 
     179        msleep( 500 ); 
    202180    } 
    203181} 
     182 
     183static int UrlsChange( vlc_object_t *p_this, char const *psz_var, 
     184                       vlc_value_t oldval, vlc_value_t newval, 
     185                       void *p_data ) 
     186{ 
     187    services_discovery_sys_t *p_sys  = (services_discovery_sys_t *)p_data; 
     188    p_sys->b_update = VLC_TRUE; 
     189    return VLC_SUCCESS; 
     190} 
     191 
     192static void ParseUrls( services_discovery_t *p_sd, char *psz_urls ) 
     193{ 
     194    services_discovery_sys_t *p_sys = p_sd->p_sys; 
     195    for( ;; ) 
     196    { 
     197        int i; 
     198        char *psz_tok = strchr( psz_urls, '|' ); 
     199        if( psz_tok ) *psz_tok = '\0'; 
     200        for( i = 0; i < p_sys->i_urls; i++ ) 
     201            if( !strcmp( psz_urls, p_sys->ppsz_urls[i] ) ) 
     202                break; 
     203        if( i == p_sys->i_urls ) 
     204        { 
     205            /* Only add new urls. 
     206             * FIXME: We don't delete urls which have been removed from 
     207             * the config since we don't have a way to know which inputs 
     208             * they spawned */ 
     209            input_item_t *p_input; 
     210            INSERT_ELEM( p_sys->ppsz_urls, p_sys->i_urls, p_sys->i_urls, 
     211                         strdup( psz_urls ) ); 
     212            p_input = input_ItemNewExt( p_sd, psz_urls, 
     213                                        psz_urls, 0, NULL, -1 ); 
     214            input_ItemAddOption( p_input, "demux=podcast" ); 
     215            services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ ); 
     216            INSERT_ELEM( p_sys->pp_input, p_sys->i_input, p_sys->i_input, 
     217                         input_CreateThread( p_sd, p_input ) ); 
     218        } 
     219        if( psz_tok )  psz_urls = psz_tok+1; 
     220        else           return; 
     221    } 
     222}