private void OnLogInternal(IntPtr data, VlcLogLevel level, IntPtr ctx, string format, IntPtr args) { if (this._log != null) { // Original source for va_list handling: https://stackoverflow.com/a/37629480/2663813 var byteLength = Win32Interops._vscprintf(format, args) + 1; var utf8Buffer = Marshal.AllocHGlobal(byteLength); string formattedDecodedMessage; try { Win32Interops.vsprintf(utf8Buffer, format, args); //Yeah, ok the message is formatted, but it's an UTF-8 string treated as ASCII inside an UTF-16 string. Do the conversion var sbDecoded = new StringBuilder(Win32Interops.MultiByteToWideChar(Win32Interops.CP_UTF8, 0, utf8Buffer, byteLength, null, 0)); Win32Interops.MultiByteToWideChar(Win32Interops.CP_UTF8, 0, utf8Buffer, byteLength, sbDecoded, sbDecoded.Capacity); formattedDecodedMessage = sbDecoded.ToString(); } finally { Marshal.FreeHGlobal(utf8Buffer); } string module; string file; uint? line; this.Manager.GetLogContext(ctx, out module, out file, out line); // Do the notification on another thread, so that VLC is not interrupted by the logging ThreadPool.QueueUserWorkItem(eventArgs => { this._log(this.myMediaPlayerInstance, (VlcMediaPlayerLogEventArgs)eventArgs); }, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line)); } }
private void OnLogInternal(IntPtr data, VlcLogLevel level, IntPtr ctx, string format, IntPtr args) { if (this._log != null) { // Original source for va_list handling: https://stackoverflow.com/a/37629480/2663813 var byteLength = Win32Interops._vscprintf(format, args) + 1; var utf8Buffer = Marshal.AllocHGlobal(byteLength); string formattedDecodedMessage; try { Win32Interops.vsprintf(utf8Buffer, format, args); formattedDecodedMessage = Utf8InteropStringConverter.Utf8InteropToString(utf8Buffer); } finally { Marshal.FreeHGlobal(utf8Buffer); } string module; string file; uint? line; this.Manager.GetLogContext(ctx, out module, out file, out line); // Do the notification on another thread, so that VLC is not interrupted by the logging #if NETSTANDARD1_3 Task.Run(() => this._log(this.myMediaPlayerInstance, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line))); #else ThreadPool.QueueUserWorkItem(eventArgs => { this._log(this.myMediaPlayerInstance, (VlcMediaPlayerLogEventArgs)eventArgs); }, new VlcMediaPlayerLogEventArgs(level, formattedDecodedMessage, module, file, line)); #endif } }
public VlcMediaPlayerLogEventArgs(VlcLogLevel level, string message, string module, string sourceFile, uint?sourceLine) { this.Level = level; this.Message = message; this.Module = module; this.SourceFile = sourceFile; this.SourceLine = sourceLine; }