Commit 45ea01f1 authored by Martin Finkel's avatar Martin Finkel

Media: Add libvlc option extra param to constructors

parent d709e6d9
......@@ -154,15 +154,26 @@ namespace LibVLCSharp.Shared
EntryPoint = "libvlc_media_get_codec_description")]
internal static extern IntPtr LibvlcMediaGetCodecDescription(TrackType type, uint codec);
}
Media(Func<IntPtr> create, Action<IntPtr> release, params string[] options)
: base(create, release)
{
if(options == null) return;
foreach(var optionUtf8 in options.ToUtf8())
if(optionUtf8 != IntPtr.Zero)
MarshalUtils.PerformInteropAndFree(() => Native.LibVLCMediaAddOption(NativeReference, optionUtf8), optionUtf8);
}
/// <summary>
/// Media Constructs a libvlc Media instance
/// </summary>
/// <param name="libVLC">A libvlc instance</param>
/// <param name="mrl">A path, location, or node name, depending on the 3rd parameter</param>
/// <param name="type">The type of the 2nd argument.</param>
public Media(LibVLC libVLC, string mrl, FromType type = FromType.FromPath)
: base(() => SelectNativeCtor(libVLC, mrl, type), Native.LibVLCMediaRelease)
/// <param name="options">the libvlc options</param>
public Media(LibVLC libVLC, string mrl, FromType type = FromType.FromPath, params string[] options)
: this(() => SelectNativeCtor(libVLC, mrl, type), Native.LibVLCMediaRelease, options)
{
}
......@@ -171,40 +182,12 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="libVLC">A libvlc instance</param>
/// <param name="uri">The absolute URI of the resource.</param>
public Media(LibVLC libVLC, Uri uri)
: base(() => SelectNativeCtor(libVLC, uri?.AbsoluteUri ?? string.Empty, FromType.FromLocation), Native.LibVLCMediaRelease)
{
}
static IntPtr SelectNativeCtor(LibVLC libVLC, string mrl, FromType type)
/// <param name="options">the libvlc options</param>
public Media(LibVLC libVLC, Uri uri, params string[] options)
: this(() => SelectNativeCtor(libVLC, uri?.AbsoluteUri ?? string.Empty, FromType.FromLocation),
Native.LibVLCMediaRelease,
options)
{
if (libVLC == null) throw new ArgumentNullException(nameof(libVLC));
if (string.IsNullOrEmpty(mrl)) throw new ArgumentNullException(nameof(mrl));
var mrlPtr = mrl.ToUtf8();
if (mrlPtr == IntPtr.Zero)
throw new ArgumentException($"error marshalling {mrl} to UTF-8 for native interop");
IntPtr result;
switch (type)
{
case FromType.FromLocation:
result = Native.LibVLCMediaNewLocation(libVLC.NativeReference, mrlPtr);
break;
case FromType.FromPath:
result = Native.LibVLCMediaNewPath(libVLC.NativeReference, mrlPtr);
break;
case FromType.AsNode:
result = Native.LibVLCMediaNewAsNode(libVLC.NativeReference, mrlPtr);
break;
default:
result = IntPtr.Zero;
break;
}
Marshal.FreeHGlobal(mrlPtr);
return result;
}
/// <summary>
......@@ -217,7 +200,7 @@ namespace LibVLCSharp.Shared
/// Directory descriptors are supported on systems that provide fdopendir().
/// Sockets are supported on all platforms where they are file descriptors,
/// i.e.all except Windows.
///
///
/// \note This library will <b>not</b> automatically close the file descriptor
/// under any circumstance.Nevertheless, a file descriptor can usually only be
/// rendered once in a media player.To render it a second time, the file
......@@ -225,8 +208,9 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="libVLC">A libvlc instance</param>
/// <param name="fd">open file descriptor</param>
public Media(LibVLC libVLC, int fd)
: base(() => Native.LibVLCMediaNewFd(libVLC.NativeReference, fd), Native.LibVLCMediaRelease)
/// <param name="options">the libvlc options</param>
public Media(LibVLC libVLC, int fd, params string[] options)
: this(() => Native.LibVLCMediaNewFd(libVLC.NativeReference, fd), Native.LibVLCMediaRelease, options)
{
}
......@@ -244,24 +228,58 @@ namespace LibVLCSharp.Shared
/// requires libvlc 3.0 or higher
/// </summary>
/// <param name="libVLC">the libvlc instance</param>
/// <param name="input">the media to be used by libvlc. LibVLCSharp will NOT dispose or close it.
/// <param name="input">the media to be used by libvlc. LibVLCSharp will NOT dispose or close it.
/// Use <see cref="StreamMediaInput"/> or implement your own.</param>
/// <param name="options">the libvlc options</param>
public Media(LibVLC libVLC, MediaInput input, params string[] options)
: base(() => CtorFromInput(libVLC, input), Native.LibVLCMediaRelease)
: this(() => CtorFromInput(libVLC, input), Native.LibVLCMediaRelease, options)
{
foreach(var option in options)
{
var optionUtf8 = option.ToUtf8();
}
internal Media(IntPtr mediaPtr)
: base(() => mediaPtr, Native.LibVLCMediaRelease)
{
}
static IntPtr SelectNativeCtor(LibVLC libVLC, string mrl, FromType type)
{
if (libVLC == null)
throw new ArgumentNullException(nameof(libVLC));
if (string.IsNullOrEmpty(mrl))
throw new ArgumentNullException(nameof(mrl));
var mrlPtr = mrl.ToUtf8();
if (mrlPtr == IntPtr.Zero)
throw new ArgumentException($"error marshalling {mrl} to UTF-8 for native interop");
MarshalUtils.PerformInteropAndFree(() => Native.LibVLCMediaAddOption(NativeReference, optionUtf8), optionUtf8);
IntPtr result;
switch (type)
{
case FromType.FromLocation:
result = Native.LibVLCMediaNewLocation(libVLC.NativeReference, mrlPtr);
break;
case FromType.FromPath:
result = Native.LibVLCMediaNewPath(libVLC.NativeReference, mrlPtr);
break;
case FromType.AsNode:
result = Native.LibVLCMediaNewAsNode(libVLC.NativeReference, mrlPtr);
break;
default:
result = IntPtr.Zero;
break;
}
Marshal.FreeHGlobal(mrlPtr);
return result;
}
static IntPtr CtorFromInput(LibVLC libVLC, MediaInput input)
{
if (libVLC == null) throw new ArgumentNullException(nameof(libVLC));
if (input == null) throw new ArgumentNullException(nameof(input));
if (libVLC == null)
throw new ArgumentNullException(nameof(libVLC));
if (input == null)
throw new ArgumentNullException(nameof(input));
return Native.LibVLCMediaNewCallbacks(libVLC.NativeReference,
OpenMediaCallbackHandle,
......@@ -271,11 +289,6 @@ namespace LibVLCSharp.Shared
GCHandle.ToIntPtr(input.GcHandle));
}
internal Media(IntPtr mediaPtr)
: base(() => mediaPtr, Native.LibVLCMediaRelease)
{
}
/// <summary>Add an option to the media.</summary>
/// <param name="option">the media option</param>
/// <remarks>
......
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