[chronojump] Webcam: a new test cannot be done until webcam ends (with the delay)



commit 20b8280b47e6d44707a8ead2b41efbc1adf5ce23
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jun 7 15:51:47 2019 +0200

    Webcam: a new test cannot be done until webcam ends (with the delay)

 src/executeProcess.cs |  9 +++++++++
 src/gui/chronojump.cs | 11 ++++++++++-
 src/gui/webcam.cs     |  8 ++++++--
 src/webcamFfmpeg.cs   | 13 +++++++++++++
 4 files changed, 38 insertions(+), 3 deletions(-)
---
diff --git a/src/executeProcess.cs b/src/executeProcess.cs
index 1e0a16fb..4fcb37fb 100644
--- a/src/executeProcess.cs
+++ b/src/executeProcess.cs
@@ -205,10 +205,16 @@ 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
+        *
+        * To prevent a new instace of ffmpeg to be created,
+        * if we want to just check if ffmpeg binary is running for any processID pass -1 on processID
+        * an alternative will be check:
+        * public static bool IsFileLocked(FileInfo finfo)
         */
        public static bool IsRunning3 (int processID, string executable)
        {
@@ -220,6 +226,9 @@ class ExecuteProcess
                pdebug = Process.GetProcessesByName(executable);
                LogB.Information((pdebug.Length > 0).ToString());
 
+               if(processID == -1)
+                       return (pdebug.Length > 0);
+
                /*
                LogB.Information("running with LastPartOfPath of executable: " + 
Util.GetLastPartOfPath(executable));
                pdebug = Process.GetProcessesByName(Util.GetLastPartOfPath(executable));
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index eb05e425..5b017cb3 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -2270,6 +2270,12 @@ public partial class ChronoJumpWindow
                        portRE.Close();
 
                LogB.Information("Bye3!");
+
+               //TODO: if camera is opened close it! Note that this is intended to kill a remaining ffmpeg 
process
+               //but maybe we will kill any ffmpeg instance open by any other possible program on the 
computer
+               //maybe better kill ffmpeg before opening other instance
+               //and at end check if it is running that process and kill the last one ffmpeg instance
+               //LogB.Information("Bye4!");
                
                Log.End();
 
@@ -4315,8 +4321,11 @@ public partial class ChronoJumpWindow
                }
 
                LogB.Information(" cantouch1 ");
-               if(! execute_auto_doing)
+
+               //if webcam started then do not call sensitiveGuiEventDone(), because will be called at 
webcamEnd (that has a delay)
+               if(! execute_auto_doing && ! webcamManage.ReallyStarted)
                        sensitiveGuiEventDone();
+
                LogB.Information(" cantouch3 ");
 
                if (currentEventExecute.Cancel)
diff --git a/src/gui/webcam.cs b/src/gui/webcam.cs
index 8dcec367..4171ee9c 100644
--- a/src/gui/webcam.cs
+++ b/src/gui/webcam.cs
@@ -31,7 +31,7 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.VBox vbox_contacts_camera;
        [Widget] Gtk.CheckButton checkbutton_video;
        [Widget] Gtk.CheckButton checkbutton_video_encoder;
-       [Widget] Gtk.HBox hbox_video_capture;
+       //[Widget] Gtk.HBox hbox_video_capture;
        [Widget] Gtk.HBox hbox_video_encoder;
        [Widget] Gtk.HBox hbox_video_encoder_no_capturing;
        [Widget] Gtk.HBox hbox_video_encoder_capturing;
@@ -335,6 +335,7 @@ public partial class ChronoJumpWindow
                        else {
                                //call it later to be able to have some video on a short test like a jump.
                                LogB.Information(string.Format("Preparing to call webcamEndDo() in {0} s", 
preferences.videoStopAfter));
+
                                GLib.Timeout.Add(Convert.ToUInt32(preferences.videoStopAfter * 1000), new 
GLib.TimeoutHandler(webcamEndDo));
                        }
                }
@@ -349,10 +350,13 @@ public partial class ChronoJumpWindow
                if(webcamEndParams.uniqueID != -1 && ! resultExit.success)
                        new DialogMessage(Constants.MessageTypes.WARNING, resultExit.error);
 
-               LogB.Information(string.Format("calling button_video_play_this_test_sensitive {0}-{1}-{2}", 
webcamEndParams.guiContactsEncoder, webcamManage.ReallyStarted, resultExit.success));
+               LogB.Information(string.Format("calling button_video_play_this_test_sensitive {0}-{1}-{2}",
+                                       webcamEndParams.guiContactsEncoder, webcamManage.ReallyStarted, 
resultExit.success));
                button_video_play_this_test_sensitive (webcamEndParams.guiContactsEncoder, 
webcamManage.ReallyStarted && resultExit.success);
                button_video_play_selected_test(current_menuitem_mode);
 
+               sensitiveGuiEventDone();
+
                return false; //do not call this Timeout routine again
        }
 
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index fd926afc..95e76d82 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -166,6 +166,19 @@ public class WebcamFfmpeg : Webcam
 
        public override Result VideoCaptureStart()
        {
+               /*
+                * TODO: apply also this, but right now we will just unsensitive:
+                * execute test (contacts and encoder)
+                * and other camera related buttons
+                * is complicated because button_execute_test.Sensitive = true happens at different places
+                * also having this code will help to prevent problems of ffmpeg working all the time and 
filling users HD
+                *
+                * TODO: do some check related to ffmpeg capture time length
+                */
+               //check if process is running from a previous call:
+               if(ExecuteProcess.IsRunning3 (-1, executable))
+                       return new Result (false, "", "ffmpeg is already running");
+
                //Delete temp video if exists
                deleteTempFiles();
 


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