[chronojump] Implemented webcam preview
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Implemented webcam preview
- Date: Tue, 13 Nov 2018 17:28:38 +0000 (UTC)
commit c9be7edd2330473b64cf8402bf834f71699a36e6
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Nov 13 18:28:18 2018 +0100
Implemented webcam preview
glade/app1.glade | 88 ++++++++++++++++++++++++++++---------------------
src/gui/chronojump.cs | 40 ++++++++++++++--------
src/gui/encoder.cs | 1 +
src/gui/event.cs | 2 +-
src/gui/eventExecute.cs | 2 ++
src/webcam.cs | 7 ++--
src/webcamFfmpeg.cs | 66 +++++++++++++++++++++++++++----------
src/webcamMplayer.cs | 8 ++++-
8 files changed, 142 insertions(+), 72 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index ab2b6da9..a6822f1a 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1787,6 +1787,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>
@@ -8743,6 +8746,10 @@ EncoderInertialCapture</property>
<property name="can_focus">False</property>
<property name="spacing">4</property>
<child>
+ <widget class="GtkHBox" id="hbox64">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
<widget class="GtkCheckButton"
id="checkbutton_video">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -8787,8 +8794,33 @@ EncoderInertialCapture</property>
</child>
</widget>
<packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkHBox" id="hbox62">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <widget class="GtkButton"
id="button_video_preview">
+ <property name="label"
translatable="yes">Preview</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip" translatable="yes">Skip
this person (will perform tests at the end)</property>
+ <signal name="clicked"
handler="on_button_video_preview_clicked" swapped="no"/>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
@@ -8807,6 +8839,13 @@ EncoderInertialCapture</property>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
@@ -19253,42 +19292,6 @@ Concentric</property>
<placeholder/>
</child>
<child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
<widget class="GtkLabel"
id="label_force_sensor_ai_rfd_a">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -19573,6 +19576,9 @@ Concentric</property>
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<widget class="GtkCheckButton"
id="checkbutton_force_sensor_ai_b">
<property name="width_request">30</property>
<property name="visible">True</property>
@@ -19655,6 +19661,9 @@ Concentric</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -27907,6 +27916,9 @@ then click this button.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 174dfe05..3ad60e2c 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -297,6 +297,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.HBox hbox_video_capture;
[Widget] Gtk.Label label_video_feedback;
[Widget] Gtk.CheckButton checkbutton_video;
+ [Widget] Gtk.Button button_video_preview;
//[Widget] Gtk.Label label_video;
[Widget] Gtk.Image image_video_yes;
[Widget] Gtk.Image image_video_no;
@@ -3873,7 +3874,8 @@ public partial class ChronoJumpWindow
checkbutton_video_encoder.Clicked -= new EventHandler(on_checkbutton_video_encoder_clicked);
checkbutton_video_encoder.Active = preferences.videoOn;
checkbutton_video_encoder.Clicked += new EventHandler(on_checkbutton_video_encoder_clicked);
-
+
+ button_video_preview.Visible = checkbutton_video.Active;
changeVideoButtons(preferences.videoOn);
videoCapturePrepare(true); //if error, show message
@@ -4277,6 +4279,7 @@ public partial class ChronoJumpWindow
if(! preferences.videoOn || webcamManage == null)
return;
+ button_video_preview.Visible = false;
string errorMessage = "";
if(ncams == 1 && webcamManage.RecordPrepare(preferences.videoDevice).success)
{
@@ -6102,11 +6105,23 @@ LogB.Debug("mc finished 5");
//TODO: manage different playVideo. Playing is very different than capturing, separate it.
Webcam webcam;
+ private void on_button_video_preview_clicked (object o, EventArgs args)
+ {
+ playPreview();
+ }
+ private void playPreview ()
+ {
+ //constructor for playpreview
+ webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(),
preferences.videoDevice);
+ Webcam.Result result = webcam.PlayPreview ();
+ }
+
//Not used on encoder
- private bool playVideo(string fileName, bool play)
+ private void playVideo (string fileName)
{
- webcam = new WebcamFfmpeg (UtilAll.GetOSEnum());
- Webcam.Result result = webcam.Play(fileName);
+ //constructor for playpreview
+ webcam = new WebcamFfmpeg (Webcam.Action.PLAYFILE, UtilAll.GetOSEnum(), "");
+ Webcam.Result result = webcam.PlayFile (fileName);
/*
* TODO: reimplement this with ffmpeg
@@ -6131,7 +6146,6 @@ LogB.Debug("mc finished 5");
return true;
}
*/
- return false;
}
@@ -6172,56 +6186,56 @@ LogB.Debug("mc finished 5");
break;
}
- playVideo(Util.GetVideoFileName(currentSession.UniqueID, type, id), true);
+ playVideo(Util.GetVideoFileName(currentSession.UniqueID, type, id));
}
private void on_video_play_selected_jump_clicked (object o, EventArgs args) {
if (myTreeViewJumps.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.JUMP,
- myTreeViewJumps.EventSelectedID), true);
+ myTreeViewJumps.EventSelectedID));
}
private void on_video_play_selected_jump_rj_clicked (object o, EventArgs args) {
if (myTreeViewJumpsRj.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.JUMP_RJ,
- myTreeViewJumpsRj.EventSelectedID), true);
+ myTreeViewJumpsRj.EventSelectedID));
}
private void on_video_play_selected_run_clicked (object o, EventArgs args) {
if (myTreeViewRuns.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.RUN,
- myTreeViewRuns.EventSelectedID), true);
+ myTreeViewRuns.EventSelectedID));
}
private void on_video_play_selected_run_interval_clicked (object o, EventArgs args) {
if (myTreeViewRunsInterval.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.RUN_I,
- myTreeViewRunsInterval.EventSelectedID), true);
+ myTreeViewRunsInterval.EventSelectedID));
}
private void on_video_play_selected_reaction_time_clicked (object o, EventArgs args) {
if (myTreeViewReactionTimes.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.RT,
- myTreeViewReactionTimes.EventSelectedID), true);
+ myTreeViewReactionTimes.EventSelectedID));
}
private void on_video_play_selected_pulse_clicked (object o, EventArgs args) {
if (myTreeViewPulses.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.PULSE,
- myTreeViewPulses.EventSelectedID), true);
+ myTreeViewPulses.EventSelectedID));
}
private void on_video_play_selected_multi_chronopic_clicked (object o, EventArgs args) {
if (myTreeViewMultiChronopic.EventSelectedID > 0)
playVideo(Util.GetVideoFileName(currentSession.UniqueID,
Constants.TestTypes.MULTICHRONOPIC,
- myTreeViewMultiChronopic.EventSelectedID), true);
+ myTreeViewMultiChronopic.EventSelectedID));
}
/* ---------------------------------------------------------
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 1a31f009..73eafccc 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -7253,6 +7253,7 @@ public partial class ChronoJumpWindow
/* end of thread stuff */
/* video stuff */
+
private void encoderStartVideoRecord() {
/*
* TODO: reimplement this with ffmpeg
diff --git a/src/gui/event.cs b/src/gui/event.cs
index 6909a126..6431a96c 100644
--- a/src/gui/event.cs
+++ b/src/gui/event.cs
@@ -316,7 +316,7 @@ public class EditEventWindow
LogB.Information("Exists and clicked " + videoFileName);
Webcam webcam = new WebcamMplayer ();
- Webcam.Result result = webcam.Play(videoFileName);
+ Webcam.Result result = webcam.PlayFile(videoFileName);
}
}
diff --git a/src/gui/eventExecute.cs b/src/gui/eventExecute.cs
index 9c163282..5847dc31 100644
--- a/src/gui/eventExecute.cs
+++ b/src/gui/eventExecute.cs
@@ -2255,6 +2255,7 @@ public partial class ChronoJumpWindow
checkbutton_video.Sensitive = true;
if(preferences.videoOn) {
label_video_feedback.Text = "";
+ button_video_preview.Visible = true;
//capturer.ClickStop();
//videoCapturePrepare(false); //if error, show message
}
@@ -2411,6 +2412,7 @@ public partial class ChronoJumpWindow
if(preferences.videoOn) {
//it will be recorded on temp, but chronojump will move it to chronojump/multimedia
folders
label_video_feedback.Text = "";
+ button_video_preview.Visible = true;
//capturer.ClickStop();
//videoCapturePrepare(false); //if error, show message
}
diff --git a/src/webcam.cs b/src/webcam.cs
index bd877c22..94592aa7 100644
--- a/src/webcam.cs
+++ b/src/webcam.cs
@@ -93,6 +93,7 @@ public abstract class Webcam
string.Format(Catalog.GetString("Error. {0} cannot save video."), "mplayer");
public bool Running;
+ public enum Action { CAPTURE, PLAYPREVIEW, PLAYFILE }
protected Process process;
protected string videoDevice;
@@ -124,7 +125,9 @@ public abstract class Webcam
public abstract Result CapturePrepare (CaptureTypes captureType);
- public abstract Result Play(string filename);
+ public abstract Result PlayPreview();
+
+ public abstract Result PlayFile(string filename);
public abstract bool Snapshot();
@@ -194,7 +197,7 @@ public class WebcamManage
LogB.Information("wRS at gui chronojump.cs 0, videoDevice: " + videoDevice);
//w = new WebcamMplayer (videoDevice);
- w = new WebcamFfmpeg (os, videoDevice);
+ w = new WebcamFfmpeg (Webcam.Action.CAPTURE, os, videoDevice);
Webcam.Result result = w.CapturePrepare (Webcam.CaptureTypes.VIDEO);
LogB.Information("wRS at gui chronojump.cs 1, videoDevice: " + videoDevice);
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index 2ee74fec..255e53b8 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -29,46 +29,64 @@ public class WebcamFfmpeg : Webcam
private UtilAll.OperatingSystems os;
private int processID;
- public WebcamFfmpeg (UtilAll.OperatingSystems os, string videoDevice)
+ // constructor ----------------------------------
+
+ public WebcamFfmpeg (Webcam.Action action, UtilAll.OperatingSystems os, string videoDevice)
{
this.os = os;
this.videoDevice = videoDevice;
- executable = "ffmpeg";
- if(os == UtilAll.OperatingSystems.WINDOWS)
- executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
+ if(action == Webcam.Action.CAPTURE)
+ {
+ executable = "ffmpeg";
+ if(os == UtilAll.OperatingSystems.WINDOWS)
+ executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
+ }
+ else // PLAYPREVIEW || PLAYFILE
+ {
+ executable = "ffplay";
+ if(os == UtilAll.OperatingSystems.WINDOWS)
+ executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffplay.exe");
+ }
Running = false;
}
- /*
- * constructor for Play
- */
+ // public methods ----------------------------------
- public WebcamFfmpeg (UtilAll.OperatingSystems os)
+ public override Result CapturePrepare (CaptureTypes captureType)
{
- this.os = os;
+ if(process != null)
+ return new Result (false, "");
- executable = "ffplay";
- if(os == UtilAll.OperatingSystems.WINDOWS)
- executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffplay.exe");
+ return new Result (true, "");
}
-
- public override Result CapturePrepare (CaptureTypes captureType)
+ public override Result PlayPreview ()
{
if(process != null)
return new Result (false, "");
+ List<string> parameters = createParametersPlayPreview();
+
+ process = new Process();
+ bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false);
+ if(! success)
+ {
+ process = null;
+ return new Result (false, "", programFfmpegNotInstalled);
+ }
+
+ Running = true;
return new Result (true, "");
}
- public override Result Play(string filename)
+ public override Result PlayFile (string filename)
{
if(process != null || filename == "")
return new Result (false, "");
- List<string> parameters = createParametersPlay(filename);
+ List<string> parameters = createParametersPlayFile (filename);
process = new Process();
bool success = ExecuteProcess.RunAtBackground (ref process, executable, parameters, false);
@@ -81,6 +99,7 @@ public class WebcamFfmpeg : Webcam
Running = true;
return new Result (true, "");
}
+
public override bool Snapshot()
{
//only implemented on mplayer
@@ -107,7 +126,20 @@ public class WebcamFfmpeg : Webcam
return new Result (true, "");
}
- private List<string> createParametersPlay(string filename)
+ // private methods ----------------------------------
+
+ private List<string> createParametersPlayPreview()
+ {
+ // ffplay /dev/video0
+ List<string> parameters = new List<string>();
+ int i=0;
+ parameters.Insert (i++, videoDevice);
+ parameters.Insert (i++, "-window_title");
+ parameters.Insert (i++, "Chronojump webcam preview");
+ return parameters;
+ }
+
+ private List<string> createParametersPlayFile(string filename)
{
// ffplay out.mp4
List<string> parameters = new List<string>();
diff --git a/src/webcamMplayer.cs b/src/webcamMplayer.cs
index 74c3bd9a..b6094bc6 100644
--- a/src/webcamMplayer.cs
+++ b/src/webcamMplayer.cs
@@ -100,7 +100,13 @@ public class WebcamMplayer : Webcam
return new Result (true, "");
}
- public override Result Play(string filename)
+ public override Result PlayPreview ()
+ {
+ //not implemented
+ return new Result (false, "");
+ }
+
+ public override Result PlayFile (string filename)
{
if(process != null || filename == "")
return new Result (false, "");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]