[vlc-commits] lib: change libvlc_media_discoverer_t creation

Thomas Guillem git at videolan.org
Tue Jan 13 23:32:45 CET 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jan  8 16:10:00 2015 +0000| [fa7924acb3613ab69c5221517391134623f68fd9] | committer: Jean-Baptiste Kempf

lib: change libvlc_media_discoverer_t creation

libvlc_media_discoverer_new_from_name was creating a services_discovery_t and
was starting it, so libvlc_MediaDiscovererStarted event (or any other events)
could not be received.

To fix that, Split libvlc_media_discoverer_new_from_name into
libvlc_media_discoverer_new and libvlc_media_discoverer_start. That way, we can
attach events between create and start.

libvlc_media_discoverer_new_from_name is now deprecated, but it still works
like before.

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fa7924acb3613ab69c5221517391134623f68fd9
---

 NEWS                                  |    6 ++++
 include/vlc/libvlc_media_discoverer.h |   52 ++++++++++++++++++++++++++++++--
 lib/libvlc.sym                        |    3 ++
 lib/media_discoverer.c                |   53 ++++++++++++++++++++++++++-------
 4 files changed, 100 insertions(+), 14 deletions(-)

diff --git a/NEWS b/NEWS
index d2b7aa8..c468ada 100644
--- a/NEWS
+++ b/NEWS
@@ -78,6 +78,12 @@ Qt interface:
 Skins2:
  * Support key accelerators
 
+libVLC:
+ * split of libvlc_media_discoverer_new_from_name into libvlc_media_discoverer_new,
+   libvlc_media_discoverer_new and libvlc_media_discoverer_start.
+   This allows to attach media events between create and start.
+
+
 
 Changes between 2.1.x and 2.2.0:
 --------------------------------
diff --git a/include/vlc/libvlc_media_discoverer.h b/include/vlc/libvlc_media_discoverer.h
index cf263b0..2626802 100644
--- a/include/vlc/libvlc_media_discoverer.h
+++ b/include/vlc/libvlc_media_discoverer.h
@@ -48,15 +48,61 @@ extern "C" {
 typedef struct libvlc_media_discoverer_t libvlc_media_discoverer_t;
 
 /**
- * Discover media service by name.
+ * \deprecated Use libvlc_media_discoverer_new() and libvlc_media_discoverer_start().
+ */
+LIBVLC_DEPRECATED LIBVLC_API libvlc_media_discoverer_t *
+libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
+                                       const char * psz_name );
+
+/**
+ * Create a media discoverer object by name.
+ *
+ * After this object is created, you should attach to events in order to be
+ * notified of the discoverer state.
+ * You should also attach to media_list events in order to be notified of new
+ * items discovered.
+ *
+ * You need to call libvlc_media_discoverer_start() in order to start the
+ * discovery.
+ *
+ * \see libvlc_media_discoverer_media_list
+ * \see libvlc_media_discoverer_event_manager
+ * \see libvlc_media_discoverer_start
  *
  * \param p_inst libvlc instance
  * \param psz_name service name
  * \return media discover object or NULL in case of error
+ * \version LibVLC 3.0.0 or later
  */
 LIBVLC_API libvlc_media_discoverer_t *
-libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
-                                       const char * psz_name );
+libvlc_media_discoverer_new( libvlc_instance_t * p_inst,
+                             const char * psz_name );
+
+/**
+ * Start media discovery.
+ *
+ * To stop it, call libvlc_media_discoverer_stop() or
+ * libvlc_media_discoverer_release() directly.
+ *
+ * \see libvlc_media_discoverer_stop
+ *
+ * \param p_mdis media discover object
+ * \return -1 in case of error, 0 otherwise
+ * \version LibVLC 3.0.0 or later
+ */
+LIBVLC_API int
+libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis );
+
+/**
+ * Stop media discovery.
+ *
+ * \see libvlc_media_discoverer_start
+ *
+ * \param p_mdis media discover object
+ * \version LibVLC 3.0.0 or later
+ */
+LIBVLC_API void
+libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis );
 
 /**
  * Release media discover object. If the reference count reaches 0, then
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index c0c66dd..f0512c6 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -76,8 +76,11 @@ libvlc_media_discoverer_event_manager
 libvlc_media_discoverer_is_running
 libvlc_media_discoverer_localized_name
 libvlc_media_discoverer_media_list
+libvlc_media_discoverer_new
 libvlc_media_discoverer_new_from_name
 libvlc_media_discoverer_release
+libvlc_media_discoverer_start
+libvlc_media_discoverer_stop
 libvlc_media_duplicate
 libvlc_media_event_manager
 libvlc_media_get_duration
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index b126c95..a2532cb 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -181,12 +181,9 @@ static void services_discovery_ended( const vlc_event_t * p_event,
 
 /**************************************************************************
  *       new (Public)
- *
- * Init an object.
  **************************************************************************/
 libvlc_media_discoverer_t *
-libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
-                                       const char * psz_name )
+libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char * psz_name )
 {
     /* podcast SD is a hack and only works with custom playlist callbacks. */
     if( !strncasecmp( psz_name, "podcast", 7 ) )
@@ -250,14 +247,45 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
                       services_discovery_removeall,
                       p_mdis );
 
+    return p_mdis;
+}
+
+/**************************************************************************
+ *       start (Public)
+ **************************************************************************/
+LIBVLC_API int
+libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis )
+{
     /* Here we go */
-    if( !vlc_sd_Start( p_mdis->p_sd ) )
+    return vlc_sd_Start( p_mdis->p_sd ) ? 0 : -1;
+}
+
+/**************************************************************************
+ *       stop (Public)
+ **************************************************************************/
+LIBVLC_API void
+libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis )
+{
+    return vlc_sd_Stop( p_mdis->p_sd );
+}
+
+/**************************************************************************
+ *       new_from_name (Public)
+ *
+ * \deprecated Use libvlc_media_discoverer_new and libvlc_media_discoverer_start
+ **************************************************************************/
+libvlc_media_discoverer_t *
+libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
+                                       const char * psz_name )
+{
+    libvlc_media_discoverer_t *p_mdis = libvlc_media_discoverer_new( p_inst, psz_name );
+
+    if( !p_mdis )
+        return NULL;
+
+    if( libvlc_media_discoverer_start( p_mdis ) != 0)
     {
-        libvlc_printerr( "%s: internal module error",
-                         p_mdis->p_sd->psz_name );
-        libvlc_media_list_release( p_mdis->p_mlist );
-        libvlc_event_manager_release( p_mdis->p_event_manager );
-        free( p_mdis );
+        libvlc_media_discoverer_release( p_mdis );
         return NULL;
     }
 
@@ -295,7 +323,10 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
 
     libvlc_media_list_release( p_mdis->p_mlist );
 
-    vlc_sd_StopAndDestroy( p_mdis->p_sd );
+    if( p_mdis->running )
+        vlc_sd_Stop( p_mdis->p_sd );
+
+    vlc_sd_Destroy( p_mdis->p_sd );
 
     /* Free catname_to_submedialist and all the mlist */
     char ** all_keys = vlc_dictionary_all_keys( &p_mdis->catname_to_submedialist );



More information about the vlc-commits mailing list