[chronojump] webcam ending better with new IsRunning3 method



commit ebf092bed106bac2889a87abbbc5e32cc1dca544
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Nov 12 13:41:25 2018 +0100

    webcam ending better with new IsRunning3 method

 src/executeProcess.cs | 20 +++++++++++++++++++-
 src/webcamFfmpeg.cs   | 11 +++++------
 2 files changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/src/executeProcess.cs b/src/executeProcess.cs
index 49b9e620..c954d4ec 100644
--- a/src/executeProcess.cs
+++ b/src/executeProcess.cs
@@ -179,10 +179,27 @@ class ExecuteProcess
                return true;
        }
 
+       /*
+        * This is the best method because it does not need the process,
+        * note that process maybe is null
+        * and some code in IsRunning2old will fail
+        */
+       public static bool IsRunning3 (int processID, string executable)
+       {
+               Process[] pNameArray = Process.GetProcessesByName(Util.GetLastPartOfPath(executable));
+               if (pNameArray.Length == 0)
+                       return false;
+
+               foreach(Process p in pNameArray)
+                       if(p.Id == processID)
+                               return true;
 
+               return false;
+       }
+       /*
        //better method than below
        //https://stackoverflow.com/a/262291
-       public static bool IsRunning2 (Process process, string executable)
+       public static bool IsRunning2old (Process process, string executable)
        {
                Process[] pNameArray = 
Process.GetProcessesByName(Util.GetLastPartOfPath(process.ProcessName));
                if (pNameArray.Length == 0)
@@ -194,6 +211,7 @@ class ExecuteProcess
 
                return false;
        }
+       */
 
        //This seems is not working with ffmpeg capture, try method obove
        public static bool IsRunning(Process process)
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index 8c317be4..e7f421bd 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -27,6 +27,7 @@ using System.Text.RegularExpressions; //Regex
 public class WebcamFfmpeg : Webcam
 {
        private UtilAll.OperatingSystems os;
+       private int processID;
 
        public WebcamFfmpeg (UtilAll.OperatingSystems os, string videoDevice)
        {
@@ -80,6 +81,7 @@ public class WebcamFfmpeg : Webcam
                        return new Result (false, "", programFfmpegNotInstalled);
                }
 
+               processID = process.Id;
                streamWriter = process.StandardInput;
                Running = true;
 
@@ -210,15 +212,12 @@ public class WebcamFfmpeg : Webcam
 
                /*
                 * above process.Close() will end the process
-                * if not, play with kill
-                *
-               //System.Threading.Thread.Sleep(500);
-               //better check if process still exists to later copy the video
+                * without using this file copied from /tmp maybe is not finished, so a bad ended file is 
copied to .local/share/Chronojump/multimedia/video
+               */
                do {
                        LogB.Information("waiting 100 ms to end Ffmpeg");
                        System.Threading.Thread.Sleep(100);
-               } while(ExecuteProcess.IsRunning2(process, captureExecutable));
-               */
+               } while(ExecuteProcess.IsRunning3(processID, captureExecutable));
 
                streamWriter = null;
                process = null;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]