From b93beb4cfd29d89c93072e13cec75f4bcf7f25ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Sat, 21 Feb 2009 15:40:00 +0200 Subject: [PATCH] Cleanup instance and media class --- bindings/cil/src/Makefile.am | 1 + bindings/cil/src/instance.cs | 148 ++++++++++++++++++++++++ bindings/cil/src/libvlc.cs | 211 ++++++++++++++--------------------- bindings/cil/src/media.cs | 29 +---- 4 files changed, 237 insertions(+), 152 deletions(-) create mode 100644 bindings/cil/src/instance.cs diff --git a/bindings/cil/src/Makefile.am b/bindings/cil/src/Makefile.am index 4ac2cb4a3e..280d6d34ba 100644 --- a/bindings/cil/src/Makefile.am +++ b/bindings/cil/src/Makefile.am @@ -7,6 +7,7 @@ SOURCES_dll = \ ustring.cs \ exception.cs \ marshal.cs \ + instance.cs \ media.cs \ player.cs \ libvlc.cs diff --git a/bindings/cil/src/instance.cs b/bindings/cil/src/instance.cs new file mode 100644 index 0000000000..1641613705 --- /dev/null +++ b/bindings/cil/src/instance.cs @@ -0,0 +1,148 @@ +/** + * @file instance.cs + * @brief Bindings to LibVLC for the .NET Common Intermediate Language + * @ingroup API + * + * @defgroup API Managed interface to LibVLC + * This is the primary class library for .NET applications + * to embed and control LibVLC. + */ + +/********************************************************************** + * 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 * + * 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, you can get it from: * + * http://www.gnu.org/copyleft/gpl.html * + **********************************************************************/ + +using System; +using System.Runtime.InteropServices; + +namespace VideoLAN.LibVLC +{ + /** + * @brief InstanceHandle: unmanaged LibVLC instance pointer + * @ingroup Internals + */ + internal sealed class InstanceHandle : NonNullHandle + { + protected override void Destroy () + { + LibVLC.Release (handle, null); + } + }; + + /** + * @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 VLC : BaseObject + { + internal InstanceHandle Handle + { + get + { + return handle as InstanceHandle; + } + } + + /** + * Loads the native LibVLC and creates a LibVLC instance. + * + * @param args VLC command line parameters for the LibVLC Instance. + */ + public VLC (string[] args) + { + U8String[] argv = new U8String[args.Length]; + for (int i = 0; i < args.Length; i++) + argv[i] = new U8String (args[i]); + + handle = LibVLC.Create (argv.Length, argv, ex); + Raise (); + } + + /** + * Starts a VLC interface plugin. + * + * @param name name of the interface plugin (e.g. "http", "qt4", ...) + */ + public void AddInterface (string name) + { + U8String uname = new U8String (name); + + LibVLC.AddIntf (Handle, uname, ex); + Raise (); + } + + /** + * 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 void Run () + { + LibVLC.Wait (Handle); + } + + /** + * The human-readable LibVLC version number. + */ + public static string Version + { + get + { + return U8String.FromNative (LibVLC.GetVersion ()); + } + } + + /** + * The human-readable LibVLC C compiler infos. + */ + public static string Compiler + { + get + { + return U8String.FromNative (LibVLC.GetCompiler ()); + } + } + + /** + * The unique commit identifier from the LibVLC source control system, + * or "exported" if unknown. + */ + public static string ChangeSet + { + get + { + return U8String.FromNative (LibVLC.GetChangeset ()); + } + } + + /** + * The unmanaged VLC-internal instance object. + * Do not use this unless you really know what you are doing. + */ + public SafeHandle Object + { + get + { + return LibVLC.GetVLCInstance (Handle); + } + } + }; +}; diff --git a/bindings/cil/src/libvlc.cs b/bindings/cil/src/libvlc.cs index 4625472ecb..6f66b583ee 100644 --- a/bindings/cil/src/libvlc.cs +++ b/bindings/cil/src/libvlc.cs @@ -1,11 +1,7 @@ /** * @file libvlc.cs - * @brief Bindings to LibVLC for the .NET Common Intermediate Language - * @ingroup API - * - * @defgroup API Managed interface to LibVLC - * This is the primary class library for .NET applications - * to embed and control LibVLC. + * @brief Unmanaged LibVLC APIs + * @ingroup Internals * * @defgroup Internals LibVLC internals * This covers internal marshalling functions to use the native LibVLC. @@ -35,11 +31,12 @@ using System.Runtime.InteropServices; namespace VideoLAN.LibVLC { /** - * @brief InstanceHandle: unmanaged LibVLC instance pointer + * @brief Native: unmanaged LibVLC APIs * @ingroup Internals */ - internal sealed class InstanceHandle : NonNullHandle + internal static class LibVLC { + /* core.c */ [DllImport ("libvlc.dll", EntryPoint="libvlc_get_version")] public static extern IntPtr GetVersion (); @@ -47,139 +44,99 @@ namespace VideoLAN.LibVLC public static extern IntPtr GetCompiler (); [DllImport ("libvlc.dll", EntryPoint="libvlc_get_changeset")] - public static extern IntPtr GetChangeSet (); + public static extern IntPtr GetChangeset (); [DllImport ("libvlc.dll", EntryPoint="libvlc_new")] public static extern - InstanceHandle Create (int argc, U8String[] argv, - NativeException ex); + InstanceHandle Create (int argc, U8String[] argv, NativeException ex); /*[DllImport ("libvlc.dll", EntryPoint="libvlc_retain")] - public static extern void Hold (InstanceHandle h, - NativeException ex);*/ + public static extern + void Retain (InstanceHandle h, NativeException ex);*/ [DllImport ("libvlc.dll", EntryPoint="libvlc_release")] - private static extern void Release (IntPtr h, - NativeException ex); + public static extern + void Release (IntPtr h, NativeException ex); [DllImport ("libvlc.dll", EntryPoint="libvlc_add_intf")] - public static extern void AddInterface (InstanceHandle h, - U8String name, - NativeException ex); + public static extern + void AddIntf (InstanceHandle h, U8String name, NativeException ex); [DllImport ("libvlc.dll", EntryPoint="libvlc_wait")] - public static extern void Run (InstanceHandle h); + public static extern + void Wait (InstanceHandle h); [DllImport ("libvlc.dll", EntryPoint="libvlc_get_vlc_instance")] - public static extern NonNullHandle GetVLC (InstanceHandle h); + public static extern + SafeHandle GetVLCInstance (InstanceHandle h); - protected override void Destroy () - { - Release (handle, null); - } - }; + /* media.c */ + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_new")] + public static extern + MediaHandle MediaCreate (InstanceHandle inst, U8String mrl, + NativeException ex); - /** - * @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 VLC : BaseObject - { - internal InstanceHandle Handle - { - get - { - return handle as InstanceHandle; - } - } - - /** - * Loads the native LibVLC and creates a LibVLC instance. - * - * @param args VLC command line parameters for the LibVLC Instance. - */ - public VLC (string[] args) - { - U8String[] argv = new U8String[args.Length]; - for (int i = 0; i < args.Length; i++) - argv[i] = new U8String (args[i]); - - handle = InstanceHandle.Create (argv.Length, argv, ex); - Raise (); - } - - /** - * Starts a VLC interface plugin. - * - * @param name name of the interface plugin (e.g. "http", "qt4", ...) - */ - public void AddInterface (string name) - { - U8String uname = new U8String (name); - - InstanceHandle.AddInterface (Handle, uname, ex); - Raise (); - } - - /** - * 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 void Run () - { - InstanceHandle.Run (Handle); - } - - /** - * The human-readable LibVLC version number. - */ - public static string Version - { - get - { - return U8String.FromNative (InstanceHandle.GetVersion ()); - } - } - - /** - * The human-readable LibVLC C compiler infos. - */ - public static string Compiler - { - get - { - return U8String.FromNative (InstanceHandle.GetCompiler ()); - } - } - - /** - * The unique commit identifier from the LibVLC source control system, - * or "exported" if unknown. - */ - public static string ChangeSet - { - get - { - return U8String.FromNative (InstanceHandle.GetChangeSet ()); - } - } - - /** - * 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); - } - } + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_new_as_node")] + public static extern + MediaHandle MediaCreateAsNode (InstanceHandle inst, U8String name, + NativeException ex); + + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_add_option")] + public static extern + void MediaAddOption (MediaHandle media, U8String options, + NativeException ex); + + [DllImport ("libvlc.dll", + EntryPoint="libvlc_media_add_option_untrusted")] + public static extern + void MediaAddUntrustedOption (MediaHandle media, U8String options, + NativeException ex); + + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_release")] + public static extern + void MediaRelease (IntPtr ptr); + + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_mrl")] + public static extern + void MediaGetMRL (MediaHandle media); + + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_duplicate")] + public static extern + MediaHandle MediaDuplicate (MediaHandle media); + + /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_read_meta")] + public static extern + MediaHandle MediaDuplicate (MediaHandle media, int type, + NativeException ex);*/ + + /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_state")] + public static extern + int MediaGetState (MediaHandle media, NativeException ex);*/ + + /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_subitems")] + public static extern + MediaListHandle MediaSubItems (MediaHandle media, NativeException ex);*/ + + /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_state")] + public static extern + EventManagerHandle MediaGetEventManager (MediaHandle media, + NativeException ex);*/ + + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_duration")] + public static extern + long MediaGetDuration (MediaHandle media, NativeException ex); + + [DllImport ("libvlc.dll", EntryPoint="libvlc_media_is_preparsed")] + public static extern + int MediaIsPreparsed (MediaHandle media, NativeException ex); + + /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_set_user_data")] + public static extern + void MediaIsPreparsed (MediaHandle media, IntPtr data, + NativeException ex);*/ + + /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_user_data")] + public static extern + IntPtr MediaIsPreparsed (MediaHandle media, NativeException ex);*/ }; }; diff --git a/bindings/cil/src/media.cs b/bindings/cil/src/media.cs index 51582baf50..f5415f561e 100644 --- a/bindings/cil/src/media.cs +++ b/bindings/cil/src/media.cs @@ -33,30 +33,9 @@ namespace VideoLAN.LibVLC */ internal sealed class MediaHandle : NonNullHandle { - [DllImport ("libvlc.dll", - EntryPoint="libvlc_media_new")] - public static extern - MediaHandle Create (InstanceHandle inst, U8String mrl, - NativeException ex); - - [DllImport ("libvlc.dll", - EntryPoint="libvlc_media_release")] - private static extern void Release (IntPtr ptr); - - [DllImport ("libvlc.dll", - EntryPoint="libvlc_media_add_option")] - public static extern void AddOption (MediaHandle ptr, U8String options, - NativeException ex); - - [DllImport ("libvlc.dll", - EntryPoint="libvlc_media_add_option_untrusted")] - public static extern void AddUntrustedOption (MediaHandle ptr, - U8String options, - NativeException ex); - protected override void Destroy () { - Release (handle); + LibVLC.MediaRelease (handle); } }; @@ -84,7 +63,7 @@ namespace VideoLAN.LibVLC { U8String umrl = new U8String (mrl); - handle = MediaHandle.Create (instance.Handle, umrl, ex); + handle = LibVLC.MediaCreate (instance.Handle, umrl, ex); Raise (); } @@ -93,9 +72,9 @@ namespace VideoLAN.LibVLC U8String uopts = new U8String (options); if (trusted) - MediaHandle.AddOption (Handle, uopts, ex); + LibVLC.MediaAddOption (Handle, uopts, ex); else - MediaHandle.AddUntrustedOption (Handle, uopts, ex); + LibVLC.MediaAddUntrustedOption (Handle, uopts, ex); Raise (); } }; -- 2.39.2