]> git.sesse.net Git - vlc/blob - bindings/cil/src/libvlc.cs
4625472ecb5a6920fd6fc7965efb920bb27dfc7a
[vlc] / bindings / cil / src / libvlc.cs
1 /**
2  * @file libvlc.cs
3  * @brief Bindings to LibVLC for the .NET Common Intermediate Language
4  * @ingroup API
5  *
6  * @defgroup API Managed interface to LibVLC
7  * This is the primary class library for .NET applications
8  * to embed and control LibVLC.
9  *
10  * @defgroup Internals LibVLC internals
11  * This covers internal marshalling functions to use the native LibVLC.
12  * Only VLC developpers should need to read this section.
13  */
14
15 /**********************************************************************
16  *  Copyright (C) 2007-2009 RĂ©mi Denis-Courmont.                      *
17  *  This program is free software; you can redistribute and/or modify *
18  *  it under the terms of the GNU General Public License as published *
19  *  by the Free Software Foundation; version 2 of the license, or (at *
20  *  your option) any later version.                                   *
21  *                                                                    *
22  *  This program is distributed in the hope that it will be useful,   *
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
25  *  See the GNU General Public License for more details.              *
26  *                                                                    *
27  *  You should have received a copy of the GNU General Public License *
28  *  along with this program; if not, you can get it from:             *
29  *  http://www.gnu.org/copyleft/gpl.html                              *
30  **********************************************************************/
31
32 using System;
33 using System.Runtime.InteropServices;
34
35 namespace VideoLAN.LibVLC
36 {
37     /**
38      * @brief InstanceHandle: unmanaged LibVLC instance pointer
39      * @ingroup Internals
40      */
41     internal sealed class InstanceHandle : NonNullHandle
42     {
43         [DllImport ("libvlc.dll", EntryPoint="libvlc_get_version")]
44         public static extern IntPtr GetVersion ();
45
46         [DllImport ("libvlc.dll", EntryPoint="libvlc_get_compiler")]
47         public static extern IntPtr GetCompiler ();
48
49         [DllImport ("libvlc.dll", EntryPoint="libvlc_get_changeset")]
50         public static extern IntPtr GetChangeSet ();
51
52         [DllImport ("libvlc.dll", EntryPoint="libvlc_new")]
53         public static extern
54         InstanceHandle Create (int argc, U8String[] argv,
55                                NativeException ex);
56
57         /*[DllImport ("libvlc.dll", EntryPoint="libvlc_retain")]
58         public static extern void Hold (InstanceHandle h,
59                                          NativeException ex);*/
60
61         [DllImport ("libvlc.dll", EntryPoint="libvlc_release")]
62         private static extern void Release (IntPtr h,
63                                             NativeException ex);
64
65         [DllImport ("libvlc.dll", EntryPoint="libvlc_add_intf")]
66         public static extern void AddInterface (InstanceHandle h,
67                                                   U8String name,
68                                                   NativeException ex);
69
70         [DllImport ("libvlc.dll", EntryPoint="libvlc_wait")]
71         public static extern void Run (InstanceHandle h);
72
73         [DllImport ("libvlc.dll", EntryPoint="libvlc_get_vlc_instance")]
74         public static extern NonNullHandle GetVLC (InstanceHandle h);
75
76         protected override void Destroy ()
77         {
78             Release (handle, null);
79         }
80     };
81
82     /**
83      * @brief VLC: VLC media player instance
84      * @ingroup API
85      *
86      * The VLC class provides represent a run-time instance of a media player.
87      * An instance can spawn multiple independent medias, however
88      * configuration settings, message logging, etc are common to all medias
89      * from the same instance.
90      */
91     public class VLC : BaseObject
92     {
93         internal InstanceHandle Handle
94         {
95             get
96             {
97                 return handle as InstanceHandle;
98             }
99         }
100
101         /**
102          * Loads the native LibVLC and creates a LibVLC instance.
103          *
104          * @param args VLC command line parameters for the LibVLC Instance.
105          */
106         public VLC (string[] args)
107         {
108             U8String[] argv = new U8String[args.Length];
109             for (int i = 0; i < args.Length; i++)
110                 argv[i] = new U8String (args[i]);
111
112             handle = InstanceHandle.Create (argv.Length, argv, ex);
113             Raise ();
114         }
115
116         /**
117          * Starts a VLC interface plugin.
118          *
119          * @param name name of the interface plugin (e.g. "http", "qt4", ...)
120          */
121         public void AddInterface (string name)
122         {
123             U8String uname = new U8String (name);
124
125             InstanceHandle.AddInterface (Handle, uname, ex);
126             Raise ();
127         }
128
129         /**
130          * Waits until VLC instance exits. This can happen if a fatal error
131          * occurs (e.g. cannot parse the arguments), if the user has quit
132          * through an interface, or if the special vlc://quit item was played.
133          */
134         public void Run ()
135         {
136             InstanceHandle.Run (Handle);
137         }
138
139         /**
140          * The human-readable LibVLC version number.
141          */
142         public static string Version
143         {
144             get
145             {
146                 return U8String.FromNative (InstanceHandle.GetVersion ());
147             }
148         }
149
150         /**
151          * The human-readable LibVLC C compiler infos.
152          */
153         public static string Compiler
154         {
155             get
156             {
157                 return U8String.FromNative (InstanceHandle.GetCompiler ());
158             }
159         }
160
161         /**
162          * The unique commit identifier from the LibVLC source control system,
163          * or "exported" if unknown.
164          */
165         public static string ChangeSet
166         {
167             get
168             {
169                 return U8String.FromNative (InstanceHandle.GetChangeSet ());
170             }
171         }
172
173         /**
174          * The unmanaged VLC-internal instance object.
175          * Do not use this unless you really know what you are doing.
176          */
177         public SafeHandle Object
178         {
179             get
180             {
181                 return InstanceHandle.GetVLC (Handle);
182             }
183         }
184     };
185 };