Commit 7aa5203c authored by Martin Finkel's avatar Martin Finkel

Renaming projects + removing CppSharp Autogen + removing unused bindings +...

Renaming projects + removing CppSharp Autogen + removing unused bindings + adding dll version check attribute with Cauldron.Interception.Fody dependency
parent 8ad6612f
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using NUnit.Framework;
using VideoLAN.LibVLC;
using VideoLAN.LibVLC.Manual;
using Media = VideoLAN.LibVLC.Media;
namespace Bindings.Tests
namespace LibVLCSharp.Tests
{
[TestFixture]
public class EventManagerTests
......@@ -40,9 +39,9 @@ namespace Bindings.Tests
get
{
var dir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var binDir = Path.Combine(dir, "..\\..\\..\\");
var files = Directory.GetFiles(binDir);
return files.First();
//var binDir = Path.Combine(dir, "..\\..\\..\\");
var files = Directory.GetFiles(dir);
return files.First(f => f.Contains("Klang"));
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Cauldron.Interception />
</Weavers>
\ No newline at end of file
......@@ -5,9 +5,9 @@ using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using VideoLAN.LibVLC;
using VideoLAN.LibVLC.Manual;
using VideoLAN.LibVLC.Events;
namespace Bindings.Tests
namespace LibVLCSharp.Tests
{
[TestFixture]
public class InstanceTests
......
......@@ -6,12 +6,13 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.2.1" />
<PackageReference Include="Cauldron.Interception.Fody" Version="2.0.18" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Moq" Version="4.7.142" />
<PackageReference Include="NUnit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibVlcSharp\LibVlcSharp.csproj" />
<ProjectReference Include="..\LibVlcSharp\LibVLCSharp.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
using System.Linq;
using NUnit.Framework;
using VideoLAN.LibVLC.Manual;
using VideoLAN.LibVLC;
namespace Bindings.Tests
namespace LibVLCSharp.Tests
{
[TestFixture]
public class MediaDiscovererTests
......
......@@ -2,10 +2,10 @@
using System.IO;
using NUnit.Framework;
using VideoLAN.LibVLC;
using VideoLAN.LibVLC.Manual;
using MediaList = VideoLAN.LibVLC.Manual.MediaList;
using Media = VideoLAN.LibVLC.Media;
using MediaList = VideoLAN.LibVLC.MediaList;
namespace Bindings.Tests
namespace LibVLCSharp.Tests
{
[TestFixture]
public class MediaListTests
......
......@@ -5,10 +5,10 @@ using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using VideoLAN.LibVLC;
using VideoLAN.LibVLC.Manual;
using MediaPlayer = VideoLAN.LibVLC.Manual.MediaPlayer;
using Media = VideoLAN.LibVLC.Media;
using MediaPlayer = VideoLAN.LibVLC.MediaPlayer;
namespace Bindings.Tests
namespace LibVLCSharp.Tests
{
[TestFixture]
public class MediaPlayerTests
......@@ -45,7 +45,7 @@ namespace Bindings.Tests
{
var instance = new Instance();
var mp = new MediaPlayer(instance);
var media = new Media(instance, RealMediaPath, Media.FromType.FromPath);
var media = new Media(instance, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation);
var tcs = new TaskCompletionSource<bool>();
mp.Media = media;
......
......@@ -3,9 +3,9 @@ using System.IO;
using System.Linq;
using NUnit.Framework;
using VideoLAN.LibVLC;
using VideoLAN.LibVLC.Manual;
using Media = VideoLAN.LibVLC.Media;
namespace Bindings.Tests
namespace LibVLCSharp.Tests
{
[TestFixture]
public class MediaTests
......@@ -73,9 +73,9 @@ namespace Bindings.Tests
get
{
var dir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var binDir = Path.Combine(dir, "..\\..\\..\\");
var files = Directory.GetFiles(binDir);
return files.First();
//var binDir = Path.Combine(dir, "..\\..\\..\\");
var files = Directory.GetFiles(dir);
return files.First(f => f.Contains("Klang"));
}
}
......
using NUnit.Framework;
using VideoLAN.LibVLC;
namespace LibVLCSharp.Tests
{
[TestFixture]
public class VersionCheckTests
{
[Test]
public void ShouldThrowIfDllVersionNotHighEnough()
{
Assert.Throws<VLCException>(UnavailableAPIMethod);
}
[LibVLC(10)]
void UnavailableAPIMethod() => Assert.Fail("should not reach here");
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using CppSharp;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Parser;
using ASTContext = CppSharp.AST.ASTContext;
namespace libvlcsharp
{
internal class LibVLC : ILibrary
{
public void Preprocess(Driver driver, ASTContext ctx)
{
var libnewF = ctx.FindFunction("libvlc_new").Single();
var instance = ctx.FindClass("libvlc_instance_t").Single();
var m = new Method(libnewF)
{
Access = AccessSpecifier.Public,
Kind = CXXMethodKind.Constructor,
IsFinal = true
};
instance.Methods.Add(m);
}
public void Postprocess(Driver driver, ASTContext ctx)
{
// TODO: rename LibvlcCallbackT to VLCCallback
RenameClasses(ctx);
RenameEnums(ctx);
ctx.SetClassAsValueType("Event");
}
private void RenameClasses(ASTContext ctx)
{
void Rename(string originalName, string newName)
{
ctx.FindClass(originalName).Single().Name = newName;
}
Rename("LibvlcInstanceT", "Instance");
Rename("LibvlcEventManagerT", "EventManager");
Rename("LibvlcModuleDescriptionT", "ModuleDescription");
Rename("LibvlcMediaTrackT", "MediaTrack");
Rename("LibvlcMediaPlayerT", "MediaPlayer");
Rename("LibvlcEqualizerT", "Equalizer");
Rename("LibvlcTrackDescriptionT", "TrackDescription");
Rename("VlcLogT", "Log");
Rename("LibvlcRendererItemT", "RendererItem");
Rename("LibvlcRendererDiscovererT", "RendererDiscoverer");
Rename("LibvlcRdDescriptionT", "RendererDiscovererDescription");
Rename("LibvlcMediaT", "Media");
Rename("LibvlcMediaListT", "MediaList");
Rename("LibvlcMediaStatsT", "MediaStats");
Rename("LibvlcMediaTrackInfoT", "MediaTrackInfo");
Rename("LibvlcAudioTrackT", "AudioTrack");
Rename("LibvlcVideoTrackT", "VideoTrack");
Rename("LibvlcSubtitleTrackT", "SubtitleTrack");
Rename("LibvlcMediaSlaveT", "MediaSlave");
Rename("LibvlcTitleDescriptionT", "TitleDescription");
Rename("LibvlcChapterDescriptionT", "ChapterDescription");
Rename("LibvlcAudioOutputT", "AudioOutput");
Rename("LibvlcAudioOutputDeviceT", "AudioOutputDevice");
Rename("LibvlcVideoViewpointT", "VideoViewpoint");
Rename("LibvlcMediaDiscovererT", "MediaDiscoverer");
Rename("LibvlcMediaDiscovererDescriptionT", "MediaDiscovererDescription");
Rename("LibvlcEventT", "Event");
Rename("LibvlcDialogId", "DialogId");
Rename("LibvlcDialogCbs", "DialogCallback");
Rename("LibvlcLogIteratorT", "LogIterator");
Rename("LibvlcLogMessageT", "LogMessage");
}
private void RenameEnums(ASTContext ctx)
{
Rename("LibvlcLogLevel", "LogLevel", true, "LIBVLC_");
Rename("LibvlcStateT", "VLCState", strip: "Libvlc");
Rename("LibvlcMediaOption", "MediaOption", strip: "LibvlcMediaOption");
Rename("LibvlcTrackTypeT", "TrackType", strip: "LibvlcTrack");
Rename("LibvlcVideoOrientT", "VideoOrientation", strip: "LibvlcVideoOrient");
Rename("LibvlcVideoProjectionT", "VideoProjection", strip: "LibvlcVideoProjection");
Rename("LibvlcMetaT", "MetadataType", strip: "LibvlcMeta");
Rename("LibvlcMediaTypeT", "MediaType", strip: "LibvlcMediaType");
Rename("LibvlcMediaParseFlagT", "MediaParseOptions", strip: "LibvlcMedia");
Rename("LibvlcMediaParsedStatusT", "MediaParsedStatus", strip: "LibvlcMediaParsedStatus");
Rename("LibvlcMediaSlaveTypeT", "MediaSlaveType", strip: "LibvlcMediaSlaveType");
Rename("LibvlcTitle", "Title", strip: "LibvlcTitle");
Rename("LibvlcVideoMarqueeOptionT", "VideoMarqueeOption", strip: "LibvlcMarquee");
Rename("LibvlcNavigateModeT", "NavigationMode", strip: "LibvlcNavigate");
Rename("LibvlcPositionT", "Position", strip: "LibvlcPosition");
Rename("LibvlcTeletextKeyT", "TeletextKey", strip: "LibvlcTeletextKey");
Rename("LibvlcVideoLogoOptionT", "VideoLogoOption", strip: "LibvlcLogo");
Rename("LibvlcVideoAdjustOptionT", "VideoAdjustOption", strip: "LibvlcAdjust");
Rename("LibvlcAudioOutputDeviceTypesT", "AudioOutputDeviceType", strip: "LibvlcAudioOutput");
Rename("LibvlcAudioOutputChannelT", "AudioOutputChannel", strip: "LibvlcAudioChannel");
Rename("LibvlcMediaPlayerRole", "MediaPlayerRole", strip: "LibvlcRole");
Rename("LibvlcPlaybackModeT", "PlaybackMode", strip: "LibvlcPlaybackMode");
Rename("LibvlcMediaDiscovererCategoryT", "MediaDiscovererCategory", strip: "LibvlcMediaDiscoverer");
Rename("LibvlcDialogQuestionType", "DialogQuestionType", true, "LIBVLC_DIALOG_QUESTION_");
Rename("LibvlcEventE", "EventType", strip: "Libvlc");
void Rename(string originalName, string newName, bool formatValues = false, string strip = null)
{
var match = ctx.FindEnum(originalName).Single();
match.Name = newName;
if (string.IsNullOrEmpty(strip)) return;
match.Items.ForEach(item =>
{
var name = item.Name.Replace(strip, string.Empty);
item.Name = formatValues
? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name.ToLower())
: name;
});
}
}
public void Setup(Driver driver)
{
var rootPath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).Parent.Parent.Parent.FullName;
var h = Path.Combine(rootPath, "include");
var libFolder = Path.Combine(rootPath, "include\\lib");
driver.ParserOptions = new ParserOptions
{
IncludeDirs = new List<string> { h },
//Verbose = true
};
var options = driver.Options;
options.GeneratorKind = GeneratorKind.CSharp;
options.CompileCode = true;
options.OutputDir = Path.Combine(rootPath, "..\\LibVlcSharp\\Generated\\");
options.StripLibPrefix = false;
options.GenerateSingleCSharpFile = false;
options.GenerateSequentialLayout = true;
//options.CheckSymbols = true;
var module = options.AddModule("VideoLAN.LibVLC.Generated");
module.SharedLibraryName = "libvlc";
module.Headers.Add("vlc\\vlc.h");
module.LibraryDirs.Add(libFolder);
}
public void SetupPasses(Driver driver)
{
driver.AddTranslationUnitPass(new MoveCustomFunctionToClassPass());
driver.AddTranslationUnitPass(new RenameEventClasses());
}
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net47</TargetFrameworks>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CppSharp" Version="0.8.14" />
</ItemGroup>
</Project>
\ No newline at end of file
using System.Linq;
using CppSharp.AST;
using CppSharp.Passes;
using ASTContext = CppSharp.AST.ASTContext;
namespace libvlcsharp
{
internal class MoveCustomFunctionToClassPass : TranslationUnitPass
{
public override bool VisitFunctionDecl(Function function)
{
if (function.Name == "libvlc_new")
{
var instance = ASTContext.FindClass("libvlc_instance_t").Single();
MoveFunction(function, instance);
}
return true;
}
private static void MoveFunction(Function function, Class @class)
{
// TODO: Need to make a constructor which passes its params to the native libvlc_new call and store the returned pointer in field
// TODO: also add finalizer with libvlc_release and pass the pointer
var method = new Method(function)
{
Namespace = @class,
Kind = CXXMethodKind.Constructor,
};
//function.ExplicitlyIgnore();
//@class.Methods.Add(method);
//@class.Functions.Add(function);
function.Namespace = @class;
function.OriginalNamespace = @class;
function.Access = AccessSpecifier.Internal;
}
}
}
\ No newline at end of file
using System;
using CppSharp;
namespace libvlcsharp
{
partial class Program
{
static void Main(string[] args)
{
ConsoleDriver.Run(new LibVLC());
Console.ReadKey();
}
}
}
\ No newline at end of file
using System.Linq;
using CppSharp.AST;
using CppSharp.Passes;
namespace libvlcsharp
{
internal class RenameEventClasses : TranslationUnitPass
{
public override bool VisitClassDecl(Class @class)
{
if (@class.Name == string.Empty && @class.Fields.Count == 1)
{
@class.Name = @class.Fields.First().Name;
return true;
}
return base.VisitClassDecl(@class);
}
}
}
\ No newline at end of file
/*****************************************************************************
* deprecated.h: libvlc deprecated API
*****************************************************************************
* Copyright (C) 1998-2008 VLC authors and VideoLAN
* $Id: 27323a434498604ca281900c3e4087a42d22a5d8 $
*
* Authors: Clément Stenac <zorglub@videolan.org>
* Jean-Paul Saman <jpsaman@videolan.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef LIBVLC_DEPRECATED_H
#define LIBVLC_DEPRECATED_H 1
# ifdef __cplusplus
extern "C" {
# endif
/**
* \ingroup libvlc libvlc_media_player
* @{
*/
/**
* Get movie fps rate
*
* This function is provided for backward compatibility. It cannot deal with
* multiple video tracks. In LibVLC versions prior to 3.0, it would also fail
* if the file format did not convey the frame rate explicitly.
*
* \deprecated Consider using libvlc_media_tracks_get() instead.
*
* \param p_mi the Media Player
* \return frames per second (fps) for this playing movie, or 0 if unspecified
*/
LIBVLC_DEPRECATED
LIBVLC_API float libvlc_media_player_get_fps( libvlc_media_player_t *p_mi );
/** end bug */
/**
* \deprecated Use libvlc_media_player_set_nsobject() instead
*/
LIBVLC_DEPRECATED
LIBVLC_API void libvlc_media_player_set_agl ( libvlc_media_player_t *p_mi, uint32_t drawable );
/**
* \deprecated Use libvlc_media_player_get_nsobject() instead
*/
LIBVLC_DEPRECATED
LIBVLC_API uint32_t libvlc_media_player_get_agl ( libvlc_media_player_t *p_mi );
/**
* \deprecated Use libvlc_track_description_list_release() instead
*/
LIBVLC_DEPRECATED LIBVLC_API
void libvlc_track_description_release( libvlc_track_description_t *p_track_description );
/** @}*/
/**
* \ingroup libvlc libvlc_video
* @{
*/
/**
* Get current video height.
* \deprecated Use libvlc_video_get_size() instead.
*
* \param p_mi the media player
* \return the video pixel height or 0 if not applicable
*/
LIBVLC_DEPRECATED LIBVLC_API
int libvlc_video_get_height( libvlc_media_player_t *p_mi );
/**
* Get current video width.
* \deprecated Use libvlc_video_get_size() instead.
*
* \param p_mi the media player
* \return the video pixel width or 0 if not applicable
*/
LIBVLC_DEPRECATED LIBVLC_API
int libvlc_video_get_width( libvlc_media_player_t *p_mi );
/**
* Get the description of available titles.
*
* \param p_mi the media player
* \return list containing description of available titles.
* It must be freed with libvlc_track_description_list_release()
*/
LIBVLC_DEPRECATED LIBVLC_API libvlc_track_description_t *
libvlc_video_get_title_description( libvlc_media_player_t *p_mi );
/**
* Get the description of available chapters for specific title.
*
* \param p_mi the media player
* \param i_title selected title
* \return list containing description of available chapter for title i_title.
* It must be freed with libvlc_track_description_list_release()
*/
LIBVLC_DEPRECATED LIBVLC_API libvlc_track_description_t *
libvlc_video_get_chapter_description( libvlc_media_player_t *p_mi, int i_title );
/**
* Set new video subtitle file.
* \deprecated Use libvlc_media_player_add_slave() instead.
*
* \param p_mi the media player
* \param psz_subtitle new video subtitle file
* \return the success status (boolean)
*/
LIBVLC_DEPRECATED LIBVLC_API int
libvlc_video_set_subtitle_file( libvlc_media_player_t *p_mi, const char *psz_subtitle );
/**
* Toggle teletext transparent status on video output.
* \deprecated use libvlc_video_set_teletext() instead.
*
* \param p_mi the media player
*/
LIBVLC_DEPRECATED LIBVLC_API void
libvlc_toggle_teletext( libvlc_media_player_t *p_mi );
/** @}*/
/**
* \ingroup libvlc libvlc_audio
* @{
*/
/**
* Backward compatibility stub. Do not use in new code.
* \deprecated Use libvlc_audio_output_device_list_get() instead.
* \return always 0.
*/
LIBVLC_DEPRECATED LIBVLC_API
int libvlc_audio_output_device_count( libvlc_instance_t *p_instance, const char *psz_audio_output );
/**
* Backward compatibility stub. Do not use in new code.
* \deprecated Use libvlc_audio_output_device_list_get() instead.
* \return always NULL.
*/
LIBVLC_DEPRECATED LIBVLC_API
char *libvlc_audio_output_device_longname( libvlc_instance_t *p_instance, const char *psz_output,
int i_device );
/**
* Backward compatibility stub. Do not use in new code.
* \deprecated Use libvlc_audio_output_device_list_get() instead.
* \return always NULL.
*/
LIBVLC_DEPRECATED LIBVLC_API
char *libvlc_audio_output_device_id( libvlc_instance_t *p_instance, const char *psz_audio_output, int i_device );
/**
* Stub for backward compatibility.
* \return always -1.
*/
LIBVLC_DEPRECATED
LIBVLC_API int libvlc_audio_output_get_device_type( libvlc_media_player_t *p_mi );
/**
* Stub for backward compatibility.
*/
LIBVLC_DEPRECATED
LIBVLC_API void libvlc_audio_output_set_device_type( libvlc_media_player_t *p_mp,
int device_type );
/** @}*/
/**
* \ingroup libvlc libvlc_media
* @{
*/
/**
* Parse a media.
*
* This fetches (local) art, meta data and tracks information.
* The method is synchronous.
*
* \deprecated This function could block indefinitely.
* Use libvlc_media_parse_with_options() instead
*
* \see libvlc_media_parse_with_options
* \see libvlc_media_get_meta
* \see libvlc_media_get_tracks_info
*
* \param p_md media descriptor object
*/
LIBVLC_DEPRECATED LIBVLC_API void
libvlc_media_parse( libvlc_media_t *p_md );
/**
* Parse a media.
*
* This fetches (local) art, meta data and tracks information.
* The method is the asynchronous of libvlc_media_parse().
*
* To track when this is over you can listen to libvlc_MediaParsedChanged
* event. However if the media was already parsed you will not receive this
* event.
*
* \deprecated You can't be sure to receive the libvlc_MediaParsedChanged
* event (you can wait indefinitely for this event).
* Use libvlc_media_parse_with_options() instead
*
* \see libvlc_media_parse
* \see libvlc_MediaParsedChanged
* \see libvlc_media_get_meta
* \see libvlc_media_get_tracks_info
*
* \param p_md media descriptor object
*/
LIBVLC_DEPRECATED LIBVLC_API void
libvlc_media_parse_async( libvlc_media_t *p_md );
/**
* Return true is the media descriptor object is parsed
*
* \deprecated This can return true in case of failure.
* Use libvlc_media_get_parsed_status() instead