Commit d0735d9c authored by Jakob Leben's avatar Jakob Leben

podcast: implement "live" podcast item removal

parent d8e75306
...@@ -91,6 +91,9 @@ struct services_discovery_sys_t ...@@ -91,6 +91,9 @@ struct services_discovery_sys_t
char **ppsz_urls; char **ppsz_urls;
int i_urls; int i_urls;
input_item_t **pp_items;
int i_items;
vlc_thread_t thread; vlc_thread_t thread;
vlc_mutex_t lock; vlc_mutex_t lock;
vlc_cond_t wait; vlc_cond_t wait;
...@@ -120,6 +123,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -120,6 +123,8 @@ static int Open( vlc_object_t *p_this )
p_sys->ppsz_urls = NULL; p_sys->ppsz_urls = NULL;
p_sys->i_input = 0; p_sys->i_input = 0;
p_sys->pp_input = NULL; p_sys->pp_input = NULL;
p_sys->pp_items = NULL;
p_sys->i_items = 0;
vlc_mutex_init( &p_sys->lock ); vlc_mutex_init( &p_sys->lock );
vlc_cond_init( &p_sys->wait ); vlc_cond_init( &p_sys->wait );
p_sys->b_update = true; p_sys->b_update = true;
...@@ -172,6 +177,8 @@ static void Close( vlc_object_t *p_this ) ...@@ -172,6 +177,8 @@ static void Close( vlc_object_t *p_this )
free( p_sd->p_sys->pp_input ); free( p_sd->p_sys->pp_input );
for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] ); for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
free( p_sys->ppsz_urls ); free( p_sys->ppsz_urls );
for( i = 0; i < p_sys->i_items; i++ ) vlc_gc_decref( p_sys->pp_items[i] );
free( p_sys->pp_items );
free( p_sys ); free( p_sys );
} }
...@@ -193,8 +200,7 @@ static void *Run( void *data ) ...@@ -193,8 +200,7 @@ static void *Run( void *data )
int canc = vlc_savecancel (); int canc = vlc_savecancel ();
msg_Dbg( p_sd, "Update required" ); msg_Dbg( p_sd, "Update required" );
char* psz_urls = var_GetNonEmptyString( p_sd, "podcast-urls" ); char* psz_urls = var_GetNonEmptyString( p_sd, "podcast-urls" );
if( psz_urls != NULL ) ParseUrls( p_sd, psz_urls );
ParseUrls( p_sd, psz_urls );
free( psz_urls ); free( psz_urls );
p_sys->b_update = false; p_sys->b_update = false;
...@@ -237,31 +243,66 @@ static int UrlsChange( vlc_object_t *p_this, char const *psz_var, ...@@ -237,31 +243,66 @@ static int UrlsChange( vlc_object_t *p_this, char const *psz_var,
static void ParseUrls( services_discovery_t *p_sd, char *psz_urls ) static void ParseUrls( services_discovery_t *p_sd, char *psz_urls )
{ {
services_discovery_sys_t *p_sys = p_sd->p_sys; services_discovery_sys_t *p_sys = p_sd->p_sys;
int i_new_items = 0;
input_item_t **pp_new_items;
int i_new_urls;
char **ppsz_new_urls = NULL;
int i, j;
for( ;; ) for( ;; )
{ {
int i; if( !psz_urls ) break;
char *psz_tok = strchr( psz_urls, '|' ); char *psz_tok = strchr( psz_urls, '|' );
if( psz_tok ) *psz_tok = '\0'; if( psz_tok ) *psz_tok = '\0';
for( i = 0; i < p_sys->i_urls; i++ ) for( i = 0; i < p_sys->i_urls; i++ )
if( !strcmp( psz_urls, p_sys->ppsz_urls[i] ) ) if( !strcmp( psz_urls, p_sys->ppsz_urls[i] ) )
break; break;
if( i == p_sys->i_urls ) if( i == p_sys->i_urls )
{ {
/* Only add new urls. INSERT_ELEM( ppsz_new_urls, i_new_urls, i_new_urls,
* FIXME: We don't delete urls which have been removed from
* the config since we don't have a way to know which inputs
* they spawned */
input_item_t *p_input;
INSERT_ELEM( p_sys->ppsz_urls, p_sys->i_urls, p_sys->i_urls,
strdup( psz_urls ) ); strdup( psz_urls ) );
input_item_t *p_input;
p_input = input_item_New( p_sd, psz_urls, psz_urls ); p_input = input_item_New( p_sd, psz_urls, psz_urls );
input_item_AddOption( p_input, "demux=podcast", VLC_INPUT_OPTION_TRUSTED ); input_item_AddOption( p_input, "demux=podcast", VLC_INPUT_OPTION_TRUSTED );
INSERT_ELEM( pp_new_items, i_new_items, i_new_items, p_input );
services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ ); services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ );
vlc_gc_decref( p_input );
INSERT_ELEM( p_sys->pp_input, p_sys->i_input, p_sys->i_input, INSERT_ELEM( p_sys->pp_input, p_sys->i_input, p_sys->i_input,
input_CreateAndStart( p_sd, p_input, NULL ) ); input_CreateAndStart( p_sd, p_input, NULL ) );
} }
else
{
INSERT_ELEM( ppsz_new_urls, i_new_urls, i_new_urls,
strdup( p_sys->ppsz_urls[i]) );
INSERT_ELEM( pp_new_items, i_new_items, i_new_items, p_sys->pp_items[i] );
}
if( psz_tok ) psz_urls = psz_tok+1; if( psz_tok ) psz_urls = psz_tok+1;
else return; else break;
}
/* delete removed items and signal the removal */
for( i = 0; i<p_sys->i_items; ++i )
{
for( j = 0; j < i_new_items; ++j )
if( pp_new_items[j] == p_sys->pp_items[i] ) break;
if( j == i_new_items )
{
services_discovery_RemoveItem( p_sd, p_sys->pp_items[i] );
vlc_gc_decref( p_sys->pp_items[i] );
}
} }
free( p_sys->pp_items );
for( int i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
free( p_sys->ppsz_urls );
p_sys->ppsz_urls = ppsz_new_urls;
p_sys->i_urls = i_new_urls;
p_sys->pp_items = pp_new_items;
p_sys->i_items = i_new_items;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment