[chronojump] Webcam: new file webcamFfmpegSupportedModes.cs



commit 25b06bc5d60dddedd16a4dcb980f9ca5ce958299
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Jun 7 17:36:09 2019 +0200

    Webcam: new file webcamFfmpegSupportedModes.cs

 src/Makefile.am                   |   1 +
 src/gui/preferences.cs            |  78 +++-------------------------
 src/webcamFfmpegSupportedModes.cs | 105 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 114 insertions(+), 70 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index a0ef601a..53e3dd03 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -220,6 +220,7 @@ SOURCES = \
        webcam.cs\
        webcamFfmpeg.cs\
        webcamFfmpegDevices.cs\
+       webcamFfmpegSupportedModes.cs\
        webcamMplayer.cs
 
 RESOURCES = \
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 985d8354..56a89eea 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -790,27 +790,6 @@ public class PreferencesWindow
                Util.TestSound = false;
        }
 
-       /*
-TODO:
-       moure els mètodes de sota a una classe específica
-               que la classe incorpori el parsejat
-               que al parsejar es pleni una llista de objectes de una altra classe
-               aquesta nova classe seria resolutionFramerate
-               que tindria
-               int width
-               int height
-               List<float> framerate (aixo tambe aniria be pel windows que mostra un min i max de fps per 
cada resolucio, a linux i mac mostra llista de resolucions i framerates però diferent)
-
-               si conve la llista de objectes resolutionFramerate podria ser un altre objecte que els 
ordenes i fes prints com calgui, o tingues gets que anessin be per a omplir algun dialeg a gui/preferences
-
-               jo crec que tot aixo hauria d'estar a src/webcamFfmpegSupportedModes.cs
-               on hi hauria les classes:
-               - webcamResolutioFramerate
-               - webcamResolutioFramerateList
-               - i els metodes que hi ha aqui sota per saber els valors (per cada SO)
-               - i els metodes de parseig dels anteriors (per cada SO)
-       */
-
        //for mac and maybe windows, because in Linux it founds a default mode and it works
        private void on_button_video_get_supported_modes_clicked (object o, EventArgs args)
        {
@@ -818,61 +797,20 @@ TODO:
                if(cameraCode == "")
                        return;
 
-               string modesStr = "";
-
-               //TODO: move all this to a class similar to WebcamDevices
-               if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.LINUX)
-               {
-                       List<string> parameters = new List<string>();
-                       parameters.Add("--list-formats-ext");
-                       ExecuteProcess.Result execute_result = ExecuteProcess.run ("v4l2-ctl", parameters, 
true, true);
-                       if(! execute_result.success) {
-                               new DialogMessage("Chronojump - Modes of this webcam",
-                                               Constants.MessageTypes.WARNING, "Need to install v4l2-ctl (on 
v4l-utils) to know modes");
-                               return;
-                       }
-
-                       modesStr = execute_result.stdout;
-               }
-               else if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.WINDOWS)
-               {
-                       string executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
-                       //ffmpeg -f dshow -list_options true -i video="USB 2.0 WebCamera"
-                       List<string> parameters = new List<string>();
-                       parameters.Add("-f");
-                       parameters.Add("dshow");
-                       parameters.Add("-list_options");
-                       parameters.Add("true");
-                       parameters.Add("-i");
-                       parameters.Add("video=" + cameraCode);
-                       ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, 
true, true);
-
-                       //TODO: check if ffmpeg installed, but take care because right now this always gets 
error, so we need to not return
-                       /*
-                       if(! execute_result.success) {
-                               new DialogMessage("Chronojump - Modes of this webcam",
-                                               Constants.MessageTypes.WARNING, "Need to install ffmpeg");
-                               return;
-                       }
-                       */
+               WebcamFfmpegSupportedModes modes = new WebcamFfmpegSupportedModes ();
+               modes.GetModes(UtilAll.GetOSEnum(), cameraCode);
 
