Commit 8c15518c authored by Martin Finkel's avatar Martin Finkel

move marshalling func to util class

parent 4e07fc09
......@@ -496,7 +496,7 @@ namespace VideoLAN.LibVLC
{
get
{
return Retrieve(() => Native.LibVLCAudioFilterListGet(NativeReference),
return MarshalUtils.Retrieve(() => Native.LibVLCAudioFilterListGet(NativeReference),
Marshal.PtrToStructure<ModuleDescription.Internal>,
intern => ModuleDescription.__CreateInstance(intern),
module => module.Next, Native.LibVLCModuleDescriptionListRelease);
......@@ -516,7 +516,7 @@ namespace VideoLAN.LibVLC
{
get
{
return Retrieve(() => Native.LibVLCVideoFilterListGet(NativeReference),
return MarshalUtils.Retrieve(() => Native.LibVLCVideoFilterListGet(NativeReference),
Marshal.PtrToStructure<ModuleDescription.Internal>,
intern => ModuleDescription.__CreateInstance(intern),
module => module.Next, Native.LibVLCModuleDescriptionListRelease);
......@@ -534,7 +534,7 @@ namespace VideoLAN.LibVLC
{
get
{
return Retrieve(() => Native.LibVLCAudioOutputListGet(NativeReference),
return MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputListGet(NativeReference),
Marshal.PtrToStructure<AudioOutputDescription.Internal>,
intern => AudioOutputDescription.__CreateInstance(intern),
module => module.Next, Native.LibVLCAudioOutputListRelease);
......@@ -565,7 +565,7 @@ namespace VideoLAN.LibVLC
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName)
{
return Retrieve(() => Native.LibVLCAudioOutputDeviceListGet(NativeReference, audioOutputName),
return MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputDeviceListGet(NativeReference, audioOutputName),
Marshal.PtrToStructure<AudioOutputDevice.Internal>,
s => AudioOutputDevice.__CreateInstance(s),
device => device.Next, Native.LibVLCAudioOutputDeviceListRelease);
......@@ -659,26 +659,6 @@ namespace VideoLAN.LibVLC
public bool DialogHandlersSet => _dialogCbsPtr != IntPtr.Zero;
static TU[] Retrieve<T, TU>(Func<IntPtr> getRef, Func<IntPtr, T> retrieve,
Func<T, TU> create, Func<TU, TU> next, Action<IntPtr> releaseRef)
{
var nativeRef = getRef();
if (nativeRef == IntPtr.Zero) return Array.Empty<TU>();
var structure = retrieve(nativeRef);
var obj = create(structure);
var resultList = new List<TU>();
while (obj != null)
{
resultList.Add(obj);
obj = next(obj);
}
releaseRef(nativeRef);
return resultList.ToArray();
}
/// <summary>
/// Code taken from Vlc.DotNet
/// </summary>
......
using System;
using System.Collections.Generic;
namespace VideoLAN.LibVLC
{
public static class MarshalUtils
{
public static TU[] Retrieve<T, TU>(Func<IntPtr> getRef, Func<IntPtr, T> retrieve,
Func<T, TU> create, Func<TU, TU> next, Action<IntPtr> releaseRef)
{
var nativeRef = getRef();
if (nativeRef == IntPtr.Zero) return Array.Empty<TU>();
var structure = retrieve(nativeRef);
var obj = create(structure);
var resultList = new List<TU>();
while (obj != null)
{
resultList.Add(obj);
obj = next(obj);
}
releaseRef(nativeRef);
return resultList.ToArray();
}
}
}
\ No newline at end of file
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