[chronojump] webcam start/stop improved on contacts now (test waits until really record)
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] webcam start/stop improved on contacts now (test waits until really record)
- Date: Thu, 2 May 2019 15:56:12 +0000 (UTC)
commit 08fe0d004c8c9aab13e09054f0fb4acd4dd78543
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu May 2 17:08:19 2019 +0200
webcam start/stop improved on contacts now (test waits until really record)
glade/app1.glade | 27 +++++++++++++--
src/execute/event.cs | 23 ++-----------
src/gui/chronojump.cs | 42 ++++++++++-------------
src/gui/chronopic.cs | 2 +-
src/gui/webcam.cs | 93 ++++++++++++++++++++++++++++++++++++++++++---------
src/webcam.cs | 2 ++
6 files changed, 124 insertions(+), 65 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 641c3539..a08e369c 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1890,6 +1890,9 @@
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<widget class="GtkLabel"
id="label_start_selector_jumps">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -10184,6 +10187,18 @@ EncoderInertialCapture</property>
<widget class="GtkHBox" id="hbox62">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="spacing">4</property>
+ <child>
+ <widget class="GtkProgressBar"
id="pulsebar_webcam">
+ <property name="width_request">50</property>
+ <property name="can_focus">False</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">-1</property>
+ </packing>
+ </child>
<child>
<widget class="GtkButton"
id="button_video_preview">
<property name="can_focus">True</property>
@@ -10225,7 +10240,7 @@ EncoderInertialCapture</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -10236,7 +10251,7 @@ EncoderInertialCapture</property>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
@@ -10279,7 +10294,7 @@ EncoderInertialCapture</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
</widget>
@@ -20729,6 +20744,9 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -29328,6 +29346,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/execute/event.cs b/src/execute/event.cs
index 8a2836dc..4d2c700a 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -66,6 +66,8 @@ public class EventExecute
protected string feedbackMessage;
protected bool needShowFeedbackMessage;
+ public bool WebcamStarted;
+
//instances with the info to create
public PrepareEventGraphJumpSimple PrepareEventGraphJumpSimpleObject;
public PrepareEventGraphJumpReactive PrepareEventGraphJumpReactiveObject;
@@ -354,20 +356,6 @@ public class EventExecute
// <-------------------------- end of races specific
- //camera stuff: show something when record really starts
- if(webcamStarting)
- {
- if(! checkWebcamFileStarted)
- {
- if(WebcamManage.RecordingFileStarted ())
- {
- LogB.Information("WebcamManage.RecodingFileStarted");
- UtilGtk.PrintLabelWithTooltip(egd.Label_video_feedback, "Recording
video.");
- checkWebcamFileStarted = true;
- }
- }
- }
-
//check if it should finish by time
if(shouldFinishByTime()) {
finish = true;
@@ -611,13 +599,6 @@ public class EventExecute
public Event EventDone {
get { return eventDone; }
}
-
- private bool webcamStarting = false;
- private bool checkWebcamFileStarted = false;
- public bool WebcamStarting {
- get { return webcamStarting; }
- set { webcamStarting = value; }
- }
// multi Chronopic stuff
public int Chronopics { get { return chronopics; } }
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 18d02f7a..1a698493 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3944,11 +3944,27 @@ public partial class ChronoJumpWindow
return;
}
- on_button_execute_test_accepted();
+ on_button_execute_test_acceptedPre();
}
UtilGtk.DeviceColors(viewport_chronopics, true);
}
+ // camera stuff if needed
+ private void on_button_execute_test_acceptedPre()
+ {
+ button_video_play_this_test_sensitive (WebcamManage.GuiContactsEncoder.CONTACTS, false);
+ webcamManage = new WebcamManage();
+ if(! webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1))
+ {
+ on_button_execute_test_accepted();
+ return;
+ }
+
+ bool waitUntilRecording = true;
+ if(! waitUntilRecording)
+ on_button_execute_test_accepted();
+ }
+
void on_button_execute_test_accepted ()
{
bool canCaptureC = cp2016.StoredCanCaptureContacts;
@@ -3961,8 +3977,6 @@ public partial class ChronoJumpWindow
event_execute_ButtonCancel.Clicked -= new EventHandler(on_cancel_clicked);
event_execute_ButtonFinish.Clicked -= new EventHandler(on_finish_clicked);
- webcamManage = new WebcamManage();
-
if(current_menuitem_mode == Constants.Menuitem_modes.JUMPSSIMPLE)
{
LogB.Debug("radio_menuitem_mode_jumps_simple");
@@ -4184,9 +4198,6 @@ public partial class ChronoJumpWindow
//UtilGtk.ChronopicColors(viewport_chronopics, label_chronopics, label_connected_chronopics,
chronopicWin.Connected);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
if (! canCaptureC)
currentEventExecute.SimulateInitValues(rand);
@@ -4493,10 +4504,6 @@ public partial class ChronoJumpWindow
repetitiveConditionsWin, progressbarLimit, egd
);
- //webcamStart (2);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
//suitable for limited by jump and time
//simulated always simulate limited by jumps
if(! canCaptureC)
@@ -4642,9 +4649,6 @@ public partial class ChronoJumpWindow
image_run_execute_photocell
);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
if (! canCaptureC)
currentEventExecute.SimulateInitValues(rand);
@@ -4777,9 +4781,6 @@ public partial class ChronoJumpWindow
image_run_execute_photocell
);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
//suitable for limited by tracks and time
if(! canCaptureC)
currentEventExecute.SimulateInitValues(rand);
@@ -4998,9 +4999,6 @@ public partial class ChronoJumpWindow
progressbarLimit, egd, description
);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
if (! canCaptureC)
currentEventExecute.SimulateInitValues(rand);
@@ -5158,9 +5156,6 @@ public partial class ChronoJumpWindow
preferences.volumeOn, preferences.gstreamer, egd
);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
if(! canCaptureC)
currentEventExecute.SimulateInitValues(rand);
@@ -5446,9 +5441,6 @@ public partial class ChronoJumpWindow
app1, egd
);
- currentEventExecute.WebcamStarting =
- webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1);
-
//mark to only get inside on_multi_chronopic_finished one time
multiFinishing = false;
currentEventExecute.Manage();
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index b55504b8..19871ade 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -88,7 +88,7 @@ public partial class ChronoJumpWindow
return;
} else {
button_activate_chronopics.Show();
- on_button_execute_test_accepted();
+ on_button_execute_test_acceptedPre();
return;
}
}
diff --git a/src/gui/webcam.cs b/src/gui/webcam.cs
index abb71ff0..a974ce34 100644
--- a/src/gui/webcam.cs
+++ b/src/gui/webcam.cs
@@ -22,6 +22,8 @@ using System;
using Gtk;
using Glade;
using System.IO; //"File" things
+using System.Diagnostics; //Stopwatch
+using System.Threading;
public partial class ChronoJumpWindow
{
@@ -44,6 +46,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Image image_video_encoder_no;
[Widget] Gtk.Button button_video_play_this_test;
[Widget] Gtk.Button button_video_play_this_test_encoder;
+ [Widget] Gtk.ProgressBar pulsebar_webcam;
private enum WebcamEncoderFileStarted { NEEDTOCHECK, RECORDSTARTED, NOCAMERA }
@@ -90,8 +93,11 @@ public partial class ChronoJumpWindow
WebcamManage webcamManage;
- private bool webcamStart (WebcamManage.GuiContactsEncoder guiContactsEncoder, int ncams)
+ //private bool webcamStart (WebcamManage.GuiContactsEncoder guiContactsEncoder, int ncams, bool
waitUntilRecording)
+ private bool webcamStart (WebcamManage.GuiContactsEncoder guiContactsEncoder, int ncams)//, bool
waitUntilRecording)
{
+ bool waitUntilRecording = true; //only applies to contacts, right now
+
if(guiContactsEncoder == WebcamManage.GuiContactsEncoder.ENCODER)
hbox_video_encoder.Sensitive = false;
@@ -104,7 +110,7 @@ public partial class ChronoJumpWindow
hbox_video_encoder_capturing.Visible = true;
}
- button_video_preview_visibile (guiContactsEncoder, false);
+ button_video_preview_visible (guiContactsEncoder, false);
string errorMessage = "";
if(ncams == 1)
@@ -127,14 +133,75 @@ public partial class ChronoJumpWindow
label_video_feedback_text (guiContactsEncoder, "Preparing camera");
}
- //TODO depending on errorMessage:
- //new DialogMessage(Constants.MessageTypes.WARNING, result.error);
- //button_video_play_this_test.Sensitive = false;
+ if(waitUntilRecording)
+ {
+ webcamStartThreadBeforeTestStatus = statusEnum.NOT_STARTED;
+ webcamStartThread = new Thread (new ThreadStart (webcamStartThreadBeforeTest));
+ GLib.Idle.Add (new GLib.IdleHandler (pulseWebcamGTK));
+ webcamStartThread.Start();
+ }
+
+ return true;
+ }
+
+ Thread webcamStartThread; //TODO: remember to stop/kill this on Chronojump exit
+ private enum statusEnum { NOT_STARTED, STARTING, FAILURE, SUCCESS };
+ static statusEnum webcamStartThreadBeforeTestStatus;
+ static Stopwatch swWebcamStart;
+
+ //Attention: no GTK here
+ private void webcamStartThreadBeforeTest()
+ {
+ bool problems = false;
+ swWebcamStart = new Stopwatch();
+ swWebcamStart.Start();
+ do {
+ System.Threading.Thread.Sleep(100);
+ if(swWebcamStart.Elapsed.TotalSeconds >= 10)
+ problems = true;
+ } while(! WebcamManage.RecordingFileStarted() && ! problems);
+ swWebcamStart.Stop();
+
+ if(problems) {
+ LogB.Information("Problems starting camera.");
+ webcamStartThreadBeforeTestStatus = statusEnum.FAILURE;
+ } else
+ webcamStartThreadBeforeTestStatus = statusEnum.SUCCESS;
+ }
+ private bool pulseWebcamGTK ()
+ {
+ if(webcamStartThreadBeforeTestStatus == statusEnum.NOT_STARTED)
+ {
+ label_video_feedback_text (WebcamManage.GuiContactsEncoder.CONTACTS, "Initializing
camera.");
+ pulsebar_webcam.Visible = true;
+ webcamStartThreadBeforeTestStatus = statusEnum.STARTING;
+ }
+
+ if ( ! webcamStartThread.IsAlive )
+ {
+ pulsebar_webcam.Visible = false;
+ if(webcamStartThreadBeforeTestStatus == statusEnum.FAILURE)
+ label_video_feedback_text (WebcamManage.GuiContactsEncoder.CONTACTS,
"Problems starting camera.");
+ else if(webcamStartThreadBeforeTestStatus == statusEnum.SUCCESS)
+ {
+ webcamManage.ReallyStarted = true;
+ label_video_feedback_text (WebcamManage.GuiContactsEncoder.CONTACTS,
"Recording ...");
+ }
+
+ on_button_execute_test_accepted ();
+
+ LogB.ThreadEnded();
+ return false;
+ }
+
+ pulsebar_webcam.Fraction = Util.DivideSafeFraction(swWebcamStart.Elapsed.TotalSeconds, 10);
+ Thread.Sleep (50);
+ //LogB.Debug(webcamStartThread.ThreadState.ToString());
return true;
}
- private void button_video_preview_visibile (WebcamManage.GuiContactsEncoder guiContactsEncoder, bool
visible)
+ private void button_video_preview_visible (WebcamManage.GuiContactsEncoder guiContactsEncoder, bool
visible)
{
if(guiContactsEncoder == WebcamManage.GuiContactsEncoder.CONTACTS)
button_video_preview.Visible = visible;
@@ -226,8 +293,8 @@ public partial class ChronoJumpWindow
//can pass a -1 uniqueID if test is cancelled
private void webcamEnd (Constants.TestTypes testType, int uniqueID)
{
- //on contacts tests, we have WebcamStarting. No need to stop camera because it is not
recording
- if(testType != Constants.TestTypes.ENCODER && ! currentEventExecute.WebcamStarting)
+ //on contacts tests, we have WebcamStarted. No need to stop camera because it is not recording
+ if(testType != Constants.TestTypes.ENCODER && ! webcamManage.ReallyStarted)
return;
WebcamManage.GuiContactsEncoder guiContactsEncoder = WebcamManage.GuiContactsEncoder.CONTACTS;
@@ -242,18 +309,13 @@ public partial class ChronoJumpWindow
}
if(! preferences.videoOn || webcamManage == null)
- {
- button_video_play_this_test_sensitive (guiContactsEncoder, false);
return;
- }
Webcam.Result result = webcamManage.RecordEnd (1);
if(! result.success)
{
new DialogMessage(Constants.MessageTypes.WARNING, result.error);
- button_video_play_this_test_sensitive (guiContactsEncoder, false);
-
return;
}
@@ -280,7 +342,8 @@ public partial class ChronoJumpWindow
if(webcamEndParams.uniqueID != -1 && ! resultExit.success)
new DialogMessage(Constants.MessageTypes.WARNING, resultExit.error);
- button_video_play_this_test_sensitive (webcamEndParams.guiContactsEncoder,
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);
return false; //do not call this Timeout routine again
@@ -317,7 +380,7 @@ public partial class ChronoJumpWindow
}
//button_video_play_this_test.Sensitive = false;
- button_video_play_this_test_sensitive (guiContactsEncoder, false);
+ //button_video_play_this_test_sensitive (guiContactsEncoder, false);
if(! preferences.videoOn || webcamManage == null)
return;
diff --git a/src/webcam.cs b/src/webcam.cs
index f3e6a01a..de0f57bb 100644
--- a/src/webcam.cs
+++ b/src/webcam.cs
@@ -181,12 +181,14 @@ public class WebcamManage
Webcam webcam2;
private UtilAll.OperatingSystems os;
//TODO: implement an List<T> of objects containing webcam and video device
+ public bool ReallyStarted;
public enum GuiContactsEncoder { CONTACTS, ENCODER }
public WebcamManage()
{
os = UtilAll.GetOSEnum();
+ ReallyStarted = false;
}
// 1 camera
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]