]> git.sesse.net Git - vlc/commitdiff
control/media_discoverer.c: Implementation of a media_discoverer libvlc object based...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Fri, 17 Aug 2007 08:10:42 +0000 (08:10 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Fri, 17 Aug 2007 08:10:42 +0000 (08:10 +0000)
include/vlc/libvlc.h
include/vlc/libvlc_structures.h
include/vlc_playlist.h
src/Makefile.am
src/control/libvlc_internal.h
src/control/media_discoverer.c [new file with mode: 0644]
src/playlist/services_discovery.c

index 67273021f103818b3dbb5736dccfdb05d52db5c2..b24098a410695f524aefb40379f9652afc96849c 100644 (file)
@@ -692,13 +692,6 @@ VLC_PUBLIC_API void libvlc_video_set_viewport( libvlc_instance_t *, const libvlc
 
 /** @} */
 
-/**
- * defgroup libvlc_vlm VLM
- * \ingroup libvlc
- * LibVLC VLM handling
- * @{
- */
-
 /** defgroup libvlc_audio Audio
  * \ingroup libvlc
  * LibVLC Audio handling
@@ -780,6 +773,34 @@ VLC_PUBLIC_API void libvlc_audio_set_channel( libvlc_instance_t *, int, libvlc_e
 
 /** @} */
 
+/*****************************************************************************
+ * Services/Media Discovery
+ *****************************************************************************/
+/** defgroup libvlc_media_discoverer Media Discoverer
+ * \ingroup libvlc
+ * LibVLC Media Discoverer
+ * @{
+ */
+
+VLC_PUBLIC_API libvlc_media_discoverer_t *
+libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
+                                       const char * psz_name,
+                                       libvlc_exception_t * p_e );
+VLC_PUBLIC_API void   libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis );
+VLC_PUBLIC_API char * libvlc_media_discoverer_localized_name( libvlc_media_discoverer_t * p_mdis );
+
+VLC_PUBLIC_API libvlc_media_list_t * libvlc_media_discoverer_media_list( );
+
+/**@} */
+
+/*****************************************************************************
+ * VLM
+ *****************************************************************************/
+/** defgroup libvlc_vlm VLM
+ * \ingroup libvlc
+ * LibVLC VLM
+ * @{
+ */
 
 /**
  * Add a broadcast, with one input
@@ -926,7 +947,6 @@ VLC_PUBLIC_API LIBVLC_VLM_GET_MEDIA_ATTRIBUTE( seekable, int, Bool, 0);
 
 #undef LIBVLC_VLM_GET_MEDIA_ATTRIBUTE
 
-/** @} */
 /** @} */
 
 /*****************************************************************************
index ad2b6a337495da1762713b15dba99c3cbbf03304..5c207affc29f3daaeb657bbc635218d77f592b08 100644 (file)
@@ -197,6 +197,19 @@ libvlc_rectangle_t;
 /**@} */
 
 
+/*****************************************************************************
+ * Services/Media Discovery
+ *****************************************************************************/
+/** defgroup libvlc_media_discoverer Media Discoverer
+ * \ingroup libvlc
+ * LibVLC Media Discoverer
+ * @{
+ */
+
+typedef struct libvlc_media_discoverer_t libvlc_media_discoverer_t;
+
+/**@} */
+
 /*****************************************************************************
  * Message log handling
  *****************************************************************************/
