Commit ce00d0cc authored by Xavier de Blas's avatar Xavier de Blas

testing-stuff/ffmpegCapture copies correctly when ended

parent c6c6cea1
#this will create a binary that will work on linux and windows (and hopefully mac)
mcs *.cs -out:ffmpegCapture.exe
......@@ -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)
......
......@@ -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;
......
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment