public void ExitCamera() { Console.WriteLine("Exit camera"); Console.WriteLine("streamWriter is null: " + (streamWriter == null).ToString()); try { streamWriter.Write('q'); //encara que hi hagi el process.Close() de sota, no es tanca la càmera sense aquest 'q' //streamWriter.Flush(); // streamWriter.WriteLine("\x3"); //streamWriter.Flush(); //process.StandardInput.WriteLine("\x3"); // streamWriter.WriteLine("q\n"); } catch { //maybe Mplayer window has been closed by user process = null; Running = false; return; } Console.WriteLine("closing ..."); process.Close(); //this does not work //Console.WriteLine("waiting for exit ..."); //process.WaitForExit(); Console.WriteLine("done!"); //amb el process.Close(); tanca i tanca be pero es perden fotogrames inicials i finals, vaja que no tanca massa be, no estic segur de si realment enviar la q serveix de algo, vaig a fer-ho sense la q //si que tanca be pq ara he provat sense enviar el q, nomes amb el process.Close() i la camera es queda oberta /* * //System.Threading.Thread.Sleep(500); * //better check if process still exists to later copy the video * do { * Console.WriteLine("waiting 100 ms to end Ffmpeg"); * System.Threading.Thread.Sleep(100); * } while(ExecuteProcess.IsRunning2(process, captureExecutable)); */ do { Console.WriteLine("waiting 100 ms to end Ffmpeg"); System.Threading.Thread.Sleep(100); } while(ExecuteProcess.IsRunning3(processID, "ffmpeg")); //note on Linux and Windows we need to check ffmpeg and not ffmpeg.exe streamWriter = null; process = null; Running = false; }
public override void ExitCamera() { LogB.Information("Exit camera"); LogB.Information("streamWriter is null: " + (streamWriter == null).ToString()); LogB.Information("Action: " + action.ToString()); if (action == Action.PLAYPREVIEW || action == Action.PLAYFILE) { LogB.Information("killing ..."); try { process.Kill(); } catch { LogB.Information("catched!"); } LogB.Information("done!"); } else { //action == Action.CAPTURE try { streamWriter.Write('q'); streamWriter.Flush(); //seems is not needed } catch { //maybe capturer process (could be a window) has been closed by user process = null; Running = false; return; } LogB.Information("closing ..."); process.Close(); LogB.Information("done!"); } if (action == Action.CAPTURE) { /* * above process.Close() will end the process * without using this file copied from /tmp maybe is not finished, so a bad ended file is copied to .local/share/Chronojump/multimedia/video */ bool exitBucle = false; do { LogB.Information("waiting 100 ms to tmp capture file being unlocked"); System.Threading.Thread.Sleep(100); if (!File.Exists(Util.GetVideoTempFileName())) //PlayPreview does not have tmp file { exitBucle = true; } else if (!ExecuteProcess.IsFileLocked(new System.IO.FileInfo(Util.GetVideoTempFileName()))) //we are capturing, wait file is not locked { exitBucle = true; } } while(!exitBucle); do { LogB.Information("waiting 100 ms to end Ffmpeg"); System.Threading.Thread.Sleep(100); } while(ExecuteProcess.IsRunning3(processID, "ffmpeg")); //note on Linux and Windows we need to check ffmpeg and not ffmpeg.exe } streamWriter = null; process = null; Running = false; }