This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #278 from jeremyVignelles/Logging
Added the ability to get VLC log messages from the application
- Loading branch information
Showing
22 changed files
with
426 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
17 changes: 17 additions & 0 deletions
17
src/Vlc.DotNet.Core.Interops/Signatures/libvlc.h/libvlc_log_cb.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Vlc.DotNet.Core.Interops.Signatures | ||
{ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
/// <summary> | ||
/// The delegate type that represent logging functions | ||
/// </summary> | ||
/// <param name="data">The data given to libvlc_log_set. In our case, this value will always be <see langword="null" /></param> | ||
/// <param name="level">The log level</param> | ||
/// <param name="logContext">The address of the structure that contains information about the log event. <see cref="GetLogContext"/></param> | ||
/// <param name="format">The format of the log messages</param> | ||
/// <param name="args">The va_list of printf arguments.</param> | ||
[LibVlcFunction("libvlc_log_cb")] | ||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void LogCallback(IntPtr data, VlcLogLevel level, IntPtr logContext, [MarshalAs(UnmanagedType.LPStr)] string format, IntPtr args); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Vlc.DotNet.Core.Interops/Signatures/libvlc.h/libvlc_log_get_context.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Vlc.DotNet.Core.Interops.Signatures | ||
{ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
/// <summary> | ||
/// Gets log message debug infos. | ||
/// | ||
/// This function retrieves self-debug information about a log message: | ||
/// - the name of the VLC module emitting the message, | ||
/// - the name of the source code module (i.e.file) and | ||
/// - the line number within the source code module. | ||
/// | ||
/// The returned module name and file name will be NULL if unknown. | ||
/// The returned line number will similarly be zero if unknown. | ||
/// </summary> | ||
/// <param name="logContext">The log message context (as passed to the <see cref="LogCallback"/>)</param> | ||
/// <param name="module">The module name storage.</param> | ||
/// <param name="file">The source code file name storage.</param> | ||
/// <param name="line">The source code file line number storage.</param> | ||
[LibVlcFunction("libvlc_log_get_context")] | ||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] | ||
public delegate void GetLogContext(IntPtr logContext, out IntPtr module, out IntPtr file, out UIntPtr line); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Vlc.DotNet.Core.Interops/Signatures/libvlc.h/libvlc_log_level_e.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Vlc.DotNet.Core.Interops.Signatures | ||
{ | ||
public enum VlcLogLevel | ||
: int | ||
{ | ||
Debug = 0, | ||
Notice = 2, | ||
Warning = 3, | ||
Error = 4 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Vlc.DotNet.Core.Interops/Signatures/libvlc.h/libvlc_log_set.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Vlc.DotNet.Core.Interops.Signatures | ||
{ | ||
/// <summary> | ||
/// Registers a log callback | ||
/// </summary> | ||
/// <param name="libVlcInstance">The libvlc instance.</param> | ||
/// <param name="callback">The method that will be called whenever a log is available.</param> | ||
/// <param name="userData">User provided data to carry with the event.</param> | ||
[LibVlcFunction("libvlc_log_set")] | ||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
public delegate void SetLog(IntPtr libVlcInstance, LogCallback callback, IntPtr userData); | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using Vlc.DotNet.Core.Interops.Signatures; | ||
|
||
namespace Vlc.DotNet.Core.Interops | ||
{ | ||
using System.Runtime.InteropServices; | ||
|
||
public sealed partial class VlcManager | ||
{ | ||
/// <summary> | ||
/// Gets log message debug infos. | ||
/// | ||
/// This function retrieves self-debug information about a log message: | ||
/// - the name of the VLC module emitting the message, | ||
/// - the name of the source code module (i.e.file) and | ||
/// - the line number within the source code module. | ||
/// | ||
/// The returned module name and file name will be NULL if unknown. | ||
/// The returned line number will similarly be zero if unknown. | ||
/// </summary> | ||
/// <param name="logContext">The log message context (as passed to the <see cref="LogCallback"/>)</param> | ||
/// <param name="module">The module name storage.</param> | ||
/// <param name="file">The source code file name storage.</param> | ||
/// <param name="line">The source code file line number storage.</param> | ||
public void GetLogContext(IntPtr logContext, out string module, out string file, out uint? line) | ||
{ | ||
UIntPtr _line; | ||
IntPtr _module; | ||
IntPtr _file; | ||
GetInteropDelegate<GetLogContext>().Invoke(logContext, out _module, out _file, out _line); | ||
if (_line == UIntPtr.Zero) | ||
{ | ||
line = null; | ||
} | ||
else | ||
{ | ||
line = _line.ToUInt32(); | ||
} | ||
|
||
module = Marshal.PtrToStringAnsi(_module); | ||
file = Marshal.PtrToStringAnsi(_file); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using Vlc.DotNet.Core.Interops.Signatures; | ||
|
||
namespace Vlc.DotNet.Core.Interops | ||
{ | ||
public sealed partial class VlcManager | ||
{ | ||
/// <summary> | ||
/// Keeps a reference to the last callback that was given to the <see cref="SetLog"/> method. | ||
/// This is to avoid garbage collection of the delegate before the function is called. | ||
/// </summary> | ||
private LogCallback _logCallbackReference; | ||
|
||
public void SetLog(LogCallback callback) | ||
{ | ||
if (callback == null) | ||
{ | ||
throw new ArgumentException("Callback for log is not initialized."); | ||
} | ||
this._logCallbackReference = callback; | ||
GetInteropDelegate<SetLog>().Invoke(this.myVlcInstance, this._logCallbackReference, IntPtr.Zero); | ||
} | ||
} | ||
} |
Oops, something went wrong.