[chronojump] webcam get supported modes for mac (done!)



commit 50aa563cf0037da255e407d56d1ce8cd3bc12258
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 20 15:46:02 2019 +0200

    webcam get supported modes for mac (done!)

 glade/preferences_win.glade |  27 +++++++++--
 src/gui/preferences.cs      |  18 +++++++
 src/webcam.cs               |   1 +
 src/webcamFfmpeg.cs         | 114 ++++++++++++++++++++++++++++++++++++++++++++
 src/webcamMplayer.cs        |   5 ++
 5 files changed, 162 insertions(+), 3 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index 5e8f9fe6..e80810e6 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -3774,6 +3774,27 @@ Other</property>
                               <widget class="GtkVBox" id="vbox30">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
+                                <property name="spacing">12</property>
+                                <child>
+                                  <widget class="GtkButton" id="button_video_get_supported_modes">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">True</property>
+                                    <signal name="clicked" 
handler="on_button_video_get_supported_modes_clicked" swapped="no"/>
+                                    <child>
+                                      <widget class="GtkLabel" id="label86">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">Get supported 
modes</property>
+                                      </widget>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="expand">True</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
                                 <child>
                                   <widget class="GtkButton" id="button_video_preview">
                                     <property name="visible">True</property>
@@ -3793,8 +3814,8 @@ Other</property>
                                             <property name="stock">gtk-missing-image</property>
                                           </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>
@@ -3816,7 +3837,7 @@ Other</property>
                                   <packing>
                                     <property name="expand">True</property>
                                     <property name="fill">False</property>
-                                    <property name="position">0</property>
+                                    <property name="position">1</property>
                                   </packing>
                                 </child>
                               </widget>
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 40a62b43..968d6e65 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -784,6 +784,24 @@ public class PreferencesWindow
                Util.TestSound = false;
        }
 
+       //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)
+       {
+               string cameraCode = wd_list.GetCodeOfFullname(UtilGtk.ComboGetActive(combo_camera));
+               if(cameraCode == "")
+                       return;
+
+               Webcam webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(),
+                               cameraCode, "8000x8000", "8000"); //select and impossible mode just to get an 
error on mac, this error will give us the "Supported modes"
+
+               Webcam.Result result = webcamPlay.PlayPreviewNoBackgroundWantStdoutAndStderr();
+
+               //display the result (if any)
+               if(result.output != "")
+                       new DialogMessage("Chronojump - Modes of this webcam",
+                                       Constants.MessageTypes.INFO, result.output);
+       }
+
        private void on_button_video_preview_clicked (object o, EventArgs args)
        {
                string cameraCode = wd_list.GetCodeOfFullname(UtilGtk.ComboGetActive(combo_camera));
diff --git a/src/webcam.cs b/src/webcam.cs
index de0f57bb..ba95a9f5 100644
--- a/src/webcam.cs
+++ b/src/webcam.cs
@@ -145,6 +145,7 @@ public abstract class Webcam
 
        public abstract Result PlayPreview();
        public abstract Result PlayPreviewNoBackground();
+       public abstract Result PlayPreviewNoBackgroundWantStdoutAndStderr();
 
        public abstract Result PlayFile(string filename);
 
diff --git a/src/webcamFfmpeg.cs b/src/webcamFfmpeg.cs
index d633ff03..3a0d778d 100644
--- a/src/webcamFfmpeg.cs
+++ b/src/webcamFfmpeg.cs
@@ -104,6 +104,26 @@ public class WebcamFfmpeg : Webcam
 
                return new Result (true, "");
        }
+       //used to know "Supported modes" on mac and maybe on windows
+       public override Result PlayPreviewNoBackgroundWantStdoutAndStderr() //experimental
+       {
+               List<string> parameters = createParametersPlayPreview();
+
+               process = new Process();
+               ExecuteProcess.Result execute_result = ExecuteProcess.run (executable, parameters, true, 
true);
+               //LogB.Information("Stdout: ", execute_result.stdout);
+               //LogB.Information("Stderr: ", execute_result.stderr);
+               LogB.Information("allOutput: ", execute_result.allOutput);
+
+               string parsed = parseSupportedModes(execute_result.allOutput);
+
+               if(! execute_result.success)
+               {
+                       return new Result (false, parsed);
+               }
+
+               return new Result (true, parsed);
+       }
 
        //snapshot in 2 seconds
        public override bool Snapshot ()
