Commit e8b3f3f7 authored by Martin Finkel's avatar Martin Finkel

cleanup

parent d650da4b
......@@ -90,10 +90,9 @@ namespace Bindings.Tests
public void Categories()
{
var instance = new Instance(0, null);
//var md1 = instance.MediaDiscoverers(MediaDiscovererCategory.Devices);
var md1 = instance.MediaDiscoverers(MediaDiscovererCategory.Devices);
var md2 = instance.MediaDiscoverers(MediaDiscovererCategory.Lan);
//var md3 = instance.MediaDiscoverers(MediaDiscovererCategory.Localdirs);
var md3 = instance.MediaDiscoverers(MediaDiscovererCategory.Localdirs);
}
}
}
\ No newline at end of file
......@@ -402,15 +402,14 @@ namespace libvlcsharp
device => device.Next, Internal.LibVLCAudioOutputDeviceListRelease);
}
//https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__discoverer.html#ga9a4676e452daa2fd4b5eb371542afc29
// code inspired from https://code.videolan.org/videolan/libvlcpp/blob/master/vlcpp/Instance.hpp
// https://stackoverflow.com/questions/13457375/how-do-i-call-an-unmanaged-function-that-has-a-char-as-out-parameter-from-c
// https://stackoverflow.com/questions/11131676/how-do-i-marshall-a-pointer-to-a-pointer-of-an-array-of-structures
/// <summary>Get media discoverer services by category</summary>
/// <param name="category">category of services to fetch</param>
/// <returns>the number of media discoverer services (0 on error)</returns>
/// <remarks>LibVLC 3.0.0 and later.</remarks>
public IEnumerable<MediaDiscovererDescription> MediaDiscoverers(MediaDiscovererCategory category)
{
var arrayResultPtr = IntPtr.Zero;
var count = Internal.LibVLCMediaDiscovererListGet(NativeReference, category, ref arrayResultPtr);
//var count = Internal.LibVLCMediaDiscovererListGet(NativeReference, category, out var arrayResultPtr).ToInt32();
if (count == 0) return Enumerable.Empty<MediaDiscovererDescription>();
......@@ -419,11 +418,8 @@ namespace libvlcsharp
for (var i = 0; i < (int)count; i++)
{
var ptr = Marshal.ReadIntPtr(arrayResultPtr, i * IntPtr.Size);
var s = (MediaDiscovererDescription.Internal) Marshal.PtrToStructure(ptr, typeof(MediaDiscovererDescription.Internal));
var mdd = MediaDiscovererDescription.__CreateInstance(s);
Debug.WriteLine(mdd.Longname);
Debug.WriteLine(mdd.Name);
var managedStruct = (MediaDiscovererDescription.Internal) Marshal.PtrToStructure(ptr, typeof(MediaDiscovererDescription.Internal));
var mdd = MediaDiscovererDescription.__CreateInstance(managedStruct);
mediaDiscovererDescription[i] = mdd;
}
......@@ -431,37 +427,7 @@ namespace libvlcsharp
return mediaDiscovererDescription;
}
/// <summary>Get media discoverer services by category</summary>
/// <param name="p_inst">libvlc instance</param>
/// <param name="i_cat">category of services to fetch</param>
/// <param name="ppp_services">
/// <para>address to store an allocated array of media discoverer</para>
/// <para>services (must be freed with libvlc_media_discoverer_list_release() by</para>
/// <para>the caller) [OUT]</para>
/// </param>
/// <returns>the number of media discoverer services (0 on error)</returns>
/// <remarks>LibVLC 3.0.0 and later.</remarks>
//private ulong LibvlcMediaDiscovererListGet(global::libvlcsharp.Instance p_inst, global::libvlcsharp.MediaDiscovererCategory i_cat, global::libvlcsharp.MediaDiscovererDescription ppp_services)
//{
// var __arg0 = ReferenceEquals(p_inst, null) ? global::System.IntPtr.Zero : p_inst.NativeReference;
// var __arg2 = ReferenceEquals(ppp_services, null) ? global::System.IntPtr.Zero : ppp_services.NativeReference;
// var __ret = __Internal.LibvlcMediaDiscovererListGet(__arg0, i_cat, __arg2);
// return __ret;
//}
/// <summary>Release an array of media discoverer services</summary>
/// <param name="ppServices">array to release</param>
/// <param name="count">number of elements in the array</param>
/// <remarks>
/// <para>LibVLC 3.0.0 and later.</para>
/// <para>libvlc_media_discoverer_list_get()</para>
/// </remarks>
private void ReleaseMediaDiscovererList(MediaDiscovererDescription ppServices, ulong count)
{
Internal.LibVLCMediaDiscovererListRelease(ppServices.NativeReference, count);
}
public void SetDialogHandlers()
{
}
......
......@@ -88,25 +88,16 @@ namespace libvlcsharp
/// <summary>Media discoverer description</summary>
/// <remarks>libvlc_media_discoverer_list_get()</remarks>
public unsafe partial class MediaDiscovererDescription //: IDisposable
public unsafe class MediaDiscovererDescription //: IDisposable
{
[StructLayout(LayoutKind.Sequential)]
public struct Internal
{
//[FieldOffset(0)]
internal IntPtr psz_name;
//[FieldOffset(8)]
internal IntPtr psz_longname;
//[FieldOffset(16)]
//internal IntPtr i_cat;
internal int i_cat;
//[SuppressUnmanagedCodeSecurity]
//[DllImport("libvlc", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
// EntryPoint="??0libvlc_media_discoverer_description_t@@QEAA@AEBU0@@Z")]
//internal static extern global::System.IntPtr cctor(global::System.IntPtr instance, global::System.IntPtr _0);
}
public IntPtr NativeReference { get; protected set; }
......@@ -179,25 +170,9 @@ namespace libvlcsharp
NativeReference = IntPtr.Zero;
}
public string Name
{
get
{
//Encoding.UTF8.GetBytes(((Internal*)NativeReference)->psz_name))
var r2 = (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(((Internal*)NativeReference)->psz_name);
//var r2 = Marshal.PtrToStringAuto(((Internal*)NativeReference)->psz_name);
var r1 = Marshal.PtrToStringAnsi(((Internal*)NativeReference)->psz_name);
return r1;
//var r4 = Marshal.PtrToStringUni(((Internal*)NativeReference)->psz_name);
//return r3;
}
}
//=> (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(((Internal*)NativeReference)->psz_name);
public string Name => (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(((Internal*)NativeReference)->psz_name);
public string Longname => (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(((Internal*)NativeReference)->psz_longname);
//public string Longname => Marshal.PtrToStringAnsi(((Internal*)NativeReference)->psz_longname);
//public MediaDiscovererCategory Category => (MediaDiscovererCategory) ((Internal*) NativeReference)->i_cat;
public MediaDiscovererCategory Category => (MediaDiscovererCategory)((Internal*)NativeReference)->i_cat;
}
public unsafe partial class libvlc_media_discoverer
......
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