VideoEncodedImageReceiverNative.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Runtime.InteropServices;
  3. #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_ANDROID
  4. using AOT;
  5. #endif
  6. namespace Agora.Rtc
  7. {
  8. internal static class VideoEncodedFrameObserverNative
  9. {
  10. internal static IVideoEncodedFrameObserver VideoEncodedFrameObserver;
  11. private static class LocalVideoEncodedVideoFrameInfo
  12. {
  13. internal static readonly EncodedVideoFrameInfo info = new EncodedVideoFrameInfo();
  14. }
  15. #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_ANDROID
  16. [MonoPInvokeCallback(typeof(Func_EncodedVideoFrameObserver_Native))]
  17. #endif
  18. internal static bool OnEncodedVideoFrameReceived(uint uid, IntPtr imageBuffer, UInt64 length, IntPtr videoEncodedFrameInfoPtr)
  19. {
  20. if (VideoEncodedFrameObserver == null)
  21. return true;
  22. var videoEncodedFrameInfo = (IrisEncodedVideoFrameInfo)(Marshal.PtrToStructure(videoEncodedFrameInfoPtr, typeof(IrisEncodedVideoFrameInfo)) ??
  23. new IrisEncodedVideoFrameInfo());
  24. var localVideoEncodedFrameInfo = LocalVideoEncodedVideoFrameInfo.info;
  25. localVideoEncodedFrameInfo.codecType = (VIDEO_CODEC_TYPE)videoEncodedFrameInfo.codecType;
  26. localVideoEncodedFrameInfo.width = videoEncodedFrameInfo.width;
  27. localVideoEncodedFrameInfo.height = videoEncodedFrameInfo.height;
  28. localVideoEncodedFrameInfo.framesPerSecond = videoEncodedFrameInfo.framesPerSecond;
  29. localVideoEncodedFrameInfo.frameType = (VIDEO_FRAME_TYPE_NATIVE)videoEncodedFrameInfo.frameType;
  30. localVideoEncodedFrameInfo.rotation = (VIDEO_ORIENTATION)videoEncodedFrameInfo.rotation;
  31. localVideoEncodedFrameInfo.trackId = videoEncodedFrameInfo.trackId;
  32. localVideoEncodedFrameInfo.captureTimeMs = videoEncodedFrameInfo.captureTimeMs;
  33. localVideoEncodedFrameInfo.uid = videoEncodedFrameInfo.uid;
  34. localVideoEncodedFrameInfo.streamType = (VIDEO_STREAM_TYPE)videoEncodedFrameInfo.streamType;
  35. try
  36. {
  37. return VideoEncodedFrameObserver.OnEncodedVideoFrameReceived(uid, imageBuffer, length, localVideoEncodedFrameInfo);
  38. }
  39. catch(Exception e)
  40. {
  41. AgoraLog.LogError("[Exception] IVideoEncodedFrameObserver.OnEncodedVideoFrameReceived: " + e);
  42. return false;
  43. }
  44. }
  45. }
  46. }