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

Cleanup instance and media class

parent e876396a
...@@ -7,6 +7,7 @@ SOURCES_dll = \ ...@@ -7,6 +7,7 @@ SOURCES_dll = \
ustring.cs \ ustring.cs \
exception.cs \ exception.cs \
marshal.cs \ marshal.cs \
instance.cs \
media.cs \ media.cs \
player.cs \ player.cs \
libvlc.cs libvlc.cs
......
/**
* @file instance.cs
* @brief Bindings to LibVLC for the .NET Common Intermediate Language
* @ingroup API
*
* @defgroup API Managed interface to LibVLC
* This is the primary class library for .NET applications
* to embed and control LibVLC.
*/
/**********************************************************************
* 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.Runtime.InteropServices;
namespace VideoLAN.LibVLC
{
/**
* @brief InstanceHandle: unmanaged LibVLC instance pointer
* @ingroup Internals
*/
internal sealed class InstanceHandle : NonNullHandle
{
protected override void Destroy ()
{
LibVLC.Release (handle, null);
}
};
/**
* @brief VLC: VLC media player instance
* @ingroup API
*
* 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 class VLC : BaseObject
{
internal InstanceHandle Handle
{
get
{
return handle as InstanceHandle;
}
}
/**
* Loads the native LibVLC and creates a LibVLC instance.
*
* @param args VLC command line parameters for the LibVLC Instance.
*/
public VLC (string[] args)
{
U8String[] argv = new U8String[args.Length];
for (int i = 0; i < args.Length; i++)
argv[i] = new U8String (args[i]);
handle = LibVLC.Create (argv.Length, argv, ex);
Raise ();
}
/**
* Starts a VLC interface plugin.
*
* @param name name of the interface plugin (e.g. "http", "qt4", ...)
*/
public void AddInterface (string name)
{
U8String uname = new U8String (name);
LibVLC.AddIntf (Handle, uname, ex);
Raise ();
}
/**
* Waits until VLC instance exits. This can happen if a fatal error
* 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 Run ()
{
LibVLC.Wait (Handle);
}
/**
* The human-readable LibVLC version number.
*/
public static string Version
{
get
{
return U8String.FromNative (LibVLC.GetVersion ());
}
}
/**
* The human-readable LibVLC C compiler infos.
*/
public static string Compiler
{
get
{
return U8String.FromNative (LibVLC.GetCompiler ());
}
}
/**
* The unique commit identifier from the LibVLC source control system,
* or "exported" if unknown.
*/
public static string ChangeSet
{
get
{
return U8String.FromNative (LibVLC.GetChangeset ());
}
}
/**
* The unmanaged VLC-internal instance object.
* Do not use this unless you really know what you are doing.
*/
public SafeHandle Object
{
get
{
return LibVLC.GetVLCInstance (Handle);
}
}
};
};
/** /**
* @file libvlc.cs * @file libvlc.cs
* @brief Bindings to LibVLC for the .NET Common Intermediate Language * @brief Unmanaged LibVLC APIs
* @ingroup API * @ingroup Internals
*
* @defgroup API Managed interface to LibVLC
* This is the primary class library for .NET applications
* to embed and control LibVLC.
* *
* @defgroup Internals LibVLC internals * @defgroup Internals LibVLC internals
* This covers internal marshalling functions to use the native LibVLC. * This covers internal marshalling functions to use the native LibVLC.
...@@ -35,11 +31,12 @@ using System.Runtime.InteropServices; ...@@ -35,11 +31,12 @@ using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC namespace VideoLAN.LibVLC
{ {
/** /**
* @brief InstanceHandle: unmanaged LibVLC instance pointer * @brief Native: unmanaged LibVLC APIs
* @ingroup Internals * @ingroup Internals
*/ */
internal sealed class InstanceHandle : NonNullHandle internal static class LibVLC
{ {
/* core.c */
[DllImport ("libvlc.dll", EntryPoint="libvlc_get_version")] [DllImport ("libvlc.dll", EntryPoint="libvlc_get_version")]
public static extern IntPtr GetVersion (); public static extern IntPtr GetVersion ();
...@@ -47,139 +44,99 @@ namespace VideoLAN.LibVLC ...@@ -47,139 +44,99 @@ namespace VideoLAN.LibVLC
public static extern IntPtr GetCompiler (); public static extern IntPtr GetCompiler ();
[DllImport ("libvlc.dll", EntryPoint="libvlc_get_changeset")] [DllImport ("libvlc.dll", EntryPoint="libvlc_get_changeset")]
public static extern IntPtr GetChangeSet (); public static extern IntPtr GetChangeset ();
[DllImport ("libvlc.dll", EntryPoint="libvlc_new")] [DllImport ("libvlc.dll", EntryPoint="libvlc_new")]
public static extern public static extern
InstanceHandle Create (int argc, U8String[] argv, InstanceHandle Create (int argc, U8String[] argv, NativeException ex);
NativeException ex);
/*[DllImport ("libvlc.dll", EntryPoint="libvlc_retain")] /*[DllImport ("libvlc.dll", EntryPoint="libvlc_retain")]
public static extern void Hold (InstanceHandle h, public static extern
NativeException ex);*/ void Retain (InstanceHandle h, NativeException ex);*/
[DllImport ("libvlc.dll", EntryPoint="libvlc_release")] [DllImport ("libvlc.dll", EntryPoint="libvlc_release")]
private static extern void Release (IntPtr h, public static extern
NativeException ex); void Release (IntPtr h, NativeException ex);
[DllImport ("libvlc.dll", EntryPoint="libvlc_add_intf")] [DllImport ("libvlc.dll", EntryPoint="libvlc_add_intf")]
public static extern void AddInterface (InstanceHandle h, public static extern
U8String name, void AddIntf (InstanceHandle h, U8String name, NativeException ex);
NativeException ex);
[DllImport ("libvlc.dll", EntryPoint="libvlc_wait")] [DllImport ("libvlc.dll", EntryPoint="libvlc_wait")]
public static extern void Run (InstanceHandle h); public static extern
void Wait (InstanceHandle h);
[DllImport ("libvlc.dll", EntryPoint="libvlc_get_vlc_instance")] [DllImport ("libvlc.dll", EntryPoint="libvlc_get_vlc_instance")]
public static extern NonNullHandle GetVLC (InstanceHandle h); public static extern
SafeHandle GetVLCInstance (InstanceHandle h);
protected override void Destroy () /* media.c */
{ [DllImport ("libvlc.dll", EntryPoint="libvlc_media_new")]
Release (handle, null); public static extern
} MediaHandle MediaCreate (InstanceHandle inst, U8String mrl,
}; NativeException ex);
/** [DllImport ("libvlc.dll", EntryPoint="libvlc_media_new_as_node")]
* @brief VLC: VLC media player instance public static extern
* @ingroup API MediaHandle MediaCreateAsNode (InstanceHandle inst, U8String name,
* NativeException ex);
* The VLC class provides represent a run-time instance of a media player.
* An instance can spawn multiple independent medias, however [DllImport ("libvlc.dll", EntryPoint="libvlc_media_add_option")]
* configuration settings, message logging, etc are common to all medias public static extern
* from the same instance. void MediaAddOption (MediaHandle media, U8String options,
*/ NativeException ex);
public class VLC : BaseObject
{ [DllImport ("libvlc.dll",
internal InstanceHandle Handle EntryPoint="libvlc_media_add_option_untrusted")]
{ public static extern
get void MediaAddUntrustedOption (MediaHandle media, U8String options,
{ NativeException ex);
return handle as InstanceHandle;
} [DllImport ("libvlc.dll", EntryPoint="libvlc_media_release")]
} public static extern
void MediaRelease (IntPtr ptr);
/**
* Loads the native LibVLC and creates a LibVLC instance. [DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_mrl")]
* public static extern
* @param args VLC command line parameters for the LibVLC Instance. void MediaGetMRL (MediaHandle media);
*/
public VLC (string[] args) [DllImport ("libvlc.dll", EntryPoint="libvlc_media_duplicate")]
{ public static extern
U8String[] argv = new U8String[args.Length]; MediaHandle MediaDuplicate (MediaHandle media);
for (int i = 0; i < args.Length; i++)
argv[i] = new U8String (args[i]); /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_read_meta")]
public static extern
handle = InstanceHandle.Create (argv.Length, argv, ex); MediaHandle MediaDuplicate (MediaHandle media, int type,
Raise (); NativeException ex);*/
}
/*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_state")]
/** public static extern
* Starts a VLC interface plugin. int MediaGetState (MediaHandle media, NativeException ex);*/
*
* @param name name of the interface plugin (e.g. "http", "qt4", ...) /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_subitems")]
*/ public static extern
public void AddInterface (string name) MediaListHandle MediaSubItems (MediaHandle media, NativeException ex);*/
{
U8String uname = new U8String (name); /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_state")]
public static extern
InstanceHandle.AddInterface (Handle, uname, ex); EventManagerHandle MediaGetEventManager (MediaHandle media,
Raise (); NativeException ex);*/
}
[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_duration")]
/** public static extern
* Waits until VLC instance exits. This can happen if a fatal error long MediaGetDuration (MediaHandle media, NativeException ex);
* occurs (e.g. cannot parse the arguments), if the user has quit
* through an interface, or if the special vlc://quit item was played. [DllImport ("libvlc.dll", EntryPoint="libvlc_media_is_preparsed")]
*/ public static extern
public void Run () int MediaIsPreparsed (MediaHandle media, NativeException ex);
{
InstanceHandle.Run (Handle); /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_set_user_data")]
} public static extern
void MediaIsPreparsed (MediaHandle media, IntPtr data,
/** NativeException ex);*/
* The human-readable LibVLC version number.
*/ /*[DllImport ("libvlc.dll", EntryPoint="libvlc_media_get_user_data")]
public static string Version public static extern
{ IntPtr MediaIsPreparsed (MediaHandle media, NativeException ex);*/
get
{
return U8String.FromNative (InstanceHandle.GetVersion ());
}
}
/**
* The human-readable LibVLC C compiler infos.
*/
public static string Compiler
{
get
{
return U8String.FromNative (InstanceHandle.GetCompiler ());
}
}
/**
* The unique commit identifier from the LibVLC source control system,
* or "exported" if unknown.
*/
public static string ChangeSet
{
get
{
return U8String.FromNative (InstanceHandle.GetChangeSet ());
}
}
/**
* The unmanaged VLC-internal instance object.
* Do not use this unless you really know what you are doing.
*/
public SafeHandle Object
{
get
{
return InstanceHandle.GetVLC (Handle);
}
}
}; };
}; };
...@@ -33,30 +33,9 @@ namespace VideoLAN.LibVLC ...@@ -33,30 +33,9 @@ namespace VideoLAN.LibVLC
*/ */
internal sealed class MediaHandle : NonNullHandle 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 () protected override void Destroy ()
{ {
Release (handle); LibVLC.MediaRelease (handle);
} }
}; };
...@@ -84,7 +63,7 @@ namespace VideoLAN.LibVLC ...@@ -84,7 +63,7 @@ namespace VideoLAN.LibVLC
{ {
U8String umrl = new U8String (mrl); U8String umrl = new U8String (mrl);
handle = MediaHandle.Create (instance.Handle, umrl, ex); handle = LibVLC.MediaCreate (instance.Handle, umrl, ex);
Raise (); Raise ();
} }
...@@ -93,9 +72,9 @@ namespace VideoLAN.LibVLC ...@@ -93,9 +72,9 @@ namespace VideoLAN.LibVLC
U8String uopts = new U8String (options); U8String uopts = new U8String (options);
if (trusted) if (trusted)
MediaHandle.AddOption (Handle, uopts, ex); LibVLC.MediaAddOption (Handle, uopts, ex);
else else
MediaHandle.AddUntrustedOption (Handle, uopts, ex); LibVLC.MediaAddUntrustedOption (Handle, uopts, ex);
Raise (); Raise ();
} }
}; };
......
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