media_library.c
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:5k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * tree.c: libvlc tags tree functions
  3.  * Create a tree of the 'tags' of a media_list's medias.
  4.  *****************************************************************************
  5.  * Copyright (C) 2007 the VideoLAN team
  6.  * $Id: fd68429940d60455666381ef9ec51dbbf1545f47 $
  7.  *
  8.  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. #ifdef HAVE_CONFIG_H
  25. # include <config.h>
  26. #endif
  27. #include <vlc/libvlc.h>
  28. #include <vlc/libvlc_media.h>
  29. #include <vlc/libvlc_media_list.h>
  30. #include <vlc/libvlc_media_library.h>
  31. #include <vlc/libvlc_events.h>
  32. #include <vlc_common.h>
  33. #include "libvlc_internal.h"
  34. struct libvlc_media_library_t
  35. {
  36.     libvlc_event_manager_t * p_event_manager;
  37.     libvlc_instance_t *      p_libvlc_instance;
  38.     int                      i_refcount;
  39.     libvlc_media_list_t *    p_mlist;
  40. };
  41. /*
  42.  * Private functions
  43.  */
  44. /*
  45.  * Public libvlc functions
  46.  */
  47. /**************************************************************************
  48.  *       new (Public)
  49.  **************************************************************************/
  50. libvlc_media_library_t *
  51. libvlc_media_library_new( libvlc_instance_t * p_inst,
  52.                           libvlc_exception_t * p_e )
  53. {
  54.     (void)p_e;
  55.     libvlc_media_library_t * p_mlib;
  56.     p_mlib = malloc(sizeof(libvlc_media_library_t));
  57.     if( !p_mlib )
  58.         return NULL;
  59.     p_mlib->p_libvlc_instance = p_inst;
  60.     p_mlib->i_refcount = 1;
  61.     p_mlib->p_mlist = NULL;
  62.     p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst, p_e );
  63.     return p_mlib;
  64. }
  65. /**************************************************************************
  66.  *       release (Public)
  67.  **************************************************************************/
  68. void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
  69. {
  70.     p_mlib->i_refcount--;
  71.     if( p_mlib->i_refcount > 0 )
  72.         return;
  73.     libvlc_event_manager_release( p_mlib->p_event_manager );
  74.     free( p_mlib );
  75. }
  76. /**************************************************************************
  77.  *       retain (Public)
  78.  **************************************************************************/
  79. void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
  80. {
  81.     p_mlib->i_refcount++;
  82. }
  83. /**************************************************************************
  84.  *       load (Public)
  85.  *
  86.  * It doesn't yet load the playlists
  87.  **************************************************************************/
  88. void
  89. libvlc_media_library_load( libvlc_media_library_t * p_mlib,
  90.                            libvlc_exception_t * p_e )
  91. {
  92.     char *psz_datadir = config_GetUserDataDir();
  93.     char * psz_uri;
  94.     if( !psz_datadir ) /* XXX: i doubt that this can ever happen */
  95.     {
  96.         libvlc_exception_raise( p_e, "Can't get data directory" );
  97.         return;
  98.     }
  99.     if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
  100.                   psz_datadir ) == -1 )
  101.     {
  102.         free( psz_datadir );
  103.         libvlc_exception_raise( p_e, "Can't get create the path" );
  104.         return;
  105.     }
  106.     free( psz_datadir );
  107.     if( p_mlib->p_mlist )
  108.         libvlc_media_list_release( p_mlib->p_mlist );
  109.     p_mlib->p_mlist = libvlc_media_list_new(
  110.                         p_mlib->p_libvlc_instance,
  111.                         p_e );
  112.     libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri, p_e );
  113.     free( psz_uri );
  114.     return;
  115. }
  116. /**************************************************************************
  117.  *       save (Public)
  118.  **************************************************************************/
  119. void
  120. libvlc_media_library_save( libvlc_media_library_t * p_mlib,
  121.                            libvlc_exception_t * p_e )
  122. {
  123.     (void)p_mlib;
  124.     libvlc_exception_raise( p_e, "Not supported" );
  125. }
  126. /**************************************************************************
  127.  *        media_list (Public)
  128.  **************************************************************************/
  129. libvlc_media_list_t *
  130. libvlc_media_library_media_list( libvlc_media_library_t * p_mlib,
  131.                                      libvlc_exception_t * p_e )
  132. {
  133.     (void)p_e;
  134.     if( p_mlib->p_mlist )
  135.         libvlc_media_list_retain( p_mlib->p_mlist );
  136.     return p_mlib->p_mlist;
  137. }