]> git.sesse.net Git - vlc/blobdiff - src/control/media_discoverer.c
HTTPd: stat -> utf8_stat
[vlc] / src / control / media_discoverer.c
index a0875490a81ff2e0a0e3241ce550e2552a65b13a..0a3123e5d041c5d344ba46e0e6fcff077d615157 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include "libvlc_internal.h"
-#include <vlc/libvlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <assert.h>
-#include "vlc_services_discovery.h"
+
+#include <vlc/libvlc.h>
+#include <vlc/libvlc_media.h>
+#include <vlc/libvlc_media_list.h>
+#include <vlc/libvlc_media_discoverer.h>
+#include <vlc/libvlc_events.h>
+
+#include <vlc_services_discovery.h>
+
+#include "libvlc_internal.h"
+#include "media_internal.h" // libvlc_media_new_from_input_item()
+#include "media_list_internal.h" // _libvlc_media_list_add_media()
+
+struct libvlc_media_discoverer_t
+{
+    libvlc_event_manager_t * p_event_manager;
+    libvlc_instance_t *      p_libvlc_instance;
+    services_discovery_t *   p_sd;
+    libvlc_media_list_t *    p_mlist;
+    bool                     running;
+    vlc_dictionary_t         catname_to_submedialist;
+};
 
 /*
  * Private functions
@@ -57,7 +80,7 @@ static void services_discovery_item_added( const vlc_event_t * p_event,
         {
             libvlc_media_t * p_catmd;
             p_catmd = libvlc_media_new_as_node( p_mdis->p_libvlc_instance, psz_cat, NULL );
-            p_mlist = libvlc_media_subitems( p_catmd, NULL );
+            p_mlist = libvlc_media_subitems( p_catmd );
             p_mlist->b_read_only = true;
 
             /* Insert the newly created mlist in our dictionary */
@@ -155,7 +178,8 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
     p_mdis = malloc(sizeof(libvlc_media_discoverer_t));
     if( !p_mdis )
     {
-        libvlc_exception_raise( p_e, "Not enough memory" );
+        libvlc_exception_raise( p_e );
+        libvlc_printerr( "Not enough memory" );
         return NULL;
     }
 
@@ -174,12 +198,13 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
     libvlc_event_manager_register_event_type( p_mdis->p_event_manager,
             libvlc_MediaDiscovererEnded, NULL );
 
-    p_mdis->p_sd = services_discovery_Create( (vlc_object_t*)p_inst->p_libvlc_int, psz_name );
+    p_mdis->p_sd = vlc_sd_Create( (vlc_object_t*)p_inst->p_libvlc_int );
 
     if( !p_mdis->p_sd )
     {
         libvlc_media_list_release( p_mdis->p_mlist );
-        libvlc_exception_raise( p_e, "Can't find the services_discovery module named '%s'", psz_name );
+        libvlc_exception_raise( p_e );
+        libvlc_printerr( "%s: no such discovery module found", psz_name );
         free( p_mdis );
         return NULL;
     }
@@ -202,11 +227,11 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
                       p_mdis );
 
     /* Here we go */
-    bool ret = services_discovery_Start( p_mdis->p_sd );
-    if(!ret)
+    if( !vlc_sd_Start( p_mdis->p_sd, psz_name ) )
     {
         libvlc_media_list_release( p_mdis->p_mlist );
-        libvlc_exception_raise( p_e, "Can't start the services_discovery module named '%s'", psz_name );
+        libvlc_exception_raise( p_e );
+        libvlc_printerr( "%s: internal module error", psz_name );
         free( p_mdis );
         return NULL;
     }
@@ -223,7 +248,7 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
     int i;
 
     libvlc_media_list_release( p_mdis->p_mlist );
-    services_discovery_StopAndRelease( p_mdis->p_sd );
+    vlc_sd_StopAndDestroy( p_mdis->p_sd );
 
     /* Free catname_to_submedialist and all the mlist */
     char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );
@@ -235,7 +260,8 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
     }
     free( all_keys );
 
-    vlc_dictionary_clear( &p_mdis->catname_to_submedialist );
+    vlc_dictionary_clear( &p_mdis->catname_to_submedialist, NULL, NULL );
+    libvlc_event_manager_release( p_mdis->p_event_manager );
 
     free( p_mdis );
 }