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

Fix TrackDescription retrieval

parent 9ef18f69
......@@ -41,16 +41,25 @@ namespace Bindings.Tests
}
[Test]
public void TrackDescription()
public async Task TrackDescription()
{
//FIX ME
var instance = new Instance();
var mp = new MediaPlayer(instance);
var media = new Media(instance, RealMediaPath, Media.FromType.FromPath);
var tcs = new TaskCompletionSource<bool>();
mp.Media = media;
var track = mp.AudioTrack;
Assert.True(mp.SetAudioTrack(track));
Assert.IsNotEmpty(mp.AudioTrackDescription);
mp.Play();
mp.EventManager.Playing += (sender, args) =>
{
Assert.Zero(mp.AudioTrack);
var description = mp.AudioTrackDescription;
Assert.True(mp.SetAudioTrack(description.First().Id));
Assert.IsNotEmpty(description);
tcs.SetResult(true);
};
await tcs.Task;
Assert.True(tcs.Task.Result);
}
[Test]
......
......@@ -411,13 +411,13 @@ namespace VideoLAN.LibVLC
//}
/// <remarks>Use libvlc_track_description_list_release() instead</remarks>
public static void LibvlcTrackDescriptionRelease(global::VideoLAN.LibVLC.TrackDescription p_track_description)
{
var __arg0 = ReferenceEquals(p_track_description, null)
? global::System.IntPtr.Zero
: p_track_description.__Instance;
__Internal.LibvlcTrackDescriptionRelease(__arg0);
}
//public static void LibvlcTrackDescriptionRelease(global::VideoLAN.LibVLC.TrackDescription p_track_description)
//{
// var __arg0 = ReferenceEquals(p_track_description, null)
// ? global::System.IntPtr.Zero
// : p_track_description.__Instance;
// __Internal.LibvlcTrackDescriptionRelease(__arg0);
//}
/// <summary>Get current video height.</summary>
/// <param name="p_mi">the media player</param>
......
......@@ -204,145 +204,6 @@ namespace VideoLAN.LibVLC
}
}
/// <summary>
/// <para>Description for video, audio tracks and subtitles. It contains</para>
/// <para>id, name (description string) and pointer to next record.</para>
/// </summary>
public unsafe partial class TrackDescription : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
public partial struct __Internal
{
[FieldOffset(0)]
internal int i_id;
[FieldOffset(8)]
internal global::System.IntPtr psz_name;
[FieldOffset(16)]
internal global::System.IntPtr p_next;
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0libvlc_track_description_t@@QEAA@AEBU0@@Z")]
internal static extern global::System.IntPtr cctor(global::System.IntPtr instance, global::System.IntPtr _0);
}
public global::System.IntPtr __Instance { get; protected set; }
protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.TrackDescription> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.TrackDescription>();
protected void*[] __OriginalVTables;
protected bool __ownsNativeInstance;
internal static global::VideoLAN.LibVLC.TrackDescription __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.TrackDescription(native.ToPointer(), skipVTables);
}
internal static global::VideoLAN.LibVLC.TrackDescription __CreateInstance(global::VideoLAN.LibVLC.TrackDescription.__Internal native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.TrackDescription(native, skipVTables);
}
private static void* __CopyValue(global::VideoLAN.LibVLC.TrackDescription.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.TrackDescription.__Internal));
*(global::VideoLAN.LibVLC.TrackDescription.__Internal*) ret = native;
return ret.ToPointer();
}
private TrackDescription(global::VideoLAN.LibVLC.TrackDescription.__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
protected TrackDescription(void* native, bool skipVTables = false)
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
}
public TrackDescription()
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.TrackDescription.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
public TrackDescription(global::VideoLAN.LibVLC.TrackDescription _0)
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.TrackDescription.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance) = *((global::VideoLAN.LibVLC.TrackDescription.__Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
}
public virtual void Dispose(bool disposing)
{
if (__Instance == IntPtr.Zero)
return;
global::VideoLAN.LibVLC.TrackDescription __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__Instance = IntPtr.Zero;
}
public int IId
{
get
{
return ((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->i_id;
}
set
{
((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->i_id = value;
}
}
public sbyte* PszName
{
get
{
return (sbyte*) ((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->psz_name;
}
set
{
((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->psz_name = (global::System.IntPtr) value;
}
}
public global::VideoLAN.LibVLC.TrackDescription PNext
{
get
{
global::VideoLAN.LibVLC.TrackDescription __result0;
if (((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->p_next == IntPtr.Zero) __result0 = null;
else if (global::VideoLAN.LibVLC.TrackDescription.NativeToManagedMap.ContainsKey(((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->p_next))
__result0 = (global::VideoLAN.LibVLC.TrackDescription) global::VideoLAN.LibVLC.TrackDescription.NativeToManagedMap[((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->p_next];
else __result0 = global::VideoLAN.LibVLC.TrackDescription.__CreateInstance(((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->p_next);
return __result0;
}
set
{
((global::VideoLAN.LibVLC.TrackDescription.__Internal*) __Instance)->p_next = ReferenceEquals(value, null) ? global::System.IntPtr.Zero : value.__Instance;
}
}
}
public unsafe partial class TitleDescription : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 24)]
......
......@@ -1137,11 +1137,19 @@ namespace VideoLAN.LibVLC.Manual
if (trackPtr == IntPtr.Zero) return Array.Empty<TrackDescription>();
var trackDescriptions = new List<TrackDescription>();
var tracks = Marshal.PtrToStructure<TrackDescription>(trackPtr);
while (tracks != null)
{
trackDescriptions.Add(tracks);
tracks = tracks.PNext;
var track = Marshal.PtrToStructure<TrackDescription>(trackPtr);
while (true)
{
trackDescriptions.Add(track);
if (track.Next != IntPtr.Zero)
{
track = Marshal.PtrToStructure<TrackDescription>(track.Next);
}
else
{
break;
}
}
return trackDescriptions.ToArray();
}
......
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
namespace VideoLAN.LibVLC
{
/// <summary>
/// <para>Description for video, audio tracks and subtitles. It contains</para>
/// <para>id, name (description string) and pointer to next record.</para>
/// </summary>
public struct TrackDescription
{
public int Id { get; set; }
public string Name { get; set; }
public IntPtr Next { get; set; }
public override bool Equals(object obj)
{
if (!(obj is TrackDescription))
{
return false;
}
var description = (TrackDescription)obj;
return Id == description.Id &&
Name == description.Name &&
EqualityComparer<IntPtr>.Default.Equals(Next, description.Next);
}
}
}
\ 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