Commit cb23e297 authored by Martin Finkel's avatar Martin Finkel

cleanup

parent d1a3cc84
......@@ -8,10 +8,12 @@ namespace LibVLCSharp.Tests
[TestFixture]
public class EventManagerTests : BaseSetup
{
string RealMediaPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "sample.mp3");
[Test]
public void MetaChangedEventSubscribe()
{
var media = new Media(new Instance(), Path.GetTempFileName(), Media.FromType.FromPath);
var media = new Media(new Instance(), Path.GetTempFileName());
var eventManager = media.EventManager;
var eventHandlerCalled = false;
const Media.MetadataType description = Media.MetadataType.Description;
......@@ -23,29 +25,10 @@ namespace LibVLCSharp.Tests
media.SetMeta(Media.MetadataType.Description, "test");
Assert.True(eventHandlerCalled);
}
[Test]
public void SubItemAdded()
{
// FIXME
var instance = new Instance();
var media = new Media(instance, RealMp3Path, Media.FromType.FromPath);
var subItem = new Media(instance, Path.GetTempFileName(), Media.FromType.FromPath);
var eventManager = media.EventManager;
var eventHandlerCalled = false;
eventManager.SubItemAdded += (sender, args) =>
{
Assert.AreEqual(subItem, args.SubItem);
eventHandlerCalled = true;
};
media.SubItems.Lock();
Assert.True(media.SubItems.AddMedia(subItem));
media.SubItems.Unlock();
Assert.True(eventHandlerCalled);
}
[Test]
public void DurationChanged()
{
var media = new Media(new Instance(), RealMp3Path, Media.FromType.FromPath);
......@@ -102,14 +85,5 @@ namespace LibVLCSharp.Tests
Assert.True(tcs.Task.Result);
Assert.True(openingCalled);
}
[Test]
public void SubItemTreeAdded()
{
var media = new Media(new Instance(), RealMp3Path, Media.FromType.FromPath);
//TODO: Implement MediaList.cs
Assert.Fail();
}
}
}
\ No newline at end of file
......@@ -65,12 +65,9 @@ namespace LibVLCSharp.Tests
Assert.True(media.IsParsed);
Assert.NotZero(media.Duration);
using (var mp = new MediaPlayer(media))
/// <summary>
/// add media file for tests in \bin\x64\Debug\net47
/// </summary>
{
Assert.True(mp.Play());
await Task.Delay(3000); // have to wait a bit for statistics to populate
await Task.Delay(4000); // have to wait a bit for statistics to populate
Assert.Greater(media.Statistics.DemuxBitrate, 0);
mp.Stop();
}
......@@ -78,6 +75,7 @@ namespace LibVLCSharp.Tests
}
}
string RealMediaPath => Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "sample.mp3");
[Test]
public void Duplicate()
{
......@@ -89,9 +87,7 @@ namespace LibVLCSharp.Tests
[Test]
public void CreateMediaFromFileStream()
{
Assert.Fail();
// TODO: fix this.
var media = new Media(new Instance(), new FileStream("realFileUri", FileMode.Open, FileAccess.Read, FileShare.Read));
var media = new Media(new Instance(), new FileStream(RealMediaPath, FileMode.Open, FileAccess.Read, FileShare.Read));
media.Parse();
Assert.NotZero(media.Tracks.First().Data.Audio.Channels);
}
......
......@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Threading.Tasks;
using VideoLAN.LibVLC.Events;
namespace LibVLCSharp.Shared
{
......@@ -199,6 +200,11 @@ namespace LibVLCSharp.Shared
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_retain")]
internal static extern void LibVLCMediaRetain(IntPtr media);
[SuppressUnmanagedCodeSecurity]
[DllImport("libvlc", CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_get_codec_description")]
internal static extern string LibvlcMediaGetCodecDescription(TrackType type, uint codec);
}
#region enums
......@@ -255,7 +261,8 @@ namespace LibVLCSharp.Shared
}
/// <summary>
/// <summary>Parse flags used by libvlc_media_parse_with_options()</summary>
/// <summary>Parse flags used by libvlc_media_parse_with_options()
/// </summary>
/// <remarks>libvlc_media_parse_with_options</remarks>
[Flags]
public enum MediaParseOptions
......@@ -276,6 +283,7 @@ namespace LibVLCSharp.Shared
DoInteract = 8
}
/// <summary>
/// Parse status used sent by libvlc_media_parse_with_options() or returned by
/// libvlc_media_get_parsed_status()
/// </summary>
......@@ -358,7 +366,7 @@ namespace LibVLCSharp.Shared
}
public Media(MediaList mediaList)
: base(() => Native.LibVLCMediaListMedia(mediaList.__Instance), Native.LibVLCMediaRelease)
: base(() => Native.LibVLCMediaListMedia(mediaList.NativeReference), Native.LibVLCMediaRelease)
{
}
......@@ -491,11 +499,7 @@ namespace LibVLCSharp.Shared
/// <summary>Save the meta previously set</summary>
/// <returns>true if the write operation was successful</returns>
public bool SaveMeta()
{
var r = Native.LibVLCMediaSaveMeta(NativeReference);
return r != 0;
}
public bool SaveMeta() => Native.LibVLCMediaSaveMeta(NativeReference) != 0;
/// <summary>
/// Get current <see cref="VLCState"/> of media descriptor object.
......@@ -505,7 +509,8 @@ namespace LibVLCSharp.Shared
/// <summary>Get the current statistics about the media
/// structure that contain the statistics about the media
/// </summary>
public MediaStats Statistics => Native.LibVLCMediaGetStats(NativeReference, out var mediaStats) == 0 ? default(MediaStats) : mediaStats;
public MediaStats Statistics => Native.LibVLCMediaGetStats(NativeReference, out var mediaStats) == 0
? default(MediaStats) : mediaStats;
MediaEventManager _eventManager;
/// <summary>
......@@ -537,10 +542,7 @@ namespace LibVLCSharp.Shared
/// libvlc_media_get_meta
/// libvlc_media_get_tracks_info
/// </summary>
public void Parse()
{
Native.LibVLCMediaParse(NativeReference);
}
public void Parse() => Native.LibVLCMediaParse(NativeReference);
/// <summary>Parse a media.
/// This fetches (local) art, meta data and tracks information.
......@@ -676,10 +678,7 @@ namespace LibVLCSharp.Shared
/// <para>libvlc_media_parse_with_options</para>
/// <para>LibVLC 3.0.0 or later</para>
/// </remarks>
public void ParseStop()
{
Native.LibVLCMediaParseStop(NativeReference);
}
public void ParseStop() => Native.LibVLCMediaParseStop(NativeReference);
// TODO: Whats userData?
//public IntPtr UserData
......@@ -733,7 +732,7 @@ namespace LibVLCSharp.Shared
get
{
var ptr = Native.LibVLCMediaSubitems(NativeReference);
return new MediaList(ptr);
return new MediaList(ptr); //should cache MediaList C# object.
}
}
......@@ -752,20 +751,18 @@ namespace LibVLCSharp.Shared
/// <para>libvlc_media_player_play())</para>
/// <para>LibVLC 3.0.0 and later.</para>
/// </remarks>
public bool AddSlave(MediaSlaveType type, uint priority, string uri)
{
return Native.LibVLCMediaAddSlaves(NativeReference, type, priority, uri) != 0;
}
[LibVLC(3)]
public bool AddSlave(MediaSlaveType type, uint priority, string uri) =>
Native.LibVLCMediaAddSlaves(NativeReference, type, priority, uri) != 0;
/// <summary>
/// <para>Clear all slaves previously added by libvlc_media_slaves_add() or</para>
/// <para>internally.</para>
/// </summary>
/// <remarks>LibVLC 3.0.0 and later.</remarks>
public void ClearSlaves()
{
Native.LibVLCMediaClearSlaves(NativeReference);
}
[LibVLC(3)]
public void ClearSlaves() => Native.LibVLCMediaClearSlaves(NativeReference);
/// <summary>Get a media descriptor's slave list</summary>
/// <para>address to store an allocated array of slaves (must be</para>
......@@ -778,6 +775,7 @@ namespace LibVLCSharp.Shared
/// <para>LibVLC 3.0.0 and later.</para>
/// <para>libvlc_media_slaves_add</para>
/// </remarks>
[LibVLC(3)]
public IEnumerable<MediaSlave> Slaves
{
get
......
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