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
            }
        }
        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));
            }
        }
Beispiel #3
0
        static internal T CppFunction <T>()
        {
            string sCppFunctionName = null;

            try
            {
                object[] aAttrs = typeof(T).GetCustomAttributes(typeof(CppFunctionAttribute), false);
                if (aAttrs.Length == 0)
                {
                    throw new Exception("Could not find the AjaFunctionAttribute.");
                }
                CppFunctionAttribute cAjaAttr = (CppFunctionAttribute)aAttrs[0];
                sCppFunctionName = cAjaAttr.sFunctionName;
                if (!_ahCppFunctionsUsed.ContainsKey(sCppFunctionName))
                {
                    IntPtr pFuncAddress = Win32Interops.GetProcAddress(_pWrapperDllHandler, cAjaAttr.sFunctionName);
                    if (pFuncAddress == IntPtr.Zero)
                    {
                        throw new System.ComponentModel.Win32Exception();
                    }
                    Delegate dFunctionPointer = Marshal.GetDelegateForFunctionPointer(pFuncAddress, typeof(T));
                    _ahCppFunctionsUsed.Add(cAjaAttr.sFunctionName, dFunctionPointer);
                }
                return((T)Convert.ChangeType(_ahCppFunctionsUsed[cAjaAttr.sFunctionName], typeof(T), null));
            }
            catch (System.ComponentModel.Win32Exception e)
            {
                throw new MissingMethodException(String.Format("Function " + sCppFunctionName + " was not found in aja dll."), e);
            }
        }
Beispiel #4
0
 protected override void DestroyWindowCore(HandleRef hwnd)
 {
     if (MediaPlayer == null)
     {
         return;
     }
     Win32Interops.SetParent(IntPtr.Zero, hwnd.Handle);
     MediaPlayer.Dispose();
     MediaPlayer = null;
 }
Beispiel #5
0
        static Ebur128CppInterop()
        {
            string sAssemblyPath = typeof(Ebur128CppInterop).Assembly.Location;
            string sAssemblyDir  = System.IO.Path.GetDirectoryName(sAssemblyPath);

            (new Logger()).WriteNotice("Ebur128CppInterop's assembly path = " + sAssemblyPath); //.GetExecutingAssembly()
            string sDll = System.IO.Path.Combine(sAssemblyDir, "EBUR128_x64_Debug.dll");

            (new Logger()).WriteNotice(sDll + " found [" + System.IO.File.Exists(sDll) + "]");
            _pWrapperDllHandler = Win32Interops.LoadLibrary(sDll); //Win32Project1 // can be a full path
            if (_pWrapperDllHandler == IntPtr.Zero)
            {
                (new Logger()).WriteNotice("kernel32 GetLastError = [" + Win32Interops.GetLastError() + "] [dll = " + sDll + "]");
                sDll = System.IO.Path.Combine(sAssemblyDir, "EBUR128_x64_Release.dll");
                (new Logger()).WriteNotice(sDll + " found [" + System.IO.File.Exists(sDll) + "]");
                _pWrapperDllHandler = Win32Interops.LoadLibrary(sDll); //Win32Project1 // can be a full path
                if (_pWrapperDllHandler == IntPtr.Zero)
                {
                    (new Logger()).WriteNotice("kernel32 GetLastError = [" + Win32Interops.GetLastError() + "] [dll = " + sDll + "]");
                    throw new System.ComponentModel.Win32Exception($"dll library was not found or cannot be loaded [{sDll}]");
                }
            }
            _ahCppFunctionsUsed = new Dictionary <string, Delegate>();
        }
Beispiel #6
0
 protected override HandleRef BuildWindowCore(HandleRef hwndParent)
 {
     Win32Interops.SetParent(MediaPlayer.Handle, hwndParent.Handle);
     return(new HandleRef(this, MediaPlayer.Handle));
 }