Commit 8c3e4b40 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

* control/media_library.c: Initial implementation.

* control/media_list.c: Implement _set_name _add_from_file.
parent 48b6fb5c
...@@ -412,6 +412,20 @@ VLC_PUBLIC_API void ...@@ -412,6 +412,20 @@ VLC_PUBLIC_API void
VLC_PUBLIC_API void VLC_PUBLIC_API void
libvlc_media_list_retain( libvlc_media_list_t * ); 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 VLC_PUBLIC_API void
libvlc_media_list_add_media_descriptor( libvlc_media_list_t *, libvlc_media_list_add_media_descriptor( libvlc_media_list_t *,
libvlc_media_descriptor_t *, libvlc_media_descriptor_t *,
...@@ -453,6 +467,38 @@ VLC_PUBLIC_API libvlc_media_list_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 * Media List Player
*****************************************************************************/ *****************************************************************************/
......
...@@ -147,6 +147,19 @@ typedef struct libvlc_media_list_player_t libvlc_media_list_player_t; ...@@ -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 * Playlist
*****************************************************************************/ *****************************************************************************/
...@@ -256,10 +269,13 @@ typedef struct libvlc_log_message_t ...@@ -256,10 +269,13 @@ typedef struct libvlc_log_message_t
typedef enum libvlc_event_type_t { typedef enum libvlc_event_type_t {
libvlc_MediaDescriptorMetaChanged, libvlc_MediaDescriptorMetaChanged,
libvlc_MediaDescriptorSubItemAdded, libvlc_MediaDescriptorSubItemAdded,
libvlc_MediaInstanceReachedEnd, libvlc_MediaInstanceReachedEnd,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
libvlc_MediaListItemDeleted, libvlc_MediaListItemDeleted,
libvlc_MediaListItemChanged, libvlc_MediaListItemChanged,
} libvlc_event_type_t; } libvlc_event_type_t;
/** /**
...@@ -275,6 +291,7 @@ typedef struct libvlc_event_t ...@@ -275,6 +291,7 @@ typedef struct libvlc_event_t
void * p_obj; void * p_obj;
union event_type_specific union event_type_specific
{ {
/* media descriptor */
struct struct
{ {
libvlc_meta_t meta_type; libvlc_meta_t meta_type;
...@@ -283,6 +300,8 @@ typedef struct libvlc_event_t ...@@ -283,6 +300,8 @@ typedef struct libvlc_event_t
{ {
libvlc_media_descriptor_t * new_child; libvlc_media_descriptor_t * new_child;
} media_descriptor_subitem_added; } media_descriptor_subitem_added;
/* media list */
struct struct
{ {
libvlc_media_descriptor_t * item; libvlc_media_descriptor_t * item;
......
...@@ -319,6 +319,7 @@ SOURCES_libvlc_control = \ ...@@ -319,6 +319,7 @@ SOURCES_libvlc_control = \
control/media_instance.c \ control/media_instance.c \
control/media_list.c \ control/media_list.c \
control/media_list_player.c \ control/media_list_player.c \
control/media_library.c \
control/mediacontrol_internal.h \ control/mediacontrol_internal.h \
control/mediacontrol_core.c \ control/mediacontrol_core.c \
control/mediacontrol_util.c \ control/mediacontrol_util.c \
......
...@@ -87,6 +87,7 @@ struct libvlc_media_list_t ...@@ -87,6 +87,7 @@ struct libvlc_media_list_t
vlc_mutex_t object_lock; vlc_mutex_t object_lock;
libvlc_media_list_t * p_media_provider; /* For dynamic sublist */ libvlc_media_list_t * p_media_provider; /* For dynamic sublist */
libvlc_tag_query_t * p_query; /* For dynamic sublist */ libvlc_tag_query_t * p_query; /* For dynamic sublist */
char * psz_name; /* Usually NULL */
DECL_ARRAY(void *) items; DECL_ARRAY(void *) items;
}; };
...@@ -114,6 +115,14 @@ struct libvlc_media_list_player_t ...@@ -114,6 +115,14 @@ struct libvlc_media_list_player_t
libvlc_media_instance_t * p_mi; 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 struct libvlc_media_discoverer_t
{ {
libvlc_event_manager_t * p_event_manager; libvlc_event_manager_t * p_event_manager;
......
/*****************************************************************************
* 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;
}
...@@ -276,6 +276,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst, ...@@ -276,6 +276,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
ARRAY_INIT(p_mlist->items); ARRAY_INIT(p_mlist->items);
p_mlist->i_refcount = 1; p_mlist->i_refcount = 1;
p_mlist->p_media_provider = NULL; p_mlist->p_media_provider = NULL;
p_mlist->psz_name = NULL;
return p_mlist; return p_mlist;
} }
...@@ -314,6 +315,7 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist ) ...@@ -314,6 +315,7 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
free( p_mlist ); free( p_mlist );
} }
/************************************************************************** /**************************************************************************
* libvlc_media_list_retain (Public) * libvlc_media_list_retain (Public)
* *
...@@ -326,6 +328,77 @@ void libvlc_media_list_retain( libvlc_media_list_t * p_mlist ) ...@@ -326,6 +328,77 @@ void libvlc_media_list_retain( libvlc_media_list_t * p_mlist )
vlc_mutex_unlock( &p_mlist->object_lock ); 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) * libvlc_media_list_count (Public)
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment