Commit c83ced1e authored by Martin Finkel's avatar Martin Finkel

Added more tests, cleanup track structs

parent 8f30c533
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using VideoLAN.LibVLC;
......@@ -48,5 +50,56 @@ namespace Bindings.Tests
var media = new Media(new Instance(), new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate));
media.AddOption("-sout-all");
}
[Test]
public void CreateRealMedia()
{
var instance = new Instance();
var media = new Media(instance, RealMediaPath, Media.FromType.FromPath);
Assert.False(media.IsParsed);
media.Parse();
//media.ParseAsync();
Assert.True(media.IsParsed);
Assert.NotZero(media.Duration);
Assert.NotZero(media.Tracks.First().Data.Audio.Channels);
Assert.AreEqual(Media.MediaParsedStatus.Done, media.ParsedStatus);
Assert.AreEqual(Media.MediaType.File, media.Type);
}
string RealMediaPath
{
get
{
var dir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var binDir = Path.Combine(dir, "..\\..\\..\\");
var files = Directory.GetFiles(binDir);
return files.First();
}
}
[Test]
public void Duplicate()
{
var media = new Media(new Instance(), new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate));
var duplicate = media.Duplicate();
Assert.AreNotEqual(duplicate.NativeReference, media.NativeReference);
}
[Test]
public void CreateMediaFromFileStream()
{
// TODO: fix this.
var media = new Media(new Instance(), new FileStream(RealMediaPath, FileMode.OpenOrCreate));
}
[Test]
public void SetMetadata()
{
var media = new Media(new Instance(), Path.GetTempFileName(), Media.FromType.FromPath);
const string test = "test";
media.SetMeta(Media.MetadataType.ShowName, test);
Assert.True(media.SaveMeta());
Assert.AreEqual(test, media.Meta(Media.MetadataType.ShowName));
}
}
}
......@@ -393,448 +393,47 @@ namespace VideoLAN.LibVLC
}
}
public unsafe partial class AudioTrack : IDisposable
public struct AudioTrack
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
public partial struct __Internal
{
[FieldOffset(0)]
internal uint i_channels;
[FieldOffset(4)]
internal uint i_rate;
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0libvlc_audio_track_t@@QEAA@AEBU0@@Z")]
internal static extern global::System.IntPtr cctor(global::System.IntPtr instance, global::System.IntPtr _0);
}
public uint Channels;
public uint Rate;
}
public global::System.IntPtr __Instance { get; protected set; }
protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.AudioTrack> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.AudioTrack>();
protected void*[] __OriginalVTables;
public struct VideoTrack
{
public uint Height;
protected bool __ownsNativeInstance;
public uint Width;
internal static global::VideoLAN.LibVLC.AudioTrack __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.AudioTrack(native.ToPointer(), skipVTables);
}
public uint SarNum;
internal static global::VideoLAN.LibVLC.AudioTrack __CreateInstance(global::VideoLAN.LibVLC.AudioTrack.__Internal native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.AudioTrack(native, skipVTables);
}
public uint SarDen;
private static void* __CopyValue(global::VideoLAN.LibVLC.AudioTrack.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.AudioTrack.__Internal));
*(global::VideoLAN.LibVLC.AudioTrack.__Internal*) ret = native;
return ret.ToPointer();
}
public uint FrameRateNum;
private AudioTrack(global::VideoLAN.LibVLC.AudioTrack.__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
public uint FrameRateDen;
protected AudioTrack(void* native, bool skipVTables = false)
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
}
public VideoOrientation Orientation;
public AudioTrack()
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.AudioTrack.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
public VideoProjection Projection;
public AudioTrack(global::VideoLAN.LibVLC.AudioTrack _0)
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.AudioTrack.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::VideoLAN.LibVLC.AudioTrack.__Internal*) __Instance) = *((global::VideoLAN.LibVLC.AudioTrack.__Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
}
public virtual void Dispose(bool disposing)
{
if (__Instance == IntPtr.Zero)
return;
global::VideoLAN.LibVLC.AudioTrack __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__Instance = IntPtr.Zero;
}
public uint IChannels
{
get
{
return ((global::VideoLAN.LibVLC.AudioTrack.__Internal*) __Instance)->i_channels;
}
set
{
((global::VideoLAN.LibVLC.AudioTrack.__Internal*) __Instance)->i_channels = value;
}
}
public uint IRate
{
get
{
return ((global::VideoLAN.LibVLC.AudioTrack.__Internal*) __Instance)->i_rate;
}
set
{
((global::VideoLAN.LibVLC.AudioTrack.__Internal*) __Instance)->i_rate = value;
}
}
public VideoViewpoint Pose;
}
public unsafe partial class VideoTrack : IDisposable
/// <summary>Viewpoint for video outputs</summary>
/// <remarks>allocate using libvlc_video_new_viewpoint()</remarks>
public struct VideoViewpoint
{
[StructLayout(LayoutKind.Explicit, Size = 48)]
public partial struct __Internal
{
[FieldOffset(0)]
internal uint i_height;
[FieldOffset(4)]
internal uint i_width;
[FieldOffset(8)]
internal uint i_sar_num;
[FieldOffset(12)]
internal uint i_sar_den;
[FieldOffset(16)]
internal uint i_frame_rate_num;
[FieldOffset(20)]
internal uint i_frame_rate_den;
[FieldOffset(24)]
internal global::VideoLAN.LibVLC.VideoOrientation i_orientation;
[FieldOffset(28)]
internal global::VideoLAN.LibVLC.VideoProjection i_projection;
[FieldOffset(32)]
internal global::VideoLAN.LibVLC.VideoTrack._.__Internal pose;
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0libvlc_video_track_t@@QEAA@AEBU0@@Z")]
internal static extern global::System.IntPtr cctor(global::System.IntPtr instance, global::System.IntPtr _0);
}
public unsafe partial class _
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
public partial struct __Internal
{
[FieldOffset(0)]
internal float f_yaw_degrees;
[FieldOffset(4)]
internal float f_pitch_degrees;
[FieldOffset(8)]
internal float f_roll_degrees;
[FieldOffset(12)]
internal float f_fov_degrees;
}
}
public global::System.IntPtr __Instance { get; protected set; }
protected int __PointerAdjustment;
internal static readonly global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.VideoTrack> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.VideoTrack>();
protected void*[] __OriginalVTables;
protected bool __ownsNativeInstance;
internal static global::VideoLAN.LibVLC.VideoTrack __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.VideoTrack(native.ToPointer(), skipVTables);
}
internal static global::VideoLAN.LibVLC.VideoTrack __CreateInstance(global::VideoLAN.LibVLC.VideoTrack.__Internal native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.VideoTrack(native, skipVTables);
}
private static void* __CopyValue(global::VideoLAN.LibVLC.VideoTrack.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.VideoTrack.__Internal));
*(global::VideoLAN.LibVLC.VideoTrack.__Internal*) ret = native;
return ret.ToPointer();
}
private VideoTrack(global::VideoLAN.LibVLC.VideoTrack.__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
protected VideoTrack(void* native, bool skipVTables = false)
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
}
public VideoTrack()
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.VideoTrack.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
public VideoTrack(global::VideoLAN.LibVLC.VideoTrack _0)
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.VideoTrack.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance) = *((global::VideoLAN.LibVLC.VideoTrack.__Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
}
public virtual void Dispose(bool disposing)
{
if (__Instance == IntPtr.Zero)
return;
global::VideoLAN.LibVLC.VideoTrack __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__Instance = IntPtr.Zero;
}
public uint IHeight
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_height;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_height = value;
}
}
public uint IWidth
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_width;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_width = value;
}
}
public uint ISarNum
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_sar_num;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_sar_num = value;
}
}
public uint ISarDen
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_sar_den;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_sar_den = value;
}
}
public uint IFrameRateNum
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_frame_rate_num;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_frame_rate_num = value;
}
}
public uint IFrameRateDen
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_frame_rate_den;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_frame_rate_den = value;
}
}
public global::VideoLAN.LibVLC.VideoOrientation IOrientation
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_orientation;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_orientation = value;
}
}
public global::VideoLAN.LibVLC.VideoProjection IProjection
{
get
{
return ((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_projection;
}
set
{
((global::VideoLAN.LibVLC.VideoTrack.__Internal*) __Instance)->i_projection = value;
}
}
public float Yaw;
public float Pitch;
public float Roll;
public float Fov;
}
public unsafe partial class SubtitleTrack : IDisposable
public struct SubtitleTrack
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
public partial struct __Internal
{
[FieldOffset(0)]
internal global::System.IntPtr psz_encoding;
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0libvlc_subtitle_track_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.SubtitleTrack> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.SubtitleTrack>();
protected void*[] __OriginalVTables;
protected bool __ownsNativeInstance;
internal static global::VideoLAN.LibVLC.SubtitleTrack __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.SubtitleTrack(native.ToPointer(), skipVTables);
}
internal static global::VideoLAN.LibVLC.SubtitleTrack __CreateInstance(global::VideoLAN.LibVLC.SubtitleTrack.__Internal native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.SubtitleTrack(native, skipVTables);
}
private static void* __CopyValue(global::VideoLAN.LibVLC.SubtitleTrack.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.SubtitleTrack.__Internal));
*(global::VideoLAN.LibVLC.SubtitleTrack.__Internal*) ret = native;
return ret.ToPointer();
}
private SubtitleTrack(global::VideoLAN.LibVLC.SubtitleTrack.__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
protected SubtitleTrack(void* native, bool skipVTables = false)
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
}
public SubtitleTrack()
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.SubtitleTrack.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
public SubtitleTrack(global::VideoLAN.LibVLC.SubtitleTrack _0)
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.SubtitleTrack.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::VideoLAN.LibVLC.SubtitleTrack.__Internal*) __Instance) = *((global::VideoLAN.LibVLC.SubtitleTrack.__Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
}
public virtual void Dispose(bool disposing)
{
if (__Instance == IntPtr.Zero)
return;
global::VideoLAN.LibVLC.SubtitleTrack __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__Instance = IntPtr.Zero;
}
public sbyte* PszEncoding
{
get
{
return (sbyte*) ((global::VideoLAN.LibVLC.SubtitleTrack.__Internal*) __Instance)->psz_encoding;
}
set
{
((global::VideoLAN.LibVLC.SubtitleTrack.__Internal*) __Instance)->psz_encoding = (global::System.IntPtr) value;
}
}
public IntPtr Encoding;
}
/// <summary>A slave of a libvlc_media_t</summary>
......
......@@ -1066,155 +1066,7 @@ namespace VideoLAN.LibVLC
public string Description => (string)Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(((Internal*)NativeReference)->psz_description);
}
/// <summary>Viewpoint for video outputs</summary>
/// <remarks>allocate using libvlc_video_new_viewpoint()</remarks>
public unsafe partial class VideoViewpoint : IDisposable
{
[StructLayout(LayoutKind.Explicit, Size = 16)]
public partial struct __Internal
{
[FieldOffset(0)]
internal float f_yaw;
[FieldOffset(4)]
internal float f_pitch;
[FieldOffset(8)]
internal float f_roll;
[FieldOffset(12)]
internal float f_field_of_view;
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = global::System.Runtime.InteropServices.CallingConvention.Cdecl,
EntryPoint="??0libvlc_video_viewpoint_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.VideoViewpoint> NativeToManagedMap = new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::VideoLAN.LibVLC.VideoViewpoint>();
protected void*[] __OriginalVTables;
protected bool __ownsNativeInstance;
internal static global::VideoLAN.LibVLC.VideoViewpoint __CreateInstance(global::System.IntPtr native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.VideoViewpoint(native.ToPointer(), skipVTables);
}
internal static global::VideoLAN.LibVLC.VideoViewpoint __CreateInstance(global::VideoLAN.LibVLC.VideoViewpoint.__Internal native, bool skipVTables = false)
{
return new global::VideoLAN.LibVLC.VideoViewpoint(native, skipVTables);
}
private static void* __CopyValue(global::VideoLAN.LibVLC.VideoViewpoint.__Internal native)
{
var ret = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.VideoViewpoint.__Internal));
*(global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) ret = native;
return ret.ToPointer();
}
private VideoViewpoint(global::VideoLAN.LibVLC.VideoViewpoint.__Internal native, bool skipVTables = false)
: this(__CopyValue(native), skipVTables)
{
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
protected VideoViewpoint(void* native, bool skipVTables = false)
{
if (native == null)
return;
__Instance = new global::System.IntPtr(native);
}
public VideoViewpoint()
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.VideoViewpoint.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
}
public VideoViewpoint(global::VideoLAN.LibVLC.VideoViewpoint _0)
{
__Instance = Marshal.AllocHGlobal(sizeof(global::VideoLAN.LibVLC.VideoViewpoint.__Internal));
__ownsNativeInstance = true;
NativeToManagedMap[__Instance] = this;
*((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance) = *((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) _0.__Instance);
}
public void Dispose()
{
Dispose(disposing: true);
}
public virtual void Dispose(bool disposing)
{
if (__Instance == IntPtr.Zero)
return;
global::VideoLAN.LibVLC.VideoViewpoint __dummy;
NativeToManagedMap.TryRemove(__Instance, out __dummy);
if (__ownsNativeInstance)
Marshal.FreeHGlobal(__Instance);
__Instance = IntPtr.Zero;
}
public float FYaw
{
get
{
return ((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_yaw;
}
set
{
((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_yaw = value;
}
}
public float FPitch
{
get
{
return ((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_pitch;
}
set
{
((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_pitch = value;
}
}
public float FRoll
{
get
{
return ((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_roll;
}
set
{
((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_roll = value;
}
}
public float FFieldOfView
{
get
{
return ((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_field_of_view;
}
set
{
((global::VideoLAN.LibVLC.VideoViewpoint.__Internal*) __Instance)->f_field_of_view = value;
}
}
}
public unsafe partial class libvlc_media_player
{
public partial struct __Internal
......@@ -2832,16 +2684,16 @@ namespace VideoLAN.LibVLC
/// <para>(the result must be released with free() or libvlc_free()).</para>
/// </returns>
/// <remarks>LibVLC 3.0.0 and later</remarks>
public static global::VideoLAN.LibVLC.VideoViewpoint LibvlcVideoNewViewpoint()
{
var __ret = __Internal.LibvlcVideoNewViewpoint();
global::VideoLAN.LibVLC.VideoViewpoint __result0;
if (__ret == IntPtr.Zero) __result0 = null;