-                       //modesStr = execute_result.stdout;
-                       modesStr = execute_result.allOutput;
-               }
-               else if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
+               if(modes.ErrorStr != "")
                {
-                       //select and impossible mode just to get an error on mac, this error will give us the 
"Supported modes"
-                       Webcam webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(),
-                                       cameraCode, "8000x8000", "8000");
-
-                       Webcam.Result result = webcamPlay.PlayPreviewNoBackgroundWantStdoutAndStderr();
-                       modesStr = result.output;
+                       new DialogMessage("Chronojump - Modes of this webcam",
+                                       Constants.MessageTypes.WARNING, modes.ErrorStr);
+                       return;
                }
 
                //display the result (if any)
-               if(modesStr != "")
+               if(modes.ModesStr != "")
                        new DialogMessage("Chronojump - Modes of this webcam",
-                                       Constants.MessageTypes.INFO, modesStr, true); //showScrolledWinBar
+                                       Constants.MessageTypes.INFO, modes.ModesStr, true); 
//showScrolledWinBar
        }
 
        private void on_button_video_preview_clicked (object o, EventArgs args)
diff --git a/src/webcamFfmpegSupportedModes.cs b/src/webcamFfmpegSupportedModes.cs
new file mode 100644
index 00000000..420458f8
--- /dev/null
+++ b/src/webcamFfmpegSupportedModes.cs
@@ -0,0 +1,105 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Copyright (C) 2004-2017   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.Collections.Generic; //List<T>
+
+
+public class WebcamFfmpegSupportedModes 
+{
+       private string modesStr;
+       private string errorStr;
+
+       //for mac and maybe windows, because in Linux it founds a default mode and it works
+       public WebcamFfmpegSupportedModes ()
+       {
+               modesStr = "";
+               errorStr = "";
+       }
+
+       public void GetModes(UtilAll.OperatingSystems os, string cameraCode)
+       {
+               if(os == UtilAll.OperatingSystems.LINUX)
+                       getModesLinux();
+               else if(os == UtilAll.OperatingSystems.WINDOWS)
+                       getModesWindows(cameraCode);
+               else if(UtilAll.GetOSEnum() == UtilAll.OperatingSystems.MACOSX)
+                       getModesMac(cameraCode);
+       }
+
+       private void getModesLinux()
+       {
+               List<string> parameters = new List<string>();
+               parameters.Add("--list-formats-ext");
+               ExecuteProcess.Result execute_result = ExecuteProcess.run ("v4l2-ctl", parameters, true, 
true);
+               if(! execute_result.success) {
+                       errorStr = "Need to install v4l2-ctl (on v4l-utils) to know modes";
+                       return;
+               }
+
+               modesStr = execute_result.stdout;
+       }
+
+       private void getModesWindows(string cameraCode)
+       {
+               string executable = System.IO.Path.Combine(Util.GetPrefixDir(), "bin/ffmpeg.exe");
+               //ffmpeg -f dshow -list_options true -i video="USB 2.0 WebCamera"
+               List<string> parameters = new List<string>();
+               parameters.Add("-f");
+               parameters.Add("dshow");
+               parameters.Add("-list_options");
+               parameters.Add("true");
+               parameters.Add("-i");
+               parameters.Add("video=" + cameraCode);
+               ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, 
true);
+
+               //TODO: check if ffmpeg installed, but take care because right now this always gets error, so 
we need to not return
+               /*
+                  if(! execute_result.success) {
+                  new DialogMessage("Chronojump - Modes of this webcam",
+                  Constants.MessageTypes.WARNING, "Need to install ffmpeg");
+                  return;
+                  }
+                  */
+
+               //modesStr = execute_result.stdout;
+               modesStr = execute_result.allOutput;
+       }
+
+       private void getModesMac(string cameraCode)
+       {
+               //select and impossible mode just to get an error on mac, this error will give us the 
"Supported modes"
+               Webcam webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(),
+                               cameraCode, "8000x8000", "8000");
+
+               Webcam.Result result = webcamPlay.PlayPreviewNoBackgroundWantStdoutAndStderr();
+               modesStr = result.output;
+       }
+
+       public string ErrorStr
+       {
+               get { return errorStr;  }
+       }
+
+       public string ModesStr
+       {
+               get { return modesStr;  }
+       }
+}


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