Commit a16be806 authored by Jérémy VIGNELLES's avatar Jérémy VIGNELLES Committed by Martin Finkel

Standardized builds of LibVLCSharp + other fixes

Given that the WINDOWS constant is meaningless (Linux mono builds as
a .net framework too, and have WINDOWS set), and that .net core builds
running on windows should execute the same actions as .net fx,
I introduced a DESKTOP flag, for standard, core and framework.

Consolidated packages versions

Updated MSBuild.Sdk.Extras

removed useless unsafe blocks

(cherry picked from commit 4ddf9bdf083c71e2c64874c20c0eccc9fbd1cf2a)
parent f3d15c6e
<Project>
<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>$(DefineConstants);PORTABLE</DefineConstants>
<DefineConstants>$(DefineConstants);PORTABLE;DESKTOP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">
<DefineConstants>$(DefineConstants);XAML;WINDOWS_CLASSIC;WINDOWS</DefineConstants>
<DefineConstants>$(DefineConstants);XAML;DESKTOP</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0.16299'">
<DefineConstants>$(DefineConstants);NETFX_CORE;XAML;WINDOWS_UWP;WINDOWS</DefineConstants>
......@@ -26,6 +26,6 @@
<DefineConstants>$(DefineConstants);MONO;ANDROID</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
<DefineConstants>$(DefineConstants);NETCORE;DESKTOP</DefineConstants>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -97,13 +97,13 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\packages\VideoLAN.LibVLC.Android.3.0.0\build\VideoLAN.LibVLC.Android.targets" Condition="Exists('..\packages\VideoLAN.LibVLC.Android.3.0.0\build\VideoLAN.LibVLC.Android.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\VideoLAN.LibVLC.Android.3.0.0-alpha\build\VideoLAN.LibVLC.Android.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\VideoLAN.LibVLC.Android.3.0.0-alpha\build\VideoLAN.LibVLC.Android.targets'))" />
<Error Condition="!Exists('..\packages\VideoLAN.LibVLC.Android.3.0.0\build\VideoLAN.LibVLC.Android.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\VideoLAN.LibVLC.Android.3.0.0\build\VideoLAN.LibVLC.Android.targets'))" />
</Target>
<Import Project="..\packages\VideoLAN.LibVLC.Android.3.0.0-alpha\build\VideoLAN.LibVLC.Android.targets" Condition="Exists('..\packages\VideoLAN.LibVLC.Android.3.0.0-alpha\build\VideoLAN.LibVLC.Android.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="VideoLAN.LibVLC.Android" version="3.0.0-alpha" targetFramework="monoandroid71" />
<package id="VideoLAN.LibVLC.Android" version="3.0.0" targetFramework="monoandroid81" />
</packages>
\ No newline at end of file
......@@ -11,7 +11,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha2" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha3" />
</ItemGroup>
<ItemGroup>
......
......@@ -120,7 +120,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="VideoLAN.LibVLC.iOS">
<Version>3.0.0-alpha</Version>
<Version>3.0.0-alpha2</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
</ItemGroup>
......
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSBuild.Sdk.Extras/1.6.46">
<PropertyGroup>
<Title>LibVLCSharp.Forms</Title>
<Summary>Xamarin.Forms integration for LibVLCSharp</Summary>
......@@ -7,12 +7,10 @@
<TargetFrameworks>netstandard2.0;MonoAndroid81;Xamarin.iOS10</TargetFrameworks>
<RootNamespace>LibVLCSharp.Forms</RootNamespace>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<DefineConstants>$(DefineConstants);</DefineConstants>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<Version>0.0.1-alpha</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.2.0" PrivateAssets="All" />
<PackageReference Include="Xamarin.Forms" Version="3.0.0.446417" />
</ItemGroup>
<ItemGroup>
......@@ -27,5 +25,4 @@
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.iOS'))">
<Compile Include="Platforms\iOS\**\*.cs" />
</ItemGroup>
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>
\ No newline at end of file
......@@ -11,7 +11,7 @@
<PackageReference Include="Moq" Version="4.7.142" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha1" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibVLCSharp\LibVLCSharp.csproj" />
......
<Project Sdk="MSBuild.Sdk.Extras/1.6.41">
<Project Sdk="MSBuild.Sdk.Extras/1.6.46">
<PropertyGroup>
<Title>LibVLCSharp.WPF</Title>
<TargetFramework>net461</TargetFramework>
......
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="MSBuild.Sdk.Extras/1.6.46">
<PropertyGroup>
<Title>LibVLCSharp</Title>
<Summary>.NET bindings for LibVLC</Summary>
<Description>.NET bindings for LibVLC</Description>
<PackageTags>libvlc native xamarin .net video audio media mediaplayer</PackageTags>
<TargetFrameworks>netstandard2.0;MonoAndroid81;net461;netcoreapp2.0;Xamarin.iOS10;Xamarin.Mac20</TargetFrameworks>
<TargetFrameworks>netstandard2.0;MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20</TargetFrameworks>
<RootNamespace>LibVLCSharp</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);</DefineConstants>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>default</LangVersion>
......@@ -19,12 +18,9 @@
<PackageProjectUrl>https://github.com/mfkl/LibVLCSharp</PackageProjectUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.2.0" PrivateAssets="All" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<Compile Include="Shared\**\*.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('MonoAndroid'))">
<Compile Include="Platforms\Android\**\*.cs" />
<ProjectReference Include="..\LibVLCSharp.Android.AWindow\LibVLCSharp.Android.AWindow.csproj" />
......@@ -41,5 +37,4 @@
<ItemGroup Condition="$(TargetFramework.StartsWith('Xamarin.Mac'))">
<Compile Include="Platforms\Mac\**\*.cs" />
</ItemGroup>
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>
\ No newline at end of file
......@@ -36,23 +36,13 @@ namespace LibVLCSharp.Shared
public static void Initialize()
{
#if WINDOWS
InitializeWindows();
#if DESKTOP
InitializeDesktop();
#elif ANDROID
InitializeAndroid();
#elif NETCORE
InitializeNetCore();
#endif
}
#if NETCORE
static void InitializeNetCore()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
InitializeWindows();
}
#endif
#if ANDROID
static void InitializeAndroid()
{
......@@ -63,24 +53,28 @@ namespace LibVLCSharp.Shared
}
#endif
//TODO: Add Unload library func using handles
static void InitializeWindows()
static void InitializeDesktop()
{
var myPath = new Uri(typeof(LibVLC).Assembly.CodeBase).LocalPath;
var myPath = typeof(LibVLC).Assembly.Location;
var appExecutionDirectory = Path.GetDirectoryName(myPath);
if (appExecutionDirectory == null)
throw new NullReferenceException(nameof(appExecutionDirectory));
var arch = Environment.Is64BitProcess ? Win64 : Win86;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var arch = Environment.Is64BitProcess ? Win64 : Win86;
var libvlccorePath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlccore}.dll"));
var libvlcPath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlc}.dll"));
var libvlccorePath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlccore}.dll"));
var libvlcPath = Path.Combine(Path.Combine(appExecutionDirectory, Libvlc),
Path.Combine(arch, $"{Libvlc}.dll"));
Debug.WriteLine(nameof(libvlccorePath) + ": " + libvlccorePath);
Debug.WriteLine(nameof(libvlcPath) + ": " + libvlcPath);
Debug.WriteLine(nameof(libvlccorePath) + ": " + libvlccorePath);
Debug.WriteLine(nameof(libvlcPath) + ": " + libvlcPath);
LoadLibvlcLibraries(libvlccorePath, libvlcPath);
LoadLibvlcLibraries(libvlccorePath, libvlcPath);
}
}
//TODO: check if Store app
......
......@@ -84,7 +84,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_get_xwindow")]
internal static extern uint LibVLCMediaPlayerGetXwindow(IntPtr mediaPlayer);
#if WINDOWS
#if DESKTOP
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_media_player_set_hwnd")]
......@@ -388,12 +388,12 @@ namespace LibVLCSharp.Shared
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_size")]
internal static extern unsafe int LibVLCVideoGetSize(IntPtr mediaPlayer, uint num, uint* px, uint* py);
internal static extern int LibVLCVideoGetSize(IntPtr mediaPlayer, uint num, ref uint px, ref uint py);
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_video_get_cursor")]
internal static extern unsafe int LibVLCVideoGetCursor(IntPtr mediaPlayer, uint num, int* px, int* py);
internal static extern int LibVLCVideoGetCursor(IntPtr mediaPlayer, uint num, ref int px, ref int py);
[SuppressUnmanagedCodeSecurity]
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
......@@ -775,7 +775,7 @@ namespace LibVLCSharp.Shared
set => Native.LibVLCMediaPlayerSetXwindow(NativeReference, value);
}
#if WINDOWS
#if DESKTOP
/// <summary>
/// Set a Win32/Win64 API window handle (HWND) where the media player
/// should render its video output. If LibVLC was built without
......@@ -1311,18 +1311,7 @@ namespace LibVLCSharp.Shared
/// <returns></returns>
public bool Size(uint num, ref uint px, ref uint py)
{
unsafe
{
fixed (uint* refPx = &px)
{
var pxPtr = refPx;
fixed (uint* refPy = &py)
{
var pyPtr = refPy;
return Native.LibVLCVideoGetSize(NativeReference, num, pxPtr, pyPtr) == 0;
}
}
}
return Native.LibVLCVideoGetSize(NativeReference, num, ref px, ref py) == 0;
}
/// <summary>
......@@ -1343,18 +1332,7 @@ namespace LibVLCSharp.Shared
/// <returns>true on success, false on failure</returns>
public bool Cursor(uint num, ref int px, ref int py)
{
unsafe
{
fixed (int* refPx = &px)
{
var pxPtr = refPx;
fixed (int* refPy = &py)
{
var pyPtr = refPy;
return Native.LibVLCVideoGetCursor(NativeReference, num, pxPtr, pyPtr) == 0;
}
}
}
return Native.LibVLCVideoGetCursor(NativeReference, num, ref px, ref py) == 0;
}
/// <summary>
......
......@@ -6,7 +6,7 @@
<RuntimeIdentifiers>win7-x64;win7-x86</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha1" />
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.0-alpha3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibVLCSharp\LibVLCSharp.csproj" />
......
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