index 6ecce99988fd3c9e4ec16c0b6ec3543817117058..4d47c52a40aea29bf277e929240ac6f13bfc2932 100644 (file)
@@ -425,7 +425,7 @@ VLC_EXPORT( void,                   services_discovery_Destroy, ( services_disco
 VLC_EXPORT( int,                    services_discovery_Start, ( services_discovery_t * p_this ) );
 
 /* Read info from discovery object */
-VLC_EXPORT( const char *,           services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
+VLC_EXPORT( char *,                 services_discovery_GetLocalizedName, ( services_discovery_t * p_this ) );
 
 /* Receive event notification (prefered way to get new items) */
 VLC_EXPORT( vlc_event_manager_t *,  services_discovery_EventManager, ( services_discovery_t * p_this ) );
index da6f8412e2edbf6a256286a1bc9b7738c323fd00..20d05c9986202a9661ae809dbd50097eb94ac246 100644 (file)
@@ -322,6 +322,7 @@ SOURCES_libvlc_control = \
        control/mediacontrol_core.c \
        control/mediacontrol_util.c \
        control/mediacontrol_audio_video.c \
+       control/media_discoverer.c \
        control/tag_query.c
 
 ###############################################################################
index 85a94bfcab1ed04bd2162ffae8e5164f92cdcc4a..5984c9a16f298123f4d82feb3687f25e916d1e9e 100644 (file)
@@ -114,7 +114,13 @@ struct libvlc_media_list_player_t
     libvlc_media_instance_t *  p_mi;
 };
 
-
+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;
+};
 
 /* 
  * Event Handling
diff --git a/src/control/media_discoverer.c b/src/control/media_discoverer.c
new file mode 100644 (file)
index 0000000..19ddb06
--- /dev/null
@@ -0,0 +1,141 @@
+/*****************************************************************************
+ * media_discoverer.c: libvlc new API media discoverer functions
+ *****************************************************************************
+ * Copyright (C) 2007 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "libvlc_internal.h"
+#include <vlc/libvlc.h>
+#include <assert.h>
+#include "vlc_playlist.h"
+
+/*
+ * Private functions
+ */
+/**************************************************************************
+ *       services_discovery_item_added (Private) (VLC event callback)
+ **************************************************************************/
+
+static void services_discovery_item_added( const vlc_event_t * p_event,
+                                           void * user_data )
+{
+    input_item_t * p_item = p_event->u.services_discovery_item_added.p_new_item;
+    libvlc_media_descriptor_t * p_md;
+    libvlc_media_discoverer_t * p_mdis = user_data;
+
+    p_md = libvlc_media_descriptor_new_from_input_item(
+            p_mdis->p_libvlc_instance,
+            p_item, NULL );
+
+    libvlc_media_list_lock( p_mdis->p_mlist );
+    libvlc_media_list_add_media_descriptor( p_mdis->p_mlist, p_md, NULL );
+    libvlc_media_list_unlock( p_mdis->p_mlist );
+}
+
+/**************************************************************************
+ *       services_discovery_item_removed (Private) (VLC event callback)
+ **************************************************************************/
+
+static void services_discovery_item_removed( const vlc_event_t * p_event,
+                                             void * user_data )
+{
+    /* Not handled */
+}
+
+/*
+ * Public libvlc functions
+ */
+
+/**************************************************************************
+ *       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_exception_t * p_e )
+{
+    libvlc_media_discoverer_t * p_mdis;
+    
+    p_mdis = malloc(sizeof(libvlc_media_discoverer_t));
+    if( !p_mdis )
+    {
+        libvlc_exception_raise( p_e, "Not enough memory" );
+        return NULL;
+    }
+
+    p_mdis->p_libvlc_instance = p_inst;
+    p_mdis->p_mlist = libvlc_media_list_new( p_inst, NULL );
+    p_mdis->p_sd = services_discovery_Create( (vlc_object_t*)p_inst->p_libvlc_int, psz_name );
+
+    if( !p_mdis->p_sd )
+    {
+        free( p_mdis );
+        return NULL;
+    }
+
+    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
+                      vlc_ServicesDiscoveryItemAdded,
+                      services_discovery_item_added,
+                      p_mdis );
+    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
+                      vlc_ServicesDiscoveryItemRemoved,
+                      services_discovery_item_removed,
+                      p_mdis );
+    
+    services_discovery_Start( p_mdis->p_sd );
+
+    /* Here we go */
+
+    return p_mdis;
+}
+
+/**************************************************************************
+ * release (Public)
+ **************************************************************************/
+void
+libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
+{
+    libvlc_media_list_release( p_mdis->p_mlist );
+    services_discovery_Destroy( p_mdis->p_sd );
+    free( p_mdis );
+}
+
+/**************************************************************************
+ * localized_name (Public)
+ **************************************************************************/
+char *
+libvlc_media_discoverer_localized_name( libvlc_media_discoverer_t * p_mdis )
+{
+    return services_discovery_GetLocalizedName( p_mdis->p_sd );
+}
+
+/**************************************************************************
+ * media_list (Public)
+ **************************************************************************/
+libvlc_media_list_t *
+libvlc_media_discoverer_media_list( libvlc_media_discoverer_t * p_mdis )
+{
+    libvlc_media_list_retain( p_mdis->p_sd );
+    return p_mdis->p_sd;
+}
+
index 5d9ee36204ef40500c5d8173bfd84bb224315986..51c796523192687eaa4a1c82a716f13075d9f012 100644 (file)
@@ -103,7 +103,7 @@ int services_discovery_Start ( services_discovery_t * p_sd )
 /***********************************************************************
  * GetLocalizedName
  ***********************************************************************/
-const char *
+char *
 services_discovery_GetLocalizedName ( services_discovery_t * p_sd )
 {
     return p_sd->psz_localized_name ? strdup( p_sd->psz_localized_name ) : NULL;