Commit dfc12b7c authored by Martin Finkel's avatar Martin Finkel

fix chromecast marshalling

parent d5301649
......@@ -12,53 +12,52 @@ namespace LibVLCSharp.Tests
[TestFixture]
public class RendererDiscovererTests : BaseSetup
{
// This test depends on both accepting the network access request made by the test runner
// and having a chromecast on the same local network.
[Test]
public async Task DiscoverItems()
{
Core.Initialize();
var instance = new Instance(new []{"--verbose=2"});
instance.Log += (sender, args) =>
{
WriteLine(args.Message);
};
var instance = new Instance();
var mp = new MediaPlayer(instance)
{
Media = new Media(instance, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4",
Media.FromType.FromLocation)
};
// Assert.True(mp.Play());
Assert.True(mp.Play());
var rendererList = instance.RendererList;
Assert.IsNotEmpty(rendererList);
var rendererDiscoverer = new RendererDiscoverer(instance, /*"microdns"*/ rendererList[0].Name);
var rendererDiscoverer = new RendererDiscoverer(instance, rendererList[0].Name);
var rendererItems = new List<RendererItem>();
var tcs = new TaskCompletionSource<bool>();
rendererDiscoverer.EventManager.ItemAdded += (sender, args) =>
{
WriteLine($"New item discovered: {args.RendererItem.Name} of type {args.RendererItem.Type}");
if(args.RendererItem.CanRenderVideo)
if (args.RendererItem.CanRenderVideo)
WriteLine("Can render video");
if(args.RendererItem.CanRenderAudio)
if (args.RendererItem.CanRenderAudio)
WriteLine("Can render audio");
tcs.SetResult(true);
rendererItems.Add(args.RendererItem);
tcs.SetResult(true);
};
Assert.True(rendererDiscoverer.Start());
//await Task.Delay(10000);
await tcs.Task;
Assert.True(tcs.Task.Result);
Assert.IsNotEmpty(rendererItems);
Assert.True(mp.SetRenderer(rendererItems.First()));
Console.ReadKey();
await Task.Delay(10000);
}
}
}
}
\ No newline at end of file
......@@ -1424,13 +1424,13 @@ namespace VideoLAN.LibVLC
void OnItemDeleted(IntPtr args)
{
var rendererItem = RetrieveEvent(args).Union.RendererDiscovererItemDeleted.Item;
var rendererItem = RetrieveEvent(args).RendererItem;
_itemDeleted?.Invoke(this, new RendererDiscovererItemDeletedEventArgs(new RendererItem(rendererItem)));
}
void OnItemAdded(IntPtr args)
{
var rendererItem = RetrieveEvent(args).Union.RendererDiscovererItemAdded.Item;
var rendererItem = RetrieveEvent(args).RendererItem;
_itemAdded?.Invoke(this, new RendererDiscovererItemAddedEventArgs(new RendererItem(rendererItem)));
}
}
......
......@@ -160,6 +160,7 @@ namespace VideoLAN.LibVLC.Events
public EventType Type;
public IntPtr Sender;
public IntPtr RendererItem;
public EventUnion Union;
......@@ -200,10 +201,6 @@ namespace VideoLAN.LibVLC.Events
// vlm
public VlmMediaEvent VlmMediaEvent;
// renderer
public RendererDiscovererItemAdded RendererDiscovererItemAdded;
public RendererDiscovererItemDeleted RendererDiscovererItemDeleted;
}
#region Media
......@@ -363,18 +360,8 @@ namespace VideoLAN.LibVLC.Events
public IntPtr MediaName;
public IntPtr InstanceName;
}
public struct RendererDiscovererItemAdded
{
public IntPtr Item;
}
public struct RendererDiscovererItemDeleted
{
public IntPtr Item;
}
}
#region Media events
public class MediaMetaChangedEventArgs : EventArgs
......
......@@ -64,13 +64,14 @@ namespace VideoLAN.LibVLC
{
const int VideoRenderer = 0x0002;
const int AudioRenderer = 0x0001;
readonly ICustomMarshaler _utf8Marshaler = Utf8StringMarshaler.GetInstance();
struct Native
{
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_renderer_item_name")]
internal static extern string LibVLCRendererItemName(IntPtr rendererItem);
internal static extern IntPtr LibVLCRendererItemName(IntPtr rendererItem);
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
......@@ -85,12 +86,12 @@ namespace VideoLAN.LibVLC
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_renderer_item_type")]
internal static extern string LibVLCRendererItemType(IntPtr rendererItem);
internal static extern IntPtr LibVLCRendererItemType(IntPtr rendererItem);
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_renderer_item_icon_uri")]
internal static extern string LibVLCRendererItemIconUri(IntPtr rendererItem);
internal static extern IntPtr LibVLCRendererItemIconUri(IntPtr rendererItem);
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
......@@ -98,16 +99,17 @@ namespace VideoLAN.LibVLC
internal static extern int LibVLCRendererItemFlags(IntPtr rendererItem);
}
public RendererItem(IntPtr reference) : base(() => reference, Native.LibVLCRendererItemRelease)
public RendererItem(IntPtr reference) :
base(() => reference, Native.LibVLCRendererItemRelease)
{
Native.LibVLCRendererItemHold(reference); //fail
Native.LibVLCRendererItemHold(reference);
}
public string Name => Native.LibVLCRendererItemName(NativeReference);
public string Name => _utf8Marshaler.MarshalNativeToManaged(Native.LibVLCRendererItemName(NativeReference)) as string;
public string Type => Native.LibVLCRendererItemType(NativeReference);
public string Type => _utf8Marshaler.MarshalNativeToManaged(Native.LibVLCRendererItemType(NativeReference)) as string;
public string IconUri => Native.LibVLCRendererItemIconUri(NativeReference);
public string IconUri => _utf8Marshaler.MarshalNativeToManaged(Native.LibVLCRendererItemIconUri(NativeReference)) as string;
public bool CanRenderVideo => (Native.LibVLCRendererItemFlags(NativeReference) & VideoRenderer) != 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