void capturing() { while (!quitCaptureThread_) { controlAndMeasureFPS(); var monitor = NativeRecorder.GetMonitor(monitorNumber_); // todo: if (monitor == null) { Debug.LogErrorFormat("Failed to get monitor ({0}) informaiton", monitorNumber_); continue; } var frame = new NativeRecorder.Frame(); int res = NativeRecorder.CaptureDesktopFrame(monitor.Rect, frame); if (res == (int)APIResult.Fatal) { Debug.LogErrorFormat("Fatal error occurred when capturing desktop frame"); break; } else if (res != 0) { Debug.LogErrorFormat("Failed to capture desktop frame"); continue; } long ms = recordingTimer_.ElapsedMilliseconds; framesToEncode_.Enqueue(new Frame(frame.Data, frame.Width, frame.Height, ms)); } }
public void StartRecording(RecordingParameters parameters) { if (state_ != State.Running) { var param = parameters as RecordingParameters; var monitor = NativeRecorder.GetMonitor(param.Monitor); if (monitor == null || monitor.Width <= 0 || monitor.Height <= 0) { Debug.LogErrorFormat("Failed to get monitor ({0}) informaiton", param.Monitor); return; } monitorNumber_ = param.Monitor; int res = NativeRecorder.StartRecording(monitor.Width, monitor.Height, param.RecordLength, param.Fps, param.Quality); state_ = State.Running; recordingTimer_.Reset(); // need? recordingTimer_.Start(); fps_ = param.Fps; msList.Clear(); msList.Enqueue(recordingTimer_.ElapsedMilliseconds); startFrameCaptureThread(); startFrameEncodeThread(); Debug.Log("StartRecording: result=" + (APIResult)res); } }
public void FinishRecording(string saveVideoPath) { if (state_ == State.Running) { state_ = State.Stopped; stopFrameCaptureThread(); stopFrameEncodeThread(); int res = NativeRecorder.FinishRecording(saveVideoPath); Debug.Log("FinishRecording: path=" + saveVideoPath + ", result=" + (APIResult)res); } }
void encoding() { while (!quitEncodeThread_) { if (framesToEncode_.Count >= 1) { var frame = framesToEncode_.Dequeue(); int res = NativeRecorder.EncodeDesktopFrame(frame.Data, frame.TimeMilliSeconds * 0.001f); if (res == (int)APIResult.Fatal) { Debug.LogErrorFormat("Fatal error occurred when encoding"); break; } else if (res != 0) { Debug.LogErrorFormat("Failed to encode"); continue; } } else { System.Threading.Thread.Sleep(100); // sleep 100ms if there is no frame to encode. } } // flush while (framesToEncode_.Count >= 1) { var frame = framesToEncode_.Dequeue(); int res = NativeRecorder.EncodeDesktopFrame(frame.Data, frame.TimeMilliSeconds * 0.001f); if (res == (int)APIResult.Fatal) { Debug.LogErrorFormat("Fatal error occurred when encoding (Flush)"); break; } else if (res != (int)APIResult.OK) { Debug.LogErrorFormat("Failed to encode (Flush)"); continue; } } }
string[] monitorLabels() { int count = NativeRecorder.GetMonitorCount(); List <string> texts = new List <string>(); for (int i = 0; i < count; i++) { var monitor = NativeRecorder.GetMonitor(i); if (monitor != null) { string t = string.Format( "Monitor{0} ({1}x{2}{3})", (i + 1), monitor.Width, monitor.Height, monitor.IsPrimary ? ", PRIMARY" : ""); texts.Add(t); } } return(texts.ToArray()); }
public void SetLogPath(string filepath) { Debug.LogFilePath = filepath; NativeRecorder.SetLogPath(filepath); return; }