summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
256878b)
Destroying the instance object while a descriptor is still alive will crash(!).
I wonder why libvlc_instance_t is not reference counted as the other handler types... ?
* libvlc_exception_t: structure for unmanaged LibVLC exceptions
*/
[StructLayout (LayoutKind.Sequential)]
* libvlc_exception_t: structure for unmanaged LibVLC exceptions
*/
[StructLayout (LayoutKind.Sequential)]
- internal sealed class NativeException : IDisposable
+ public sealed class NativeException : IDisposable
namespace VideoLAN.LibVLC
{
namespace VideoLAN.LibVLC
{
+ public sealed class VLC
+ {
+ 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 ();
+
+ return new Instance (h);
+ }
+ };
+
/** Safe handle for unmanaged LibVLC instance pointer */
/** Safe handle for unmanaged LibVLC instance pointer */
- internal sealed class InstanceHandle : NonNullHandle
+ public sealed class InstanceHandle : NonNullHandle
{
private InstanceHandle ()
{
{
private InstanceHandle ()
{
InstanceHandle Create (int argc, U8String[] argv, NativeException ex);
[DllImport ("libvlc-control.dll", EntryPoint="libvlc_destroy")]
InstanceHandle Create (int argc, U8String[] argv, NativeException ex);
[DllImport ("libvlc-control.dll", EntryPoint="libvlc_destroy")]
- static extern void Destroy (InstanceHandle ptr, NativeException ex);
+ static extern void Destroy (IntPtr ptr, NativeException ex);
protected override bool ReleaseHandle ()
{
protected override bool ReleaseHandle ()
{
+ Destroy (handle, null);
- public class VLCInstance : IDisposable
+ public class Instance : BaseObject<InstanceHandle>
- NativeException ex;
- InstanceHandle self;
-
- public VLCInstance (string[] args)
+ internal Instance (InstanceHandle self) : base (self)
- U8String[] argv = new U8String[args.Length];
- for (int i = 0; i < args.Length; i++)
- argv[i] = new U8String (args[i]);
-
- ex = new NativeException ();
- self = InstanceHandle.Create (argv.Length, argv, ex);
- ex.Raise ();
- }
-
- public void Dispose ()
- {
- ex.Dispose ();
- self.Close ();
}
public MediaDescriptor CreateDescriptor (string mrl)
}
public MediaDescriptor CreateDescriptor (string mrl)
};
/** Safe handle for unmanaged LibVLC media descriptor */
};
/** Safe handle for unmanaged LibVLC media descriptor */
- internal sealed class DescriptorHandle : NonNullHandle
+ public sealed class DescriptorHandle : NonNullHandle
{
private DescriptorHandle ()
{
{
private DescriptorHandle ()
{
[DllImport ("libvlc-control.dll",
EntryPoint="libvlc_media_descriptor_release")]
[DllImport ("libvlc-control.dll",
EntryPoint="libvlc_media_descriptor_release")]
- public static extern void Release (DescriptorHandle ptr);
+ public static extern void Release (IntPtr ptr);
protected override bool ReleaseHandle ()
{
protected override bool ReleaseHandle ()
{
- public class MediaDescriptor
+ public class MediaDescriptor : BaseObject<DescriptorHandle>
- NativeException ex;
- DescriptorHandle self;
-
- internal MediaDescriptor (DescriptorHandle self)
+ internal MediaDescriptor (DescriptorHandle self) : base (self)
- this.self = self;
- ex = new NativeException ();
* Abstract safe handle class for non-NULL pointers
* (Microsoft.* namespace has a similar class, but lets stick to System.*)
*/
* Abstract safe handle class for non-NULL pointers
* (Microsoft.* namespace has a similar class, but lets stick to System.*)
*/
- internal abstract class NonNullHandle : SafeHandle
+ public abstract class NonNullHandle : SafeHandle
{
protected NonNullHandle ()
: base (IntPtr.Zero, true)
{
protected NonNullHandle ()
: base (IntPtr.Zero, true)
+
+ public class BaseObject<HandleT> : IDisposable where HandleT : SafeHandle
+ {
+ protected NativeException ex;
+ protected HandleT self;
+
+ internal BaseObject (HandleT self)
+ {
+ this.self = self;
+ ex = new NativeException ();
+ }
+
+ public void Dispose ()
+ {
+ ex.Dispose ();
+ self.Close ();
+ }
+ };
using System;
using VideoLAN.LibVLC;
using System;
using VideoLAN.LibVLC;
+namespace VideoLAN.LibVLC.Test
{
public sealed class Test
{
public static int Main (string[] args)
{
{
public sealed class Test
{
public static int Main (string[] args)
{
- VLCInstance vlc = new VLCInstance (args);
+ string[] argv = new string[3]{ "-vvv", "-I", "dummy" };
+
+ Instance vlc = VLC.CreateInstance (argv);
+ MediaDescriptor md = vlc.CreateDescriptor (args[0]);
+
+ md.Dispose ();
+ vlc.Dispose ();