@@ -439,6 +459,100 @@ public class WebcamFfmpeg : Webcam
                Running = false;
        }
 
+       private string parseSupportedModes(string allOutput)
+       {
+               string str = "";
+
+               /*
+                * break the big string in \n strings
+                * https://stackoverflow.com/a/1547483
+                */
+               string[] lines = allOutput.Split(
+                               new[] { Environment.NewLine },
+                               StringSplitOptions.None
+                               );
+
+               bool started = false;
+               foreach(string l in lines)
+               {
+                       LogB.Information("line: " + l);
+
+                       //devices start after the videoDevString line
+                       if(! started)
+                       {
+                               if(l.Contains("Supported modes"))
+                                       started = true;
+
+                               continue;
+                       }
+
+                       str = parseSupportedMode(l) + "\nstdout";
+
+                       //after the list of video devices comes the list of audio devices, skip it
+                       if(l.Contains("Input/output"))
+                               break;
+               }
+               return str;
+       }
+       private string parseSupportedMode(string l) //TODO: currently only for mac
+       {
+               if(! l.Contains("avfoundation"))
+                       return "";
+
+               //parse this:
+               //      [avfoundation @ 0x7f849a8be800]   1280x720@[23.999981 23.999981]fps
+               //use: https://regex101.com/r/lZ5mN8/50
+               //      (\d+)x(\d+)@\[(\d+).(\d+)\s+
+
+               Match match = Regex.Match(l, @"(\d+)x(\d+)@\[(\d+).(\d+)\s+");
+
+               LogB.Information("match group count: ", match.Groups.Count.ToString());
+               if(match.Groups.Count != 5) //first is all match, second is the first int (width), last one 
is the decimals of the resolution
+                       return "";
+
+               return string.Format("Resolution: {0}x{1}, Framerate: {2}.{3}",
+                               match.Groups[1].Value, match.Groups[2].Value,
+                               match.Groups[3].Value, match.Groups[4].Value);
+       }
+       /* test ParseSupportModes
+        *
+WebcamFfmpeg.parseSupportedModes(@"[avfoundation @ 0x7f849a8be800] Supported modes:
+[avfoundation @ 0x7f849a8be800]   160x120@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   160x120@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   160x120@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   160x120@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   176x144@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   176x144@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   176x144@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   176x144@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   320x240@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   320x240@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   320x240@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   320x240@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   352x288@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   352x288@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   352x288@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   352x288@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   640x480@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   640x480@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   640x480@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   640x480@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   960x540@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   960x540@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   960x540@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   960x540@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   1024x576@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   1024x576@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   1024x576@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   1024x576@[14.999993 14.999993]fps
+[avfoundation @ 0x7f849a8be800]   1280x720@[29.970000 29.970000]fps
+[avfoundation @ 0x7f849a8be800]   1280x720@[25.000000 25.000000]fps
+[avfoundation @ 0x7f849a8be800]   1280x720@[23.999981 23.999981]fps
+[avfoundation @ 0x7f849a8be800]   1280x720@[14.999993 14.999993]fps
+0: Input/output error");
+*/
+
+
        /*
         * protected methods
         */
diff --git a/src/webcamMplayer.cs b/src/webcamMplayer.cs
index 6046fe4a..5d271234 100644
--- a/src/webcamMplayer.cs
+++ b/src/webcamMplayer.cs
@@ -110,6 +110,11 @@ public class WebcamMplayer : Webcam
                //not implemented
                return new Result (false, "");
        }
+       public override Result PlayPreviewNoBackgroundWantStdoutAndStderr() //experimental
+       {
+               //not implemented
+               return new Result (false, "");
+       }
 
        public override Result PlayFile (string filename)
        {


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