Commit 4e07fc09 authored by Martin Finkel's avatar Martin Finkel

libvlc_renderer_item_hold call is currently failing

parent 49e3d4aa
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using VideoLAN.LibVLC;
using static System.Diagnostics.Debug;
......@@ -9,12 +10,13 @@ namespace LibVLCSharp.Tests
public class RendererDiscovererTests
{
[Test]
public async Task T()
public async Task DiscoverItems()
{
var instance = new Instance();
var rendererDiscoverer = new RendererDiscoverer(instance, "microdns");
var em = rendererDiscoverer.EventManager;
var itemAdded = false;
em.ItemAdded += (sender, args) =>
{
......@@ -23,12 +25,22 @@ namespace LibVLCSharp.Tests
WriteLine("Can render video");
if(args.RendererItem.CanRenderAudio)
WriteLine("Can render audio");
itemAdded = true;
};
if(!rendererDiscoverer.Start())
NUnit.Framework.Assert.Fail();
await Task.Delay(1000);
await Task.Delay(10000);
NUnit.Framework.Assert.True(itemAdded);
}
[Test]
public void RetrieveListInformation()
{
var rd = new RendererDiscoverer(new Instance(), "rd");
NUnit.Framework.Assert.Positive(rd.List.Length);
}
}
}
......@@ -6,6 +6,8 @@ namespace VideoLAN.LibVLC
{
public class RendererDiscoverer : Internal
{
readonly IntPtr _instanceNativeReference;
struct Native
{
[SuppressUnmanagedCodeSecurity]
......@@ -36,17 +38,18 @@ namespace VideoLAN.LibVLC
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_renderer_discoverer_list_get")]
internal static extern UIntPtr LibVLCRendererDiscovererGetList(IntPtr instance, out IntPtr discovererList);
internal static extern ulong LibVLCRendererDiscovererGetList(IntPtr instance, ref IntPtr discovererList);
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_renderer_discoverer_list_release")]
internal static extern void LibVLCRendererDiscovererReleaseList(IntPtr discovererList, UIntPtr count);
internal static extern void LibVLCRendererDiscovererReleaseList(IntPtr discovererList, ulong count);
}
public RendererDiscoverer(Instance instance, string name)
: base(() => Native.LibVLCRendererDiscovererNew(instance.NativeReference, name), Native.LibVLCRendererDiscovererRelease)
{
_instanceNativeReference = instance.NativeReference;
}
RendererDiscovererEventManager _eventManager;
......@@ -67,6 +70,42 @@ namespace VideoLAN.LibVLC
public bool Start() => Native.LibVLCRendererDiscovererStart(NativeReference) == 0;
public void Stop() => Native.LibVLCRendererDiscovererStop(NativeReference);
public Description[] List
{
get
{
var discoverList = IntPtr.Zero;
var count = Native.LibVLCRendererDiscovererGetList(_instanceNativeReference, ref discoverList);
if (count == 0) return Array.Empty<Description>();
var rendererDiscovererDescription = new Description[(int)count];
for (var i = 0; i < (int)count; i++)
{
var ptr = Marshal.ReadIntPtr(discoverList, i * IntPtr.Size);
var managedStruct = (Description)Marshal.PtrToStructure(ptr, typeof(Description));
rendererDiscovererDescription[i] = managedStruct;
}
Native.LibVLCRendererDiscovererReleaseList(discoverList, count);
return rendererDiscovererDescription;
}
}
public struct Description
{
public string Name { get; }
public string LongName { get; }
public Description(string name, string longName)
{
Name = name;
LongName = longName;
}
}
}
public class RendererItem : Internal
......@@ -109,7 +148,7 @@ namespace VideoLAN.LibVLC
public RendererItem(IntPtr reference) : base(() => reference, Native.LibVLCRendererItemRelease)
{
Native.LibVLCRendererItemHold(reference);
Native.LibVLCRendererItemHold(reference); //fail
}
public string Name => Native.LibVLCRendererItemName(NativeReference);
......
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