7using System.Runtime.InteropServices;
8using System.Threading.Tasks;
15 #region --IMediaRecorder--
21 recorder.FrameSize(out var
width, out var height);
22 return (
width, height);
26 public NativeRecorder(Func<Bridge.RecordingHandler, IntPtr, IntPtr> recorderCreator)
28 recordingTask =
new TaskCompletionSource<string>();
29 var handle = GCHandle.Alloc(recordingTask, GCHandleType.Normal);
30 recorder = recorderCreator(OnRecording, (IntPtr) handle);
35 var handle = GCHandle.Alloc(pixelBuffer, GCHandleType.Pinned);
36 CommitFrame(handle.AddrOfPinnedObject(), timestamp);
42 recorder.CommitFrame(nativeBuffer, timestamp);
47 recorder.CommitSamples(sampleBuffer, sampleBuffer.Length, timestamp);
52 recorder.FinishWriting();
53 return recordingTask.Task;
59 #region --Operations--
61 private readonly IntPtr recorder;
62 private readonly TaskCompletionSource<string> recordingTask;
64 [MonoPInvokeCallback(typeof(Bridge.RecordingHandler))]
65 private static void OnRecording(IntPtr context, IntPtr path)
68 var handle = (GCHandle) context;
69 var recordingTask = handle.Target as TaskCompletionSource<string>;
72 if (path != IntPtr.Zero)
73 recordingTask.SetResult(Marshal.PtrToStringAnsi(path));
75 recordingTask.SetException(
new Exception(
@"Recorder failed to finish writing"));
Task< string > FinishWriting()
Finish writing and return the path to the recorded media file.
void CommitFrame(IntPtr nativeBuffer, long timestamp)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.
NativeRecorder(Func< Bridge.RecordingHandler, IntPtr, IntPtr > recorderCreator)
void CommitFrame< T >(T[] pixelBuffer, long timestamp)
Commit a video pixel buffer for encoding. The pixel buffer MUST have an RGBA8888 pixel layout.
void CommitSamples(float[] sampleBuffer, long timestamp)
Commit an audio sample buffer for encoding.