Commit 335866b0 authored by Martin Finkel's avatar Martin Finkel

Remove ApiVersion checks

parent c4715d41
using LibVLCSharp.Shared;
using NUnit.Framework;
namespace LibVLCSharp.Tests
{
[TestFixture]
public class VersionCheckTests : BaseSetup
{
[Test]
public void ShouldThrowIfDllVersionNotHighEnough()
{
Assert.Throws<VLCException>(UnavailableAPIMethod);
}
[ApiVersion(int.MaxValue)]
void UnavailableAPIMethod() => Assert.Fail("should not reach here");
bool _result;
[ApiVersion(major: 0, minor: 0, min: false, strict: true)]
public bool UnavailableAPIProperty
{
get { Assert.Fail(); return _result; }
}
[Test]
public void ShouldThrowIfDllVersionTooHigh()
{
Assert.Throws<VLCException>(() =>
{
var r = UnavailableAPIProperty;
});
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Cauldron.Interception />
</Weavers>
\ No newline at end of file
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
//using Cauldron.Interception;
namespace LibVLCSharp.Shared
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property,
AllowMultiple = true,
Inherited = false)]
public class ApiVersion : Attribute//, IMethodInterceptor, IPropertyGetterInterceptor
{
struct Native
{
/// <summary>Retrieve libvlc version.</summary>
/// <returns>a string containing the libvlc version</returns>
/// <remarks>Example: &quot;1.1.0-git The Luggage&quot;</remarks>
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_get_version")]
internal static extern IntPtr LibVLCVersion();
}
readonly Version _requiredVersion;
Version _dllVersion;
readonly bool _minimum;
readonly bool _strict;
public ApiVersion(int major, int minor = 0, bool min = true, bool strict = false)
{
_requiredVersion = new Version(major, minor);
_minimum = min;
_strict = strict;
}
Version DllVersion
{
get
{
if (_dllVersion != null) return _dllVersion;
var version = Marshal.PtrToStringAnsi(Native.LibVLCVersion());
if (string.IsNullOrEmpty(version))
throw new VLCException("Cannot retrieve native dll version");
version = version.Split('-', ' ')[0];
_dllVersion = new Version(version);
return _dllVersion;
}
}
bool Check
{
get
{
if(_minimum)
{
if(_strict)
return DllVersion.CompareTo(_requiredVersion) > 0;
return DllVersion.CompareTo(_requiredVersion) >= 0;
}
if (_strict)
return DllVersion.CompareTo(_requiredVersion) < 0;
return DllVersion.CompareTo(_requiredVersion) <= 0;
}
}
public void OnEnter(Type declaringType, object instance, MethodBase methodbase, object[] values)
{
PerformCheck();
}
public void OnException(Exception e)
{
}
public void OnExit()
{
}
//public void OnGet(PropertyInterceptionInfo propertyInterceptionInfo, object value)
//{
// PerformCheck();
//}
void PerformCheck()
{
if (!Check)
throw new VLCException("This API requires " + (_minimum ? "minimum" : "maximum")
+ $" version {_requiredVersion.Major}.{_requiredVersion.Minor} of libvlc. "
+ $"Currently used dll version is {_dllVersion.Major}.{_dllVersion.Minor}");
}
}
}
\ No newline at end of file
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace LibVLCSharp.Shared
{
......@@ -59,7 +58,6 @@ namespace LibVLCSharp.Shared
/// libvlc_media_player_set_equalizer().
/// version LibVLC 2.2.0 or later
/// </summary>
[ApiVersion(2, 2)]
public Equalizer() : base(Native.LibVLCAudioEqualizerNew, Native.LibVLCAudioEqualizerRelease)
{
}
......@@ -71,7 +69,6 @@ namespace LibVLCSharp.Shared
/// version LibVLC 2.2.0 or later
/// </summary>
/// <param name="index">index of the preset, counting from zero</param>
[ApiVersion(2, 2)]
public Equalizer(uint index) : base(() => Native.LibVLCAudioEqualizerNewFromPreset(index), Native.LibVLCAudioEqualizerRelease)
{
}
......@@ -85,7 +82,6 @@ namespace LibVLCSharp.Shared
/// <param name="preamp">preamp value (-20.0 to 20.0 Hz)</param>
/// LibVLC 2.2.0 or later
/// <returns>true on success, false otherwise</returns>
[ApiVersion(2, 2)]
public bool SetPreamp(float preamp) => Native.LibVLCAudioEqualizerSetPreamp(NativeReference, preamp) == 0;
/// <summary>
......@@ -103,7 +99,6 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="amp">amplification value (-20.0 to 20.0 Hz)</param>
/// <param name="band">index, counting from zero, of the frequency band to set</param>
[ApiVersion(2, 2)]
public bool SetAmp(float amp, uint band) =>
Native.LibVLCAudioEqualizerSetAmpAtIndex(NativeReference, amp, band) == 0;
......@@ -113,7 +108,6 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="band">index, counting from zero, of the frequency band to get</param>
/// <returns>amplification value (Hz); NaN if there is no such frequency band</returns>
[ApiVersion(2, 2)]
public float Amp(uint band) => Native.LibVLCAudioEqualizerGetAmpAtIndex(NativeReference, band);
/// <summary>
......@@ -144,7 +138,6 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="index">index index of the band, counting from zero</param>
/// <returns>equalizer band frequency (Hz), or -1 if there is no such band</returns>
[ApiVersion(2, 2)]
public float BandFrequency(uint index) => Native.LibVLCAudioEqualizerGetBandFrequency(index);
}
}
\ No newline at end of file
......@@ -299,7 +299,6 @@ namespace LibVLCSharp.Shared
/// <param name="name">human-readable application name, e.g. &quot;FooBar player 1.2.3&quot;</param>
/// <param name="http">HTTP User Agent, e.g. &quot;FooBar/1.2.3 Python/2.6.0&quot;</param>
/// <remarks>LibVLC 1.1.1 or later</remarks>
[ApiVersion(1, 1)]
public void SetUserAgent(string name, string http)
{
Native.LibVLCSetUserAgent(NativeReference, name, http);
......@@ -313,7 +312,6 @@ namespace LibVLCSharp.Shared
/// <param name="version">application version numbers, e.g. &quot;1.2.3&quot;</param>
/// <param name="icon">application icon name, e.g. &quot;foobar&quot;</param>
/// <remarks>LibVLC 2.1.0 or later.</remarks>
[ApiVersion(2, 1)]
public void SetAppId(string id, string version, string icon)
{
Native.LibVLCSetAppId(NativeReference, id, version, icon);
......@@ -328,7 +326,6 @@ namespace LibVLCSharp.Shared
/// <para>complete (causing a deadlock if called from within the callback).</para>
/// <para>LibVLC 2.1.0 or later</para>
/// </remarks>
[ApiVersion(2, 1)]
public void UnsetLog()
{
Native.LibVLCLogUnset(NativeReference);
......@@ -402,7 +399,6 @@ namespace LibVLCSharp.Shared
/// <para>(the FILE pointer must remain valid until libvlc_log_unset())</para>
/// <param name="filename">open/create file with Write access. If existing, resets content.</param>
/// <remarks>LibVLC 2.1.0 or later</remarks>
[ApiVersion(2, 1)]
public void SetLogFile(string filename)
{
if (string.IsNullOrEmpty(filename)) throw new NullReferenceException(nameof(filename));
......@@ -498,7 +494,6 @@ namespace LibVLCSharp.Shared
/// <para>explicit audio device.</para>
/// <para>LibVLC 2.1.0 or later.</para>
/// </remarks>
[ApiVersion(2, 1)]
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName)
{
......@@ -512,7 +507,6 @@ namespace LibVLCSharp.Shared
/// <param name="category">category of services to fetch</param>
/// <returns>the number of media discoverer services (0 on error)</returns>
/// <remarks>LibVLC 3.0.0 and later.</remarks>
[ApiVersion(3)]
public MediaDiscoverer.Description[] MediaDiscoverers(MediaDiscoverer.Category category)
{
var arrayResultPtr = IntPtr.Zero;
......
......@@ -341,7 +341,6 @@ namespace LibVLCSharp.Shared
/// <param name="libVLC"></param>
/// <param name="stream"></param>
/// <param name="options"></param>
[ApiVersion(3)]
public Media(LibVLC libVLC, Stream stream, params string[] options)
: base(() => CtorFromCallbacks(libVLC, stream), Native.LibVLCMediaRelease)
{
......@@ -599,7 +598,6 @@ namespace LibVLCSharp.Shared
/// <para>libvlc_media_player_play())</para>
/// <para>LibVLC 3.0.0 and later.</para>
/// </remarks>
[ApiVersion(3)]
public bool AddSlave(MediaSlaveType type, uint priority, string uri) =>
Native.LibVLCMediaAddSlaves(NativeReference, type, priority, uri) != 0;
......@@ -609,7 +607,6 @@ namespace LibVLCSharp.Shared
/// <para>internally.</para>
/// </summary>
/// <remarks>LibVLC 3.0.0 and later.</remarks>
[ApiVersion(3)]
public void ClearSlaves() => Native.LibVLCMediaClearSlaves(NativeReference);
/// <summary>Get a media descriptor's slave list</summary>
......@@ -623,7 +620,6 @@ namespace LibVLCSharp.Shared
/// <para>LibVLC 3.0.0 and later.</para>
/// <para>libvlc_media_slaves_add</para>
/// </remarks>
[ApiVersion(3)]
public IEnumerable<MediaSlave> Slaves
{
get
......
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
using LibVLCSharp.Shared.Structures;
namespace LibVLCSharp.Shared
......@@ -713,7 +712,6 @@ namespace LibVLCSharp.Shared
/// version LibVLC 1.1.1 or later
/// </summary>
/// <param name="pause">play/resume if true, pause if false</param>
[ApiVersion(1, 1)]
public void SetPause(bool pause) => Native.LibVLCMediaPlayerSetPause(NativeReference, pause);
/// <summary>
......@@ -910,7 +908,6 @@ namespace LibVLCSharp.Shared
/// <summary>
/// Get the frames per second (fps) for this playing movie, or 0 if unspecified
/// </summary>
[ApiVersion(major: 3, minor: 0, min: false, strict: true)]
public float Fps
{
get { _fps = Native.LibVLCMediaPlayerGetFps(NativeReference); return _fps; }
......@@ -996,11 +993,7 @@ namespace LibVLCSharp.Shared
/// <summary>
/// Toggle teletext transparent status on video output.
/// </summary>
[ApiVersion(3, 0, false, true)]
public void ToggleTeletext()
{
Native.LibVLCToggleTeletext(NativeReference);
}
public void ToggleTeletext() => Native.LibVLCToggleTeletext(NativeReference);
/// <summary>
/// Apply new equalizer settings to a media player.
......@@ -1387,11 +1380,7 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="subtitle">new video subtitle file</param>
/// <returns></returns>
[ApiVersion(3, 0, false, true)]
public bool SetSubtitleFile(string subtitle)
{
return Native.LibVLCVideoSetSubtitleFile(NativeReference, subtitle) != 0;
}
public bool SetSubtitleFile(string subtitle) => Native.LibVLCVideoSetSubtitleFile(NativeReference, subtitle) != 0;
public long SpuDelay => Native.LibVLCVideoGetSpuDelay(NativeReference);
......@@ -1400,7 +1389,6 @@ namespace LibVLCSharp.Shared
/// <summary>
/// Get the description of available titles.
/// </summary>
// [ApiVersion(3, 0, false, true)]
public TrackDescription[] TitleDescription
{
get
......@@ -1415,7 +1403,6 @@ namespace LibVLCSharp.Shared
/// </summary>
/// <param name="titleIndex">selected title</param>
/// <returns></returns>
[ApiVersion(3, 0, false, true)]
public TrackDescription[] ChapterDescription(int titleIndex)
{
var ptr = Native.LibVLCVideoGetChapterDescription(NativeReference, titleIndex);
......@@ -1587,7 +1574,6 @@ namespace LibVLCSharp.Shared
/// <param name="uri">Uri of the slave (should contain a valid scheme).</param>
/// <param name="select">True if this slave should be selected when it's loaded</param>
/// <returns></returns>
[ApiVersion(3)]
public bool AddSlave(MediaSlaveType type, string uri, bool select) =>
Native.LibVLCMediaPlayerAddSlave(NativeReference, type, uri, select) == 0;
......@@ -1596,11 +1582,9 @@ namespace LibVLCSharp.Shared
/// <param name="viewpoint"></param>
/// <param name="absolute"></param>
/// <returns></returns>
[ApiVersion(3)]
public bool UpdateViewpoint(VideoViewpoint viewpoint, bool absolute) =>
Native.LibVLCVideoUpdateViewpoint(NativeReference, viewpoint, absolute) == 0;
[ApiVersion(3)]
public bool SetRenderer(RendererItem rendererItem) =>
Native.LibVLCMediaPlayerSetRenderer(NativeReference, rendererItem.NativeReference) == 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