]> git.sesse.net Git - vlc/blobdiff - bindings/cil/src/libvlc.cs
Start rewriting the CIL bindings
[vlc] / bindings / cil / src / libvlc.cs
index b251c4131fb06248c9ee3d907318696fb78c16f8..4625472ecb5a6920fd6fc7965efb920bb27dfc7a 100644 (file)
@@ -1,12 +1,19 @@
 /**
  * @file libvlc.cs
- * @brief libvlc CIL bindings
+ * @brief Bindings to LibVLC for the .NET Common Intermediate Language
+ * @ingroup API
  *
- * $Id$
+ * @defgroup API Managed interface to LibVLC
+ * This is the primary class library for .NET applications
+ * to embed and control LibVLC.
+ *
+ * @defgroup Internals LibVLC internals
+ * This covers internal marshalling functions to use the native LibVLC.
+ * Only VLC developpers should need to read this section.
  */
 
 /**********************************************************************
- *  Copyright (C) 2007 Rémi Denis-Courmont.                           *
+ *  Copyright (C) 2007-2009 Rémi Denis-Courmont.                      *
  *  This program is free software; you can redistribute and/or modify *
  *  it under the terms of the GNU General Public License as published *
  *  by the Free Software Foundation; version 2 of the license, or (at *
  **********************************************************************/
 
 using System;
