Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
 public void SetLogPath(string filepath)
 {
     Debug.LogFilePath = filepath;
     NativeRecorder.SetLogPath(filepath);
     return;
 }