Commit 9507bd46 authored by Xavier de Blas's avatar Xavier de Blas

personWin ffmpeg at background and closes nicely on any situation

parent 223fad93
......@@ -347,12 +347,12 @@
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkButton" id="button_take_photo_start_end_camera">
<widget class="GtkButton" id="button_take_photo_preview_camera">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip" translatable="yes">Start webcam</property>
<signal name="clicked" handler="on_button_take_photo_start_end_camera_clicked" swapped="no"/>
<property name="tooltip" translatable="yes">Preview</property>
<signal name="clicked" handler="on_button_take_photo_preview_camera_clicked" swapped="no"/>
<child>
<widget class="GtkHBox" id="hbox7">
<property name="visible">True</property>
......@@ -650,9 +650,6 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<widget class="GtkLabel" id="label218">
<property name="visible">True</property>
......@@ -2079,6 +2076,9 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</widget>
</child>
</widget>
......
......@@ -815,7 +815,6 @@ public class PersonAddModifyWindow
[Widget] Gtk.Image image_photo_do;
[Widget] Gtk.Button button_add_photo_file;
[Widget] Gtk.Button button_take_photo_start_end_camera;
[Widget] Gtk.Button button_take_photo_do;
[Widget] Gtk.HBox hbox_camera;
......@@ -1067,15 +1066,13 @@ public class PersonAddModifyWindow
Gtk.Window capturerWindow;
Webcam webcam;
//CapturerBin capturer;
void on_button_take_photo_start_end_camera_clicked (object o, EventArgs args)
void on_button_take_photo_preview_camera_clicked (object o, EventArgs args)
{
// A) end if it's running
if(webcam != null && webcam.Running)
{
webcam.ExitCamera();
button_take_photo_start_end_camera.TooltipText = Catalog.GetString("Start webcam");
return;
//return;
}
// B) start if it's not running
......@@ -1083,7 +1080,8 @@ public class PersonAddModifyWindow
//Webcam.Result result = webcam.CapturePrepare (Webcam.CaptureTypes.PHOTO);
//constructor for playpreview
webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), videoDevice);
Webcam.Result result = webcam.PlayPreviewNoBackground ();
//Webcam.Result result = webcam.PlayPreviewNoBackground ();
Webcam.Result result = webcam.PlayPreview ();
if (! result.success)
{
......@@ -1096,6 +1094,10 @@ public class PersonAddModifyWindow
{
if(webcam == null)
webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), videoDevice);
else if(webcam != null && webcam.Running)
{
webcam.ExitCamera();
}
if(webcam.Snapshot())
{
......@@ -1892,6 +1894,8 @@ public class PersonAddModifyWindow
SqlitePersonSession.Update (currentPersonSession);
}
if(webcam != null && webcam.Running)
webcam.ExitCamera();
PersonAddModifyWindowBox.person_win.Hide();
PersonAddModifyWindowBox = null;
......
......@@ -30,11 +30,13 @@ public class WebcamFfmpeg : Webcam
{
private UtilAll.OperatingSystems os;
private int processID;
private Action action;
// constructor ----------------------------------
public WebcamFfmpeg (Webcam.Action action, UtilAll.OperatingSystems os, string videoDevice)
{
this.action = action;
this.os = os;
this.videoDevice = videoDevice;
......@@ -331,40 +333,58 @@ public class WebcamFfmpeg : Webcam
{
LogB.Information("Exit camera");
LogB.Information("streamWriter is null: " + (streamWriter == null).ToString());
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("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!");
}
Console.WriteLine("closing ...");
process.Close();
Console.WriteLine("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
*/
/*
* 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
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;
......
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