NativePlugin.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. using UnityEngine;
  2. using UnityEngine.Rendering;
  3. using System;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. #if UNITY_IOS || UNITY_TVOS || ENABLE_IL2CPP
  7. using AOT;
  8. #endif
  9. //-----------------------------------------------------------------------------
  10. // Copyright 2012-2022 RenderHeads Ltd. All rights reserved.
  11. //-----------------------------------------------------------------------------
  12. namespace RenderHeads.Media.AVProMovieCapture
  13. {
  14. public partial class NativePlugin
  15. {
  16. public const string ScriptVersion = "5.1.0";
  17. #if UNITY_EDITOR_OSX || (!UNITY_EDITOR && (UNITY_STANDALONE_OSX || UNITY_IOS))
  18. public const string ExpectedPluginVersion = "5.1.0";
  19. #elif UNITY_ANDROID && !UNITY_EDITOR
  20. public const string ExpectedPluginVersion = "5.1.0";
  21. #else
  22. public const string ExpectedPluginVersion = "5.1.0";
  23. #endif
  24. }
  25. public enum NoneAutoCustom
  26. {
  27. None,
  28. Auto,
  29. Custom,
  30. }
  31. public enum AudioCaptureSource
  32. {
  33. None = 0,
  34. Unity = 1,
  35. Microphone = 2,
  36. Manual = 3,
  37. Wwise = 4,
  38. UnityAudioMixer = 5,
  39. }
  40. public enum StereoPacking
  41. {
  42. None,
  43. TopBottom,
  44. LeftRight,
  45. }
  46. public enum Transparency
  47. {
  48. None,
  49. Codec, // Currently only for HEVC and ProRes 4444 on macOS/iOS, and supported DirectShow codecs (eg Lagarith/Uncompressed) on Windows
  50. TopBottom,
  51. LeftRight,
  52. }
  53. public enum SphericalVideoLayout
  54. {
  55. None,
  56. Equirectangular360,
  57. Equirectangular180,
  58. //TODO: Cubemap32
  59. }
  60. public enum StopMode
  61. {
  62. None,
  63. FramesEncoded,
  64. SecondsEncoded,
  65. SecondsElapsed,
  66. }
  67. public enum StartTriggerMode
  68. {
  69. Manual,
  70. OnStart,
  71. }
  72. public enum StartDelayMode
  73. {
  74. None,
  75. RealSeconds,
  76. GameSeconds,
  77. Manual,
  78. }
  79. public enum ImageSequenceFormat
  80. {
  81. PNG,
  82. JPEG, // Apple and Android platforms only
  83. TIFF, // Apple platforms only
  84. HEIF, // Apple platforms only
  85. }
  86. public enum OutputTarget
  87. {
  88. VideoFile,
  89. ImageSequence,
  90. NamedPipe,
  91. }
  92. // Android vulkan pre-transform
  93. public enum AndroidVulkanPreTransform
  94. {
  95. None,
  96. Portrait,
  97. PortraitUpsideDown,
  98. LandscapeLeft,
  99. LandscapeRight
  100. };
  101. public partial class NativePlugin
  102. {
  103. #if UNITY_IOS && !UNITY_EDITOR
  104. const string PluginName = "__Internal";
  105. #elif UNITY_ANDROID && !UNITY_EDITOR
  106. const string PluginName = "libAVProMovieCaptureNative";
  107. #else
  108. const string PluginName = "AVProMovieCapture";
  109. #endif
  110. public enum Platform
  111. {
  112. Unknown = -2,
  113. Current = -1,
  114. First = 0,
  115. Windows = 0,
  116. macOS = 1,
  117. iOS = 2,
  118. Android = 3,
  119. Count = 4,
  120. }
  121. public static string[] PlatformNames = { "Windows", "macOS", "iOS", "Android" };
  122. // The Apple platforms have a fixed set of known codecs
  123. public static readonly string[] VideoCodecNamesMacOS = { "H264", "HEVC", "MJPEG", "ProRes 4:2:2", "ProRes 4:4:4:4" };
  124. public static readonly string[] AudioCodecNamesMacOS = { "AAC", "FLAC", "Apple Lossless", "Linear PCM", "Uncompresssed" };
  125. public static readonly string[] VideoCodecNamesIOS = { "H264", "HEVC", "MJPEG" };
  126. public static readonly string[] AudioCodecNamesIOS = { "AAC", "FLAC", "Apple Lossless", "Linear PCM", "Uncompresssed" };
  127. public static readonly string[] VideoCodecNamesAndroid = { "H264", "HEVC"/*, "VP8", "VP9"*/ };
  128. public static readonly string[] AudioCodecNamesAndroid = { "AAC"/*, "OPUS", "FLAC"*/ };
  129. public enum PixelFormat
  130. {
  131. RGBA32,
  132. BGRA32, // Note: This is the native format for Unity textures with red and blue swapped.
  133. YCbCr422_YUY2,
  134. YCbCr422_UYVY,
  135. YCbCr422_HDYC,
  136. }
  137. public const int MaxRenderWidth = 16384;
  138. public const int MaxRenderHeight = 16384;
  139. #region RenderEventFunctions
  140. // Used by GL.IssuePluginEvent
  141. private const int PluginID = 0xFA30000;
  142. public enum PluginEvent
  143. {
  144. CaptureFrameBuffer = 0,
  145. FreeResources = 1,
  146. Setup = 2,
  147. }
  148. private static System.IntPtr _renderEventFunction = System.IntPtr.Zero;
  149. private static System.IntPtr _freeEventFunction = System.IntPtr.Zero;
  150. public static void RenderThreadEvent(PluginEvent renderEvent, int handle)
  151. {
  152. switch (renderEvent)
  153. {
  154. case PluginEvent.CaptureFrameBuffer:
  155. #if UNITY_ANDROID && !UNITY_EDITOR
  156. CommandBuffer commandBuffer = new CommandBuffer();
  157. System.IntPtr data = new System.IntPtr(handle);
  158. commandBuffer.IssuePluginEventAndData(RenderCaptureEventFunction, PluginID, data);
  159. Graphics.ExecuteCommandBuffer(commandBuffer);
  160. if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3)
  161. GL.InvalidateState();
  162. #else
  163. GL.IssuePluginEvent(RenderCaptureEventFunction, PluginID | (int)renderEvent | handle);
  164. #endif
  165. break;
  166. case PluginEvent.FreeResources:
  167. GL.IssuePluginEvent(RenderFreeEventFunction, PluginID | (int)renderEvent);
  168. break;
  169. case PluginEvent.Setup:
  170. #if UNITY_ANDROID && !UNITY_EDITOR
  171. if (RenderSetupEventFunction != System.IntPtr.Zero)
  172. {
  173. GL.IssuePluginEvent(RenderSetupEventFunction, PluginID | (int)renderEvent | handle);
  174. }
  175. #endif
  176. break;
  177. }
  178. }
  179. private static System.IntPtr RenderCaptureEventFunction
  180. {
  181. get
  182. {
  183. if (_renderEventFunction == System.IntPtr.Zero)
  184. {
  185. _renderEventFunction = GetRenderEventFunc();
  186. }
  187. Debug.Assert(_renderEventFunction != System.IntPtr.Zero);
  188. return _renderEventFunction;
  189. }
  190. }
  191. private static System.IntPtr RenderFreeEventFunction
  192. {
  193. get
  194. {
  195. if (_freeEventFunction == System.IntPtr.Zero)
  196. {
  197. _freeEventFunction = GetFreeResourcesEventFunc();
  198. }
  199. Debug.Assert(_freeEventFunction != System.IntPtr.Zero);
  200. return _freeEventFunction;
  201. }
  202. }
  203. [DllImport(PluginName, EntryPoint="AVPMC_GetRenderEventFunc")]
  204. private static extern System.IntPtr GetRenderEventFunc();
  205. [DllImport(PluginName, EntryPoint="AVPMC_GetFreeResourcesEventFunc")]
  206. private static extern System.IntPtr GetFreeResourcesEventFunc();
  207. #if UNITY_ANDROID && !UNITY_EDITOR
  208. private static System.IntPtr _setupEventFunction = System.IntPtr.Zero;
  209. private static System.IntPtr RenderSetupEventFunction
  210. {
  211. get
  212. {
  213. if (_setupEventFunction == System.IntPtr.Zero)
  214. {
  215. _setupEventFunction = GetSetupEventFunc();
  216. }
  217. return _setupEventFunction;
  218. }
  219. }
  220. [DllImport(PluginName, EntryPoint="AVPMC_GetSetupEventFunc")]
  221. private static extern System.IntPtr GetSetupEventFunc();
  222. #endif
  223. #endregion
  224. #if UNITY_EDITOR_OSX || (!UNITY_EDITOR && (UNITY_STANDALONE_OSX || UNITY_IOS))
  225. internal class Logger
  226. {
  227. private enum LogFlag : int {
  228. Error = 1 << 0,
  229. Warning = 1 << 1,
  230. Info = 1 << 2,
  231. Debug = 1 << 3,
  232. Verbose = 1 << 4,
  233. };
  234. private enum LogLevel : int
  235. {
  236. Off = 0,
  237. Error = LogFlag.Error,
  238. Warning = Error | LogFlag.Warning,
  239. Info = Warning | LogFlag.Info,
  240. Debug = Info | LogFlag.Debug,
  241. Verbose = Debug | LogFlag.Verbose,
  242. All = -1,
  243. };
  244. #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
  245. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  246. #endif
  247. private delegate void DebugLogCallbackDelegate(LogLevel level, [In, MarshalAs(UnmanagedType.LPWStr)] string str);
  248. #if UNITY_IOS || UNITY_TVOS || ENABLE_IL2CPP
  249. [MonoPInvokeCallback(typeof(DebugLogCallbackDelegate))]
  250. #endif
  251. private static void DebugLogCallback(LogLevel level, string str)
  252. {
  253. if (level == LogLevel.Error)
  254. {
  255. Debug.LogError(str);
  256. }
  257. else if (level == LogLevel.Warning)
  258. {
  259. Debug.LogWarning(str);
  260. }
  261. else
  262. {
  263. Debug.Log(str);
  264. }
  265. }
  266. private DebugLogCallbackDelegate _callbackDelegate = new DebugLogCallbackDelegate(DebugLogCallback);
  267. internal Logger()
  268. {
  269. IntPtr func = Marshal.GetFunctionPointerForDelegate(_callbackDelegate);
  270. NativePlugin.SetLogFunction(func);
  271. }
  272. ~Logger()
  273. {
  274. NativePlugin.SetLogFunction(IntPtr.Zero);
  275. }
  276. }
  277. internal static Logger _logger;
  278. private static void SetupDebugLogCallback()
  279. {
  280. _logger = new Logger();
  281. }
  282. #if !UNITY_EDITOR_OSX && UNITY_IOS
  283. [DllImport(PluginName, EntryPoint="AVPMC_PluginBootstrap")]
  284. public static extern void MCPluginBootstrap();
  285. #endif
  286. static NativePlugin()
  287. {
  288. #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
  289. SetupDebugLogCallback();
  290. #endif
  291. #if !UNITY_EDITOR_OSX && UNITY_IOS
  292. NativePlugin.MCPluginBootstrap();
  293. #endif
  294. }
  295. #endif
  296. //////////////////////////////////////////////////////////////////////////
  297. // Global Init/Deinit
  298. [DllImport(PluginName, EntryPoint="AVPMC_Init")]
  299. [return: MarshalAs(UnmanagedType.U1)]
  300. public static extern bool Init();
  301. [DllImport(PluginName, EntryPoint="AVPMC_Deinit")]
  302. public static extern void Deinit();
  303. [Flags]
  304. public enum MicrophoneRecordingOptions: int
  305. {
  306. None = 0,
  307. MixWithOthers = 1,
  308. DefaultToSpeaker = 2,
  309. }
  310. [DllImport(PluginName, EntryPoint="AVPMC_SetMicrophoneRecordingHint")]
  311. public static extern void SetMicrophoneRecordingHint([MarshalAs(UnmanagedType.U1)] bool enabled, MicrophoneRecordingOptions options = MicrophoneRecordingOptions.None);
  312. public static string GetPluginVersionString()
  313. {
  314. return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(GetPluginVersion());
  315. }
  316. [DllImport(PluginName, EntryPoint="AVPMC_IsTrialVersion")]
  317. [return: MarshalAs(UnmanagedType.U1)]
  318. public static extern bool IsTrialVersion();
  319. public static bool IsBasicEdition()
  320. {
  321. string version = NativePlugin.GetPluginVersionString();
  322. return version.IndexOf("basic", StringComparison.OrdinalIgnoreCase) >= 0;
  323. }
  324. //////////////////////////////////////////////////////////////////////////
  325. // Video Codecs
  326. [DllImport(PluginName, EntryPoint="AVPMC_GetVideoCodecCount")]
  327. public static extern int GetVideoCodecCount();
  328. [DllImport(PluginName, EntryPoint="AVPMC_IsConfigureVideoCodecSupported")]
  329. [return: MarshalAs(UnmanagedType.U1)]
  330. public static extern bool IsConfigureVideoCodecSupported(int codecIndex);
  331. [DllImport(PluginName, EntryPoint="AVPMC_GetVideoCodecMediaApi")]
  332. public static extern MediaApi GetVideoCodecMediaApi(int codecIndex);
  333. [DllImport(PluginName, EntryPoint="AVPMC_ConfigureVideoCodec")]
  334. public static extern void ConfigureVideoCodec(int codecIndex);
  335. public static string GetVideoCodecName(int codecIndex)
  336. {
  337. string result = "Invalid";
  338. StringBuilder nameBuffer = new StringBuilder(256);
  339. if (GetVideoCodecName(codecIndex, nameBuffer, nameBuffer.Capacity))
  340. {
  341. result = nameBuffer.ToString();
  342. }
  343. return result;
  344. }
  345. //////////////////////////////////////////////////////////////////////////
  346. // Audio Codecs
  347. [DllImport(PluginName, EntryPoint="AVPMC_GetAudioCodecCount")]
  348. public static extern int GetAudioCodecCount();
  349. [DllImport(PluginName, EntryPoint="AVPMC_IsConfigureAudioCodecSupported")]
  350. [return: MarshalAs(UnmanagedType.U1)]
  351. public static extern bool IsConfigureAudioCodecSupported(int codecIndex);
  352. [DllImport(PluginName, EntryPoint="AVPMC_GetAudioCodecMediaApi")]
  353. public static extern MediaApi GetAudioCodecMediaApi(int codecIndex);
  354. [DllImport(PluginName, EntryPoint="AVPMC_ConfigureAudioCodec")]
  355. public static extern void ConfigureAudioCodec(int codecIndex);
  356. public static string GetAudioCodecName(int codecIndex)
  357. {
  358. string result = "Invalid";
  359. StringBuilder nameBuffer = new StringBuilder(256);
  360. if (GetAudioCodecName(codecIndex, nameBuffer, nameBuffer.Capacity))
  361. {
  362. result = nameBuffer.ToString();
  363. }
  364. return result;
  365. }
  366. //////////////////////////////////////////////////////////////////////////
  367. // Audio Devices
  368. [DllImport(PluginName, EntryPoint="AVPMC_GetAudioInputDeviceCount")]
  369. public static extern int GetAudioInputDeviceCount();
  370. public static string GetAudioInputDeviceName(int index)
  371. {
  372. string result = "Invalid";
  373. StringBuilder nameBuffer = new StringBuilder(256);
  374. if (GetAudioInputDeviceName(index, nameBuffer, nameBuffer.Capacity))
  375. {
  376. result = nameBuffer.ToString();
  377. }
  378. return result;
  379. }
  380. #if UNITY_EDITOR_WIN || (!UNITY_EDITOR && UNITY_STANDALONE_WIN)
  381. [DllImport(PluginName, EntryPoint="AVPMC_GetAudioInputDeviceMediaApi")]
  382. public static extern MediaApi GetAudioInputDeviceMediaApi(int index);
  383. #else
  384. public static MediaApi GetAudioInputDeviceMediaApi(int index)
  385. {
  386. #if UNITY_EDITOR_OSX || (!UNITY_EDITOR && (UNITY_STANDALONE_OSX || UNITY_IOS))
  387. return MediaApi.AVFoundation;
  388. #elif UNITY_ANDROID && !UNITY_EDITOR
  389. return MediaApi.MediaCodec;
  390. #else
  391. return MediaApi.Unknown;
  392. #endif
  393. }
  394. #endif
  395. //////////////////////////////////////////////////////////////////////////
  396. // Container Files
  397. public static string[] GetContainerFileExtensions(int videoCodecIndex, int audioCodecIndex = -1)
  398. {
  399. string[] result = new string[0];
  400. StringBuilder extensionsBuffer = new StringBuilder(256);
  401. if (GetContainerFileExtensions(videoCodecIndex, audioCodecIndex, extensionsBuffer, extensionsBuffer.Capacity))
  402. {
  403. result = extensionsBuffer.ToString().Split(new char[] {','});
  404. }
  405. return result;
  406. }
  407. //////////////////////////////////////////////////////////////////////////
  408. // Create the Recorder
  409. [DllImport(PluginName, EntryPoint="AVPMC_CreateRecorderVideo")]
  410. public static extern int CreateRecorderVideo([MarshalAs(UnmanagedType.LPWStr)] string filename,
  411. uint width,
  412. uint height,
  413. float frameRate,
  414. int format,
  415. [MarshalAs(UnmanagedType.U1)] bool isRealTime,
  416. [MarshalAs(UnmanagedType.U1)] bool isTopDown,
  417. int videoCodecIndex,
  418. AudioCaptureSource audioSource,
  419. int audioSampleRate,
  420. int audioChannelCount,
  421. int audioInputDeviceIndex,
  422. int audioCodecIndex,
  423. [MarshalAs(UnmanagedType.U1)] bool forceGpuFlush,
  424. VideoEncoderHints hints);
  425. [DllImport(PluginName, EntryPoint="AVPMC_CreateRecorderImages")]
  426. public static extern int CreateRecorderImages([MarshalAs(UnmanagedType.LPWStr)] string filename,
  427. uint width,
  428. uint height,
  429. float frameRate,
  430. int format,
  431. [MarshalAs(UnmanagedType.U1)] bool isRealTime,
  432. [MarshalAs(UnmanagedType.U1)] bool isTopDown,
  433. int imageFormatType,
  434. [MarshalAs(UnmanagedType.U1)] bool forceGpuFlush,
  435. int startFrame,
  436. ImageEncoderHints hints);
  437. [DllImport(PluginName, EntryPoint="AVPMC_CreateRecorderPipe")]
  438. public static extern int CreateRecorderPipe([MarshalAs(UnmanagedType.LPWStr)] string filename,
  439. uint width,
  440. uint height,
  441. float frameRate,
  442. int format,
  443. [MarshalAs(UnmanagedType.U1)] bool isTopDown,
  444. /*[MarshalAs(UnmanagedType.U1)] bool supportAlpha*/int transparencyMode,
  445. [MarshalAs(UnmanagedType.U1)] bool forceGpuFlush);
  446. //////////////////////////////////////////////////////////////////////////
  447. // Update recorder
  448. [DllImport(PluginName, EntryPoint="AVPMC_Start")]
  449. [return: MarshalAs(UnmanagedType.U1)]
  450. public static extern bool Start(int handle);
  451. [DllImport(PluginName, EntryPoint="AVPMC_IsNewFrameDue")]
  452. [return: MarshalAs(UnmanagedType.U1)]
  453. public static extern bool IsNewFrameDue(int handle);
  454. [DllImport(PluginName, EntryPoint="AVPMC_SetEncodedFrameLimit")]
  455. public static extern int SetEncodedFrameLimit(int handle, uint encodedFrameLimit);
  456. [DllImport(PluginName, EntryPoint="AVPMC_EncodeFrame")]
  457. public static extern void EncodeFrame(int handle, System.IntPtr data);
  458. [DllImport(PluginName, EntryPoint="AVPMC_EncodeAudio")]
  459. public static extern void EncodeAudio(int handle, System.IntPtr data, uint length);
  460. [DllImport(PluginName, EntryPoint="AVPMC_EncodeFrameWithAudio")]
  461. public static extern void EncodeFrameWithAudio(int handle, System.IntPtr videoData, System.IntPtr audioData, uint audioLength);
  462. [DllImport(PluginName, EntryPoint="AVPMC_Pause")]
  463. public static extern void Pause(int handle);
  464. [DllImport(PluginName, EntryPoint="AVPMC_Stop")]
  465. public static extern void Stop(int handle, [MarshalAs(UnmanagedType.U1)] bool skipPendingFrames);
  466. [DllImport(PluginName, EntryPoint="AVPMC_IsFileWritingComplete")]
  467. [return: MarshalAs(UnmanagedType.U1)]
  468. public static extern bool IsFileWritingComplete(int handle);
  469. [DllImport(PluginName, EntryPoint="AVPMC_SetTexturePointer")]
  470. public static extern void SetTexturePointer(int handle, System.IntPtr texture);
  471. #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || (!UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS))
  472. [DllImport(PluginName, EntryPoint="AVPMC_SetRenderBuffer")]
  473. public static extern void SetRenderBuffer(int handle, System.IntPtr renderbuffer);
  474. #endif
  475. #if false
  476. [DllImport(PluginName, EntryPoint="AVPMC_SetColourBuffer")]
  477. public static extern void SetColourBuffer(int handle, System.IntPtr buffer);
  478. #endif
  479. //////////////////////////////////////////////////////////////////////////
  480. // Destroy recorder
  481. [DllImport(PluginName, EntryPoint="AVPMC_FreeRecorder")]
  482. public static extern void FreeRecorder(int handle);
  483. //////////////////////////////////////////////////////////////////////////
  484. // Debugging
  485. [DllImport(PluginName, EntryPoint="AVPMC_GetNumDroppedFrames")]
  486. public static extern uint GetNumDroppedFrames(int handle);
  487. [DllImport(PluginName, EntryPoint="AVPMC_GetNumDroppedEncoderFrames")]
  488. public static extern uint GetNumDroppedEncoderFrames(int handle);
  489. [DllImport(PluginName, EntryPoint="AVPMC_GetNumEncodedFrames")]
  490. public static extern uint GetNumEncodedFrames(int handle);
  491. [DllImport(PluginName, EntryPoint="AVPMC_GetEncodedSeconds")]
  492. public static extern uint GetEncodedSeconds(int handle);
  493. [DllImport(PluginName, EntryPoint="AVPMC_GetFileSize")]
  494. public static extern uint GetFileSize(int handle);
  495. //////////////////////////////////////////////////////////////////////////
  496. // Private internal functions
  497. [DllImport(PluginName, EntryPoint="AVPMC_GetPluginVersion")]
  498. private static extern System.IntPtr GetPluginVersion();
  499. [DllImport(PluginName, EntryPoint="AVPMC_GetVideoCodecName")]
  500. [return: MarshalAs(UnmanagedType.U1)]
  501. private static extern bool GetVideoCodecName(int index, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int nameBufferLength);
  502. [DllImport(PluginName, EntryPoint="AVPMC_GetAudioCodecName")]
  503. [return: MarshalAs(UnmanagedType.U1)]
  504. private static extern bool GetAudioCodecName(int index, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int nameBufferLength);
  505. [DllImport(PluginName, EntryPoint="AVPMC_GetAudioInputDeviceName")]
  506. [return: MarshalAs(UnmanagedType.U1)]
  507. private static extern bool GetAudioInputDeviceName(int index, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int nameBufferLength);
  508. [DllImport(PluginName, EntryPoint="AVPMC_GetContainerFileExtensions")]
  509. [return: MarshalAs(UnmanagedType.U1)]
  510. private static extern bool GetContainerFileExtensions(int videoCodecIndex, int audioCodecIndex, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder extensions, int extensionsBufferLength);
  511. //////////////////////////////////////////////////////////////////////////
  512. // Logging
  513. [DllImport(PluginName, EntryPoint="AVPMC_SetLogFunction")]
  514. public static extern void SetLogFunction(System.IntPtr fn);
  515. //////////////////////////////////////////////////////////////////////////
  516. // Error reporting
  517. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  518. public delegate void ErrorHandlerDelegate(int handle, int domain, int code, [In, MarshalAs(UnmanagedType.LPWStr)] string message);
  519. [DllImport(PluginName, EntryPoint="AVPMC_SetErrorHandler")]
  520. public static extern void SetErrorHandler(int handle, System.IntPtr handler);
  521. #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || (UNITY_IOS && !UNITY_EDITOR)
  522. //////////////////////////////////////////////////////////////////////////
  523. // Audio capture authorisation
  524. [DllImport(PluginName, EntryPoint = "AVPMC_AudioCaptureDeviceAuthorisationStatus")]
  525. public static extern int AudioCaptureDeviceAuthorisationStatus();
  526. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  527. public delegate void RequestAudioCaptureDeviceAuthorisationDelegate(int authorisation);
  528. [DllImport(PluginName, EntryPoint = "AVPMC_RequestAudioCaptureDeviceAuthorisation")]
  529. public static extern void RequestAudioCaptureDeviceAuthorisation(System.IntPtr callback);
  530. //////////////////////////////////////////////////////////////////////////
  531. // Photo library authorisation
  532. [DllImport(PluginName, EntryPoint="AVPMC_PhotoLibraryAuthorisationStatus")]
  533. public static extern int PhotoLibraryAuthorisationStatus(int level);
  534. [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
  535. public delegate void RequestPhotoLibraryAuthorisationDelegate(int authorisation);
  536. [DllImport(PluginName, EntryPoint = "AVPMC_RequestPhotoLibraryAuthorisation")]
  537. public static extern void RequestPhotoLibraryAuthorisation(int level, System.IntPtr callback);
  538. #endif
  539. }
  540. }