예제 #1
0
        public void RunCaptureSaveStop(CamDictionary allowedSettings)
        {
            // Example showing partial pre-trigger buffer fill, trigger, save video, then truncate save leaving playable video file
            this.RunCamera(api, allowedSettings, "\nPartial pre-trigger buffer fill, trigger, start video save, then truncate save leaving playable video file");

            api.WaitForTransition("    Letting pre-trigger buffer partially fill", CAMERA_STATE.RUNNING, 10);
            Thread.Sleep(4000);
            Console.WriteLine($"        {api.GetStatusString()}");

            this.TriggerCamera(api, "Camera triggered, starting to fill post-trigger buffer");

            Console.WriteLine($"    Percentage pre-trigger buffer filled before trigger: {api.GetPretriggerFillLevel()}");

            api.WaitForTransition("Waiting for post-trigger buffer to fill", CAMERA_STATE.TRIGGERED, 10);
            api.ExpectState(CAMERA_STATE.SAVING);

            Thread.Sleep(1000);
            Console.WriteLine($"    Truncating save before complete, video file still playable");
            Console.WriteLine($"        {api.GetStatusString()}");

            api.SaveStop();
            api.WaitForTransition("Waiting for save to finish", CAMERA_STATE.SAVING, 10);
            api.WaitForTransition("Waiting for post-trigger buffer to fill", CAMERA_STATE.SAVE_TRUNCATING, 10);

            api.ExpectRunningState();
        }
예제 #2
0
        private void MultiShotSaveVideos(long expectedVideoCount, int discardAfterVideo, int saveWait)
        {
            // param discard_after_video: set to zero to save all captured multishot videos or to the number of videos to save
            if (discardAfterVideo > 0)
            {
                Console.WriteLine($"    Saving filled multishot buffers, discarding videos after video {discardAfterVideo} is saved");
            }
            else
            {
                Console.WriteLine("    Saving filled multishot buffers");
            }

            api.ExpectState(CAMERA_STATE.RUNNING);

            Save();
            Thread.Sleep(1000);

            for (var x = 0; x < expectedVideoCount; x++)
            {
                var expectedBuffer = x + 1;
                var maxWait        = saveWait;

                api.ExpectState(CAMERA_STATE.SAVING);

                var camStatus       = api.GetCamStatus();
                var capturedBuffers = (long)camStatus["captured_buffers"];

                Console.WriteLine($"        Captured buffers: {capturedBuffers}");

                if (capturedBuffers != expectedVideoCount)
                {
                    Console.WriteLine($"        Error: captured buffer count doesn't match expected count: {capturedBuffers} != {expectedVideoCount}");
                    Environment.Exit(1);
                }

                while (expectedBuffer <= expectedVideoCount && maxWait > 0)
                {
                    // camera stays in the save state the entire time the set of captured videos are saved
                    // monitor progress by using the active buffer and save complete level
                    camStatus = api.GetCamStatus();
                    var state = (CAMERA_STATE)camStatus["state"];

                    if (state != CAMERA_STATE.SAVING)
                    {
                        Console.WriteLine($"        Current state: {api.GetTextState(state)}");
                        break;
                    }

                    var activeBuffer = (long)camStatus["active_buffer"];

                    Console.WriteLine($"        Saving buffer {activeBuffer}/{expectedVideoCount} progress {camStatus["level"]} ({maxWait})");
                    if (expectedBuffer + 1 == activeBuffer)
                    {
                        break;
                    }

                    if (discardAfterVideo > 0 && discardAfterVideo + 1 == activeBuffer)
                    {
                        Console.WriteLine("    Discarding filled multishot buffers");
                        Thread.Sleep(2000);
                        api.SaveStop(true);

                        api.WaitForTransition("Waiting for truncation to finish", CAMERA_STATE.SAVE_TRUNCATING, 5);
                        api.ExpectRunningState();
                        return;
                    }

                    Thread.Sleep(1000);
                    maxWait--;
                }
            }

            api.ExpectRunningState();
        }