Changeset 77015ab46b9aff1d25ac3ca3c064893549fd4137

Show
Ignore:
Timestamp:
10/21/07 14:18:19 (10 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1192969099 +0000
git-parent:

[256878bc4b10572511d4c96ac5ad1774482fcc56]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1192969099 +0000
Message:

Add support for allocating media_descriptors and factorize some code (generics yum yum!).
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... ?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • bindings/cil/exception.cs

    r77aa5b9 r77015ab  
    5151     */ 
    5252    [StructLayout (LayoutKind.Sequential)] 
    53     internal sealed class NativeException : IDisposable 
     53    public sealed class NativeException : IDisposable 
    5454    { 
    5555        int raised; 
  • bindings/cil/libvlc.cs

    r77aa5b9 r77015ab  
    2727namespace VideoLAN.LibVLC 
    2828{ 
     29    public sealed class VLC 
     30    { 
     31        public static Instance CreateInstance (string[] args) 
     32        { 
     33            U8String[] argv = new U8String[args.Length]; 
     34            for (int i = 0; i < args.Length; i++) 
     35                argv[i] = new U8String (args[i]); 
     36 
     37            NativeException ex = new NativeException (); 
     38 
     39            InstanceHandle h = InstanceHandle.Create (argv.Length, argv, ex); 
     40            ex.Raise (); 
     41 
     42            return new Instance (h); 
     43        } 
     44    }; 
     45 
    2946    /** Safe handle for unmanaged LibVLC instance pointer */ 
    30     internal sealed class InstanceHandle : NonNullHandle 
     47    public sealed class InstanceHandle : NonNullHandle 
    3148    { 
    3249        private InstanceHandle () 
     
    3956 
    4057        [DllImport ("libvlc-control.dll", EntryPoint="libvlc_destroy")] 
    41         static extern void Destroy (InstanceHandle ptr, NativeException ex); 
     58        static extern void Destroy (IntPtr ptr, NativeException ex); 
    4259 
    4360        protected override bool ReleaseHandle () 
    4461        { 
    45             Destroy (this, null); 
     62            Destroy (handle, null); 
    4663            return true; 
    4764        } 
    4865    }; 
    4966 
    50     public class VLCInstance : IDisposable 
     67    public class Instance : BaseObject<InstanceHandle> 
    5168    { 
    52         NativeException ex; 
    53         InstanceHandle self; 
    54  
    55         public VLCInstance (string[] args) 
     69        internal Instance (InstanceHandle self) : base (self) 
    5670        { 
    57             U8String[] argv = new U8String[args.Length]; 
    58             for (int i = 0; i < args.Length; i++) 
    59                 argv[i] = new U8String (args[i]); 
    60  
    61             ex = new NativeException (); 
    62             self = InstanceHandle.Create (argv.Length, argv, ex); 
    63             ex.Raise (); 
    64         } 
    65  
    66         public void Dispose () 
    67         { 
    68             ex.Dispose (); 
    69             self.Close (); 
    7071        } 
    7172 
     
    8182 
    8283    /** Safe handle for unmanaged LibVLC media descriptor */ 
    83     internal sealed class DescriptorHandle : NonNullHandle 
     84    public sealed class DescriptorHandle : NonNullHandle 
    8485    { 
    8586        private DescriptorHandle () 
     
    9596        [DllImport ("libvlc-control.dll", 
    9697                    EntryPoint="libvlc_media_descriptor_release")] 
    97         public static extern void Release (DescriptorHandle ptr); 
     98        public static extern void Release (IntPtr ptr); 
    9899 
    99100        protected override bool ReleaseHandle () 
    100101        { 
    101             Release (this); 
     102            Release (handle); 
    102103            return true; 
    103104        } 
    104105    }; 
    105106 
    106     public class MediaDescriptor 
     107    public class MediaDescriptor : BaseObject<DescriptorHandle> 
    107108    { 
    108         NativeException ex; 
    109         DescriptorHandle self; 
    110  
    111         internal MediaDescriptor (DescriptorHandle self) 
     109        internal MediaDescriptor (DescriptorHandle self) : base (self) 
    112110        { 
    113             this.self = self; 
    114             ex = new NativeException (); 
    115111        } 
    116112    }; 
  • bindings/cil/marshal.cs

    r77aa5b9 r77015ab  
    3131     * (Microsoft.* namespace has a similar class, but lets stick to System.*) 
    3232     */ 
    33     internal abstract class NonNullHandle : SafeHandle 
     33    public abstract class NonNullHandle : SafeHandle 
    3434    { 
    3535        protected NonNullHandle () 
     
    4646        } 
    4747    }; 
     48 
     49    public class BaseObject<HandleT> : IDisposable where HandleT : SafeHandle 
     50    { 
     51        protected NativeException ex; 
     52        protected HandleT self; 
     53 
     54        internal BaseObject (HandleT self) 
     55        { 
     56            this.self = self; 
     57            ex = new NativeException (); 
     58        } 
     59 
     60        public void Dispose () 
     61        { 
     62            ex.Dispose (); 
     63            self.Close (); 
     64        } 
     65    }; 
    4866}; 
  • bindings/cil/testvlc.cs

    r77aa5b9 r77015ab  
    2525using VideoLAN.LibVLC; 
    2626 
    27 namespace VideoLAN.VLC 
     27namespace VideoLAN.LibVLC.Test 
    2828{ 
    2929    public sealed class Test 
     
    3131        public static int Main (string[] args) 
    3232        { 
    33             VLCInstance vlc = new VLCInstance (args); 
     33            string[] argv = new string[3]{ "-vvv", "-I", "dummy" }; 
     34 
     35            Instance vlc = VLC.CreateInstance (argv); 
     36            MediaDescriptor md = vlc.CreateDescriptor (args[0]); 
     37 
     38            md.Dispose (); 
     39            vlc.Dispose (); 
    3440            return 0; 
    3541        }