FfmpegLogReceivedEventArgs.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Runtime.InteropServices;
  2. using Bmp.Core.FFMpeg.CsCorePorts.FFMpegWrap.Interops;
  3. namespace Bmp.Core.FFMpeg.CsCorePorts.FFMpegWrap;
  4. /// <summary>
  5. /// Provides data for the <see cref="FfmpegUtils.FfmpegLogReceived"/> event.
  6. /// </summary>
  7. public class FfmpegLogReceivedEventArgs : EventArgs
  8. {
  9. /// <summary>
  10. /// Gets the message.
  11. /// </summary>
  12. /// <value>
  13. /// The message.
  14. /// </value>
  15. public string Message { get; private set; }
  16. /// <summary>
  17. /// Gets the level of the message.
  18. /// </summary>
  19. /// <value>
  20. /// The level of the message.
  21. /// </value>
  22. public LogLevel Level { get; private set; }
  23. /// <summary>
  24. /// Gets the name of the class.
  25. /// </summary>
  26. /// <value>
  27. /// The name of the class.
  28. /// </value>
  29. public string ClassName { get; private set; }
  30. /// <summary>
  31. /// Gets the item name of the class.
  32. /// </summary>
  33. /// <value>
  34. /// The item name of the class.
  35. /// </value>
  36. public string ItemName { get; private set; }
  37. /// <summary>
  38. /// Gets or sets the name of the parent log context class.
  39. /// </summary>
  40. /// <value>
  41. /// The name of the parent log context class. Might me empty.
  42. /// </value>
  43. public string ParentLogContextClassName { get; set; }
  44. /// <summary>
  45. /// Gets or sets the item name of the parent log context class.
  46. /// </summary>
  47. /// <value>
  48. /// The item name of the parent log context class. Might me empty.
  49. /// </value>
  50. public string ParentLogContextItemName { get; set; }
  51. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  52. private delegate nint ItemNameFunc(nint avClass);
  53. internal unsafe FfmpegLogReceivedEventArgs(AVClass? avClass, AVClass? parentLogContext, LogLevel level, string line, void* ptr, void* ptr1)
  54. {
  55. ItemNameFunc itemNameFunc;
  56. nint strPtr;
  57. Message = line;
  58. Level = level;
  59. if (avClass != null)
  60. {
  61. var avc = avClass.Value;
  62. ClassName = Marshal.PtrToStringAnsi((nint)avc.class_name);
  63. if (avc.item_name != nint.Zero)
  64. {
  65. itemNameFunc = (ItemNameFunc)Marshal.GetDelegateForFunctionPointer(avc.item_name, typeof(ItemNameFunc));
  66. strPtr = itemNameFunc((nint)ptr);
  67. if (strPtr != nint.Zero)
  68. ItemName = Marshal.PtrToStringAnsi(strPtr);
  69. }
  70. }
  71. if (parentLogContext != null)
  72. {
  73. var pavc = parentLogContext.Value;
  74. ParentLogContextClassName = Marshal.PtrToStringAnsi((nint)pavc.class_name);
  75. if (pavc.item_name != nint.Zero)
  76. {
  77. itemNameFunc = (ItemNameFunc)Marshal.GetDelegateForFunctionPointer(pavc.item_name, typeof(ItemNameFunc));
  78. strPtr = itemNameFunc((nint)ptr1);
  79. if (strPtr != nint.Zero)
  80. ParentLogContextItemName = Marshal.PtrToStringAnsi(strPtr);
  81. }
  82. }
  83. }
  84. }