Example #1
0
 public virtual void StartRecording (Container container, VideoFormat videoFormat, AudioFormat audioFormat, RecordingCallback recordingCallback) {
     // Make sure that recording size is even
     videoFormat = new VideoFormat(
         videoFormat.width >> 1 << 1,
         videoFormat.height >> 1 << 1,
         videoFormat.framerate,
         videoFormat.bitrate,
         videoFormat.keyframeInterval
     );
     // Save state
     this.dispatch = new MainDispatch();
     this.videoFormat = videoFormat;
     this.recordingCallback = recordingCallback;
     this.framebuffer = new Texture2D(videoFormat.width, videoFormat.height, TextureFormat.ARGB32, false);
     // Start recording
     NatCorderBridge.StartRecording(
         container,
         videoFormat.width,
         videoFormat.height,
         videoFormat.framerate,
         videoFormat.bitrate,
         videoFormat.keyframeInterval,
         audioFormat.sampleRate,
         audioFormat.channelCount
     );
 }
 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
 }
 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
 }
Example #4
0
 public void CommitSamples(float[] sampleBuffer, long timestamp)
 {
     if (IsRecording)
     {
         NatCorderBridge.EncodeSamples(sampleBuffer, timestamp);
     }
 }
 public virtual void StopRecording () {
     if (audioSource != null) audioSource.Dispose();
     audioSource = null;
     NatCorderBridge.StopRecording();
     Texture2D.Destroy(framebuffer);
     framebuffer = null;
 }
Example #6
0
        public void CommitFrame(Frame frame)
        {
            var handle = ((RenderTexture)frame).GetNativeTexturePtr();

            framePool.Add(handle, frame);
            NatCorderBridge.EncodeFrame(handle, frame.timestamp);
        }
Example #7
0
 public void StopRecording()
 {
     if (audioSource != null)
     {
         audioSource.Dispose();
     }
     NatCorderBridge.StopRecording();
 }
 public NatCorderOSX () {
     var writePath = 
     #if UNITY_EDITOR
     System.IO.Directory.GetCurrentDirectory();
     #else
     Application.persistentDataPath;
     #endif
     NatCorderBridge.Initialize(null, OnVideo, writePath);
     Debug.Log("NatCorder: Initialized NatCorder 1.2 macOS backend");
 }
 public NatCorderOSX () {
     var writePath = 
     #if UNITY_EDITOR
     System.IO.Directory.GetCurrentDirectory();
     #else
     Application.persistentDataPath;
     #endif
     NatCorderBridge.Initialize(null, OnVideo, writePath);
     transformMat = new Material(Shader.Find("Hidden/NatCorder/Transform"));
     Debug.Log("NatCorder: Initialized NatCorder 1.1 macOS backend");
 }
Example #10
0
        public void Commit(Frame frame)
        {
            // Make upright
            RenderTexture surface = Acquire();

            Graphics.Blit(frame, surface, transformMat);
            RenderTexture.ReleaseTemporary(frame);
            // Commit
            var handle = surface.GetNativeTexturePtr();

            framePool.Add(handle, surface);
            NatCorderBridge.EncodeFrame(handle, frame.timestamp);
        }
 public override void StopRecording()
 {
     if (audioSource != null)
     {
         audioSource.Dispose();
     }
     #if UNITY_WEBGL && !UNITY_EDITOR
     var pathPtr = NatCorderBridge.StopRecording(); // Signature is different
     #else
     var pathPtr = IntPtr.Zero;
     #endif
     Texture2D.Destroy(framebuffer);
     audioSource = null;
     framebuffer = null;
     var callback = new GameObject("NatCorderWebGL Delegate").AddComponent <VideoDelegate>();
     callback.StartCoroutine(OnVideo(pathPtr, callback));
 }
Example #12
0
 public void StartRecording (Configuration configuration, VideoCallback videoCallback, IAudioSource audioSource) {
     // Make sure that recording size is multiple of two
     configuration = new Configuration(2 * (configuration.width / 2), 2 * (configuration.height / 2), configuration.framerate, configuration.bitrate, configuration.keyframeInterval);
     // Save state
     this.dispatch = new MainDispatch();
     this.configuration = configuration;
     this.videoCallback = videoCallback;
     this.audioSource = audioSource;
     this.framebuffer = new Texture2D(configuration.width, configuration.height, TextureFormat.ARGB32, false);
     // Start recording
     NatCorderBridge.StartRecording(
         configuration.width,
         configuration.height,
         configuration.framerate,
         configuration.bitrate,
         configuration.keyframeInterval,
         audioSource != null,
         audioSource != null ? audioSource.sampleRate : 0,
         audioSource != null ? audioSource.sampleCount : 0,
         audioSource != null ? audioSource.channelCount : 0
     );
 }
Example #13
0
 public void StartRecording(Configuration configuration, SaveCallback saveCallback, IAudioSource audioSource)
 {
     this.dispatch      = new MainDispatch();
     this.configuration = configuration;
     this.saveCallback  = saveCallback;
     this.audioSource   = audioSource;
     // Start recording
     NatCorderBridge.StartRecording(
         configuration.width,
         configuration.height,
         configuration.framerate,
         configuration.bitrate,
         configuration.keyframeInterval,
         audioSource != null,
         audioSource != null ? audioSource.sampleRate : 0,
         audioSource != null ? audioSource.channelCount : 0
         );
     // Start listening for audio
     if (audioSource != null)
     {
         audioSource.listener = this;
     }
 }
Example #14
0
 public NatCorderiOS()
 {
     NatCorderBridge.Initialize(OnEncode, OnVideo, Application.persistentDataPath);
     RenderDispatch.Initialize();
     Debug.Log("NatCorder: Initialized NatCorder 1.2 iOS backend");
 }
Example #15
0
 public NatCorderiOS()
 {
     NatCorderBridge.RegisterCallbacks(OnEncode, OnVideo);
     transformMat = new Material(Shader.Find("Hidden/NatCorder/Transform"));
     Utilities.Log("Initialized NatCorder 1.0 iOS backend");
 }
Example #16
0
 public void CommitSamples (float[] sampleBuffer, long timestamp) {
     NatCorderBridge.EncodeSamples(sampleBuffer, sampleBuffer.Length, timestamp);
 }
Example #17
0
 public void StopRecording()
 {
     NatCorderBridge.StopRecording();
 }
Example #18
0
 public NatCorderiOS()
 {
     NatCorderBridge.Initialize(OnEncode, OnVideo, Application.persistentDataPath);
     transformMat = new Material(Shader.Find("Hidden/NatCorder/Transform"));
     Debug.Log("NatCorder: Initialized NatCorder 1.1 iOS backend");
 }
Example #19
0
 public virtual void StopRecording () {
     NatCorderBridge.StopRecording();
     Texture2D.Destroy(framebuffer);
     framebuffer = null;
 }
Example #20
0
 void IAudioListener.OnSampleBuffer(float[] samples, long timestamp)
 {
     NatCorderBridge.EncodeSamples(samples, timestamp);
 }