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
*/ */
......
/** /**
* @file libvlc.cs * @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 * * 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 *
...@@ -23,327 +30,156 @@ ...@@ -23,327 +30,156 @@
**********************************************************************/ **********************************************************************/
using System; using System;
using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC namespace VideoLAN.LibVLC
{ {
/** /**
* The VLC class is used to create LibVLC Instance objects. * @brief InstanceHandle: unmanaged LibVLC instance pointer
* The VLC class has only one static method and cannot be instanciated. * @ingroup Internals
*
* @code
* string[] argv = new string[]{ "-vvv", "-I", "dummy" };
*
* Instance vlc = VLC.CreateInstance (argv);
* @endcode
*/
public sealed class VLC
{
/**
* 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) internal sealed class InstanceHandle : NonNullHandle
{ {
U8String[] argv = new U8String[args.Length]; [DllImport ("libvlc.dll", EntryPoint="libvlc_get_version")]
for (int i = 0; i < args.Length; i++) public static extern IntPtr GetVersion ();
argv[i] = new U8String (args[i]);
NativeException ex = new NativeException ();
InstanceHandle h = InstanceHandle.Create (argv.Length, argv, ex);
ex.Raise ();
return new Instance (h); [DllImport ("libvlc.dll", EntryPoint="libvlc_get_compiler")]
} public static extern IntPtr GetCompiler ();
};
/** [DllImport ("libvlc.dll", EntryPoint="libvlc_get_changeset")]
* Safe handle for unmanaged LibVLC instance pointer. public static extern IntPtr GetChangeSet ();
*/
public sealed class InstanceHandle : NonNullHandle
{
private InstanceHandle ()
{
}
[DllImport ("libvlc.dll", EntryPoint="libvlc_new")] [DllImport ("libvlc.dll", EntryPoint="libvlc_new")]
internal static extern 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);*/
[DllImport ("libvlc.dll", EntryPoint="libvlc_release")] [DllImport ("libvlc.dll", EntryPoint="libvlc_release")]
static extern void Destroy (IntPtr ptr, NativeException ex); private static extern void Release (IntPtr h,
NativeException ex);
/** [DllImport ("libvlc.dll", EntryPoint="libvlc_add_intf")]
* System.Runtime.InteropServices.SafeHandle::ReleaseHandle. public static extern void AddInterface (InstanceHandle h,
*/ U8String name,
protected override bool ReleaseHandle () NativeException ex);
{
Destroy (handle, null);
return true;
}
};
/** [DllImport ("libvlc.dll", EntryPoint="libvlc_wait")]
* LibVLC Instance provides basic media player features from VLC, public static extern void Run (InstanceHandle h);
* such as play/pause/stop and flat playlist management.
*/ [DllImport ("libvlc.dll", EntryPoint="libvlc_get_vlc_instance")]
public class Instance : BaseObject<InstanceHandle> public static extern NonNullHandle GetVLC (InstanceHandle h);
{
Dictionary<int, PlaylistItem> items;
internal Instance (InstanceHandle self) : base (self) protected override void Destroy ()
{ {
items = new Dictionary<int, PlaylistItem> (); Release (handle, null);
} }
};
/** /**
* Creates a MediaDescriptor. * @brief VLC: VLC media player instance
* @param mrl Media Resource Locator (file path or URL) * @ingroup API
* @return create MediaDescriptor object. *
* 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 MediaDescriptor CreateDescriptor (string mrl) public class VLC : BaseObject
{
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 internal InstanceHandle Handle
{
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
{ {
get get
{ {
int ret = PlaylistIsPlaying (self, ex); return handle as InstanceHandle;
ex.Raise ();
return ret != 0;
} }
} }
[DllImport ("libvlc.dll", EntryPoint="libvlc_playlist_stop")] /**
static extern void PlaylistStop (InstanceHandle self, * Loads the native LibVLC and creates a LibVLC instance.
NativeException ex); *
/** Stops playing. */ * @param args VLC command line parameters for the LibVLC Instance.
public void Stop () */
{ public VLC (string[] args)
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 ()
{ {
PlaylistClear (self, ex); U8String[] argv = new U8String[args.Length];
ex.Raise (); for (int i = 0; i < args.Length; i++)
argv[i] = new U8String (args[i]);
foreach (PlaylistItem item in items.Values) handle = InstanceHandle.Create (argv.Length, argv, ex);
item.Close (); Raise ();
items.Clear ();
} }
[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. * Starts a VLC interface plugin.
* @param mrl Media Resource Locator (file name or URL) *
* @param name playlist item user-visible name * @param name name of the interface plugin (e.g. "http", "qt4", ...)
* @param opts item options (see LibVLC documentation for details)
* @return created playlist item.
*/ */
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 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); InstanceHandle.AddInterface (Handle, uname, ex);
items.Add (id, item); Raise ();
return item;
}
/**
* 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.
*/
public PlaylistItem Add (string mrl, string[] opts)
{
return Add (mrl, null, opts);
}
/**
* 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.
*/
public PlaylistItem Add (string mrl, string name)
{
return Add (mrl, name, new string[0]);
}
/**
* Appends an item to the playlist.
* @param mrl Media Resource Locator (file name or URL)
* @return created playlist item.
*/
public PlaylistItem Add (string mrl)
{
return Add (mrl, null, new string[0]);
} }
[DllImport ("libvlc.dll",
EntryPoint="libvlc_playlist_delete_item")]
static extern int PlaylistDelete (InstanceHandle self, int id,
NativeException e);
/** /**
* Removes an item from the playlist. * Waits until VLC instance exits. This can happen if a fatal error
* @param item playlist item (as obtained from Add()) * 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 Delete (PlaylistItem item) public void Run ()
{ {
int id = item.Id; InstanceHandle.Run (Handle);
PlaylistDelete (self, id, ex);
ex.Raise ();
item.Close ();
items.Remove (id);
} }
};
/** /**
* A playlist item. * The human-readable LibVLC version number.
*/ */
public class PlaylistItem public static string Version
{ {
int id; get
bool deleted;
internal PlaylistItem (int id)
{ {
this.id = id; return U8String.FromNative (InstanceHandle.GetVersion ());
this.deleted = false;
} }
internal void Close ()
{
deleted = true;
} }
internal int Id /**
* The human-readable LibVLC C compiler infos.
*/
public static string Compiler
{ {
get get
{ {
if (deleted) return U8String.FromNative (InstanceHandle.GetCompiler ());
throw new ObjectDisposedException ("Playlist item deleted");
return id;
} }
} }
};
/** Safe handle for unmanaged LibVLC media descriptor */ /**
public sealed class DescriptorHandle : NonNullHandle * The unique commit identifier from the LibVLC source control system,
* or "exported" if unknown.
*/
public static string ChangeSet
{ {
private DescriptorHandle () get
{ {
return U8String.FromNative (InstanceHandle.GetChangeSet ());
} }
[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. * The unmanaged VLC-internal instance object.
* Do not use this unless you really know what you are doing.
*/ */
public class MediaDescriptor : BaseObject<DescriptorHandle> public SafeHandle Object
{ {
internal MediaDescriptor (DescriptorHandle self) : base (self) get
{ {
return InstanceHandle.GetVLC (Handle);
}
} }
}; };
}; };
/** /**
* @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