-using System.Collections.Generic;
 using System.Runtime.InteropServices;
 
 namespace VideoLAN.LibVLC
 {
     /**
-     * The VLC class is used to create LibVLC Instance objects.
-     * The VLC class has only one static method and cannot be instanciated.
-     *
-     * @code
-     * string[] argv = new string[]{ "-vvv", "-I", "dummy" };
-     *
-     * Instance vlc = VLC.CreateInstance (argv);
-     * @endcode
+     * @brief InstanceHandle: unmanaged LibVLC instance pointer
+     * @ingroup Internals
      */
-    public sealed class VLC
+    internal sealed class InstanceHandle : NonNullHandle
     {
-        /**
-         * Loads native LibVLC and creates a LibVLC instance.
-         *
-         * @param args VLC command line parameters for the LibVLC Instance.
-         *
-         * @return a new LibVLC Instance
-         */
-        public static Instance CreateInstance (string[] args)
-        {
-            U8String[] argv = new U8String[args.Length];
-            for (int i = 0; i < args.Length; i++)
-                argv[i] = new U8String (args[i]);
-
-            NativeException ex = new NativeException ();
-
-            InstanceHandle h = InstanceHandle.Create (argv.Length, argv, ex);
-            ex.Raise ();
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_get_version")]
+        public static extern IntPtr GetVersion ();
 
-            return new Instance (h);
-        }
-    };
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_get_compiler")]
+        public static extern IntPtr GetCompiler ();
 
-    /**
-     * Safe handle for unmanaged LibVLC instance pointer.
-     */
-    public sealed class InstanceHandle : NonNullHandle
-    {
-        private InstanceHandle ()
-        {
-        }
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_get_changeset")]
+        public static extern IntPtr GetChangeSet ();
 
         [DllImport ("libvlc.dll", EntryPoint="libvlc_new")]
-        internal static extern
-        InstanceHandle Create (int argc, U8String[] argv, NativeException ex);
+        public static extern
+        InstanceHandle Create (int argc, U8String[] argv,
+                               NativeException ex);
+
+        /*[DllImport ("libvlc.dll", EntryPoint="libvlc_retain")]
+        public static extern void Hold (InstanceHandle h,
+                                         NativeException ex);*/
 
         [DllImport ("libvlc.dll", EntryPoint="libvlc_release")]
-        static extern void Destroy (IntPtr ptr, NativeException ex);
+        private static extern void Release (IntPtr h,
+                                            NativeException ex);
 
-        /**
-         * System.Runtime.InteropServices.SafeHandle::ReleaseHandle.
-         */
-        protected override bool ReleaseHandle ()
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_add_intf")]
+        public static extern void AddInterface (InstanceHandle h,
+                                                  U8String name,
+                                                  NativeException ex);
+
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_wait")]
+        public static extern void Run (InstanceHandle h);
+
+        [DllImport ("libvlc.dll", EntryPoint="libvlc_get_vlc_instance")]
+        public static extern NonNullHandle GetVLC (InstanceHandle h);
+
+        protected override void Destroy ()
         {
-            Destroy (handle, null);
-            return true;
+            Release (handle, null);
         }
     };
 
     /**
-     * LibVLC Instance provides basic media player features from VLC,
-     * such as play/pause/stop and flat playlist management.
+     * @brief VLC: VLC media player instance
+     * @ingroup API
+     *
+     * The VLC class provides represent a run-time instance of a media player.
+     * An instance can spawn multiple independent medias, however
+     * configuration settings, message logging, etc are common to all medias
+     * from the same instance.
      */
-    public class Instance : BaseObject<InstanceHandle>
+    public class VLC : BaseObject
     {
-        Dictionary<int, PlaylistItem> items;
-
-        internal Instance (InstanceHandle self) : base (self)
-        {
-            items = new Dictionary<int, PlaylistItem> ();
-        }
-
-        /**
-         * Creates a MediaDescriptor.
-         * @param mrl Media Resource Locator (file path or URL)
-         * @return create MediaDescriptor object.
-         */
-        public MediaDescriptor CreateDescriptor (string mrl)
-        {
-            U8String umrl = new U8String (mrl);
-            DescriptorHandle dh = DescriptorHandle.Create (self, umrl, ex);
-            ex.Raise ();
-
-            return new MediaDescriptor (dh);
-        }
-
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_loop")]
-        static extern void PlaylistLoop (InstanceHandle self, bool b,
-                                         NativeException ex);
-        /** Sets the playlist loop flag. */
-        public bool Loop
-        {
-            set
-            {
-                PlaylistLoop (self, value, ex);
-                ex.Raise ();
-            }
-        }
-
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_play")]
-        static extern void PlaylistPlay (InstanceHandle self, int id, int optc,
-                                         U8String[] optv, NativeException ex);
-        /** Plays the next playlist item (if not already playing). */
-        public void Play ()
-        {
-            PlaylistPlay (self, -1, 0, new U8String[0], ex);
-            ex.Raise ();
-        }
-
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_pause")]
-        static extern void PlaylistPause (InstanceHandle self,
-                                          NativeException ex);
-        /** Toggles pause (starts playing if stopped, pauses if playing). */
-        public void TogglePause ()
-        {
-            PlaylistPause (self, ex);
-            ex.Raise ();
-        }
-
-        [DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_playlist_isplaying")]
-        static extern int PlaylistIsPlaying (InstanceHandle self,
-                                             NativeException ex);
-        /** Whether the playlist is running, or paused/stopped. */
-        public bool IsPlaying
+        internal InstanceHandle Handle
         {
             get
             {
-                int ret = PlaylistIsPlaying (self, ex);
-                ex.Raise ();
-                return ret != 0;
+                return handle as InstanceHandle;
             }
         }
 
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_stop")]
-        static extern void PlaylistStop (InstanceHandle self,
-                                         NativeException ex);
-        /** Stops playing. */
-        public void Stop ()
-        {
-            PlaylistStop (self, ex);
-            ex.Raise ();
-        }
-
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_next")]
-        static extern void PlaylistNext (InstanceHandle self,
-                                         NativeException ex);
-        /** Switches to next playlist item, and starts playing it. */
-        public void Next ()
-        {
-            PlaylistNext (self, ex);
-            ex.Raise ();
-        }
-
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_prev")]
-        static extern void PlaylistPrev (InstanceHandle self,
-                                         NativeException ex);
-        /** Switches to previous playlist item, and starts playing it. */
-        public void Prev ()
-        {
-            PlaylistPrev (self, ex);
-            ex.Raise ();
-        }
-
-        [DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_clear")]
-        static extern void PlaylistClear (InstanceHandle self,
-                                          NativeException ex);
-        /** Clears the whole playlist. */
-        public void Clear ()
+        /**
+         * Loads the native LibVLC and creates a LibVLC instance.
+         *
+         * @param args VLC command line parameters for the LibVLC Instance.
+         */
+        public VLC (string[] args)
         {
-            PlaylistClear (self, ex);
-            ex.Raise ();
+            U8String[] argv = new U8String[args.Length];
+            for (int i = 0; i < args.Length; i++)
+                argv[i] = new U8String (args[i]);
 
-            foreach (PlaylistItem item in items.Values)
-                item.Close ();
-            items.Clear ();
+            handle = InstanceHandle.Create (argv.Length, argv, ex);
+            Raise ();
         }
 
-        [DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_playlist_add_extended")]
-        static extern int PlaylistAdd (InstanceHandle self, U8String uri,
-                                       U8String name, int optc,
-                                       U8String[] optv, NativeException e);
         /**
-         * Appends an item to the playlist, with options.
-         * @param mrl Media Resource Locator (file name or URL)
-         * @param name playlist item user-visible name
-         * @param opts item options (see LibVLC documentation for details)
-         * @return created playlist item.
+         * Starts a VLC interface plugin.
+         *
+         * @param name name of the interface plugin (e.g. "http", "qt4", ...)
          */
-        public PlaylistItem Add (string mrl, string name, string[] opts)
+        public void AddInterface (string name)
         {
-            U8String umrl = new U8String (mrl);
             U8String uname = new U8String (name);
-            U8String[] optv = new U8String[opts.Length];
-            for (int i = 0; i < opts.Length; i++)
-                optv[i] = new U8String (opts[i]);
 
-            int id = PlaylistAdd (self, umrl, uname, optv.Length, optv, ex);
-            ex.Raise ();
-
-            PlaylistItem item = new PlaylistItem (id);
-            items.Add (id, item);
-            return item;
+            InstanceHandle.AddInterface (Handle, uname, ex);
+            Raise ();
         }
+
         /**
-         * Appends an item with options.
-         * @param mrl Media Resource Locator (file name or URL)
-         * @param opts item options (see LibVLC documentation for details)
-         * @return created playlist item.
+         * Waits until VLC instance exits. This can happen if a fatal error
+         * occurs (e.g. cannot parse the arguments), if the user has quit
+         * through an interface, or if the special vlc://quit item was played.
          */
-        public PlaylistItem Add (string mrl, string[] opts)
+        public void Run ()
         {
-            return Add (mrl, null, opts);
+            InstanceHandle.Run (Handle);
         }
+
         /**
-         * Appends an item to the playlist.
-         * @param mrl Media Resource Locator (file name or URL)
-         * @param name playlist item user-visible name
-         * @return created playlist item.
+         * The human-readable LibVLC version number.
          */
-        public PlaylistItem Add (string mrl, string name)
+        public static string Version
         {
-            return Add (mrl, name, new string[0]);
+            get
+            {
+                return U8String.FromNative (InstanceHandle.GetVersion ());
+            }
         }
+
         /**
-         * Appends an item to the playlist.
-         * @param mrl Media Resource Locator (file name or URL)
-         * @return created playlist item.
+         * The human-readable LibVLC C compiler infos.
          */
-        public PlaylistItem Add (string mrl)
+        public static string Compiler
         {
-            return Add (mrl, null, new string[0]);
+            get
+            {
+                return U8String.FromNative (InstanceHandle.GetCompiler ());
+            }
         }
 
-        [DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_playlist_delete_item")]
-        static extern int PlaylistDelete (InstanceHandle self, int id,
-                                          NativeException e);
         /**
-         * Removes an item from the playlist.
-         * @param item playlist item (as obtained from Add())
+         * The unique commit identifier from the LibVLC source control system,
+         * or "exported" if unknown.
          */
-        public void Delete (PlaylistItem item)
-        {
-            int id = item.Id;
-            PlaylistDelete (self, id, ex);
-            ex.Raise ();
-
-            item.Close ();
-            items.Remove (id);
-        }
-    };
-
-    /**
-     * A playlist item.
-     */
-    public class PlaylistItem
-    {
-        int id;
-        bool deleted;
-
-        internal PlaylistItem (int id)
-        {
-            this.id = id;
-            this.deleted = false;
-        }
-
-        internal void Close ()
-        {
-            deleted = true;
-        }
-
-        internal int Id
+        public static string ChangeSet
         {
             get
             {
-                if (deleted)
-                    throw new ObjectDisposedException ("Playlist item deleted");
-                return id;
+                return U8String.FromNative (InstanceHandle.GetChangeSet ());
             }
         }
-    };
-
-    /** Safe handle for unmanaged LibVLC media descriptor */
-    public sealed class DescriptorHandle : NonNullHandle
-    {
-        private DescriptorHandle ()
-        {
-        }
-
-        [DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_media_new")]
-        public static extern
-        DescriptorHandle Create (InstanceHandle inst, U8String mrl,
-                                 NativeException ex);
-
-        [DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_media_release")]
-        public static extern void Release (IntPtr ptr);
-
-        protected override bool ReleaseHandle ()
-        {
-            Release (handle);
-            return true;
-        }
-    };
 
-    /**
-     * Media descriptor. Not implemented yet.
-     */
-    public class MediaDescriptor : BaseObject<DescriptorHandle>
-    {
-        internal MediaDescriptor (DescriptorHandle self) : base (self)
+        /**
+         * The unmanaged VLC-internal instance object.
+         * Do not use this unless you really know what you are doing.
+         */
+        public SafeHandle Object
         {
+            get
+            {
+                return InstanceHandle.GetVLC (Handle);
+            }
         }
     };
 };