/// <summary> /// Initialize the attributes of the capture session and start capture. /// </summary> public bool StartCapture() { if (_captureStarted) { Debug.LogWarningFormat(LOG_FORMAT, "Previous screenshot session not finish yet!"); OnError(this, CaptureErrorCode.SCREENSHOT_ALREADY_IN_PROGRESS); return(false); } if (string.IsNullOrEmpty(saveFolder)) { saveFolder = Config.saveFolder; } else { Config.saveFolder = saveFolder; } if (captureMode == CaptureMode._360) { if (projectionType == ProjectionType.NONE) { Debug.LogFormat(LOG_FORMAT, "Projection type should be set for 360 capture, set type to equirect for generating texture properly"); projectionType = ProjectionType.EQUIRECT; } if (projectionType == ProjectionType.CUBEMAP) { if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Stereo settings not support for cubemap capture, reset to mono video capture."); stereoMode = StereoMode.NONE; } } CubemapSizeSettings(); } else if (captureMode == CaptureMode.REGULAR) { // Non 360 capture doesn't have projection type projectionType = ProjectionType.NONE; } AntiAliasingSettings(); #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN if (Config.isFreeTrial()) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported in free trial version, fall back to software encoding."); hardwareEncoding = false; } else if (!softwareEncodingOnly && gpuEncoder.instantiated && gpuEncoder.IsSupported()) { hardwareEncoding = true; } else { Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported in this device, fall back to software encoding."); } #endif #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported on macOS system, fall back to software encoding."); hardwareEncoding = false; #endif if (hardwareEncoding) { // init hardware encoding settings GPUEncoderSettings(); if (!gpuEncoder.StartScreenShot()) { OnError(this, CaptureErrorCode.SCREENSHOT_START_FAILED); return(false); } } else { // init ffmpeg encoding settings FFmpegEncoderSettings(); if (!ffmpegEncoder.StartScreenShot()) { OnError(this, CaptureErrorCode.SCREENSHOT_START_FAILED); return(false); } } _captureStarted = true; // Start garbage collect thread. if (!garbageThreadRunning) { garbageThreadRunning = true; if (garbageCollectionThread != null && garbageCollectionThread.IsAlive) { garbageCollectionThread.Abort(); garbageCollectionThread = null; } garbageCollectionThread = new Thread(GarbageCollectionProcess); garbageCollectionThread.Priority = System.Threading.ThreadPriority.Lowest; garbageCollectionThread.IsBackground = true; garbageCollectionThread.Start(); } Debug.LogFormat(LOG_FORMAT, "Screen shot session started."); return(true); }
/// <summary> /// Initialize the attributes of the capture session and start capture. /// </summary> public bool StartCapture() { if (_captureStarted) { Debug.LogWarningFormat(LOG_FORMAT, "Previous screenshot session not finish yet!"); OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.SCREENSHOT_ALREADY_IN_PROGRESS)); return(false); } saveFolderFullPath = Utils.CreateFolder(saveFolder); if (captureMode == CaptureMode._360) { if (projectionType == ProjectionType.NONE) { Debug.LogFormat(LOG_FORMAT, "Projection type should be set for 360 capture, set type to equirect for generating texture properly"); projectionType = ProjectionType.EQUIRECT; } if (projectionType == ProjectionType.CUBEMAP) { if (stereoMode != StereoMode.NONE) { Debug.LogFormat(LOG_FORMAT, "Stereo settings not support for cubemap capture, reset to mono video capture."); stereoMode = StereoMode.NONE; } } CubemapSizeSettings(); } else if (captureMode == CaptureMode.REGULAR) { // Non 360 capture doesn't have projection type projectionType = ProjectionType.NONE; } AntiAliasingSettings(); // init ffmpeg encoding settings FFmpegEncoderSettings(); #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN if (gpuEncoding) { if (FreeTrial.Check()) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported in free trial version, fall back to software encoding."); gpuEncoding = false; } // init GPU encoding settings GPUEncoderSettings(); if (!gpuEncoder.instantiated || !gpuEncoder.IsSupported()) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is not supported in current device or settings, fall back to software encoding."); gpuEncoding = false; } } #else if (gpuEncoding) { Debug.LogFormat(LOG_FORMAT, "GPU encoding is only available on windows system, fall back to software encoding."); gpuEncoding = false; } #endif if (gpuEncoding) { // init hardware encoding settings GPUEncoderSettings(); if (!gpuEncoder.StartScreenShot()) { OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.SCREENSHOT_START_FAILED)); return(false); } } else { if (!ffmpegEncoder.StartScreenShot()) { OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.SCREENSHOT_START_FAILED)); return(false); } } _captureStarted = true; // Start garbage collect thread. //if (!garbageThreadRunning) //{ // garbageThreadRunning = true; // if (garbageCollectionThread != null && // garbageCollectionThread.IsAlive) // { // garbageCollectionThread.Abort(); // garbageCollectionThread = null; // } // garbageCollectionThread = new Thread(GarbageCollectionProcess); // garbageCollectionThread.Priority = System.Threading.ThreadPriority.Lowest; // garbageCollectionThread.IsBackground = true; // garbageCollectionThread.Start(); //} Debug.LogFormat(LOG_FORMAT, "Screen shot session started."); return(true); }