1 /*****************************************************************************
2 * media_descriptor.c: Libvlc API media descriport management
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Pierre d'Herbemont <pdherbemont@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <vlc/libvlc.h>
25 #include <vlc_input.h>
28 #include "libvlc_internal.h"
31 /**************************************************************************
32 * Preparse if not already done (Private)
33 **************************************************************************/
34 static void preparse_if_needed( libvlc_media_descriptor_t *p_media_desc )
36 /* XXX: need some locking here */
37 if (!p_media_desc->b_preparsed)
39 input_Preparse( p_media_desc->p_libvlc_instance->p_libvlc_int,
40 p_media_desc->p_input_item );
41 p_media_desc->b_preparsed = VLC_TRUE;
45 /**************************************************************************
46 * Create a new media descriptor object
47 **************************************************************************/
48 libvlc_media_descriptor_t * libvlc_media_descriptor_new(
49 libvlc_instance_t *p_instance,
51 libvlc_exception_t *p_e )
53 input_item_t * p_input_item;
54 libvlc_media_descriptor_t * p_media_desc;
56 p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl );
60 libvlc_exception_raise( p_e, "Can't create md's input_item" );
64 p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
65 p_media_desc->p_libvlc_instance = p_instance;
66 p_media_desc->p_input_item = p_input_item;
67 p_media_desc->b_preparsed = VLC_FALSE;
72 /**************************************************************************
73 * Create a new media descriptor object from an input_item
75 **************************************************************************/
76 libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
77 libvlc_instance_t *p_instance,
78 input_item_t *p_input_item,
79 libvlc_exception_t *p_e )
81 libvlc_media_descriptor_t * p_media_desc;
85 libvlc_exception_raise( p_e, "No input item given" );
89 p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
90 p_media_desc->p_libvlc_instance = p_instance;
91 p_media_desc->p_input_item = p_input_item;
92 p_media_desc->b_preparsed = VLC_TRUE;
97 /**************************************************************************
98 * Delete a media descriptor object
99 **************************************************************************/
100 void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_md )
107 /* XXX: here we don't clean the item, because we can't properly track
108 * if it is needed by some other object. This is a leak(!). */
109 /* input_ItemClean( p_md->p_input_item ); */
114 /**************************************************************************
115 * Delete a media descriptor object
116 **************************************************************************/
117 libvlc_media_descriptor_t *
118 libvlc_media_descriptor_duplicate( libvlc_media_descriptor_t *p_md_orig )
120 libvlc_media_descriptor_t * p_md;
122 p_md = malloc( sizeof(libvlc_media_descriptor_t) );
123 memcpy( p_md, p_md_orig, sizeof(libvlc_media_descriptor_t) );
128 /**************************************************************************
129 * Getter for meta information
130 **************************************************************************/
131 static const int meta_conversion[] =
133 [libvlc_meta_Title] = 0, /* Offset in the vlc_meta_t structure */
134 [libvlc_meta_Artist] = 1
137 char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc,
138 libvlc_meta_t e_meta,
139 libvlc_exception_t *p_e )
146 preparse_if_needed( p_meta_desc );
148 ppsz_meta = (char**)p_meta_desc->p_input_item->p_meta;
149 ppz_meta = ppsz_meta[ meta_conversion[e_meta] ];
154 return strdup( ppz_meta );