public virtual void CommitFrame (Frame frame) { // Submit #if DEFERRED_READBACK dispatch.Dispatch(() => { if (dispatch != null) dispatch.Dispatch(() => { // Defer readback for (at least) one frame if (!IsRecording) { RenderTexture.ReleaseTemporary(frame); return; } #endif var currentRT = RenderTexture.active; RenderTexture.active = frame; framebuffer.ReadPixels(new Rect(0, 0, configuration.width, configuration.height), 0, 0, false); RenderTexture.active = currentRT; RenderTexture.ReleaseTemporary(frame); var pixelBuffer = framebuffer.GetRawTextureData(); var bufferHandle = GCHandle.Alloc(pixelBuffer, GCHandleType.Pinned); NatCorderBridge.EncodeFrame(bufferHandle.AddrOfPinnedObject(), frame.timestamp); bufferHandle.Free(); #if DEFERRED_READBACK }); else RenderTexture.ReleaseTemporary(frame); }); #endif }
public void CommitFrame (Frame frame) { // Invert var correctedFrame = AcquireFrame(); correctedFrame.timestamp = frame.timestamp; Graphics.Blit(frame, correctedFrame, transformMat); RenderTexture.ReleaseTemporary(frame); frame = correctedFrame; // Submit #if DEFERRED_READBACK dispatch.Dispatch(() => dispatch.Dispatch(() => { // Defer readback for (at least) one frame if (!IsRecording) return; #endif var currentRT = RenderTexture.active; RenderTexture.active = frame; framebuffer.ReadPixels(new Rect(0, 0, configuration.width, configuration.height), 0, 0, false); RenderTexture.active = currentRT; RenderTexture.ReleaseTemporary(frame); var pixelBuffer = framebuffer.GetRawTextureData(); var bufferHandle = GCHandle.Alloc(pixelBuffer, GCHandleType.Pinned); NatCorderBridge.EncodeFrame(bufferHandle.AddrOfPinnedObject(), frame.timestamp); bufferHandle.Free(); #if DEFERRED_READBACK })); #endif }
private void onEncode(int frame) { dispatch.Dispatch(() => { // Release RenderTexture var surface = framePool[frame]; RenderTexture.ReleaseTemporary(surface); framePool.Remove(frame); }); }
private static void OnVideo(string path) { using (var dispatch = new MainDispatch()) dispatch.Dispatch(() => instance.recordingCallback(path)); }