[chronojump] personWin ffmpeg at background and closes nicely on any situation



commit 9507bd462a32583e8f09849593fdb2d86dab7e3d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Mar 18 15:51:54 2019 +0100

    personWin ffmpeg at background and closes nicely on any situation

 glade/person_win.glade | 12 ++++----
 src/gui/person.cs      | 16 ++++++----
 src/webcamFfmpeg.cs    | 82 +++++++++++++++++++++++++++++++-------------------
 3 files changed, 67 insertions(+), 43 deletions(-)
---
diff --git a/glade/person_win.glade b/glade/person_win.glade
index 863d1517..be023396 100644
--- a/glade/person_win.glade
+++ b/glade/person_win.glade
@@ -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>
diff --git a/src/gui/person.cs b/src/gui/person.cs
index 6c09574c..b5232c6a 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -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;
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index 80108675..0f3519d7 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -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;


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