]> git.sesse.net Git - vlc/commitdiff
Libvlc: Implement media_instance_[get|set]_media_descriptor. Now, media_instance_new...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 24 Jun 2007 13:19:21 +0000 (13:19 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Sun, 24 Jun 2007 13:19:21 +0000 (13:19 +0000)
include/vlc/libvlc.h
src/control/media_instance.c

index 05de2b6c6b3b986c99e402100d451ca864954d8a..62cb2b1cf015132dc4b548a86266ab1b37e46cbc 100644 (file)
@@ -305,20 +305,45 @@ VLC_PUBLIC_API libvlc_media_instance_t * libvlc_playlist_get_media_instance(
  * @{
  */
 
+/** Create an empty Media Instance object
+ * \param p_libvlc_instance the libvlc instance in which the Media Instance
+ * should be (not used for now).
+ */
+VLC_PUBLIC_API libvlc_media_instance_t * libvlc_media_instance_new( libvlc_instance_t *, libvlc_exception_t * );
+
 /** Create a Media Instance object from a Media Descriptor
- * \param p_md the Media Descriptor from which the Media Instance should be
- * created. The p_md can then be destroyed if needed.
+ * \param p_md the media descriptor. Afterwards the p_md can safely be
+ * destroyed.
  */
-VLC_PUBLIC_API libvlc_media_instance_t * libvlc_media_instance_new( libvlc_media_descriptor_t * );
+VLC_PUBLIC_API libvlc_media_instance_t * libvlc_media_instance_new_from_media_descriptor( libvlc_media_descriptor_t *, libvlc_exception_t * );
 
-/** Destroy a Media Instance object
+/** Destroy a Media Instance object (going private)
  * \param p_mi the Media Instance to free
  */
 VLC_PUBLIC_API void libvlc_media_instance_destroy( libvlc_media_instance_t * );
 
-/* Will be renamed to libvlc_media_instance_release */
+/** Release a media_instance after use
+ * \param p_mi the Media Instance to free
+ */
 VLC_PUBLIC_API void libvlc_media_instance_release( libvlc_media_instance_t * );
 
+/** Set the media descriptor that will be used by the media_instance. If any,
+ * previous md will be released.
+ * \param p_mi the Media Instance 
+ * \param p_md the Media Descriptor. Afterwards the p_md can safely be
+ * destroyed.
+ */
+VLC_PUBLIC_API void libvlc_media_instance_set_media_descriptor( libvlc_media_instance_t *, libvlc_media_descriptor_t *, libvlc_exception_t * );
+
+/** Get the media descriptor used by the media_instance (if any). A copy of
+ * the md is returned. NULL is returned if no media instance is associated.
+ * \param p_mi the Media Instance 
+ * \param p_md the Media Descriptor. Afterwards the p_md can safely be
+ * destroyed.
+ */
+VLC_PUBLIC_API libvlc_media_descriptor_t * libvlc_media_instance_get_media_descriptor( libvlc_media_instance_t *, libvlc_exception_t * );
+
+
 VLC_PUBLIC_API void libvlc_media_instance_play ( libvlc_media_instance_t *, libvlc_exception_t * );
 VLC_PUBLIC_API void libvlc_media_instance_pause ( libvlc_media_instance_t *, libvlc_exception_t * );
 
index 71a1c5955a0d2b1ce9d8a9ddebe96a31ded471de..b6ad3861d321155d28ad3448de8050021b3cd592 100644 (file)
 #include <vlc_input.h>
 #include "input/input_internal.h"
 
+/*
+ * Release the associated input thread
+ */
+static void release_input_thread( libvlc_media_instance_t *p_mi ) 
+{
+    input_thread_t *p_input_thread;
+    vlc_bool_t should_destroy;
+    libvlc_exception_t p_e;
+
+    /* XXX: locking */
+    libvlc_exception_init( &p_e );
+
+    p_input_thread = libvlc_get_input_thread( p_mi, &p_e );
+
+    p_mi->i_input_id = -1;
+
+    if( libvlc_exception_raised( &p_e ) )
+        return;
+
+    /* release for previous libvlc_get_input_thread */
+    vlc_object_release( p_input_thread );
+
+    should_destroy = p_input_thread->i_refcount == 1;
+
+    /* release for initial p_input_thread yield (see _new()) */
+    vlc_object_release( p_input_thread );
+
+    /* No one is tracking this input_thread appart us. Destroy it */
+    if( should_destroy )
+        input_DestroyThread( p_input_thread );
+}
+
 /*
  * Retrieve the input thread. Be sure to release the object
  * once you are done with it. (libvlc Internal)
@@ -48,16 +80,45 @@ input_thread_t *libvlc_get_input_thread( libvlc_media_instance_t *p_mi,
     return p_input_thread;
 }
 
+
 /**************************************************************************
  * Create a Media Instance object
  **************************************************************************/
 libvlc_media_instance_t *
-libvlc_media_instance_new( libvlc_media_descriptor_t *p_md )
+libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance,
+                           libvlc_exception_t *p_e )
+{
+    libvlc_media_instance_t * p_mi;
+
+    if( !p_libvlc_instance )
+    {
+        libvlc_exception_raise( p_e, "invalid libvlc instance" );
+        return NULL;
+    }
+
+    p_mi = malloc( sizeof(libvlc_media_instance_t) );
+    p_mi->p_md = NULL;
+    p_mi->p_libvlc_instance = p_libvlc_instance;
+    p_mi->i_input_id = -1;
+
+    return p_mi;
+}
+
+/**************************************************************************
+ * Create a Media Instance object with a media descriptor
+ **************************************************************************/
+libvlc_media_instance_t *
+libvlc_media_instance_new_from_media_descriptor(
+                                    libvlc_media_descriptor_t * p_md,
+                                    libvlc_exception_t *p_e )
 {
     libvlc_media_instance_t * p_mi;
 
     if( !p_md )
+    {
+        libvlc_exception_raise( p_e, "invalid media descriptor" );
         return NULL;
+    }
 
     p_mi = malloc( sizeof(libvlc_media_instance_t) );
     p_mi->p_md = libvlc_media_descriptor_duplicate( p_md );
@@ -128,34 +189,65 @@ void libvlc_media_instance_destroy( libvlc_media_instance_t *p_mi )
  **************************************************************************/
 void libvlc_media_instance_release( libvlc_media_instance_t *p_mi )
 {
-    input_thread_t *p_input_thread;
-    libvlc_exception_t p_e;
-
     /* XXX: locking */
-    libvlc_exception_init( &p_e );
 
     if( !p_mi )
         return;
 
-    p_input_thread = libvlc_get_input_thread( p_mi, &p_e );
+    release_input_thread( p_mi );
 
-    if( !libvlc_exception_raised( &p_e ) )
-    {
-        /* release for previous libvlc_get_input_thread */
-        vlc_object_release( p_input_thread );
+    libvlc_media_descriptor_destroy( p_mi->p_md );
 
-        /* release for initial p_input_thread yield (see _new()) */
-        vlc_object_release( p_input_thread );
+    free( p_mi );
+}
 
-        /* No one is tracking this input_thread appart us. Destroy it */
-        if( p_input_thread->i_refcount <= 0 )
-            input_DestroyThread( p_input_thread );
-        /* btw, we still have an XXX locking here */
-    }
+/**************************************************************************
+ * Set the Media descriptor associated with the instance
+ **************************************************************************/
+void libvlc_media_instance_set_media_descriptor(
+                            libvlc_media_instance_t *p_mi,
+                            libvlc_media_descriptor_t *p_md,
+                            libvlc_exception_t *p_e )
+{
+    (void)p_e;
+
+    /* XXX : lock */
+
+    if( !p_mi )
+        return;
+
+    release_input_thread( p_mi );
 
     libvlc_media_descriptor_destroy( p_mi->p_md );
 
-    free( p_mi );
+    if( !p_md )
+    {
+        p_mi->p_md = NULL;
+        return; /* It is ok to pass a NULL md */
+    }
+
+    p_mi->p_md = libvlc_media_descriptor_duplicate( p_md );
+    
+    /* The policy here is to ignore that we were created using a different
+     * libvlc_instance, because we don't really care */
+    p_mi->p_libvlc_instance = p_md->p_libvlc_instance;
+
+}
+
+/**************************************************************************
+ * Set the Media descriptor associated with the instance
+ **************************************************************************/
+libvlc_media_descriptor_t *
+libvlc_media_instance_get_media_descriptor(
+                            libvlc_media_instance_t *p_mi,
+                            libvlc_exception_t *p_e )
+{
+    (void)p_e;
+
+    if( !p_mi->p_md )
+        return NULL;
+
+    return libvlc_media_descriptor_duplicate( p_mi->p_md );
 }
 
 /**************************************************************************
@@ -182,6 +274,12 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi,
         return;
     }
 
+    if( !p_mi->p_md )
+    {
+        libvlc_exception_raise( p_e, "no associated media descriptor" );
+        return;
+    }
+
     p_input_thread = input_CreateThread( p_mi->p_libvlc_instance->p_libvlc_int,
                                          p_mi->p_md->p_input_item );
     p_mi->i_input_id = p_input_thread->i_object_id;