]> git.sesse.net Git - vlc/commitdiff
modules/services_discovery/podcast.c: Use the new API.
authorPierre d'Herbemont <pdherbemont@videolan.org>
Sat, 18 Aug 2007 03:48:49 +0000 (03:48 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sat, 18 Aug 2007 03:48:49 +0000 (03:48 +0000)
modules/services_discovery/podcast.c

index 976205f8ed1e2fe97e9c28297ea4f93316675c82..7098e419baa6ec6f45a899ee8420a107f6843709 100644 (file)
@@ -78,8 +78,6 @@ vlc_module_end();
 struct services_discovery_sys_t
 {
     /* playlist node */
-    playlist_item_t *p_node_cat;
-    playlist_item_t *p_node_one;
     input_thread_t **pp_input;
 
     char **ppsz_urls;
@@ -101,10 +99,49 @@ static int Open( vlc_object_t *p_this )
     services_discovery_t *p_sd = ( services_discovery_t* )p_this;
     services_discovery_sys_t *p_sys  = malloc(
                                     sizeof( services_discovery_sys_t ) );
+    
+    p_sys->i_urls = 0;
+    p_sys->ppsz_urls = NULL;
+    p_sys->pp_input = NULL;
+    
+    p_sd->pf_run = Run;
+    p_sd->p_sys  = p_sys;
+
+    /* Give us a name */
+    services_discovery_SetLocalizedName( p_sd, _("Podcasts") );
 
-    vlc_value_t         val;
-    playlist_t          *p_playlist;
-    playlist_item_t     *p_item;
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close:
+ *****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    services_discovery_t *p_sd = ( services_discovery_t* )p_this;
+    services_discovery_sys_t *p_sys  = p_sd->p_sys;
+    int i;
+    for( i = 0; i < p_sys->i_urls; i++ )
+    {
+        if( p_sd->p_sys->pp_input[i] )
+        {
+            input_StopThread( p_sd->p_sys->pp_input[i] );
+            input_DestroyThread( p_sd->p_sys->pp_input[i] );
+            p_sd->p_sys->pp_input[i] = NULL;
+        }
+    }
+    free( p_sd->p_sys->pp_input );
+    for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
+    free( p_sys->ppsz_urls );
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * Run: main thread
+ *****************************************************************************/
+static void Run( services_discovery_t *p_sd )
+{
+    services_discovery_sys_t *p_sys  = p_sd->p_sys;
 
     int i, j;
     char *psz_buf;
@@ -136,90 +173,18 @@ static int Open( vlc_object_t *p_this )
     p_sys->ppsz_urls[j] = strdup( psz_tmp );
     free( psz_buf );
 
-    p_sd->pf_run = Run;
-    p_sd->p_sys  = p_sys;
-
-    /* Create our playlist node */
-    p_playlist = (playlist_t *)vlc_object_find( p_sd, VLC_OBJECT_PLAYLIST,
-                                                FIND_ANYWHERE );
-    if( !p_playlist )
-    {
-        msg_Warn( p_sd, "unable to find playlist, cancelling");
-        return VLC_EGENERIC;
-    }
-
-    p_sys->p_node_cat = playlist_NodeCreate( p_playlist, _("Podcast"),
-                                         p_playlist->p_root_category, 0 );
-    p_sys->p_node_one = playlist_NodeCreate( p_playlist, _("Podcast"),
-                                         p_playlist->p_root_onelevel, 0 );
-    p_sys->p_node_one->p_input->i_id = p_sys->p_node_cat->p_input->i_id;
-
-    p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
-    p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
-    p_sys->p_node_one->i_flags |= PLAYLIST_SKIP_FLAG;
-    p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
     p_sys->pp_input = malloc( p_sys->i_urls * sizeof( input_thread_t * ) );
     for( i = 0; i < p_sys->i_urls; i++ )
     {
         input_item_t *p_input;
         asprintf( &psz_buf, "%s", p_sys->ppsz_urls[i] );
-        p_input = input_ItemNewExt( p_playlist, psz_buf,
+        p_input = input_ItemNewExt( p_sd, psz_buf,
                                     p_sys->ppsz_urls[i], 0, NULL, -1 );
         input_ItemAddOption( p_input, "demux=podcast" );
-        p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_cat,
-                                        PLAYLIST_APPEND, PLAYLIST_END,
-                                        VLC_FALSE );
-        p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_one,
-                                        PLAYLIST_APPEND, PLAYLIST_END,
-                                        VLC_FALSE );
-        free( psz_buf );
-        p_sys->pp_input[i] = input_CreateThread( p_playlist, p_input );
-    }
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    vlc_object_release( p_playlist );
-
-    return VLC_SUCCESS;
-}
-
-/*****************************************************************************
- * Close:
- *****************************************************************************/
-static void Close( vlc_object_t *p_this )
-{
-    services_discovery_t *p_sd = ( services_discovery_t* )p_this;
-    services_discovery_sys_t *p_sys  = p_sd->p_sys;
-    playlist_t *p_playlist =  (playlist_t *) vlc_object_find( p_sd,
-                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    int i;
-    for( i = 0; i < p_sys->i_urls; i++ )
-    {
-        if( p_sd->p_sys->pp_input[i] )
-        {
-            input_StopThread( p_sd->p_sys->pp_input[i] );
-            input_DestroyThread( p_sd->p_sys->pp_input[i] );
-            p_sd->p_sys->pp_input[i] = NULL;
-        }
-    }
-    free( p_sd->p_sys->pp_input );
-    if( p_playlist )
-    {
-        playlist_NodeDelete( p_playlist, p_sys->p_node_cat, VLC_TRUE, VLC_TRUE );
-        playlist_NodeDelete( p_playlist, p_sys->p_node_one, VLC_TRUE, VLC_TRUE );
-        vlc_object_release( p_playlist );
+        services_discovery_AddItem( p_sd, p_input, NULL /* no cat */ );
+        p_sys->pp_input[i] = input_CreateThread( p_sd, p_input );
     }
-    for( i = 0; i < p_sys->i_urls; i++ ) free( p_sys->ppsz_urls[i] );
-    free( p_sys->ppsz_urls );
-    free( p_sys );
-}
 
-/*****************************************************************************
- * Run: main thread
- *****************************************************************************/
-static void Run( services_discovery_t *p_sd )
-{
     while( !p_sd->b_die )
     {
         int i;