Example #1
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();
        }