2007-06-17 18:24:49 +02:00
|
|
|
/*****************************************************************************
|
2008-03-30 03:59:32 +02:00
|
|
|
* media.c: Libvlc API media descripor management
|
2007-06-17 18:24:49 +02:00
|
|
|
*****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2009-05-25 15:09:40 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2007-06-17 18:24:49 +02:00
|
|
|
#include <vlc/libvlc.h>
|
2009-05-25 10:47:38 +02:00
|
|
|
#include <vlc/libvlc_media.h>
|
|
|
|
#include <vlc/libvlc_media_list.h> // For the subitems, here for convenience
|
|
|
|
#include <vlc/libvlc_events.h>
|
|
|
|
|
|
|
|
#include <vlc_common.h>
|
2007-06-17 18:24:49 +02:00
|
|
|
#include <vlc_input.h>
|
|
|
|
#include <vlc_meta.h>
|
2009-05-25 10:47:38 +02:00
|
|
|
#include <vlc_playlist.h> /* For the preparser */
|
2007-06-17 18:24:49 +02:00
|
|
|
|
2009-05-25 10:47:38 +02:00
|
|
|
#include "libvlc.h"
|
|
|
|
|
|
|
|
#include "libvlc_internal.h"
|
|
|
|
#include "media_internal.h"
|
2007-08-22 18:49:43 +02:00
|
|
|
|
2007-08-15 20:27:49 +02:00
|
|
|
static const vlc_meta_type_t libvlc_to_vlc_meta[] =
|
|
|
|
{
|
|
|
|
[libvlc_meta_Title] = vlc_meta_Title,
|
|
|
|
[libvlc_meta_Artist] = vlc_meta_Artist,
|
|
|
|
[libvlc_meta_Genre] = vlc_meta_Genre,
|
|
|
|
[libvlc_meta_Copyright] = vlc_meta_Copyright,
|
|
|
|
[libvlc_meta_Album] = vlc_meta_Album,
|
|
|
|
[libvlc_meta_TrackNumber] = vlc_meta_TrackNumber,
|
|
|
|
[libvlc_meta_Description] = vlc_meta_Description,
|
|
|
|
[libvlc_meta_Rating] = vlc_meta_Rating,
|
|
|
|
[libvlc_meta_Date] = vlc_meta_Date,
|
|
|
|
[libvlc_meta_Setting] = vlc_meta_Setting,
|
|
|
|
[libvlc_meta_URL] = vlc_meta_URL,
|
|
|
|
[libvlc_meta_Language] = vlc_meta_Language,
|
|
|
|
[libvlc_meta_NowPlaying] = vlc_meta_NowPlaying,
|
|
|
|
[libvlc_meta_Publisher] = vlc_meta_Publisher,
|
|
|
|
[libvlc_meta_EncodedBy] = vlc_meta_EncodedBy,
|
|
|
|
[libvlc_meta_ArtworkURL] = vlc_meta_ArtworkURL,
|
|
|
|
[libvlc_meta_TrackID] = vlc_meta_TrackID
|
|
|
|
};
|
|
|
|
|
|
|
|
static const libvlc_meta_t vlc_to_libvlc_meta[] =
|
|
|
|
{
|
|
|
|
[vlc_meta_Title] = libvlc_meta_Title,
|
|
|
|
[vlc_meta_Artist] = libvlc_meta_Artist,
|
|
|
|
[vlc_meta_Genre] = libvlc_meta_Genre,
|
|
|
|
[vlc_meta_Copyright] = libvlc_meta_Copyright,
|
|
|
|
[vlc_meta_Album] = libvlc_meta_Album,
|
|
|
|
[vlc_meta_TrackNumber] = libvlc_meta_TrackNumber,
|
|
|
|
[vlc_meta_Description] = libvlc_meta_Description,
|
|
|
|
[vlc_meta_Rating] = libvlc_meta_Rating,
|
|
|
|
[vlc_meta_Date] = libvlc_meta_Date,
|
|
|
|
[vlc_meta_Setting] = libvlc_meta_Setting,
|
|
|
|
[vlc_meta_URL] = libvlc_meta_URL,
|
|
|
|
[vlc_meta_Language] = libvlc_meta_Language,
|
|
|
|
[vlc_meta_NowPlaying] = libvlc_meta_NowPlaying,
|
|
|
|
[vlc_meta_Publisher] = libvlc_meta_Publisher,
|
|
|
|
[vlc_meta_EncodedBy] = libvlc_meta_EncodedBy,
|
|
|
|
[vlc_meta_ArtworkURL] = libvlc_meta_ArtworkURL,
|
|
|
|
[vlc_meta_TrackID] = libvlc_meta_TrackID
|
|
|
|
};
|
|
|
|
|
2007-08-16 20:05:07 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* input_item_subitem_added (Private) (vlc event Callback)
|
|
|
|
**************************************************************************/
|
|
|
|
static void input_item_subitem_added( const vlc_event_t *p_event,
|
2007-08-20 00:46:15 +02:00
|
|
|
void * user_data )
|
2007-08-16 20:05:07 +02:00
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md = user_data;
|
|
|
|
libvlc_media_t * p_md_child;
|
2007-08-16 20:05:07 +02:00
|
|
|
libvlc_event_t event;
|
|
|
|
|
2008-03-30 03:59:32 +02:00
|
|
|
p_md_child = libvlc_media_new_from_input_item(
|
2007-09-10 20:56:52 +02:00
|
|
|
p_md->p_libvlc_instance,
|
2007-08-16 20:05:07 +02:00
|
|
|
p_event->u.input_item_subitem_added.p_new_child, NULL );
|
|
|
|
|
2007-08-21 21:43:04 +02:00
|
|
|
/* Add this to our media list */
|
|
|
|
if( !p_md->p_subitems )
|
2007-08-29 02:03:55 +02:00
|
|
|
{
|
2007-08-21 21:43:04 +02:00
|
|
|
p_md->p_subitems = libvlc_media_list_new( p_md->p_libvlc_instance, NULL );
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_list_set_media( p_md->p_subitems, p_md, NULL );
|
2007-08-29 02:03:55 +02:00
|
|
|
}
|
2007-08-25 19:40:11 +02:00
|
|
|
if( p_md->p_subitems )
|
2007-08-21 21:43:04 +02:00
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_list_add_media( p_md->p_subitems, p_md_child, NULL );
|
2007-08-21 21:43:04 +02:00
|
|
|
}
|
|
|
|
|
2007-08-16 20:05:07 +02:00
|
|
|
/* Construct the event */
|
2008-03-31 06:35:08 +02:00
|
|
|
event.type = libvlc_MediaSubItemAdded;
|
2008-03-30 03:59:32 +02:00
|
|
|
event.u.media_subitem_added.new_child = p_md_child;
|
2007-08-16 20:05:07 +02:00
|
|
|
|
|
|
|
/* Send the event */
|
|
|
|
libvlc_event_send( p_md->p_event_manager, &event );
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_release( p_md_child );
|
2007-08-16 20:05:07 +02:00
|
|
|
}
|
|
|
|
|
2007-08-15 20:27:49 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* input_item_meta_changed (Private) (vlc event Callback)
|
|
|
|
**************************************************************************/
|
|
|
|
static void input_item_meta_changed( const vlc_event_t *p_event,
|
|
|
|
void * user_data )
|
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md = user_data;
|
2007-08-15 20:27:49 +02:00
|
|
|
libvlc_event_t event;
|
|
|
|
|
|
|
|
/* Construct the event */
|
2008-03-31 06:35:08 +02:00
|
|
|
event.type = libvlc_MediaMetaChanged;
|
2008-03-30 03:59:32 +02:00
|
|
|
event.u.media_meta_changed.meta_type =
|
2007-08-15 20:27:49 +02:00
|
|
|
vlc_to_libvlc_meta[p_event->u.input_item_meta_changed.meta_type];
|
|
|
|
|
|
|
|
/* Send the event */
|
|
|
|
libvlc_event_send( p_md->p_event_manager, &event );
|
|
|
|
}
|
|
|
|
|
2007-10-20 19:56:00 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* input_item_duration_changed (Private) (vlc event Callback)
|
|
|
|
**************************************************************************/
|
|
|
|
static void input_item_duration_changed( const vlc_event_t *p_event,
|
|
|
|
void * user_data )
|
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md = user_data;
|
2007-10-20 19:56:00 +02:00
|
|
|
libvlc_event_t event;
|
|
|
|
|
|
|
|
/* Construct the event */
|
2008-03-31 06:35:08 +02:00
|
|
|
event.type = libvlc_MediaDurationChanged;
|
2008-03-30 03:59:32 +02:00
|
|
|
event.u.media_duration_changed.new_duration =
|
2007-10-20 19:56:00 +02:00
|
|
|
p_event->u.input_item_duration_changed.new_duration;
|
|
|
|
|
|
|
|
/* Send the event */
|
|
|
|
libvlc_event_send( p_md->p_event_manager, &event );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* input_item_preparsed_changed (Private) (vlc event Callback)
|
|
|
|
**************************************************************************/
|
|
|
|
static void input_item_preparsed_changed( const vlc_event_t *p_event,
|
|
|
|
void * user_data )
|
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md = user_data;
|
2007-10-20 19:56:00 +02:00
|
|
|
libvlc_event_t event;
|
|
|
|
|
|
|
|
/* Construct the event */
|
2008-03-31 06:35:08 +02:00
|
|
|
event.type = libvlc_MediaPreparsedChanged;
|
2008-03-30 03:59:32 +02:00
|
|
|
event.u.media_preparsed_changed.new_status =
|
2007-10-20 19:56:00 +02:00
|
|
|
p_event->u.input_item_preparsed_changed.new_status;
|
|
|
|
|
|
|
|
/* Send the event */
|
|
|
|
libvlc_event_send( p_md->p_event_manager, &event );
|
|
|
|
}
|
2007-08-15 20:27:49 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Install event handler (Private)
|
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
static void install_input_item_observer( libvlc_media_t *p_md )
|
2007-08-15 20:27:49 +02:00
|
|
|
{
|
2007-08-16 20:05:07 +02:00
|
|
|
vlc_event_attach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemSubItemAdded,
|
|
|
|
input_item_subitem_added,
|
|
|
|
p_md );
|
2007-08-15 20:27:49 +02:00
|
|
|
vlc_event_attach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemMetaChanged,
|
|
|
|
input_item_meta_changed,
|
|
|
|
p_md );
|
2007-10-20 19:56:00 +02:00
|
|
|
vlc_event_attach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemDurationChanged,
|
|
|
|
input_item_duration_changed,
|
|
|
|
p_md );
|
|
|
|
vlc_event_attach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemPreparsedChanged,
|
|
|
|
input_item_preparsed_changed,
|
|
|
|
p_md );
|
2007-08-15 20:27:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Uninstall event handler (Private)
|
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
static void uninstall_input_item_observer( libvlc_media_t *p_md )
|
2007-08-15 20:27:49 +02:00
|
|
|
{
|
2007-08-16 20:05:07 +02:00
|
|
|
vlc_event_detach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemSubItemAdded,
|
|
|
|
input_item_subitem_added,
|
|
|
|
p_md );
|
2007-08-15 20:27:49 +02:00
|
|
|
vlc_event_detach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemMetaChanged,
|
|
|
|
input_item_meta_changed,
|
|
|
|
p_md );
|
2007-10-20 19:56:00 +02:00
|
|
|
vlc_event_detach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemDurationChanged,
|
|
|
|
input_item_duration_changed,
|
|
|
|
p_md );
|
|
|
|
vlc_event_detach( &p_md->p_input_item->event_manager,
|
|
|
|
vlc_InputItemPreparsedChanged,
|
|
|
|
input_item_preparsed_changed,
|
|
|
|
p_md );
|
2007-08-15 20:27:49 +02:00
|
|
|
}
|
2007-06-17 18:24:49 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2007-06-17 19:51:40 +02:00
|
|
|
* Preparse if not already done (Private)
|
2007-06-17 18:24:49 +02:00
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
static void preparse_if_needed( libvlc_media_t *p_md )
|
2007-06-17 18:24:49 +02:00
|
|
|
{
|
|
|
|
/* XXX: need some locking here */
|
2007-07-09 22:52:11 +02:00
|
|
|
if (!p_md->b_preparsed)
|
2007-06-17 18:24:49 +02:00
|
|
|
{
|
2007-08-22 18:47:40 +02:00
|
|
|
playlist_PreparseEnqueue(
|
2008-05-07 21:26:56 +02:00
|
|
|
libvlc_priv (p_md->p_libvlc_instance->p_libvlc_int)->p_playlist,
|
2008-12-23 16:26:51 +01:00
|
|
|
p_md->p_input_item, pl_Unlocked );
|
2008-04-14 00:08:29 +02:00
|
|
|
p_md->b_preparsed = true;
|
2007-06-17 18:24:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2007-08-15 20:27:49 +02:00
|
|
|
* Create a new media descriptor object from an input_item
|
|
|
|
* (libvlc internal)
|
|
|
|
* That's the generic constructor
|
2007-06-17 18:24:49 +02:00
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * libvlc_media_new_from_input_item(
|
2007-06-17 18:24:49 +02:00
|
|
|
libvlc_instance_t *p_instance,
|
2007-08-15 20:27:49 +02:00
|
|
|
input_item_t *p_input_item,
|
2007-06-17 18:24:49 +02:00
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md;
|
2007-06-17 18:24:49 +02:00
|
|
|
|
|
|
|
if (!p_input_item)
|
2007-06-24 13:19:48 +02:00
|
|
|
{
|
2007-08-15 20:27:49 +02:00
|
|
|
libvlc_exception_raise( p_e, "No input item given" );
|
2007-06-24 13:19:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-06-17 18:24:49 +02:00
|
|
|
|
2008-03-30 03:59:32 +02:00
|
|
|
p_md = malloc( sizeof(libvlc_media_t) );
|
2008-05-18 13:09:26 +02:00
|
|
|
if( !p_md )
|
|
|
|
{
|
|
|
|
libvlc_exception_raise( p_e, "Not enough memory" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-09 22:52:11 +02:00
|
|
|
p_md->p_libvlc_instance = p_instance;
|
|
|
|
p_md->p_input_item = p_input_item;
|
2008-04-14 00:08:29 +02:00
|
|
|
p_md->b_preparsed = false;
|
2007-08-08 23:12:02 +02:00
|
|
|
p_md->i_refcount = 1;
|
2007-12-24 19:45:10 +01:00
|
|
|
p_md->p_user_data = NULL;
|
|
|
|
|
|
|
|
p_md->state = libvlc_NothingSpecial;
|
2007-08-16 20:05:07 +02:00
|
|
|
|
2007-08-21 21:43:04 +02:00
|
|
|
/* A media descriptor can be a playlist. When you open a playlist
|
|
|
|
* It can give a bunch of item to read. */
|
|
|
|
p_md->p_subitems = NULL;
|
|
|
|
|
2007-08-20 00:46:15 +02:00
|
|
|
p_md->p_event_manager = libvlc_event_manager_new( p_md, p_instance, p_e );
|
2007-09-10 20:56:52 +02:00
|
|
|
libvlc_event_manager_register_event_type( p_md->p_event_manager,
|
2008-03-31 06:35:08 +02:00
|
|
|
libvlc_MediaMetaChanged, p_e );
|
2007-09-10 20:56:52 +02:00
|
|
|
libvlc_event_manager_register_event_type( p_md->p_event_manager,
|
2008-03-31 06:35:08 +02:00
|
|
|
libvlc_MediaSubItemAdded, p_e );
|
2007-10-25 14:30:03 +02:00
|
|
|
libvlc_event_manager_register_event_type( p_md->p_event_manager,
|
2008-03-31 06:35:08 +02:00
|
|
|
libvlc_MediaFreed, p_e );
|
2007-10-20 19:56:00 +02:00
|
|
|
libvlc_event_manager_register_event_type( p_md->p_event_manager,
|
2008-03-31 06:35:08 +02:00
|
|
|
libvlc_MediaDurationChanged, p_e );
|
2007-12-24 19:45:10 +01:00
|
|
|
libvlc_event_manager_register_event_type( p_md->p_event_manager,
|
2008-03-31 06:35:08 +02:00
|
|
|
libvlc_MediaStateChanged, p_e );
|
2007-08-16 20:05:07 +02:00
|
|
|
|
2007-07-09 22:52:11 +02:00
|
|
|
vlc_gc_incref( p_md->p_input_item );
|
2007-06-17 18:24:49 +02:00
|
|
|
|
2007-08-15 20:27:49 +02:00
|
|
|
install_input_item_observer( p_md );
|
|
|
|
|
2007-07-09 22:52:11 +02:00
|
|
|
return p_md;
|
2007-06-17 18:24:49 +02:00
|
|
|
}
|
|
|
|
|
2007-06-17 22:54:32 +02:00
|
|
|
/**************************************************************************
|
2007-08-15 20:27:49 +02:00
|
|
|
* Create a new media descriptor object
|
2007-06-17 22:54:32 +02:00
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * libvlc_media_new(
|
2007-06-17 22:54:32 +02:00
|
|
|
libvlc_instance_t *p_instance,
|
2007-08-15 20:27:49 +02:00
|
|
|
const char * psz_mrl,
|
2007-06-24 13:31:57 +02:00
|
|
|
libvlc_exception_t *p_e )
|
2007-06-17 22:54:32 +02:00
|
|
|
{
|
2007-08-15 20:27:49 +02:00
|
|
|
input_item_t * p_input_item;
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md;
|
2007-06-17 22:54:32 +02:00
|
|
|
|
2008-08-15 00:09:58 +02:00
|
|
|
p_input_item = input_item_New( p_instance->p_libvlc_int, psz_mrl, NULL );
|
2007-08-15 20:27:49 +02:00
|
|
|
|
2007-06-17 22:54:32 +02:00
|
|
|
if (!p_input_item)
|
2007-06-24 13:19:48 +02:00
|
|
|
{
|
2007-08-15 20:27:49 +02:00
|
|
|
libvlc_exception_raise( p_e, "Can't create md's input_item" );
|
2007-06-24 13:19:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-06-17 22:54:32 +02:00
|
|
|
|
2008-03-30 03:59:32 +02:00
|
|
|
p_md = libvlc_media_new_from_input_item( p_instance,
|
2007-08-15 20:27:49 +02:00
|
|
|
p_input_item, p_e );
|
2007-06-17 22:54:32 +02:00
|
|
|
|
2008-03-30 03:59:32 +02:00
|
|
|
/* The p_input_item is retained in libvlc_media_new_from_input_item */
|
2007-12-23 15:45:09 +01:00
|
|
|
vlc_gc_decref( p_input_item );
|
2008-05-18 13:09:26 +02:00
|
|
|
|
2007-07-09 22:52:11 +02:00
|
|
|
return p_md;
|
2007-06-17 22:54:32 +02:00
|
|
|
}
|
|
|
|
|
2007-12-20 00:10:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* Create a new media descriptor object
|
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * libvlc_media_new_as_node(
|
2007-12-20 00:10:31 +01:00
|
|
|
libvlc_instance_t *p_instance,
|
|
|
|
const char * psz_name,
|
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
|
|
|
input_item_t * p_input_item;
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t * p_md;
|
2007-12-20 00:10:31 +01:00
|
|
|
|
2008-08-15 00:09:58 +02:00
|
|
|
p_input_item = input_item_New( p_instance->p_libvlc_int, "vlc://nop", psz_name );
|
2007-12-20 00:10:31 +01:00
|
|
|
|
|
|
|
if (!p_input_item)
|
|
|
|
{
|
|
|
|
libvlc_exception_raise( p_e, "Can't create md's input_item" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-03-30 03:59:32 +02:00
|
|
|
p_md = libvlc_media_new_from_input_item( p_instance,
|
2007-12-20 00:10:31 +01:00
|
|
|
p_input_item, p_e );
|
|
|
|
|
|
|
|
p_md->p_subitems = libvlc_media_list_new( p_md->p_libvlc_instance, NULL );
|
|
|
|
|
|
|
|
return p_md;
|
|
|
|
}
|
|
|
|
|
2007-12-14 15:33:06 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* Add an option to the media descriptor,
|
2008-03-30 03:59:32 +02:00
|
|
|
* that will be used to determine how the media_player will read the
|
|
|
|
* media. This allow to use VLC advanced reading/streaming
|
2007-12-14 15:33:06 +01:00
|
|
|
* options in a per-media basis
|
|
|
|
*
|
|
|
|
* The options are detailled in vlc --long-help, for instance "--sout-all"
|
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
void libvlc_media_add_option(
|
|
|
|
libvlc_media_t * p_md,
|
2007-12-14 15:33:06 +01:00
|
|
|
const char * ppsz_option,
|
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
2008-05-18 13:09:26 +02:00
|
|
|
VLC_UNUSED(p_e);
|
2009-01-17 17:37:23 +01:00
|
|
|
input_item_AddOption( p_md->p_input_item, ppsz_option,
|
|
|
|
VLC_INPUT_OPTION_UNIQUE|VLC_INPUT_OPTION_TRUSTED );
|
2007-12-14 15:33:06 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 20:20:21 +01:00
|
|
|
/**************************************************************************
|
2009-06-19 00:05:50 +02:00
|
|
|
* Same as libvlc_media_add_option but with configurable flags.
|
2009-01-28 20:20:21 +01:00
|
|
|
**************************************************************************/
|
2009-06-19 00:05:50 +02:00
|
|
|
void libvlc_media_add_option_flag(
|
2009-01-28 20:20:21 +01:00
|
|
|
libvlc_media_t * p_md,
|
|
|
|
const char * ppsz_option,
|
2009-06-19 00:05:50 +02:00
|
|
|
libvlc_media_option_t i_flags,
|
2009-01-28 20:20:21 +01:00
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
input_item_AddOption( p_md->p_input_item, ppsz_option,
|
2009-06-19 00:05:50 +02:00
|
|
|
i_flags );
|
2009-01-28 20:20:21 +01:00
|
|
|
}
|
|
|
|
|
2007-06-17 18:24:49 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* Delete a media descriptor object
|
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
void libvlc_media_release( libvlc_media_t *p_md )
|
2007-06-17 18:24:49 +02:00
|
|
|
{
|
2007-06-17 22:54:32 +02:00
|
|
|
if (!p_md)
|
2007-06-17 18:24:49 +02:00
|
|
|
return;
|
|
|
|
|
2007-08-08 23:12:02 +02:00
|
|
|
p_md->i_refcount--;
|
|
|
|
|
|
|
|
if( p_md->i_refcount > 0 )
|
|
|
|
return;
|
2007-08-15 20:27:49 +02:00
|
|
|
|
2007-08-24 23:54:27 +02:00
|
|
|
if( p_md->p_subitems )
|
|
|
|
libvlc_media_list_release( p_md->p_subitems );
|
2007-08-21 21:43:04 +02:00
|
|
|
|
2007-08-15 20:27:49 +02:00
|
|
|
uninstall_input_item_observer( p_md );
|
|
|
|
vlc_gc_decref( p_md->p_input_item );
|
|
|
|
|
2007-10-25 14:30:03 +02:00
|
|
|
/* Construct the event */
|
|
|
|
libvlc_event_t event;
|
2008-03-31 06:35:08 +02:00
|
|
|
event.type = libvlc_MediaFreed;
|
2008-03-30 03:59:32 +02:00
|
|
|
event.u.media_freed.md = p_md;
|
2007-10-25 14:30:03 +02:00
|
|
|
|
|
|
|
/* Send the event */
|
|
|
|
libvlc_event_send( p_md->p_event_manager, &event );
|
|
|
|
|
2007-11-20 13:07:38 +01:00
|
|
|
libvlc_event_manager_release( p_md->p_event_manager );
|
|
|
|
|
2007-06-17 22:54:32 +02:00
|
|
|
free( p_md );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2007-08-08 23:12:02 +02:00
|
|
|
* Retain a media descriptor object
|
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
void libvlc_media_retain( libvlc_media_t *p_md )
|
2007-08-08 23:12:02 +02:00
|
|
|
{
|
|
|
|
if (!p_md)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p_md->i_refcount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Duplicate a media descriptor object
|
2007-06-17 22:54:32 +02:00
|
|
|
**************************************************************************/
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_t *
|
|
|
|
libvlc_media_duplicate( libvlc_media_t *p_md_orig )
|
2007-06-17 22:54:32 +02:00
|
|
|
{
|
2008-03-30 03:59:32 +02:00
|
|
|
return libvlc_media_new_from_input_item(
|
2007-08-15 20:27:49 +02:00
|
|
|
p_md_orig->p_libvlc_instance, p_md_orig->p_input_item, NULL );
|
2007-06-17 18:24:49 +02:00
|
|
|
}
|
|
|
|
|
2007-08-09 18:08:14 +02:00
|
|
|
/**************************************************************************
|
2008-08-08 08:29:16 +02:00
|
|
|
* Get mrl from a media descriptor object
|
2007-08-09 18:08:14 +02:00
|
|
|
**************************************************************************/
|
|
|
|
char *
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_get_mrl( libvlc_media_t * p_md,
|
2007-08-09 18:08:14 +02:00
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-05-18 13:09:26 +02:00
|
|
|
VLC_UNUSED(p_e);
|
2007-08-22 22:19:23 +02:00
|
|
|
return input_item_GetURI( p_md->p_input_item );
|
2007-08-09 18:08:14 +02:00
|
|
|
}
|
|
|
|
|
2007-06-17 18:24:49 +02:00
|
|
|
/**************************************************************************
|
2007-06-17 22:54:32 +02:00
|
|
|
* Getter for meta information
|
2007-06-17 18:24:49 +02:00
|
|
|
**************************************************************************/
|
|
|
|
|
2008-03-30 03:59:32 +02:00
|
|
|
char * libvlc_media_get_meta( libvlc_media_t *p_md,
|
2007-06-17 18:24:49 +02:00
|
|
|
libvlc_meta_t e_meta,
|
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
2007-08-18 05:22:03 +02:00
|
|
|
char * psz_meta;
|
2008-05-18 13:09:26 +02:00
|
|
|
VLC_UNUSED(p_e);
|
2007-06-17 18:24:49 +02:00
|
|
|
|
|
|
|
/* XXX: locking */
|
|
|
|
|
2007-07-09 22:52:11 +02:00
|
|
|
preparse_if_needed( p_md );
|
2007-06-17 18:24:49 +02:00
|
|
|
|
2007-08-15 20:27:49 +02:00
|
|
|
psz_meta = input_item_GetMeta( p_md->p_input_item,
|
|
|
|
libvlc_to_vlc_meta[e_meta] );
|
2008-05-18 13:09:26 +02:00
|
|
|
|
2008-02-10 15:25:37 +01:00
|
|
|
if( e_meta == libvlc_meta_ArtworkURL && !psz_meta )
|
|
|
|
{
|
|
|
|
playlist_AskForArtEnqueue(
|
2008-05-07 21:26:56 +02:00
|
|
|
libvlc_priv(p_md->p_libvlc_instance->p_libvlc_int)->p_playlist,
|
2008-12-23 16:26:51 +01:00
|
|
|
p_md->p_input_item, pl_Unlocked );
|
2008-02-10 15:25:37 +01:00
|
|
|
}
|
2007-06-17 18:24:49 +02:00
|
|
|
|
2007-08-15 19:53:27 +02:00
|
|
|
/* Should be integrated in core */
|
|
|
|
if( !psz_meta && e_meta == libvlc_meta_Title && p_md->p_input_item->psz_name )
|
2007-08-18 05:22:03 +02:00
|
|
|
{
|
|
|
|
free( psz_meta );
|
2007-08-15 19:53:27 +02:00
|
|
|
return strdup( p_md->p_input_item->psz_name );
|
2007-08-18 05:22:03 +02:00
|
|
|
}
|
2007-08-15 19:53:27 +02:00
|
|
|
|
2007-08-18 05:22:03 +02:00
|
|
|
return psz_meta;
|
2007-06-17 18:24:49 +02:00
|
|
|
}
|
2007-07-09 22:52:11 +02:00
|
|
|
|
2007-12-24 19:45:10 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* Getter for state information
|
|
|
|
* Can be error, playing, buffering, NothingSpecial.
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
libvlc_state_t
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_get_state( libvlc_media_t *p_md,
|
2007-12-24 19:45:10 +01:00
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
2008-05-18 13:09:26 +02:00
|
|
|
VLC_UNUSED(p_e);
|
2007-12-24 19:45:10 +01:00
|
|
|
return p_md->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Setter for state information (LibVLC Internal)
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
void
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_set_state( libvlc_media_t *p_md,
|
2007-12-24 19:45:10 +01:00
|
|
|
libvlc_state_t state,
|
|
|
|
libvlc_exception_t *p_e )
|
|
|
|
{
|
|
|
|
libvlc_event_t event;
|
2008-05-18 13:09:26 +02:00
|
|
|
VLC_UNUSED(p_e);
|
2007-12-24 19:45:10 +01:00
|
|
|
|
|
|
|
p_md->state = state;
|
|
|
|
|
|
|
|
/* Construct the event */
|
2008-03-31 06:35:08 +02:00
|
|
|
event.type = libvlc_MediaStateChanged;
|
2008-03-30 03:59:32 +02:00
|
|
|
event.u.media_state_changed.new_state = state;
|
2007-12-24 19:45:10 +01:00
|
|
|
|
|
|
|
/* Send the event */
|
|
|
|
libvlc_event_send( p_md->p_event_manager, &event );
|
|
|
|
}
|
|
|
|
|
2007-08-24 23:54:27 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* subitems
|
|
|
|
**************************************************************************/
|
|
|
|
libvlc_media_list_t *
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_subitems( libvlc_media_t * p_md,
|
2007-08-24 23:54:27 +02:00
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-01-28 17:23:17 +01:00
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
|
2007-08-25 03:26:35 +02:00
|
|
|
if( p_md->p_subitems )
|
|
|
|
libvlc_media_list_retain( p_md->p_subitems );
|
2007-08-24 23:54:27 +02:00
|
|
|
return p_md->p_subitems;
|
|
|
|
}
|
2007-08-25 18:28:13 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* event_manager
|
|
|
|
**************************************************************************/
|
|
|
|
libvlc_event_manager_t *
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_event_manager( libvlc_media_t * p_md,
|
2007-08-25 18:28:13 +02:00
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-01-28 17:23:17 +01:00
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
|
2007-08-25 18:28:13 +02:00
|
|
|
return p_md->p_event_manager;
|
|
|
|
}
|
2007-10-20 19:56:00 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2008-03-30 03:59:32 +02:00
|
|
|
* Get duration of media object.
|
2007-10-20 19:56:00 +02:00
|
|
|
**************************************************************************/
|
2008-05-31 21:06:17 +02:00
|
|
|
int64_t
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_get_duration( libvlc_media_t * p_md,
|
2007-10-20 19:56:00 +02:00
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-01-28 17:23:17 +01:00
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
|
2008-08-03 19:40:30 +02:00
|
|
|
if( !p_md || !p_md->p_input_item)
|
2007-10-20 19:56:00 +02:00
|
|
|
{
|
2008-08-03 19:40:30 +02:00
|
|
|
libvlc_exception_raise( p_e, "No input item" );
|
2007-10-20 19:56:00 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-03 19:40:30 +02:00
|
|
|
|
|
|
|
return input_item_GetDuration( p_md->p_input_item );
|
2007-10-20 19:56:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2008-03-30 03:59:32 +02:00
|
|
|
* Get preparsed status for media object.
|
2007-10-20 19:56:00 +02:00
|
|
|
**************************************************************************/
|
2008-03-17 20:20:33 +01:00
|
|
|
int
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_is_preparsed( libvlc_media_t * p_md,
|
2007-10-20 19:56:00 +02:00
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-01-28 17:23:17 +01:00
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
|
2008-08-03 19:40:30 +02:00
|
|
|
if( !p_md || !p_md->p_input_item)
|
2007-10-20 19:56:00 +02:00
|
|
|
{
|
2008-08-03 19:40:30 +02:00
|
|
|
libvlc_exception_raise( p_e, "No input item" );
|
2008-04-14 00:08:29 +02:00
|
|
|
return false;
|
2007-10-20 19:56:00 +02:00
|
|
|
}
|
2008-08-03 19:40:30 +02:00
|
|
|
|
|
|
|
return input_item_IsPreparsed( p_md->p_input_item );
|
2007-10-20 19:56:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Sets media descriptor's user_data. user_data is specialized data
|
|
|
|
* accessed by the host application, VLC.framework uses it as a pointer to
|
2008-03-30 03:59:32 +02:00
|
|
|
* an native object that references a libvlc_media_t pointer
|
2007-10-20 19:56:00 +02:00
|
|
|
**************************************************************************/
|
|
|
|
void
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_set_user_data( libvlc_media_t * p_md,
|
2007-10-20 19:56:00 +02:00
|
|
|
void * p_new_user_data,
|
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-01-28 17:23:17 +01:00
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
|
2007-10-20 19:56:00 +02:00
|
|
|
if( p_md )
|
|
|
|
{
|
|
|
|
p_md->p_user_data = p_new_user_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Get media descriptor's user_data. user_data is specialized data
|
|
|
|
* accessed by the host application, VLC.framework uses it as a pointer to
|
2008-03-30 03:59:32 +02:00
|
|
|
* an native object that references a libvlc_media_t pointer
|
2007-10-20 19:56:00 +02:00
|
|
|
**************************************************************************/
|
|
|
|
void *
|
2008-03-30 03:59:32 +02:00
|
|
|
libvlc_media_get_user_data( libvlc_media_t * p_md,
|
2007-10-20 19:56:00 +02:00
|
|
|
libvlc_exception_t * p_e )
|
|
|
|
{
|
2008-01-28 17:23:17 +01:00
|
|
|
VLC_UNUSED(p_e);
|
|
|
|
|
2007-10-20 19:56:00 +02:00
|
|
|
if( p_md )
|
|
|
|
{
|
|
|
|
return p_md->p_user_data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-10-22 18:57:33 +02:00
|
|
|
}
|