/// <summary> /// Splits longer recordings and processes the file so that the recording does not exceed the /// allocated local storage space. If recording is over, call StopRecording before calling this. /// </summary> private void ProcessVideoClip() { // This will change after the call to Split var localFilename = VideoCaptureHandler.CurrentFilename + ".h264"; VideoCaptureHandler.Split(); var storageFilename = $"{recordingStartTimeFilename}_{recordingSegment:000}.h264"; FileProcessing.MoveVideoToStorage(localFilename, storageFilename); recordingSegment++; }
public static async Task Main(string[] args) { Logo(); try { // TODO PrepareLogger(); // If this returns true, args were sent to an already-running instance, we can exit. if (await CommandLineSwitchPipe.TrySendArgs(args)) { return; } // Read appsettings.json and do some basic checks like path validity ValidateConfiguration(); // Set up a pipe to receive switches once we're running ctsSwitchPipe = new CancellationTokenSource(); _ = Task.Run(() => CommandLineSwitchPipe.StartServer(ProcessSwitches, ctsSwitchPipe.Token)); // The localpath should be clear of files at startup FileProcessing.MoveSnapshotsToStorage(); FileProcessing.MoveAbandonedVideoToStorage(); // TODO remove zero-length circular buffer h264, don't move it FileProcessing.ClearLocalStorage(); // The default state, although some command-line switches may change this RequestedState = new MotionDetectionState(); // If command-line args were passed to this instance, process them now if (args.Length > 0) { ProcessSwitches(args, false); if (RequestedState == null) { Console.WriteLine("No new execution state requested, exiting."); return; } } // If a command-line switch arrives in the SwitchPipe thread, it can // cancel the state-change token to end the current processing state // and request a different processing state. We loop until no new state // is requested, at which point the app exits. while (RequestedState != null) { RunningState = RequestedState; RequestedState = null; ctsRunningState = new CancellationTokenSource(); await RunningState.RunAsync(ctsRunningState.Token).ConfigureAwait(false); RunningState.Dispose(); RunningState = null; } } catch (Exception ex) { Console.WriteLine($"\nException of type {ex.GetType().Name}\n{ex.Message}"); if (ex.InnerException != null) { Console.Write(ex.InnerException.Message); } Console.WriteLine($"\n{ex.StackTrace}"); } finally { // Stephen Cleary says CTS disposal is unnecessary as long as you cancel ctsSwitchPipe?.Cancel(); ctsRunningState?.Cancel(); RequestedState?.Dispose(); RunningState?.Dispose(); } Console.WriteLine("Exiting spicam."); }