[chronojump] testing-stuff/ffmpegCapture copies correctly when ended



commit ce00d0cc0dbdf96b9bd29ba30225d00c89cf5ec6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jan 9 18:08:37 2019 +0100

    testing-stuff/ffmpegCapture copies correctly when ended

 testing-stuff/ffmpegCapture/compile.sh        |   1 +
 testing-stuff/ffmpegCapture/executeProcess.cs |  49 ++++++++++++++++++++++++++
 testing-stuff/ffmpegCapture/ffmpegCapture.exe | Bin 17920 -> 18944 bytes
 testing-stuff/ffmpegCapture/main.cs           |  19 +++++++---
 testing-stuff/ffmpegCapture/util.cs           |  15 ++++++++
 5 files changed, 80 insertions(+), 4 deletions(-)
---
diff --git a/testing-stuff/ffmpegCapture/compile.sh b/testing-stuff/ffmpegCapture/compile.sh
index b8eb3c77..98528703 100755
--- a/testing-stuff/ffmpegCapture/compile.sh
+++ b/testing-stuff/ffmpegCapture/compile.sh
@@ -1 +1,2 @@
+#this will create a binary that will work on linux and windows (and hopefully mac)
 mcs *.cs -out:ffmpegCapture.exe
diff --git a/testing-stuff/ffmpegCapture/executeProcess.cs b/testing-stuff/ffmpegCapture/executeProcess.cs
index e0305286..0738ab8e 100644
--- a/testing-stuff/ffmpegCapture/executeProcess.cs
+++ b/testing-stuff/ffmpegCapture/executeProcess.cs
@@ -179,7 +179,55 @@ class ExecuteProcess
                return true;
        }
 
+        public static bool IsRunning3 (int processID, string executable)
+        {
+                Console.WriteLine("\nCalled IsRunning3\n");
+                //Debug
+                Process[] pdebug;
 
+                Console.WriteLine("running with executable: " + executable);
+                pdebug = Process.GetProcessesByName(executable);
+                Console.WriteLine((pdebug.Length > 0).ToString());
+
+               /*
+                Console.WriteLine("running with LastPartOfPath of executable: " + 
Util.GetLastPartOfPath(executable));
+                pdebug = Process.GetProcessesByName(Util.GetLastPartOfPath(executable));
+                Console.WriteLine((pdebug.Length > 0).ToString());
+
+                Console.WriteLine("running with executable: " + executable);
+                pdebug = Process.GetProcessesByName(executable);
+                Console.WriteLine((pdebug.Length > 0).ToString());
+               */
+
+                //Debug
+                Process[] allThisMachine = Process.GetProcesses();
+                Console.WriteLine("All processes in this machine containing: " + executable);
+                foreach(Process p in allThisMachine)
+                {
+                        try {
+                               if(p.ToString().Contains(executable))
+                                       Console.WriteLine(p.ToString()); //this is problematic on windows
+                        } catch {
+                                Console.WriteLine("catched at IsRunning3");
+                        }
+                }
+
+                //Process[] pNameArray = Process.GetProcessesByName(Util.GetLastPartOfPath(executable));
+                Process[] pNameArray = Process.GetProcessesByName(executable);
+                if (pNameArray.Length == 0)
+                        return false;
+
+                Console.WriteLine("Found one or more " + executable + " process, checking Id");
+                foreach(Process p in pNameArray)
+                        if(p.Id == processID)
+                                return true;
+
+               Console.WriteLine("This Id is not running");
+
+                return false;
+        }
+
+       /*
        //better method than below
        //https://stackoverflow.com/a/262291
        public static bool IsRunning2 (Process process, string executable)
@@ -194,6 +242,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/testing-stuff/ffmpegCapture/ffmpegCapture.exe b/testing-stuff/ffmpegCapture/ffmpegCapture.exe
index 1e90a6cd..e348c3bc 100755
Binary files a/testing-stuff/ffmpegCapture/ffmpegCapture.exe and 
b/testing-stuff/ffmpegCapture/ffmpegCapture.exe differ
diff --git a/testing-stuff/ffmpegCapture/main.cs b/testing-stuff/ffmpegCapture/main.cs
index eb35de53..1ef19ac4 100644
--- a/testing-stuff/ffmpegCapture/main.cs
+++ b/testing-stuff/ffmpegCapture/main.cs
@@ -30,6 +30,7 @@ class FfmpegCapture
        private string captureExecutable = "ffmpeg";
         private StreamWriter streamWriter;
        private Process process;
+       private int processID;
        protected static internal string programFfmpegNotInstalled =
                string.Format("Error. {0} is not installed.", "ffmpeg");
        public bool Running;
@@ -128,6 +129,7 @@ class FfmpegCapture
                        return;
                }
 
+               processID = process.Id;
                streamWriter = process.StandardInput;
                Running = true;
 
@@ -144,6 +146,7 @@ class FfmpegCapture
                //return new Result (true, "");
        }
 
+       //TODO: on Windows or old machines adjust rtbufsize parameter, on our tests we have problems with 
default 3041280
        private List<string> createParametersOnlyCapture()
        {
                // ffmpeg -y -f v4l2 -framerate 30 -video_size 640x480 -input_format mjpeg -i /dev/video0 
out.mp4
@@ -229,14 +232,16 @@ class FfmpegCapture
 
        public Result ExitAndFinish (int sessionID, Constants.TestTypes testType, int testID)
        {
-               ExitCamera();
+               ExitCamera(); //this works
+
+               //testing this now
 
                //Copy the video to expected place
-               //if (! Util.CopyTempVideo(sessionID, testType, testID))
-               //      return new Result (false, "", Constants.FileCopyProblem);
+               if (! Util.CopyTempVideo(sessionID, testType, testID))
+                       return new Result (false, "", Constants.FileCopyProblem);
 
                //Delete temp video
-               //deleteTempFiles();
+               deleteTempFiles();
 
                return new Result (true, "");
        }
@@ -280,6 +285,12 @@ class FfmpegCapture
                } 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;
diff --git a/testing-stuff/ffmpegCapture/util.cs b/testing-stuff/ffmpegCapture/util.cs
index b4786605..281c4ba9 100644
--- a/testing-stuff/ffmpegCapture/util.cs
+++ b/testing-stuff/ffmpegCapture/util.cs
@@ -130,4 +130,19 @@ public class Util
                                 Path.DirectorySeparatorChar + "videos"); 
         }      
 
+       public static string GetLastPartOfPath (string fileName) {
+               //gets a complete url with report directory path and return only last part of path
+               //useful for linking images as relative and not absolute in export to HTML
+               //works on win and linux
+               int temp1 = fileName.LastIndexOf('\\');
+               int temp2 = fileName.LastIndexOf('/');
+               int posOfBar = 0;
+               if(temp1>temp2)
+                       posOfBar = temp1;
+               else
+                       posOfBar = temp2;
+
+               string lastPartOfPath = fileName.Substring(posOfBar+1, fileName.Length - posOfBar -1);
+               return lastPartOfPath;
+       }
 }


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