MetaDataObserverNative.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 MetadataObserverNative
  9. {
  10. internal static IMetadataObserver Observer;
  11. #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_ANDROID
  12. [MonoPInvokeCallback(typeof(Func_MaxMetadataSize_Native))]
  13. #endif
  14. internal static int GetMaxMetadataSize()
  15. {
  16. if (Observer == null) return 0;
  17. return Observer.GetMaxMetadataSize();
  18. }
  19. #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_ANDROID
  20. [MonoPInvokeCallback(typeof(Func_ReadyToSendMetadata_Native))]
  21. #endif
  22. internal static bool OnReadyToSendMetadata(ref IrisMetadata metadata, VIDEO_SOURCE_TYPE source_type)
  23. {
  24. if (Observer == null) return false;
  25. var localMetaData = new Metadata();
  26. localMetaData.buffer = metadata.buffer;
  27. localMetaData.size = metadata.size;
  28. localMetaData.uid = metadata.uid;
  29. localMetaData.timeStampMs = metadata.timeStampMs;
  30. var ret = Observer.OnReadyToSendMetadata(ref localMetaData, source_type);
  31. metadata.buffer = localMetaData.buffer;
  32. metadata.uid = localMetaData.uid;
  33. metadata.size = localMetaData.size;
  34. metadata.timeStampMs = localMetaData.timeStampMs;
  35. return ret;
  36. }
  37. #if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_ANDROID
  38. [MonoPInvokeCallback(typeof(Func_MetadataReceived_Native))]
  39. #endif
  40. internal static void OnMetadataReceived(IntPtr metadata)
  41. {
  42. if (Observer == null) return;
  43. var metaData = (IrisMetadata) (Marshal.PtrToStructure(metadata, typeof(IrisMetadata)) ??
  44. new IrisMetadata());
  45. var localMetaData = new Metadata();
  46. localMetaData.buffer = metaData.buffer;
  47. localMetaData.uid = metaData.uid;
  48. localMetaData.size = metaData.size;
  49. localMetaData.timeStampMs = metaData.timeStampMs;
  50. Observer.OnMetadataReceived(localMetaData);
  51. }
  52. }
  53. }