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

Remove Common Intermediate Language bindings

parent f5bd90eb
Doxyfile
INSTALL
admin
doc
config.status
Rémi Denis-Courmont <rem (at) videolan (dot) org>
This diff is collapsed.
This diff is collapsed.
# Makefile.am - master Makefile for libvlc-cil
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = \
-Wall \
check-news \
std-options \
dist-bzip2 \
no-dist-gzip \
no-exeext
SUBDIRS = src tests
DIST_SUBDIRS = $(SUBDIRS) m4
doc: Doxyfile
$(DOXYGEN)
.PHONY: doc
libvlc-cil 0.9.0
=================
Initial release.
libvlc-cil 0.9.0
=================
Common Intermediary Language bindings for LibVLC
#!/bin/sh
# SVN package rebuild script
# $Id$
#
# ***********************************************************************
# * Copyright © 2002-2005 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. *
# * *
# * 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 *
# ***********************************************************************
set -xe
cd "$(dirname "$0")"
test -f src/exception.cs || {
echo "You must run this script from your cil directory.">&2
exit 1
}
mkdir -p admin
autoreconf -sfi
set +x
echo ""
echo "Type \`./configure' to configure the package for your system"
echo "(type \`./configure -- help' for help)."
echo "Then you can use the usual \`make', \`make install', etc."
dnl configure.ac - Configure script for libvlc-cil
dnl Process this file with GNU Autoconf to produce a configure script
dnl ***********************************************************************
dnl * Copyright © 2007 Rémi Denis-Courmont. *
dnl * This program is free software; you can redistribute and/or modify *
dnl * it under the terms of the GNU General Public License as published *
dnl * by the Free Software Foundation; version 2 of the license, or (at *
dnl * your option) any later version. *
dnl * *
dnl * This program is distributed in the hope that it will be useful, *
dnl * but WITHOUT ANY WARRANTY; without even the implied warranty of *
dnl * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
dnl * See the GNU General Public License for more details. *
dnl * *
dnl * You should have received a copy of the GNU General Public License *
dnl * along with this program; if not, you can get it from: *
dnl * http://www.gnu.org/copyleft/gpl.html *
dnl ***********************************************************************
AC_COPYRIGHT([Copyright (C) 2004-2009 Remi Denis-Courmont])
AC_INIT(libvlc-cil, 1.0.0, vlc-devel_no_bulk_mail@videolan.org)
AC_PREREQ(2.50)
AC_CONFIG_SRCDIR(configure.ac)
AC_CONFIG_AUX_DIR(admin)
AC_CONFIG_MACRO_DIR(m4)
AC_ARG_VAR([CSC], [C sharp compiler command])
AC_ARG_VAR([CSFLAGS], [C sharp compiler flags])
AC_PATH_PROG([CSC], [gmcs csc], [false])
AC_ARG_VAR([DOXYGEN], [Doxygen command])
AC_PATH_PROG([DOXYGEN], [doxygen], [false])
AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile m4/Makefile src/Makefile tests/Makefile Doxyfile])
AC_OUTPUT
EXTRA_DIST = $(SOURCES_dll)
MOSTLYCLEANFILES = $(pkglib_SCRIPTS)
pkglib_SCRIPTS = VideoLAN.LibVLC.dll
SOURCES_dll = \
ustring.cs \
exception.cs \
event.cs \
marshal.cs \
instance.cs \
media.cs \
player.cs \
libvlc.cs
VideoLAN.LibVLC.dll: $(SOURCES_dll)
$(CSC) -target:library -out:$@ $(CSFLAGS) $^
/**
* @file event.cs
* @brief Unmanaged LibVLC events
* @ingroup Internals
*/
/**********************************************************************
* 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
{
/**
* @ingroup Internals
* @{
*/
/**
* @brief EventType: LibVLC event types
*/
internal enum EventType
{
MediaMetaChanged,
MediaSubItemAdded,
MediaDurationChanged,
MediaPreparsedChanged,
MediaFreed,
MediaStateChanged,
PlayerNothingSpecial,
PlayerOpening,
PlayerBuffering,
PlayerPlaying,
PlayerPaused,
PlayerStopped,
PlayerForward,
PlayerBackward,
PlayerEndReached,
PlayerEncounteredError,
PlayerTimeChanged,
PlayerPositionChanged,
PlayerSeekableChanged,
PlayerPausableChanged,
ListItemAdded,
ListWillAddItem,
ListItemDeleted,
ListWillDeleteItem,
ListViewItemAdded,
ListViewWillAddItem,
ListViewItemDeleted,
ListViewWillDeleteItem,
ListPlayerPlayed,
ListPlayerNextItemSet,
ListPlayerStopped,
DiscovererStarted,
DiscovererEnded,
PlayerTitleChanged,
};
[StructLayout (LayoutKind.Sequential)]
internal class GenericEvent
{
public EventType type;
public IntPtr obj;
};
internal delegate void GenericCallback (GenericEvent e, IntPtr d);
/* Player events */
[StructLayout (LayoutKind.Sequential)]
internal sealed class PlayerPositionEvent : GenericEvent
{
float position;
};
[StructLayout (LayoutKind.Sequential)]
internal sealed class PlayerTimeEvent : GenericEvent
{
long time;
};
[StructLayout (LayoutKind.Sequential)]
internal sealed class PlayerTitleEvent : GenericEvent
{
int title;
};
[StructLayout (LayoutKind.Sequential)]
internal sealed class PlayerSeekableEvent : GenericEvent
{
long seekable;
};
[StructLayout (LayoutKind.Sequential)]
internal sealed class PlayerPausableChangedEvent : GenericEvent
{
long pausable;
};
/** @} */
};
\ No newline at end of file
/**
* @file exception.cs
* @brief LibVLC exceptions
* @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.Runtime.InteropServices;
namespace VideoLAN.LibVLC
{
/**
* @brief VLCException: base class for LibVLC exceptions
* @ingroup API
*/
public class VLCException : Exception
{
int code;
/**
* VLC exception code.
*/
public int Code
{
get
{
return code;
}
}
/**
* Creates a managed VLC exception.
*/
public VLCException ()
{
}
/**
* Creates a managed VLC exception.
* @param message exception error message
*/
public VLCException (string message)
: base (message)
{
}
/**
* Creates a managed VLC exception wrapping another exception.
* @param message exception error message
* @param inner inner wrapped exception
*/
public VLCException (string message, Exception inner)
: base (message, inner)
{
}
/**
* Creates a VLC exception
* @param code VLC exception code
* @param message VLC exception message
*/
public VLCException (int code, string message) : base (message)
{
this.code = code;
}
/**
* Creates a VLC exception
* @param code VLC exception code
*/
public VLCException (int code) : base ()
{
this.code = code;
}
};
/**
* @brief NativeException: CIL representation for libvlc_exception_t.
* @ingroup Internals
*/
[StructLayout (LayoutKind.Sequential)]
public sealed class NativeException : IDisposable
{
int raised;
int code;
IntPtr message;
public NativeException ()
{
LibVLC.ExceptionInit (this);
}
/**
* Throws a managed exception if LibVLC has returned a native
* unmanaged exception. Clears the native exception.
*/
public void Raise ()
{
if (raised == 0)
return;
string msg = U8String.FromNative (message);
try
{
if (msg != null)
throw new VLCException (code, msg);
else
throw new VLCException (code);
}
finally
{
LibVLC.ExceptionClear (this);
}
}
/** IDisposable implementation. */
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
~NativeException ()
{
Dispose (false);
}
private void Dispose (bool disposing)
{
LibVLC.ExceptionClear (this);
}
};
};
/**
* @file instance.cs
* @brief LibVLC instance class
* @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;
/**
* @brief VideoLAN.LibVLC: VideoLAN project's LibVLC .Net bindings
* @ingroup API
*
* This namespace provides a set of managed APIs around the native LibVLC
* for the .Net Common Language Runtime.
*/
namespace VideoLAN.LibVLC
{
/**
* @brief InstanceHandle: unmanaged LibVLC instance pointer
* @ingroup Internals
*/
internal sealed class InstanceHandle : NonNullHandle
{
/**
* NonNullHandle.Destroy
*/
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.
* @version VLC 1.0
*/
public IntPtr Object
{
get
{
return LibVLC.GetVLCInstance (Handle);
}
}
};
};
/**
* @mainpage libvlc-cil documentation
*
* @section Introduction
*
* libvlc-cil is a thin API layer around LibVLC,
* the VideoLAN's project media framework C library.
* LibVLC comes built-in the VLC media player.
*
* With libvlc-cil, you can use LibVLC
* from within the .Net Common Language Runtime,
* with the CIL programming language of your preference.
* However, libvlc-cil and the code sample in this documentation
* are written is C#.
*
* @section Installation
*
* libvlc-cil does <b>not</b> include the underlying LibVLC by default.
* Make sure VLC, or at least LibVLC and the relevant VLC plugins are present.
* The LibVLC runtime library needs to be in the library search path for the
* Common Language Runtime. Check the documentation for your CLR for details.
*
* On Windows, libvlc.dll needs to be in the current directory, the DLL path
* of the running process, or the system search path (but the latter is
* uncommon and not supported by the official LibVLC installer).
*
* On Linux, libvlc.so should be in /usr/lib; if it is in another directory,
* such as /usr/local/lib, you might need to add that directory to the
* LD_LIBRARY_PATH environment variable.
*
* @section Usage
*
* First, you need to create a VLC instance. This will load and setup the
* native VLC runtime, the VLC configuration, the list of available plugins,
* the platform adaptation and the VLC log messages and objects subsystems
* @code
* using System;
* using VideoLAN.LibVLC;
* ...
*
* try {
* Console.WriteLine("Running on VLC version {0}", VLC.Version);
* }
* catch (Exception e) {
* Console.WriteLine("VLC is not available on your system.");
* throw e;
* }
*
* string[] args = new string[]{ "-v", "--ignore-config" };
* VLC vlc = new VLC(args);
* @endcode
* @see VideoLAN::LibVLC::VLC
*
* To play media, you need a media and a player.
* @code
* Media media = new Media(vlc, "http://www.example.com/video.ogv");
* Player player = new Player(media);
* player.Play();
* @endcode
* @see VideoLAN::LibVLC::Media @see VideoLAN::LibVLC::Player
*
* All these objects use unmanaged resources.
* They all implement the IDisposeable interface.
* You should dispose them when you do not need them anymore:
* @code
* player.Dispose();
* media.Dispose();
* vlc.Dispose();
* @endcode
*/
This diff is collapsed.
/**
* @file marshal.cs
* @brief Common LibVLC objects marshalling utilities
* @ingroup Internals
*/
/**********************************************************************
* 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;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace VideoLAN.LibVLC
{
/**
* @brief NonNullHandle: abstract safe handle class for non-NULL pointers
* @ingroup Internals
* Microsoft.* namespace has a similar class. However we want to use the
* System.* namespace only.
*/
internal abstract class NonNullHandle : SafeHandle
{
protected NonNullHandle ()
: base (IntPtr.Zero, true)
{
}
/**
* System.Runtime.InteropServices.SafeHandle::IsInvalid.
*/
public override bool IsInvalid
{
get
{
return handle == IntPtr.Zero;
}
}
/**
* Destroys an handle. Cannot fail.
*/
protected abstract void Destroy ();
/**
* System.Runtime.InteropServices.SafeHandle::ReleaseHandle.
*/
protected override bool ReleaseHandle ()
{
Destroy ();
return true;
}
};
/**
* @brief BaseObject: generic wrapper around a safe LibVLC handle.
* @ingroup Internals
*
* This is the baseline for all managed LibVLC objects. It wraps:
* - an unmanaged LibVLC pointer,
* - a native exception structure.
*/
public class BaseObject : IDisposable
{
internal NativeException ex; /**< buffer for LibVLC exceptions */
internal SafeHandle handle; /**< wrapped safe handle */
internal BaseObject ()
{
ex = new NativeException ();
this.handle = null;
}
/**
* Checks if the LibVLC run-time raised an exception
* If so, raises a CIL exception.
*/
internal void Raise ()
{
ex.Raise ();
}
/**
* IDisposable::Dispose.
*/
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
/**
* Releases unmanaged resources associated with the object.
* @param disposing true if the disposing the object explicitly,
* false if finalizing the object inside the GC.
*/
protected virtual void Dispose (bool disposing)
{
if (disposing)
{
ex.Dispose ();
if (handle != null)
handle.Close ();
}
ex = null;
handle = null;
}
};
internal class EventManagerHandle : NonNullHandle
{
protected override void Destroy ()
{
}
};
/**
* @brief EventingObject: wrapper around an eventing LibVLC handle.
* @ingroup Internals
*
* This is the base class for all managed LibVLC objects which do have an
* event manager.
*/
public abstract class EventingObject : BaseObject
{
private Dictionary<Delegate, IntPtr> events;
/**< references to our unmanaged function pointers */
internal EventingObject () : base ()
{
events = new Dictionary<Delegate, IntPtr> ();
}
/**
* Releases unmanaged resources associated with the object.
* @param disposing true if the disposing the object explicitly,
* false if finalizing the object inside the GC.
*/
protected override void Dispose (bool disposing)
{
events = null;
base.Dispose (disposing);
}
/**
* @return the unmanaged event manager for this object
*/
internal abstract EventManagerHandle GetManager ();
/**
* Registers an event handler.
* @param type event type to register to
* @param callback callback to invoke when the event occurs
*
* @note
* For simplicity, we require distinct callbacks for each event type.
* This is hardly an issue since most events have different formats.
*/
internal void Attach (EventType type, Delegate callback)
{
EventManagerHandle manager;
IntPtr cb = Marshal.GetFunctionPointerForDelegate (callback);
bool unref = false;
/* If things go wrong, we will leak the callback thunk... until
* this object is destroyed anyway. If we added the thunk _after_
* the critical section, the native code could try to jump to a
* non-existent address, which is much worse. */
events.Add (callback, cb);
try
{
handle.DangerousAddRef (ref unref);
manager = GetManager ();
LibVLC.EventAttach (manager, type, cb, IntPtr.Zero, ex);
}
finally
{
if (unref)
handle.DangerousRelease ();
}
Raise ();
}
internal void Detach (EventType type, Delegate callback)
{
EventManagerHandle manager;
IntPtr cb = events[callback];
bool unref = false;
try
{
handle.DangerousAddRef (ref unref);
manager = GetManager ();
LibVLC.EventDetach (manager, type, cb, IntPtr.Zero, ex);
}
finally
{
if (unref)
handle.DangerousRelease ();
}
Raise ();
events.Remove (callback);
}
};
};
/**
* @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
{
/**
* NonNullHandle.Destroy
*/
protected override void Destroy ()
{
LibVLC.MediaRelease (handle);
}
};
/**
* @brief MetaType: type of a media meta-information entry
*/
public enum MetaType
{
Title,
Artist,
Genre,
Copyright,
Album,
TrackNumber,
Description,
Rating,
Date,
Setting,
URL,
Language,
NowPlaying,
Publisher,
EncodedBy,
ArtworkURL,
TrackID,
};
/**
* @brief State: media/player state
*
* Media and Player objects are always in one of these state.
* @see Media::State and @see Player::State.
*/
public enum State
{
NothingSpecial, /**< Nothing going on */
Opening, /**< Being opened */
Buffering, /**< Buffering before play */
Playing, /**< Playing */
Paused, /**< Paused */
Stopped, /**< Stopped */
Ended, /**< Played until the end */
Error, /**< Failed */
};
/* Media events */
[StructLayout (LayoutKind.Sequential)]
internal sealed class MediaMetaEvent : GenericEvent
{
public MetaType metaType;
};
internal delegate void MediaMetaCallback (MediaMetaEvent e, IntPtr d);
/*[StructLayout (LayoutKind.Sequential)]
internal sealed class MediaSubitemEvent : GenericEvent
{
public IntPtr child; -- MediaHandle
};*/
[StructLayout (LayoutKind.Sequential)]
internal sealed class MediaDurationEvent : GenericEvent
{
public long duration;
};
internal delegate void MediaDurationCallback (MediaDurationEvent e,
IntPtr d);
[StructLayout (LayoutKind.Sequential)]
internal sealed class MediaPreparseEvent : GenericEvent
{
public int status;
};
internal delegate void MediaPreparseCallback (MediaPreparseEvent e,
IntPtr d);
/* media_freed -> bad idea w.r.t. the GC */
[StructLayout (LayoutKind.Sequential)]
internal sealed class MediaStateEvent : GenericEvent
{
public State state;
};
internal delegate void MediaStateCallback (MediaStateEvent e, IntPtr d);
/**
* @brief Media: a source media
* @ingroup API
* Each media object represents an input media, such as a file or an URL.
*/
public class Media : EventingObject, ICloneable
{
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 = LibVLC.MediaCreate (instance.Handle, umrl, ex);
Raise ();
Attach ();
}
private Media (MediaHandle handle)
{
this.handle = handle;
Attach ();
}
/**
* Duplicates a media object.
*/
public object Clone ()
{
return new Media (LibVLC.MediaDuplicate (Handle));
}
private void Attach ()
{
Attach (EventType.MediaMetaChanged,
new MediaMetaCallback (MetaCallback));
//Attach (EventType.MediaSubItemAdded, SubItemAdded);
Attach (EventType.MediaDurationChanged,
new MediaDurationCallback (DurationCallback));
/*Attach (EventType.MediaPreparsedChanged,
new MediaPreparseCallback (PreparseCallback));*/
/* MediaFreed: better not... */
Attach (EventType.MediaStateChanged,
new MediaStateCallback (StateCallback));
}
/**
* Add VLC input item options to the media.
* @code
* Media m = new Media(vlc, "http://www.example.com/music.ogg");
* m.AddOptions(":http-user-agent=LibVLC.Net "
* + ":http-proxy=proxy:8080", true);
* @endcode
* @param options VLC options in VLC input item format
* (see example below)
* @param trusted whether the options are set by a trusted agent
* (e.g. the local computer configuration) or not
* (e.g. a downloaded file).
* @version VLC 0.9.9 if trusted is false
*/
public void AddOptions (string options, bool trusted)
{
U8String uopts = new U8String (options);
if (trusted)
LibVLC.MediaAddOption (Handle, uopts, ex);
else
LibVLC.MediaAddUntrustedOption (Handle, uopts, ex);
Raise ();
}
/**
* The media location (file path, URL, ...).
* @version VLC 1.0
*/
public string Location
{
get
{
StringHandle str = LibVLC.MediaGetMRL (Handle, ex);
Raise ();
return str.Transform ();
}
}
public override string ToString ()
{
return Location;
}
/**
* @param type meta data type
* @return the meta data value, or @a null if unknown
*/
public string GetMeta (MetaType type)
{
StringHandle str = LibVLC.MediaGetMeta (Handle, type, ex);
Raise ();
return str.Transform ();
}
public delegate void MetaChange (Media media, MetaType type);
public event MetaChange MetaChanged;
private void MetaCallback (MediaMetaEvent ev, IntPtr data)
{
if (MetaChanged != null)
MetaChanged (this, ev.metaType);
}
/**
* Current state of the media.
*/
public State State
{
get
{
State ret = LibVLC.MediaGetState (Handle, ex);
Raise ();
return ret;
}
}
public delegate void StateChange (Media media, State state);
public event StateChange StateChanged;
private void StateCallback (MediaStateEvent ev, IntPtr data)
{
if (StateChanged != null)
StateChanged (this, ev.state);
}
internal override EventManagerHandle GetManager ()
{
return LibVLC.MediaEventManager (Handle, null);
}
/**
* Duration of the media in microseconds. The precision of the result
* depends on the input stram protocol and file format. The value
* might be incorrect and unknown (VLC usually returns 0 or -1 then).
*/
public long Duration
{
get
{
long duration = LibVLC.MediaGetDuration (Handle, ex);
Raise ();
return duration;
}
}
public delegate void DurationChange (Media media, long duration);
public event DurationChange DurationChanged;
private void DurationCallback (MediaDurationEvent ev, IntPtr data)
{
if (DurationChanged != null)
DurationChanged (this, ev.duration);
}
/**
* Whether the media was "preparsed". If true, the meta-infos were
* extracted, even before the media was played. This is normally only
* available if the input files is stored on a local filesystem.
*/
public bool IsPreparsed
{
get
{
int preparsed = LibVLC.MediaIsPreparsed (Handle, ex);
Raise ();
return preparsed != 0;
}
}
public delegate void PreparseChange (Media media, bool preparsed);
public event PreparseChange PreparseChanged;
private void PreparseCallback (MediaPreparseEvent ev, IntPtr data)
{
if (PreparseChanged != null)
PreparseChanged (this, ev.status != 0);
}
};
};
This diff is collapsed.
/**
* @file ustring.cs
* @brief Managed LibVLC strings
* @ingroup Internals
*/
/**********************************************************************
* Copyright (C) 2007 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 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)]
internal struct U8String
{
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)
{
mb_str = null;
if (value == null)
return;
byte[] bytes = System.Text.Encoding.UTF8.GetBytes (value);
mb_str = new byte[bytes.Length + 1];
Array.Copy (bytes, mb_str, bytes.Length);
mb_str[bytes.Length] = 0;
}
private U8String (IntPtr ptr)
{
mb_str = null;
if (ptr == IntPtr.Zero)
return;
int i = 0;
while (Marshal.ReadByte (ptr, i) != 0)
i++;
i++;
mb_str = new byte[i];
Marshal.Copy (ptr, mb_str, 0, i);
}
/**
* Object::ToString.
*/
public override string ToString ()
{
if (mb_str == null)
return null;
byte[] bytes = new byte[mb_str.Length - 1];
Array.Copy (mb_str, bytes, bytes.Length);
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)
{
return new U8String (ptr).ToString ();
}
};
/**
* @brief MemoryHandle: heap allocation by the C run-time
* @ingroup Internals
*/
internal class MemoryHandle : NonNullHandle
{
/**
* NonNullHandle.Destroy
*/
protected override void Destroy ()
{
LibVLC.Free (handle);
}
};
/**
* @brief StringHandle: heap-allocated characters array
* @ingroup Internals
*/
internal sealed class StringHandle : MemoryHandle
{
/**
* Converts an heap-allocated nul-terminated UTF-8 characters array
* into a managed string.
* @return the resulting managed string.
*/
public override string ToString ()
{
return U8String.FromNative (handle);
}
/**
* Converts the buffer (as in ToString()) and release it.
* @return managed string representation of the buffer
*/
public string Transform ()
{
string value = ToString ();
Close ();
return value;
}
};
};
EXTRA_DIST = $(SOURCES_testvlc)
MOSTLYCLEANFILES = $(check_SCRIPTS)
noinst_SCRIPTS = testvlc.exe
dist_check_SCRIPTS = missing_api
SOURCES_testvlc = testvlc.cs
LDADD_testvlc = -lib:../src -r:VideoLAN.LibVLC.dll
testvlc.exe: $(SOURCES_testvlc) ../src/VideoLAN.LibVLC.dll
$(CSC) -target:exe -out:$@ $(CSFLAGS) $(SOURCES_testvlc) \
$(LDADD_testvlc)
TESTS = missing_api
#! /bin/sh
# Finds LibVLC API mismatch within the CIL bindings
# Copyright 2008 Rémi Denis-Courmont
if test "${srcdir}" = ""; then
srcdir="$(dirname "$0")"
fi
libvlcsym="${srcdir}/../../../src/libvlc.sym"
if ! test -f "${libvlcsym}"; then
echo "Cannot find ${libvlcsym}\!" >&2
exit 77
fi
cat ${srcdir}/../src/*.cs | \
sed -n -e 's,^.*EntryPoint="\([^"]*\)".*$,\1,p' | {
cat
# Symbols we do not need:
echo 'libvlc_exception_raise'
} | \
sort -u | \
diff -u - "${libvlcsym}" | \
grep -ve '^+\(mediacontrol_\|libvlc_playlist_\)' | {
read line # ---
read line # +++
broken=no
while read line; do
match="${line#+}"
if test "${line}" != "${match}"; then
echo "Unimplemented: $match"
broken=yes
fi
match="${line#-}"
if test "${line}" != "${match}"; then
echo "Invalid: $match"
broken=yes
fi
done
test "${broken}" = "no"
}
/*
* testvlc.cs - tests for libvlc CIL bindings
*
* $Id$
*/
/**********************************************************************
* Copyright (C) 2007 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 VideoLAN.LibVLC;
namespace VideoLAN.LibVLC.Test
{
public sealed class Test
{
private static void DumpMedia (Media m)
{
Console.WriteLine ("Media: {0} {1} (duration: {2}, {3}preparsed)",
m.State, m.Location, m.Duration,
m.IsPreparsed ? "" : "not ");
}
private static void WriteMediaState (Media m, State s)
{
Console.WriteLine (" -> {0}", s);
}
private static void DumpPlayer (Player p)
{
if (!p.IsPlaying)
return;
int percent = (int)(p.Position * 100);
Console.Write ("{0}: {1} of {2} ms ({3}%)\r", p.State,
p.Time, p.Length, percent);
}
private static void Sleep (int msec)
{
System.Threading.Thread.Sleep (msec);
}
public static int Main (string[] args)
{
string[] argv = new string[]{
"-vv", "-I", "dummy", "--plugin-path=../../modules"
};
Console.WriteLine ("Running on LibVLC {0} ({1})", VLC.Version,
VLC.ChangeSet);
Console.WriteLine (" (compiled with {0})", VLC.Compiler);
VLC vlc = new VLC (argv);
foreach (string mrl in args)
{
Media media = new Media (vlc, mrl);
Player player = new Player (media);
DumpMedia (media);
DumpMedia ((Media)media.Clone ());
media.StateChanged += WriteMediaState;
/*foreach (MetaType type in Enum.GetValues (typeof (MetaType)))
{
string meta = media.GetMeta (type);
if (meta != null)
Console.WriteLine (" {0}: {1}", type, meta);
}*/
player.Play ();
do
{
DumpPlayer (player);
Sleep (500);
}
while (player.IsPlaying);
player.Stop ();
media.Dispose ();
player.Dispose ();
}
vlc.Dispose ();
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