Commit 388ff345 authored by Martin Finkel's avatar Martin Finkel

WIP Fix

parent 26673392
......@@ -200,29 +200,30 @@ namespace LibVLCSharp.Shared
internal delegate void UpdateProgressCallback(IntPtr data, IntPtr dialogId, float position, string text);
/// <summary>Dialog callbacks to be implemented</summary>
internal readonly struct DialogCallbacks
[StructLayout(LayoutKind.Sequential)]
internal struct DialogCallbacks
{
internal DialogCallbacks(DisplayErrorCallback displayError, DisplayLoginCallback displayLogin, DisplayQuestionCallback displayQuestion,
DisplayProgressCallback displayProgress, CancelCallback cancel, UpdateProgressCallback updateProgress)
{
DisplayError = displayError;
DisplayLogin = displayLogin;
DisplayQuestion = displayQuestion;
DisplayProgress = displayProgress;
Cancel = cancel;
UpdateProgress = updateProgress;
DisplayError = Marshal.GetFunctionPointerForDelegate(displayError);
DisplayLogin = Marshal.GetFunctionPointerForDelegate(displayLogin);
DisplayQuestion = Marshal.GetFunctionPointerForDelegate(displayQuestion);
DisplayProgress = Marshal.GetFunctionPointerForDelegate(displayProgress);
Cancel = Marshal.GetFunctionPointerForDelegate(cancel);
UpdateProgress = Marshal.GetFunctionPointerForDelegate(updateProgress);
}
internal readonly DisplayErrorCallback DisplayError;
internal IntPtr DisplayError { get; set; }
internal readonly DisplayLoginCallback DisplayLogin;
internal IntPtr DisplayLogin { get; set; }
internal readonly DisplayQuestionCallback DisplayQuestion;
internal IntPtr DisplayQuestion { get; set; }
internal readonly DisplayProgressCallback DisplayProgress;
internal IntPtr DisplayProgress { get; set; }
internal readonly CancelCallback Cancel;
internal IntPtr Cancel { get; set; }
internal readonly UpdateProgressCallback UpdateProgress;
internal IntPtr UpdateProgress { get; set; }
}
}
\ No newline at end of file
......@@ -24,7 +24,7 @@ namespace LibVLCSharp.Shared
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((LibVLC) obj);
return Equals((LibVLC)obj);
}
#if NET || NETSTANDARD
IntPtr _logFileHandle;
......@@ -110,7 +110,7 @@ namespace LibVLCSharp.Shared
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_dialog_set_callbacks")]
internal static extern void LibVLCDialogSetCallbacks(IntPtr libVLC, IntPtr callbacks, IntPtr data);
internal static extern void LibVLCDialogSetCallbacks(IntPtr libVLC, DialogCallbacks callbacks, IntPtr data);
[DllImport(Constants.LibraryName, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "libvlc_renderer_discoverer_list_get")]
......@@ -221,7 +221,7 @@ namespace LibVLCSharp.Shared
base.Dispose(disposing);
}
public static bool operator ==(LibVLC obj1, LibVLC obj2)
{
return obj1?.NativeReference == obj2?.NativeReference;
......@@ -310,7 +310,7 @@ namespace LibVLCSharp.Shared
{
Marshal.FreeHGlobal(_dialogCbsPtr);
_dialogCbsPtr = IntPtr.Zero;
Native.LibVLCDialogSetCallbacks(NativeReference, IntPtr.Zero, IntPtr.Zero);
//Native.LibVLCDialogSetCallbacks(NativeReference, IntPtr.Zero, IntPtr.Zero);
}
}
......@@ -363,7 +363,7 @@ namespace LibVLCSharp.Shared
public ModuleDescription[] AudioFilters => MarshalUtils.Retrieve(() => Native.LibVLCAudioFilterListGet(NativeReference),
MarshalUtils.PtrToStructure<ModuleDescriptionStructure>,
s => s.Build(),
module => module.Next,
module => module.Next,
Native.LibVLCModuleDescriptionListRelease);
/// <summary>Returns a list of video filters that are available.</summary>
......@@ -378,7 +378,7 @@ namespace LibVLCSharp.Shared
public ModuleDescription[] VideoFilters => MarshalUtils.Retrieve(() => Native.LibVLCVideoFilterListGet(NativeReference),
MarshalUtils.PtrToStructure<ModuleDescriptionStructure>,
s => s.Build(),
module => module.Next,
module => module.Next,
Native.LibVLCModuleDescriptionListRelease);
/// <summary>Gets the list of available audio output modules.</summary>
......@@ -388,10 +388,10 @@ namespace LibVLCSharp.Shared
/// <para>libvlc_audio_output_t .</para>
/// <para>In case of error, NULL is returned.</para>
/// </remarks>
public AudioOutputDescription[] AudioOutputs => MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputListGet(NativeReference),
public AudioOutputDescription[] AudioOutputs => MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputListGet(NativeReference),
ptr => MarshalUtils.PtrToStructure<AudioOutputDescriptionStructure>(ptr),
s => s.Build(),
s => s.Next,
s => s.Build(),
s => s.Next,
Native.LibVLCAudioOutputListRelease);
/// <summary>Gets a list of audio output devices for a given audio output module,</summary>
......@@ -414,30 +414,30 @@ namespace LibVLCSharp.Shared
/// <para>explicit audio device.</para>
/// <para>LibVLC 2.1.0 or later.</para>
/// </remarks>
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName) =>
MarshalUtils.Retrieve(() =>
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName) =>
MarshalUtils.Retrieve(() =>
{
var audioOutputNameUtf8 = audioOutputName.ToUtf8();
return MarshalUtils.PerformInteropAndFree(() =>
return MarshalUtils.PerformInteropAndFree(() =>
Native.LibVLCAudioOutputDeviceListGet(NativeReference, audioOutputNameUtf8), audioOutputNameUtf8);
},
},
MarshalUtils.PtrToStructure<AudioOutputDeviceStructure>,
s => s.Build(),
device => device.Next,
s => s.Build(),
device => device.Next,
Native.LibVLCAudioOutputDeviceListRelease);
/// <summary>Get media discoverer services by category</summary>
/// <param name="discovererCategory">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>
public MediaDiscovererDescription[] MediaDiscoverers(MediaDiscovererCategory discovererCategory) =>
MarshalUtils.Retrieve(NativeReference, discovererCategory,
MarshalUtils.Retrieve(NativeReference, discovererCategory,
(IntPtr nativeRef, MediaDiscovererCategory enumType, out IntPtr array) => Native.LibVLCMediaDiscovererListGet(nativeRef, enumType, out array),
MarshalUtils.PtrToStructure<MediaDiscovererDescriptionStructure>,
m => m.Build(),
Native.LibVLCMediaDiscovererListRelease);
readonly Dictionary<IntPtr, CancellationTokenSource> _cts = new Dictionary<IntPtr, CancellationTokenSource>();
static readonly Dictionary<IntPtr, CancellationTokenSource> _cts = new Dictionary<IntPtr, CancellationTokenSource>();
/// <summary>
/// Register callbacks in order to handle VLC dialogs.
......@@ -459,48 +459,98 @@ namespace LibVLCSharp.Shared
if (displayProgress == null) throw new ArgumentNullException(nameof(displayProgress));
if (updateProgress == null) throw new ArgumentNullException(nameof(updateProgress));
var dialogCbs = new DialogCallbacks(
displayError: (data, title, text) => error(title, text),
displayLogin: (data, id, title, text, username, store) =>
{
var cts = new CancellationTokenSource();
var dlg = new Dialog(new DialogId(id));
_cts[id] = cts;
login(dlg, title, text, username, store, cts.Token);
},
displayQuestion: (data, id, title, text, type, cancelText, firstActionText, secondActionText) =>
{
var cts = new CancellationTokenSource();
var dlg = new Dialog(new DialogId(id));
_cts[id] = cts;
question(dlg, title, text, type, cancelText, firstActionText, secondActionText, cts.Token);
},
displayProgress: (data, id, title, text, indeterminate, position, cancelText) =>
{
var cts = new CancellationTokenSource();
var dlg = new Dialog(new DialogId(id));
_cts[id] = cts;
displayProgress(dlg, title, text, indeterminate, position, cancelText, cts.Token);
},
cancel: (data, id) =>
{
if (_cts.TryGetValue(id, out var token))
{
token.Cancel();
_cts.Remove(id);
}
},
updateProgress: (data, id, position, text) =>
{
var dlg = new Dialog(new DialogId(id));
updateProgress(dlg, position, text);
});
_dialogCbsPtr = Marshal.AllocHGlobal(MarshalUtils.SizeOf(dialogCbs));
Marshal.StructureToPtr(dialogCbs, _dialogCbsPtr, true);
Native.LibVLCDialogSetCallbacks(NativeReference, _dialogCbsPtr, IntPtr.Zero);
_login = login;
//var dialogCbs = new DialogCallbacks(
// displayError: (data, title, text) => error(title, text),
// displayLogin: Login,
// //displayLogin: (data, id, title, text, username, store) =>
// //{
// // var cts = new CancellationTokenSource();
// // var dlg = new Dialog(new DialogId(id));
// // _cts[id] = cts;
// // login(dlg, title, text, username, store, cts.Token);
// //},
// displayQuestion: (data, id, title, text, type, cancelText, firstActionText, secondActionText) =>
// {
// var cts = new CancellationTokenSource();
// var dlg = new Dialog(new DialogId(id));
// _cts[id] = cts;
// question(dlg, title, text, type, cancelText, firstActionText, secondActionText, cts.Token);
// },
// displayProgress: (data, id, title, text, indeterminate, position, cancelText) =>
// {
// var cts = new CancellationTokenSource();
// var dlg = new Dialog(new DialogId(id));
// _cts[id] = cts;
// displayProgress(dlg, title, text, indeterminate, position, cancelText, cts.Token);
// },
// cancel: (data, id) =>
// {
// if (_cts.TryGetValue(id, out var token))
// {
// token.Cancel();
// _cts.Remove(id);
// }
// },
// updateProgress: (data, id, position, text) =>
// {
// var dlg = new Dialog(new DialogId(id));
// updateProgress(dlg, position, text);
// });
var dialogCbs = new DialogCallbacks(Error, Login, Question, Progress, Cancel, UpdateProgress);
//_dialogCbsPtr = Marshal.AllocHGlobal(MarshalUtils.SizeOf(dialogCbs));
//Marshal.StructureToPtr(dialogCbs, _dialogCbsPtr, true);
Native.LibVLCDialogSetCallbacks(NativeReference, dialogCbs, IntPtr.Zero);
}
static DisplayLogin _login;
[MonoPInvokeCallback(typeof(DisplayLoginCallback))]
static void Login(IntPtr data, IntPtr dialogId, string title, string text, string defaultUsername, bool askStore)
{
if (_login == null) return;
var cts = new CancellationTokenSource();
var dlg = new Dialog(new DialogId(dialogId));
_cts[dialogId] = cts;
_login(dlg, title, text, defaultUsername, askStore, cts.Token);
}
[MonoPInvokeCallback(typeof(DisplayErrorCallback))]
static void Error(IntPtr data, string title, string text)
{
}
[MonoPInvokeCallback(typeof(DisplayQuestionCallback))]
static void Question(IntPtr data, IntPtr dialogId, string title, string text,
DialogQuestionType type, string cancelText, string firstActionText, string secondActionText)
{
}
[MonoPInvokeCallback(typeof(DisplayProgressCallback))]
static void Progress(IntPtr data, IntPtr dialogId, string title, string text, bool indeterminate, float position, string cancelText)
{
}
[MonoPInvokeCallback(typeof(CancelCallback))]
static void Cancel(IntPtr data, IntPtr dialogId)
{
}
[MonoPInvokeCallback(typeof(UpdateProgressCallback))]
static void UpdateProgress(IntPtr data, IntPtr dialogId, float position, string text)
{
}
/// <summary>
/// True if dialog handlers are set
/// </summary>
......
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