]> git.sesse.net Git - vlc/commitdiff
* control/media_library.c: Initial implementation.
authorPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 19 Aug 2007 21:54:49 +0000 (21:54 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 19 Aug 2007 21:54:49 +0000 (21:54 +0000)
* control/media_list.c: Implement _set_name _add_from_file.

include/vlc/libvlc.h
include/vlc/libvlc_structures.h
src/Makefile.am
src/control/libvlc_internal.h
src/control/media_library.c [new file with mode: 0644]
src/control/media_list.c

index b24098a410695f524aefb40379f9652afc96849c..7d4451042e08e4ad6516cfb85bdc834e5b9457cf 100644 (file)
@@ -412,6 +412,20 @@ VLC_PUBLIC_API void
 VLC_PUBLIC_API void
     libvlc_media_list_retain( libvlc_media_list_t * );
 
+VLC_PUBLIC_API void
+    libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
+                                        const char * psz_uri,
+                                        libvlc_exception_t * p_e );
+
+VLC_PUBLIC_API void
+    libvlc_media_list_set_name( libvlc_media_list_t *,
+                                const char * psz_name,
+                                libvlc_exception_t *);
+
+VLC_PUBLIC_API char *
+    libvlc_media_list_name( libvlc_media_list_t *,
+                            libvlc_exception_t *);
+
 VLC_PUBLIC_API void
     libvlc_media_list_add_media_descriptor( libvlc_media_list_t *,
                                             libvlc_media_descriptor_t *,
@@ -453,6 +467,38 @@ VLC_PUBLIC_API libvlc_media_list_t *
 
 /** @} */
 
+/*****************************************************************************
+ * Media List
+ *****************************************************************************/
+/** defgroup libvlc_media_library Media Library
+ * \ingroup libvlc
+ * LibVLC Media Library
+ * @{
+ */
+VLC_PUBLIC_API libvlc_media_library_t *
+    libvlc_media_library_new( libvlc_instance_t * p_inst,
+                              libvlc_exception_t * p_e );
+VLC_PUBLIC_API void
+    libvlc_media_library_release( libvlc_media_library_t * p_mlib );
+VLC_PUBLIC_API void
+    libvlc_media_library_retain( libvlc_media_library_t * p_mlib );
+
+
+VLC_PUBLIC_API void
+    libvlc_media_library_load( libvlc_media_library_t * p_mlib,
+                               libvlc_exception_t * p_e );
+
+VLC_PUBLIC_API void
+    libvlc_media_library_save( libvlc_media_library_t * p_mlib,
+                               libvlc_exception_t * p_e );
+
+VLC_PUBLIC_API libvlc_media_list_t *
+    libvlc_media_library_media_list( libvlc_media_library_t * p_mlib,
+                                     libvlc_exception_t * p_e );
+
+
+/** @} */
+
 /*****************************************************************************
  * Media List Player
  *****************************************************************************/
index 5c207affc29f3daaeb657bbc635218d77f592b08..36e0220cbb1ae0fb8b83b61afda456d6cd5f978c 100644 (file)
@@ -147,6 +147,19 @@ typedef struct libvlc_media_list_player_t libvlc_media_list_player_t;
 
 /**@} */
 
+/*****************************************************************************
+ * Media Library
+ *****************************************************************************/
+/** defgroup libvlc_media_library Media Library
+ * \ingroup libvlc
+ * LibVLC Media Library
+ * @{
+ */
+
+typedef struct libvlc_media_library_t libvlc_media_library_t;
+
+/**@} */
+
 /*****************************************************************************
  * Playlist
  *****************************************************************************/
@@ -256,10 +269,13 @@ typedef struct libvlc_log_message_t
 typedef enum libvlc_event_type_t {
     libvlc_MediaDescriptorMetaChanged,
     libvlc_MediaDescriptorSubItemAdded,
+
     libvlc_MediaInstanceReachedEnd,
+
     libvlc_MediaListItemAdded,
     libvlc_MediaListItemDeleted,
     libvlc_MediaListItemChanged,
+
 } libvlc_event_type_t;
 
 /**
@@ -275,6 +291,7 @@ typedef struct libvlc_event_t
     void * p_obj;
     union event_type_specific
     {
+        /* media descriptor */
         struct
         {
             libvlc_meta_t meta_type;
@@ -283,6 +300,8 @@ typedef struct libvlc_event_t
         {
             libvlc_media_descriptor_t * new_child;
         } media_descriptor_subitem_added;
+
+        /* media list */
         struct
         {
             libvlc_media_descriptor_t * item;
index 4793da14dd3ca67469872d5bf983a033c2aae049..c92baa3abc5cf2e5ce9e6d93484d5bfb6d7c629a 100644 (file)
@@ -319,6 +319,7 @@ SOURCES_libvlc_control = \
        control/media_instance.c \
        control/media_list.c \
        control/media_list_player.c \
+       control/media_library.c \
        control/mediacontrol_internal.h \
        control/mediacontrol_core.c \
        control/mediacontrol_util.c \
index 5984c9a16f298123f4d82feb3687f25e916d1e9e..c49e806b961c9d17a8a44807a594bc62e8c402a2 100644 (file)
@@ -87,6 +87,7 @@ struct libvlc_media_list_t
     vlc_mutex_t              object_lock;
     libvlc_media_list_t *    p_media_provider; /* For dynamic sublist */
     libvlc_tag_query_t *     p_query;              /* For dynamic sublist */
+    char *                   psz_name; /* Usually NULL */
     DECL_ARRAY(void *) items;
 };
 
@@ -114,6 +115,14 @@ struct libvlc_media_list_player_t
     libvlc_media_instance_t *  p_mi;
 };
 
+struct libvlc_media_library_t
+{
+    libvlc_event_manager_t * p_event_manager;
+    libvlc_instance_t *      p_libvlc_instance;
+    int                      i_refcount;
+    libvlc_media_list_t *    p_mlist;
+};
+
 struct libvlc_media_discoverer_t
 {
     libvlc_event_manager_t * p_event_manager;
diff --git a/src/control/media_library.c b/src/control/media_library.c
new file mode 100644 (file)
index 0000000..bf24a70
--- /dev/null
@@ -0,0 +1,138 @@
+/*****************************************************************************
+ * tree.c: libvlc tags tree functions
+ * Create a tree of the 'tags' of a media_list's media_descriptors.
+ *****************************************************************************
+ * Copyright (C) 2007 the VideoLAN team
+ * $Id: media_library.c 21094 2007-08-15 04:53:01Z pdherbemont $
+ *
+ * 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 "vlc_arrays.h"
+
+/*
+ * Private functions
+ */
+
+/*
+ * Public libvlc functions
+ */
+
+/**************************************************************************
+ *       new (Public)
+ **************************************************************************/
+libvlc_media_library_t *
+libvlc_media_library_new( libvlc_instance_t * p_inst,
+                          libvlc_exception_t * p_e )
+{
+       (void)p_e;
+    libvlc_media_library_t * p_mlib;
+
+       p_mlib = malloc(sizeof(libvlc_media_library_t));
+
+       if( !p_mlib )
+               return NULL;
+
+       p_mlib->p_libvlc_instance = p_inst;
+    p_mlib->i_refcount = 1;
+    p_mlib->p_mlist = NULL;
+
+    p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst, p_e );
+
+       return p_mlib;
+}
+
+/**************************************************************************
+ *       release (Public)
+ **************************************************************************/
+void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
+{
+    p_mlib->i_refcount--;
+
+    if( p_mlib->i_refcount > 0 )
+        return;
+
+       free( p_mlib );
+}
+
+/**************************************************************************
+ *       retain (Public)
+ **************************************************************************/
+void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
+{
+       p_mlib->i_refcount++;
+}
+
+/**************************************************************************
+ *       load (Public)
+ *
+ * It doesn't yet load the playlists
+ **************************************************************************/
+void
+libvlc_media_library_load( libvlc_media_library_t * p_mlib,
+                           libvlc_exception_t * p_e )
+{
+    const char *psz_homedir = p_mlib->p_libvlc_instance->p_libvlc_int->psz_homedir;
+    char * psz_uri;
+
+    if( !psz_homedir )
+    {
+        libvlc_exception_raise( p_e, "Can't get HOME DIR" );
+        return;
+    }
+
+    if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP CONFIG_DIR DIR_SEP
+                        "ml.xsp", psz_homedir ) == -1 )
+    {
+        libvlc_exception_raise( p_e, "Can't get create the path" );
+        return;
+    }
+    if( p_mlib->p_mlist )
+        libvlc_media_list_release( p_mlib->p_mlist );
+
+    p_mlib->p_mlist = libvlc_media_list_new(
+                        p_mlib->p_libvlc_instance,
+                        p_e );
+
+    libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri, p_e );
+    free( psz_uri );
+    return;
+}
+
+/**************************************************************************
+ *       save (Public)
+ **************************************************************************/
+void
+libvlc_media_library_save( libvlc_media_library_t * p_mlib,
+                           libvlc_exception_t * p_e )
+{
+    libvlc_exception_raise( p_e, "Not supported" );
+}
+
+/**************************************************************************
+ *        media_list (Public)
+ **************************************************************************/
+libvlc_media_list_t *
+libvlc_media_library_media_list( libvlc_media_library_t * p_mlib,
+                                     libvlc_exception_t * p_e )
+{
+       (void)p_e;
+    if( p_mlib->p_mlist )
+        libvlc_media_list_retain( p_mlib->p_mlist );
+    return p_mlib->p_mlist;
+}
index be1b0d2ab945eb736877e74d684ab666c926e0ea..e717ff9af5d86300a6aba5f1e4770c7d814fed41 100644 (file)
@@ -276,6 +276,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
     ARRAY_INIT(p_mlist->items);
     p_mlist->i_refcount = 1;
     p_mlist->p_media_provider = NULL;
