Commit a744c7cf authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Start rewriting the CIL bindings

parent 866faad6
...@@ -7,6 +7,8 @@ SOURCES_dll = \ ...@@ -7,6 +7,8 @@ SOURCES_dll = \
ustring.cs \ ustring.cs \
exception.cs \ exception.cs \
marshal.cs \ marshal.cs \
media.cs \
player.cs \
libvlc.cs libvlc.cs
VideoLAN.LibVLC.dll: $(SOURCES_dll) VideoLAN.LibVLC.dll: $(SOURCES_dll)
......
/* /**
* libvlc.cs - libvlc CIL bindings * @file exception.cs
* * @brief LibVLC exceptions
* $Id$ * @ingroup API
*/ */
/********************************************************************** /**********************************************************************
* 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 * * This program is free software; you can redistribute and/or modify *
* it under the terms of the GNU General Public License as published * * it under the terms of the GNU General Public License as published *
* by the Free Software Foundation; version 2 of the license, or (at * * by the Free Software Foundation; version 2 of the license, or (at *
...@@ -27,7 +27,8 @@ using System.Runtime.InteropServices; ...@@ -27,7 +27,8 @@ using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC namespace VideoLAN.LibVLC
{ {
/** /**
* VLCException: managed base class for LibVLC exceptions * @brief VLCException: base class for LibVLC exceptions
* @ingroup API
*/ */
public class VLCException : Exception public class VLCException : Exception
{ {
...@@ -58,6 +59,10 @@ namespace VideoLAN.LibVLC ...@@ -58,6 +59,10 @@ namespace VideoLAN.LibVLC
} }
}; };
/**
* @section Internals
*/
/** /**
* libvlc_exception_t: structure for unmanaged LibVLC exceptions * libvlc_exception_t: structure for unmanaged LibVLC exceptions
*/ */
......
This diff is collapsed.
/** /**
* @file marshal.cs * @file marshal.cs
* @brief LibVLC marshalling utilities * @brief Common LibVLC objects marshalling utilities
* * @ingroup Internals
* $Id$
*/ */
/********************************************************************** /**********************************************************************
* 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 * * This program is free software; you can redistribute and/or modify *
* it under the terms of the GNU General Public License as published * * it under the terms of the GNU General Public License as published *
* by the Free Software Foundation; version 2 of the license, or (at * * by the Free Software Foundation; version 2 of the license, or (at *
...@@ -28,17 +27,21 @@ using System.Runtime.InteropServices; ...@@ -28,17 +27,21 @@ using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC namespace VideoLAN.LibVLC
{ {
/** /**
* Abstract safe handle class for non-NULL pointers * @brief NonNullHandle: abstract safe handle class for non-NULL pointers
* (Microsoft.* namespace has a similar class, * @ingroup Internals
* but lets stick to System.*). * Microsoft.* namespace has a similar class. However we want to use the
* System.* namespace only.
*/ */
public abstract class NonNullHandle : SafeHandle internal abstract class NonNullHandle : SafeHandle
{ {
protected NonNullHandle () protected NonNullHandle ()
: base (IntPtr.Zero, true) : base (IntPtr.Zero, true)
{ {
} }
/**
* System.Runtime.InteropServices.SafeHandle::IsInvalid.
*/
public override bool IsInvalid public override bool IsInvalid
{ {
get get
...@@ -46,26 +49,49 @@ namespace VideoLAN.LibVLC ...@@ -46,26 +49,49 @@ namespace VideoLAN.LibVLC
return handle == IntPtr.Zero; return handle == IntPtr.Zero;
} }
} }
protected abstract void Destroy ();
/**
* System.Runtime.InteropServices.SafeHandle::ReleaseHandle.
*/
protected override bool ReleaseHandle ()
{
Destroy ();
return true;
}
}; };
/** /**
* Generic class for managed wrapper around a native safe handle. * @brief BaseObject: generic wrapper around a safe handle.
* @ingroup Internals
* This is the baseline for all managed LibVLC objects which wrap
* an unmanaged LibVLC pointer.
*/ */
public class BaseObject<HandleT> : IDisposable where HandleT : SafeHandle public class BaseObject : IDisposable
{ {
protected NativeException ex; protected NativeException ex; /**< buffer for LibVLC exceptions */
protected HandleT self; protected SafeHandle handle; /**< wrapped safe handle */
internal BaseObject (HandleT self) internal BaseObject ()
{ {
this.self = self;
ex = new NativeException (); ex = new NativeException ();
this.handle = null;
} }
protected void Raise ()
{
ex.Raise ();
}
/**
* IDisposable::Dispose.
*/
public void Dispose () public void Dispose ()
{ {
ex.Dispose (); ex.Dispose ();
self.Close (); handle.Close ();
} }
}; };
}; };
/**
* @file media.cs
* @brief Media descriptor class
* @ingroup API
*/
/**********************************************************************
* 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.Collections.Generic;
using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC
{
/**
* @brief MediaHandle: unmanaged LibVLC media pointer
* @ingroup Internals
*/
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);
}
};
/**
* @brief Media: a source media
* Use this class to extract meta-informations from a media.
*/
public class Media : BaseObject
{
internal MediaHandle Handle
{
get
{
return handle as MediaHandle;
}
}
/**
* Creates a Media object.
*
* @param instance VLC instance
* @param mrl Media Resource Locator (file path or URL)
*/
public Media (VLC instance, string mrl)
{
U8String umrl = new U8String (mrl);
handle = MediaHandle.Create (instance.Handle, umrl, ex);
Raise ();
}
public void AddOptions (string options, bool trusted)
{
U8String uopts = new U8String (options);
if (trusted)
MediaHandle.AddOption (Handle, uopts, ex);
else
MediaHandle.AddUntrustedOption (Handle, uopts, ex);
Raise ();
}
};
};
/**
* @file player.cs
* @brief Media player class
* @ingroup API
*
* @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) 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 MediaPlayerHandle: unmanaged LibVLC media player pointer
* @ingroup Internals
*/
internal sealed class MediaPlayerHandle : NonNullHandle
{
[DllImport ("libvlc.dll",
EntryPoint="libvlc_media_player_new")]
internal static extern
MediaPlayerHandle Create (InstanceHandle inst, NativeException ex);
[DllImport ("libvlc.dll",
EntryPoint="libvlc_media_player_new_from_media")]
internal static extern
MediaPlayerHandle Create (MediaHandle media, NativeException ex);
[DllImport ("libvlc.dll",
EntryPoint="libvlc_media_player_release")]
internal static extern void Release (IntPtr ptr);
[DllImport ("libvlc.dll",
EntryPoint="libvlc_media_player_set_media")]
internal static extern
MediaPlayerHandle SetMedia (MediaPlayerHandle player,
MediaHandle media,
NativeException ex);
protected override void Destroy ()
{
Release (handle);
}
};
/**
* @brief MediaPlayer: a simple media player
* Use this class to play a media.
*/
public class MediaPlayer : BaseObject
{
internal MediaPlayerHandle Handle
{
get
{
return handle as MediaPlayerHandle;
}
}
Media media; /**< Active media */
/**
* The Media object that the MediaPlayer is using,
* or null if there is none.
*/
public Media Media
{
get
{
return media;
}
set
{
MediaHandle mh = (value != null) ? value.Handle : null;
MediaPlayerHandle.SetMedia (Handle, mh, null);
media = value;
}
}
/**
* Creates an empty MediaPlayer object.
* An input media will be needed before this media player can be used.
*
* @param instance VLC instance
*/
public MediaPlayer (VLC instance)
{
this.media = null;
handle = MediaPlayerHandle.Create (instance.Handle, ex);
ex.Raise ();
}
/**
* Creates a MediaPlayer object from a Media object.
* This allows playing the specified media.
*
* @param media media object
*/
public MediaPlayer (Media media)
{
this.media = media;
handle = MediaPlayerHandle.Create (media.Handle, ex);
ex.Raise ();
}
};
};
/* /**
* ustring.cs - Managed LibVLC string * @file ustring.cs
* * @brief Managed LibVLC strings
* $Id$ * @ingroup Internals
*/ */
/********************************************************************** /**********************************************************************
...@@ -27,13 +27,20 @@ using System.Runtime.InteropServices; ...@@ -27,13 +27,20 @@ using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC namespace VideoLAN.LibVLC
{ {
/** /**
* Managed class for UTF-8 nul-terminated character arrays * @brief U8String: Native UTF-8 characters array
* @ingroup Internals
* This supports conversion between native UTF-8 nul-terminated characters
* arrays (as used by the native LibVLC) and managed strings.
*/ */
[StructLayout (LayoutKind.Sequential)] [StructLayout (LayoutKind.Sequential)]
public struct U8String public struct U8String
{ {
public byte[] mb_str; public byte[] mb_str; /**< nul-terminated UTF-8 bytes array */
/**
* Creates an UTF-8 characters array from a .NET string.
* @param value string to convert
*/
public U8String (string value) public U8String (string value)
{ {
mb_str = null; mb_str = null;
...@@ -46,7 +53,7 @@ namespace VideoLAN.LibVLC ...@@ -46,7 +53,7 @@ namespace VideoLAN.LibVLC
mb_str[bytes.Length] = 0; mb_str[bytes.Length] = 0;
} }
public U8String (IntPtr ptr) private U8String (IntPtr ptr)
{ {
mb_str = null; mb_str = null;
if (ptr == IntPtr.Zero) if (ptr == IntPtr.Zero)
...@@ -61,6 +68,9 @@ namespace VideoLAN.LibVLC ...@@ -61,6 +68,9 @@ namespace VideoLAN.LibVLC
Marshal.Copy (ptr, mb_str, 0, i); Marshal.Copy (ptr, mb_str, 0, i);
} }
/**
* Object::ToString.
*/
public override string ToString () public override string ToString ()
{ {
if (mb_str == null) if (mb_str == null)
...@@ -72,6 +82,10 @@ namespace VideoLAN.LibVLC ...@@ -72,6 +82,10 @@ namespace VideoLAN.LibVLC
return System.Text.Encoding.UTF8.GetString (bytes); return System.Text.Encoding.UTF8.GetString (bytes);
} }
/**
* Converts a pointer to a nul-terminated UTF-8 characters array into
* a managed string.
*/
public static string FromNative (IntPtr ptr) public static string FromNative (IntPtr ptr)
{ {
return new U8String (ptr).ToString (); return new U8String (ptr).ToString ();
......
...@@ -31,28 +31,20 @@ namespace VideoLAN.LibVLC.Test ...@@ -31,28 +31,20 @@ namespace VideoLAN.LibVLC.Test
public static int Main (string[] args) public static int Main (string[] args)
{ {
string[] argv = new string[]{ string[] argv = new string[]{
"-vvv", "-I", "dummy", "--plugin-path=../../modules" "-v", "-I", "dummy", "--plugin-path=../../modules"
}; };
Instance vlc = VLC.CreateInstance (argv); Console.WriteLine("Running on VLC {0} ({1})", VLC.Version,
MediaDescriptor md = vlc.CreateDescriptor ("/dev/null"); VLC.ChangeSet);
md.Dispose (); Console.WriteLine("Compiled with {0}", VLC.Compiler);
PlaylistItem item = null; VLC vlc = new VLC (argv);
Media m = new Media (vlc, "/dev/null");
foreach (string s in args) vlc.AddInterface ("qt4");
item = vlc.Add (s); vlc.Run ();
vlc.Loop = false; m.Dispose ();
vlc.TogglePause ();
Console.ReadLine ();
vlc.Stop ();
if (item != null)
vlc.Delete (item);
vlc.Clear ();
Console.ReadLine ();
vlc.Dispose (); vlc.Dispose ();
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment