Last active
October 30, 2018 11:18
-
-
Save mfkl/c6e4b9b149da614248bf48b72ef21a05 to your computer and use it in GitHub Desktop.
record
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 0b47c38672749894a4e3c404635a390f10419e95 Mon Sep 17 00:00:00 2001 | |
From: Martin Finkel <martin@videolabs.io> | |
Date: Tue, 30 Oct 2018 18:06:53 +0700 | |
Subject: [PATCH 1/1] Add record interop | |
--- | |
.../Samples.Wpf.Advanced/MainWindow.xaml.cs | 1 + | |
.../Signatures/libvlc_events.h/libvlc_event_e.cs | 1 + | |
.../Signatures/libvlc_events.h/libvlc_event_t.cs | 10 +++++++++ | |
.../libvlc_media_player_get_chapter.cs | 4 ++++ | |
.../VlcManager.GetMediaChapter.cs | 12 +++++++++- | |
.../VlcMediaPlayer.Events.AudioDevice.cs | 26 ++++++++++++++++++++++ | |
.../VlcMediaPlayer/VlcMediaPlayer.cs | 2 ++ | |
.../VlcMediaPlayerAudioDeviceEventArgs.cs | 13 +++++++++++ | |
8 files changed, 68 insertions(+), 1 deletion(-) | |
diff --git a/src/Samples/Samples.Wpf.Advanced/MainWindow.xaml.cs b/src/Samples/Samples.Wpf.Advanced/MainWindow.xaml.cs | |
index aabf780..a257dd1 100644 | |
--- a/src/Samples/Samples.Wpf.Advanced/MainWindow.xaml.cs | |
+++ b/src/Samples/Samples.Wpf.Advanced/MainWindow.xaml.cs | |
@@ -43,6 +43,7 @@ namespace Samples.Wpf.Advanced | |
string message = $"libVlc : {args.Level} {args.Message} @ {args.Module}"; | |
System.Diagnostics.Debug.WriteLine(message); | |
}; | |
+ control.SourceProvider.MediaPlayer.Record(true, vlcLibDirectory.FullName); | |
control.SourceProvider.MediaPlayer.Play(new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi")); | |
} | |
diff --git a/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_e.cs b/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_e.cs | |
index 4f707fe..ff5d58f 100644 | |
--- a/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_e.cs | |
+++ b/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_e.cs | |
@@ -43,6 +43,7 @@ namespace Vlc.DotNet.Core.Interops.Signatures | |
MediaPlayerAudioVolume, | |
MediaPlayerAudioDevice, | |
MediaPlayerChapterChanged, | |
+ MediaPlayerRecordChanged, | |
MediaListItemAdded = 0x200, | |
MediaListWillAddItem, | |
diff --git a/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_t.cs b/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_t.cs | |
index f7587c0..829dc79 100644 | |
--- a/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_t.cs | |
+++ b/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_events.h/libvlc_event_t.cs | |
@@ -111,6 +111,9 @@ namespace Vlc.DotNet.Core.Interops.Signatures | |
[FieldOffset(0)] | |
public MediaPlayerAudioDevice MediaPlayerAudioDevice; | |
+ [FieldOffset(0)] | |
+ public MediaPlayerRecordChanged MediaPlayerRecordChanged; | |
+ | |
[FieldOffset(0)] | |
public RendererDiscovererItemAdded RendererDiscovererItemAdded; | |
@@ -173,6 +176,13 @@ namespace Vlc.DotNet.Core.Interops.Signatures | |
public int NewChapter; | |
} | |
+ [StructLayout(LayoutKind.Sequential)] | |
+ public struct MediaPlayerRecordChanged | |
+ { | |
+ public IntPtr FileName; | |
+ public bool Recording; | |
+ } | |
+ | |
[StructLayout(LayoutKind.Sequential)] | |
public struct MediaPlayerPositionChanged | |
{ | |
diff --git a/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_media_player.h/libvlc_media_player_get_chapter.cs b/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_media_player.h/libvlc_media_player_get_chapter.cs | |
index f4ed1b2..d086757 100644 | |
--- a/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_media_player.h/libvlc_media_player_get_chapter.cs | |
+++ b/src/Vlc.DotNet.Core.Interops/Signatures/libvlc_media_player.h/libvlc_media_player_get_chapter.cs | |
@@ -9,4 +9,8 @@ namespace Vlc.DotNet.Core.Interops.Signatures | |
[LibVlcFunction("libvlc_media_player_get_chapter")] | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
internal delegate int GetMediaChapter(IntPtr mediaPlayerInstance); | |
+ | |
+ [LibVlcFunction("libvlc_media_player_record")] | |
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
+ internal delegate int Record(IntPtr mediaPlayerInstance, bool enable, Utf8StringHandle path); | |
} | |
diff --git a/src/Vlc.DotNet.Core.Interops/VlcManager.GetMediaChapter.cs b/src/Vlc.DotNet.Core.Interops/VlcManager.GetMediaChapter.cs | |
index c4add0d..d382050 100644 | |
--- a/src/Vlc.DotNet.Core.Interops/VlcManager.GetMediaChapter.cs | |
+++ b/src/Vlc.DotNet.Core.Interops/VlcManager.GetMediaChapter.cs | |
@@ -11,5 +11,15 @@ namespace Vlc.DotNet.Core.Interops | |
throw new ArgumentException("Media player instance is not initialized."); | |
return GetInteropDelegate<GetMediaChapter>().Invoke(mediaPlayerInstance); | |
} | |
+ | |
+ public int Record(VlcMediaPlayerInstance mediaPlayerInstance, bool enable, string path) | |
+ { | |
+ if (mediaPlayerInstance == IntPtr.Zero) | |
+ throw new ArgumentException("Media player instance is not initialized."); | |
+ using (var handle = Utf8InteropStringConverter.ToUtf8StringHandle(path)) | |
+ { | |
+ return GetInteropDelegate<Record>().Invoke(mediaPlayerInstance, enable, handle); | |
+ } | |
+ } | |
} | |
-} | |
+} | |
\ No newline at end of file | |
diff --git a/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.Events.AudioDevice.cs b/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.Events.AudioDevice.cs | |
index b362abe..2a73a5e 100644 | |
--- a/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.Events.AudioDevice.cs | |
+++ b/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.Events.AudioDevice.cs | |
@@ -21,4 +21,30 @@ namespace Vlc.DotNet.Core | |
AudioDevice?.Invoke(this, new VlcMediaPlayerAudioDeviceEventArgs(audioDevice)); | |
} | |
} | |
+ | |
+ | |
+ public sealed partial class VlcMediaPlayer | |
+ { | |
+ private EventCallback myOnMediaPlayerRecordChangedInternalEventCallback; | |
+ public event EventHandler<VlcMediaPlayerRecordEventArgs> OnRecord; | |
+ | |
+ private void OnMediaPlayerRecordChangedInternal(IntPtr ptr) | |
+ { | |
+ var args = MarshalHelper.PtrToStructure<VlcEventArg>(ptr); | |
+ var filename = Utf8InteropStringConverter.Utf8InteropToString(args.eventArgsUnion.MediaPlayerRecordChanged.FileName); | |
+ var recording = args.eventArgsUnion.MediaPlayerRecordChanged.Recording; | |
+ | |
+ OnMediaPlayerRecord(filename, recording); | |
+ } | |
+ | |
+ public void OnMediaPlayerRecord(string filename, bool record) | |
+ { | |
+ OnRecord?.Invoke(this, new VlcMediaPlayerRecordEventArgs(filename, record)); | |
+ } | |
+ | |
+ public int Record(bool enable, string fileName) | |
+ { | |
+ return Manager.Record(myMediaPlayerInstance, enable, fileName); | |
+ } | |
+ } | |
} | |
\ No newline at end of file | |
diff --git a/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.cs b/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.cs | |
index 0fb6fc7..9f0fb55 100644 | |
--- a/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.cs | |
+++ b/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayer.cs | |
@@ -392,6 +392,7 @@ namespace Vlc.DotNet.Core | |
Manager.AttachEvent(vlcEventManager, EventTypes.MediaPlayerAudioVolume, myOnMediaPlayerAudioVolumeInternalEventCallback = OnMediaPlayerAudioVolumeInternal); | |
Manager.AttachEvent(vlcEventManager, EventTypes.MediaPlayerAudioDevice, myOnMediaPlayerAudioDeviceInternalEventCallback = OnMediaPlayerAudioDeviceInternal); | |
Manager.AttachEvent(vlcEventManager, EventTypes.MediaPlayerChapterChanged, myOnMediaPlayerChapterChangedInternalEventCallback = OnMediaPlayerChapterChangedInternal); | |
+ Manager.AttachEvent(vlcEventManager, EventTypes.MediaPlayerRecordChanged, myOnMediaPlayerRecordChangedInternalEventCallback = OnMediaPlayerRecordChangedInternal); | |
vlcEventManager.Dispose(); | |
} | |
@@ -427,6 +428,7 @@ namespace Vlc.DotNet.Core | |
Manager.DetachEvent(vlcEventManager, EventTypes.MediaPlayerAudioVolume, myOnMediaPlayerAudioVolumeInternalEventCallback); | |
Manager.DetachEvent(vlcEventManager, EventTypes.MediaPlayerAudioDevice, myOnMediaPlayerAudioDeviceInternalEventCallback); | |
Manager.DetachEvent(vlcEventManager, EventTypes.MediaPlayerChapterChanged, myOnMediaPlayerChapterChangedInternalEventCallback); | |
+ Manager.DetachEvent(vlcEventManager, EventTypes.MediaPlayerRecordChanged, myOnMediaPlayerRecordChangedInternalEventCallback); | |
vlcEventManager.Dispose(); | |
} | |
} | |
diff --git a/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayerAudioDeviceEventArgs.cs b/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayerAudioDeviceEventArgs.cs | |
index 462694f..10a5fc6 100644 | |
--- a/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayerAudioDeviceEventArgs.cs | |
+++ b/src/Vlc.DotNet.Core/VlcMediaPlayer/VlcMediaPlayerAudioDeviceEventArgs.cs | |
@@ -21,4 +21,17 @@ namespace Vlc.DotNet.Core | |
/// </summary> | |
public string Device { get; } | |
} | |
+ | |
+ | |
+ public class VlcMediaPlayerRecordEventArgs : EventArgs | |
+ { | |
+ public VlcMediaPlayerRecordEventArgs(string filename, bool record) | |
+ { | |
+ FileName = filename; | |
+ Record = record; | |
+ } | |
+ | |
+ public string FileName { get; } | |
+ public bool Record { get; } | |
+ } | |
} | |
\ No newline at end of file | |
-- | |
2.16.2.windows.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment