1
mirror of https://code.videolan.org/videolan/vlc synced 2024-08-27 04:21:53 +02:00
vlc/src/control/media_descriptor.c

160 lines
5.2 KiB
C
Raw Normal View History

2007-06-17 18:24:49 +02:00
/*****************************************************************************
* media_descriptor.c: Libvlc API media descriport management
*****************************************************************************
* 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 <vlc/libvlc.h>
#include <vlc_input.h>
#include <vlc_meta.h>
#include "libvlc_internal.h"
/**************************************************************************
* Preparse if not already done (Private)
2007-06-17 18:24:49 +02:00
**************************************************************************/
static void preparse_if_needed( libvlc_media_descriptor_t *p_md )
2007-06-17 18:24:49 +02:00
{
/* XXX: need some locking here */
if (!p_md->b_preparsed)
2007-06-17 18:24:49 +02:00
{
input_Preparse( p_md->p_libvlc_instance->p_libvlc_int,
p_md->p_input_item );
p_md->b_preparsed = VLC_TRUE;
2007-06-17 18:24:49 +02:00
}
}
/**************************************************************************
* Create a new media descriptor object
**************************************************************************/
libvlc_media_descriptor_t * libvlc_media_descriptor_new(
libvlc_instance_t *p_instance,
const char * psz_mrl,
libvlc_exception_t *p_e )
{
input_item_t * p_input_item;
libvlc_media_descriptor_t * p_md;
2007-06-17 18:24:49 +02:00
p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl );
if (!p_input_item)
{
2007-06-24 13:24:36 +02:00
libvlc_exception_raise( p_e, "Can't create md's input_item" );
return NULL;
}
2007-06-17 18:24:49 +02:00
p_md = malloc( sizeof(libvlc_media_descriptor_t) );
p_md->p_libvlc_instance = p_instance;
p_md->p_input_item = p_input_item;
p_md->b_preparsed = VLC_FALSE;
vlc_gc_incref( p_md->p_input_item );
2007-06-17 18:24:49 +02:00
return p_md;
2007-06-17 18:24:49 +02:00
}
/**************************************************************************
* Create a new media descriptor object from an input_item
* (libvlc internal)
**************************************************************************/
libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
libvlc_instance_t *p_instance,
input_item_t *p_input_item,
libvlc_exception_t *p_e )
{
libvlc_media_descriptor_t * p_md;
if (!p_input_item)
{
2007-06-24 13:24:36 +02:00
libvlc_exception_raise( p_e, "No input item given" );
return NULL;
}
p_md = malloc( sizeof(libvlc_media_descriptor_t) );
p_md->p_libvlc_instance = p_instance;
p_md->p_input_item = p_input_item;
p_md->b_preparsed = VLC_TRUE;
vlc_gc_incref( p_md->p_input_item );
return p_md;
}
2007-06-17 18:24:49 +02:00
/**************************************************************************
* Delete a media descriptor object
**************************************************************************/
void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_md )
2007-06-17 18:24:49 +02:00
{
if (!p_md)
2007-06-17 18:24:49 +02:00
return;
/* XXX: locking */
vlc_gc_decref( p_md->p_input_item );
free( p_md );
}
/**************************************************************************
* Delete a media descriptor object
**************************************************************************/
libvlc_media_descriptor_t *
libvlc_media_descriptor_duplicate( libvlc_media_descriptor_t *p_md_orig )
{
libvlc_media_descriptor_t * p_md;
p_md = malloc( sizeof(libvlc_media_descriptor_t) );
memcpy( p_md, p_md_orig, sizeof(libvlc_media_descriptor_t) );
2007-06-17 18:24:49 +02:00
vlc_gc_incref( p_md->p_input_item );
return p_md;
2007-06-17 18:24:49 +02:00
}
/**************************************************************************
* Getter for meta information
2007-06-17 18:24:49 +02:00
**************************************************************************/
static const int meta_conversion[] =
{
[libvlc_meta_Title] = 0, /* Offset in the vlc_meta_t structure */
[libvlc_meta_Artist] = 1
};
char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
2007-06-17 18:24:49 +02:00
libvlc_meta_t e_meta,
libvlc_exception_t *p_e )
{
char ** ppsz_meta;
char *ppz_meta;
2007-06-17 18:24:49 +02:00
/* XXX: locking */
preparse_if_needed( p_md );
2007-06-17 18:24:49 +02:00
ppsz_meta = (char**)p_md->p_input_item->p_meta;
ppz_meta = ppsz_meta[ meta_conversion[e_meta] ];
2007-06-17 18:24:49 +02:00
if( !ppz_meta )
return NULL;
return strdup( ppz_meta );
2007-06-17 18:24:49 +02:00
}