+    p_mlist->psz_name = NULL;
 
     return p_mlist;
 }
@@ -314,6 +315,7 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
  
     free( p_mlist );
 }
+
 /**************************************************************************
  *       libvlc_media_list_retain (Public)
  *
@@ -326,6 +328,77 @@ void libvlc_media_list_retain( libvlc_media_list_t * p_mlist )
     vlc_mutex_unlock( &p_mlist->object_lock );
 }
 
+
+/**************************************************************************
+ *       add_file_content (Public)
+ **************************************************************************/
+void
+libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
+                                    const char * psz_uri,
+                                    libvlc_exception_t * p_e )
+{
+    input_item_t * p_input_item;
+    libvlc_media_descriptor_t * p_md;
+
+    p_input_item = input_ItemNewExt( p_mlist->p_libvlc_instance->p_libvlc_int, psz_uri,
+                                _("Media Library"), 0, NULL, -1 );
+
+    if( !p_input_item )
+    {
+        libvlc_exception_raise( p_e, "Can't create an input item" );
+        return;
+    }
+
+    p_md = libvlc_media_descriptor_new_from_input_item(
+            p_mlist->p_libvlc_instance,
+            p_input_item, p_e );
+
+    if( !p_md )
+    {
+        vlc_gc_decref( p_input_item );
+        return;
+    }
+
+    libvlc_media_list_add_media_descriptor( p_mlist, p_md, p_e );
+    if( libvlc_exception_raised( p_e ) )
+        return;
+
+    input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item, VLC_TRUE );
+
+    return;
+}
+
+/**************************************************************************
+ *       set_name (Public)
+ **************************************************************************/
+void libvlc_media_list_set_name( libvlc_media_list_t * p_mlist,
+                                 const char * psz_name,
+                                 libvlc_exception_t * p_e)
+
+{
+    (void)p_e;
+    vlc_mutex_lock( &p_mlist->object_lock );
+    free( p_mlist->psz_name );
+    p_mlist->psz_name = psz_name ? strdup( psz_name ) : NULL;
+    vlc_mutex_unlock( &p_mlist->object_lock );
+}
+
+/**************************************************************************
+ *       name (Public)
+ **************************************************************************/
+char * libvlc_media_list_name( libvlc_media_list_t * p_mlist,
+                               libvlc_exception_t * p_e)
+{
+    char *ret;
+    (void)p_e;
+
+    vlc_mutex_lock( &p_mlist->object_lock );
+    ret = p_mlist->psz_name ? strdup( p_mlist->psz_name ) : NULL;
+    vlc_mutex_unlock( &p_mlist->object_lock );
+
+    return ret;
+}
+
 /**************************************************************************
  *       libvlc_media_list_count (Public)
  *