Exemplo n.º 1
0
        public void Initialize(
            int width,
            int height,
            int fps_,
            int bitrate,
            int gop
            )
        {
            FBCaptureConfig  config = new FBCaptureConfig(bitrate, fps_, gop);
            FBCAPTURE_STATUS status = FBCaptureCreate(config, out handle_);

            if (status != FBCAPTURE_STATUS.OK)
            {
                Debug.LogFormat("[ERROR] FBCaptureCreate() failed. Session status: {0}", status);
                OnFailure(ErrorType.INITIALIZE_FAILED, status);
                return;
            }

            this.fps_ = fps_;

            // create render texture for 360 capture
            SetOutputSize(width, height);

            Debug.LogFormat("[SurroundCapture] FBCapture initialized. (bitrate: {0}, fps_{1}, gop:{2})", bitrate, fps_, gop);
        }
Exemplo n.º 2
0
        public void Release()
        {
            if (handle_ == IntPtr.Zero)
            {
                return;
            }

            FBCAPTURE_STATUS status = FBCaptureRelease(handle_);

            handle_ = IntPtr.Zero;
            if (status != FBCAPTURE_STATUS.OK)
            {
                Debug.LogFormat("[Error] FBCaptureRelease() failed. Session status: {0}", status);
                OnFailure(ErrorType.RELEASE_FAILED, status);
            }
        }
Exemplo n.º 3
0
        IEnumerator CaptureScreenshot()
        {
            // yield a frame to re-render into the rendertexture
            yield return(new WaitForEndOfFrame());

            FBCAPTURE_STATUS status = FBCaptureSaveScreenShot(handle_, externalTex_.GetNativeTexturePtr(), destinationUrl_, true);

            if (status != FBCAPTURE_STATUS.OK)
            {
                Debug.LogFormat("[ERROR] FBCaptureSaveScreenShot failed. Session status: {0}", status);
                OnError(ErrorType.SCREENSHOT_FAILED, status);
            }
            else
            {
                Debug.LogFormat("[SurroundCapture] Saving screenshot: {0}", destinationUrl_);
            }
        }
Exemplo n.º 4
0
        public void StartEncoding(DestinationURL videoUrl)
        {
            FBCAPTURE_STATUS status = FBCaptureStartSession(handle_, videoUrl);

            if (status != FBCAPTURE_STATUS.OK)
            {
                Debug.LogFormat("[Error] FBCaptureStartSession() failed. Session status: {0}", status);
                OnFailure(ErrorType.START_SESSION_FAILED, status);
                return;
            }

            sessionActive_ = true;
            fps_Timer_     = 0.0f;
            numFrames_     = 0;

            Debug.LogFormat("[SurroundCapture] FBCapture session started. URL: {0}", videoUrl);
        }
Exemplo n.º 5
0
 private void OnFailure(ErrorType errorType, FBCAPTURE_STATUS status)
 {
     Release();
     ResetStatus();
     OnError(errorType, status);
 }
Exemplo n.º 6
0
        void Update()
        {
            if (!sessionActive_)
            {
                Debug.LogFormat("[LOG] fps_: {0}", 1.0f / Time.deltaTime);
                return;
            }

            FBCAPTURE_STATUS status = FBCAPTURE_STATUS.OK;

            if (stopSessionCalled_)
            {
                status = FBCaptureGetSessionStatus(handle_);
                if (status == FBCAPTURE_STATUS.OK)
                {
                    Debug.LogFormat("[SurroundCapture] Finalized capture. URL: {0}", destinationUrl_);
                    ResetStatus();
                }
                else if (status != FBCAPTURE_STATUS.SESSION_ACTIVE)
                {
                    Debug.LogFormat("[ERROR] FBCaptureStopSession() failed. Session status: {0}", status);
                    OnFailure(ErrorType.STOP_SESSION_FAIL, status);
                }
                return;
            }

            if (stopSessionRequested_)
            {
                status = FBCaptureStopSession(handle_);
                if (status == FBCAPTURE_STATUS.OK)
                {
                    Debug.Log("[SurroundCapture] Stopping session.");
                    stopSessionCalled_ = true;
                }
                else
                {
                    Debug.LogFormat("[ERROR] FBCaptureStopSession() failed. Session status: {0}", status);
                    OnFailure(ErrorType.STOP_SESSION_FAIL, status);
                }
                return;
            }

            fps_Timer_ += Time.deltaTime;
            Debug.LogFormat("[LOG] fps_: {0}", 1.0f / Time.deltaTime);
            if (fps_Timer_ < (1.0f / fps_))
            {
                return;
            }

            // rebase the fps_ timer
            fps_Timer_ -= (1.0f / fps_);

            if (sceneCamera)
            {
                sceneCamera.transform.position = transform.position;
                sceneCamera.RenderToCubemap(cubemapTex_);  // render cubemap
            }

            status = FBCaptureEncodeFrame(handle_, externalTex_.GetNativeTexturePtr());
            if (status != FBCAPTURE_STATUS.OK)
            {
                Debug.LogFormat("[ERROR] FBCaptureEncodeFrame() failed. Session status: {0}", status);
                OnFailure(ErrorType.ENCODE_FRAME_FAILED, status);
            }
            else
            {
                numFrames_++;
            }
        }