[chronojump] DB 1.64 webcam pixel_format, preferences combos populating WIP



commit e41dfbad99fced49552e97b8f5e0d081e0c641b6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jul 4 18:28:36 2019 +0200

    DB 1.64 webcam pixel_format, preferences combos populating WIP

 glade/preferences_win.glade              | 108 +++++++++++++++---------
 src/gui/event.cs                         |   2 +-
 src/gui/person.cs                        |   4 +-
 src/gui/preferences.cs                   |  91 ++++++++++++++++----
 src/gui/webcam.cs                        |   8 +-
 src/preferences.cs                       |   1 +
 src/sqlite/main.cs                       |  11 ++-
 src/sqlite/preferences.cs                |   3 +
 src/webcam/webcam.cs                     |  18 ++--
 src/webcam/webcamFfmpeg.cs               |   9 +-
 src/webcam/webcamFfmpegSupportedModes.cs | 137 ++++++++++++++++++++++++++++---
 11 files changed, 316 insertions(+), 76 deletions(-)
---
diff --git a/glade/preferences_win.glade b/glade/preferences_win.glade
index 1b264fc5..6fb3103d 100644
--- a/glade/preferences_win.glade
+++ b/glade/preferences_win.glade
@@ -3551,6 +3551,26 @@ Other</property>
                                 <property name="position">1</property>
                               </packing>
                             </child>
+                            <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">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">2</property>
+                              </packing>
+                            </child>
                           </widget>
                           <packing>
                             <property name="expand">False</property>
@@ -3559,7 +3579,7 @@ Other</property>
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="label_no_cameras">
+                          <widget class="GtkLabel" id="label_camera_error">
                             <property name="can_focus">False</property>
                           </widget>
                           <packing>
@@ -3577,7 +3597,7 @@ Other</property>
                               <widget class="GtkTable" id="table5">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="n_rows">2</property>
+                                <property name="n_rows">3</property>
                                 <property name="n_columns">3</property>
                                 <property name="column_spacing">12</property>
                                 <property name="row_spacing">10</property>
@@ -3585,22 +3605,26 @@ Other</property>
                                   <widget class="GtkLabel" id="label76">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
+                                    <property name="xalign">0</property>
                                     <property name="label" translatable="yes">Resolution</property>
                                   </widget>
                                   <packing>
-                                    <property name="x_options"/>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
+                                    <property name="x_options">GTK_FILL</property>
                                   </packing>
                                 </child>
                                 <child>
                                   <widget class="GtkLabel" id="label78">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
+                                    <property name="xalign">0</property>
                                     <property name="label" translatable="yes">Framerate</property>
                                   </widget>
                                   <packing>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
-                                    <property name="x_options"/>
+                                    <property name="top_attach">2</property>
+                                    <property name="bottom_attach">3</property>
+                                    <property name="x_options">GTK_FILL</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -3614,7 +3638,9 @@ Other</property>
                                   <packing>
                                     <property name="left_attach">1</property>
                                     <property name="right_attach">2</property>
-                                    <property name="x_options"/>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
+                                    <property name="x_options">GTK_FILL</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -3628,9 +3654,9 @@ Other</property>
                                   <packing>
                                     <property name="left_attach">1</property>
                                     <property name="right_attach">2</property>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
-                                    <property name="x_options"/>
+                                    <property name="top_attach">2</property>
+                                    <property name="bottom_attach">3</property>
+                                    <property name="x_options">GTK_FILL</property>
                                   </packing>
                                 </child>
                                 <child>
@@ -3700,6 +3726,8 @@ Other</property>
                                   <packing>
                                     <property name="left_attach">2</property>
                                     <property name="right_attach">3</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
                                     <property name="x_options"/>
                                   </packing>
                                 </child>
@@ -3766,8 +3794,34 @@ Other</property>
                                   <packing>
                                     <property name="left_attach">2</property>
                                     <property name="right_attach">3</property>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
+                                    <property name="top_attach">2</property>
+                                    <property name="bottom_attach">3</property>
+                                    <property name="x_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <widget class="GtkLabel" id="label_camera_pixel_format">
+                                    <property name="can_focus">False</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label">Pixel format</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="x_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <widget class="GtkHBox" id="hbox_combo_camera_pixel_format">
+                                    <property name="can_focus">False</property>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                  </widget>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
                                     <property name="x_options">GTK_FILL</property>
                                   </packing>
                                 </child>
@@ -3783,26 +3837,6 @@ Other</property>
                                 <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>
@@ -3811,10 +3845,10 @@ Other</property>
                                     <property name="tooltip" translatable="yes">Preview video</property>
                                     <signal name="clicked" handler="on_button_video_preview_clicked" 
swapped="no"/>
                                     <child>
-                                      <widget class="GtkHBox" id="hbox321">
+                                      <widget class="GtkVBox" id="vbox37">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
-                                        <property name="spacing">4</property>
+                                        <property name="spacing">8</property>
                                         <child>
                                           <widget class="GtkImage" id="image_video_preview">
                                             <property name="visible">True</property>
@@ -3822,8 +3856,8 @@ Other</property>
                                             <property name="stock">gtk-missing-image</property>
                                           </widget>
                                           <packing>
-                                            <property name="expand">False</property>
-                                            <property name="fill">False</property>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</property>
                                             <property name="position">0</property>
                                           </packing>
                                         </child>
@@ -3845,7 +3879,7 @@ Other</property>
                                   <packing>
                                     <property name="expand">True</property>
                                     <property name="fill">False</property>
-                                    <property name="position">1</property>
+                                    <property name="position">0</property>
                                   </packing>
                                 </child>
                               </widget>
diff --git a/src/gui/event.cs b/src/gui/event.cs
index 39eae924..1ca48159 100644
--- a/src/gui/event.cs
+++ b/src/gui/event.cs
@@ -323,7 +323,7 @@ public class EditEventWindow
                         */
 
                        //using ffmpeg
-                       Webcam webcam = new WebcamFfmpeg (Webcam.Action.PLAYFILE, UtilAll.GetOSEnum(), "", 
"", "");
+                       Webcam webcam = new WebcamFfmpeg (Webcam.Action.PLAYFILE, UtilAll.GetOSEnum(), "", 
"", "", "");
                        Webcam.Result result = webcam.PlayFile (videoFileName);
                }
        }
diff --git a/src/gui/person.cs b/src/gui/person.cs
index b8b75d68..d0b190c2 100644
--- a/src/gui/person.cs
+++ b/src/gui/person.cs
@@ -1075,7 +1075,7 @@ public class PersonAddModifyWindow
                //webcam = new WebcamMplayer (videoDevice);
                //Webcam.Result result = webcam.CapturePrepare (Webcam.CaptureTypes.PHOTO);
                //constructor for playpreview
-               webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), videoDevice, "", 
"");
+               webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), videoDevice, "", 
"", "");
                //Webcam.Result result = webcam.PlayPreviewNoBackground ();
                Webcam.Result result = webcam.PlayPreview ();
 
@@ -1089,7 +1089,7 @@ public class PersonAddModifyWindow
        void on_button_take_photo_do_clicked (object o, EventArgs args)
        {
                if(webcam == null)
-                       webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), 
videoDevice, "", "");
+                       webcam = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), 
videoDevice, "", "", "");
                else if(webcam != null && webcam.Running)
                {
                        webcam.ExitCamera();
diff --git a/src/gui/preferences.cs b/src/gui/preferences.cs
index 32e32e89..f1dd7fd3 100644
--- a/src/gui/preferences.cs
+++ b/src/gui/preferences.cs
@@ -156,11 +156,14 @@ public class PreferencesWindow
        [Widget] Gtk.HBox hbox_camera_framerate_custom;
        [Widget] Gtk.SpinButton spin_camera_framerate_custom;
        [Widget] Gtk.Entry entry_camera_framerate_custom_decimals;
+       [Widget] Gtk.Label label_camera_pixel_format;
+       [Widget] Gtk.HBox hbox_combo_camera_pixel_format;
+       [Widget] Gtk.ComboBox combo_camera_pixel_format;
        [Widget] Gtk.Box hbox_combo_camera_resolution;
        [Widget] Gtk.ComboBox combo_camera_resolution;
        [Widget] Gtk.Box hbox_combo_camera_framerate;
        [Widget] Gtk.ComboBox combo_camera_framerate;
-       [Widget] Gtk.Label label_no_cameras;
+       [Widget] Gtk.Label label_camera_error;
        [Widget] Gtk.Label label_webcam_windows;
        [Widget] Gtk.Image image_multimedia_audio;
        [Widget] Gtk.Image image_multimedia_video;
@@ -223,6 +226,8 @@ public class PreferencesWindow
        const int ENCODEROTHERPAGE = 5;
 
        static private WebcamDeviceList wd_list;
+       private WebcamFfmpegSupportedModes wfsm;
+
 
        PreferencesWindow () {
                Glade.XML gladeXML;
@@ -311,7 +316,7 @@ public class PreferencesWindow
                if(compujump)
                        PreferencesWindowBox.notebook_multimedia.GetNthPage(1).Hide();
 
-               PreferencesWindowBox.label_no_cameras.Visible = false;
+               PreferencesWindowBox.label_camera_error.Visible = false;
 
                if(UtilAll.IsWindows())
                        PreferencesWindowBox.label_webcam_windows.Visible = true;
@@ -334,7 +339,8 @@ public class PreferencesWindow
                PreferencesWindowBox.label_test_sound_result.Text = "";
 
                wd_list = UtilMultimedia.GetVideoDevices();
-               PreferencesWindowBox.createComboCamera(preferences.videoDevice, 
preferences.videoDeviceResolution, preferences.videoDeviceFramerate);
+               PreferencesWindowBox.createComboCamera(preferences.videoDevice,
+                               preferences.videoDevicePixelFormat, preferences.videoDeviceResolution, 
preferences.videoDeviceFramerate);
 
                pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "audio.png");
                PreferencesWindowBox.image_multimedia_audio.Pixbuf = pixbuf;
@@ -647,9 +653,9 @@ public class PreferencesWindow
         * end of triggers stuff
         */
 
-       private void createComboCamera(string current, string resolution, string framerate)
+       private void createComboCamera(string current, string pixelFormat, string resolution, string 
framerate)
        {
-               //1) videoDevice
+               // 1) videoDevice
 
                combo_camera = ComboBox.NewText ();
 
@@ -657,13 +663,14 @@ public class PreferencesWindow
                 * declare both because there is a return just here and if they are undeclred the method:
                 * on_button_accept_clicked () will fail
                 */
+               combo_camera_pixel_format = ComboBox.NewText ();
                combo_camera_resolution = ComboBox.NewText ();
                combo_camera_framerate = ComboBox.NewText ();
 
                if(wd_list.Count() == 0) {
                        //devices = Util.StringToStringArray(Constants.CameraNotFound);
-                       label_no_cameras.Text = wd_list.Error;
-                       label_no_cameras.Visible = true;
+                       label_camera_error.Text = wd_list.Error;
+                       label_camera_error.Visible = true;
                        current = "";
 
                        hbox_camera_resolution_framerate.Visible = false;
@@ -681,7 +688,13 @@ public class PreferencesWindow
                
                combo_camera.Active = UtilGtk.ComboMakeActive(combo_camera, current);
 
-               //2) resolution
+               // 2) pixel_format
+
+               hbox_combo_camera_pixel_format.PackStart(combo_camera_pixel_format, true, true, 0);
+               //hbox_combo_camera_pixel_format.ShowAll();
+               combo_camera_pixel_format.Changed += new EventHandler (on_combo_camera_pixel_format_changed);
+
+               // 3) resolution
 
                combo_camera_resolution = ComboBox.NewText ();
                List<string> resolutions = new List<string>();
@@ -715,7 +728,7 @@ public class PreferencesWindow
                hbox_combo_camera_resolution.ShowAll();
                combo_camera_resolution.Changed += new EventHandler (on_combo_camera_resolution_changed);
 
-               //3) framerate
+               // 4) framerate
 
                combo_camera_framerate = ComboBox.NewText ();
                List<string> framerates = new List<string>();
@@ -761,9 +774,27 @@ public class PreferencesWindow
                hbox_camera_stop_after_seconds.Visible = check_camera_stop_after.Active;
        }
 
+       private void on_combo_camera_pixel_format_changed (object o, EventArgs args)
+       {
+               string pixelFormat = UtilGtk.ComboGetActive(combo_camera_pixel_format);
+
+               if(pixelFormat != "" && wfsm != null)
+               {
+                       UtilGtk.ComboUpdate(combo_camera_resolution, 
wfsm.PopulateListByPixelFormat(pixelFormat));
+                       combo_camera_resolution.Active = 0;
+               }
+       }
        private void on_combo_camera_resolution_changed (object o, EventArgs args)
        {
-               hbox_camera_resolution_custom.Visible = UtilGtk.ComboGetActive(combo_camera_resolution) == 
Catalog.GetString("Custom");
+               string pixelFormat = UtilGtk.ComboGetActive(combo_camera_pixel_format);
+               string resolution = UtilGtk.ComboGetActive(combo_camera_resolution);
+               hbox_camera_resolution_custom.Visible = resolution == Catalog.GetString("Custom");
+
+               if(resolution != "" && resolution != Catalog.GetString("Custom") && wfsm != null)
+               {
+                       UtilGtk.ComboUpdate(combo_camera_framerate, wfsm.GetFramerates (pixelFormat, 
resolution));
+                       combo_camera_framerate.Active = 0;
+               }
        }
        private void on_combo_camera_framerate_changed (object o, EventArgs args)
        {
@@ -822,8 +853,6 @@ public class PreferencesWindow
                if(cameraCode == "")
                        return;
 
-               WebcamFfmpegSupportedModes wfsm;
-
                if(operatingSystem == UtilAll.OperatingSystems.LINUX)
                        wfsm = new WebcamFfmpegSupportedModesLinux();
                else if(operatingSystem == UtilAll.OperatingSystems.WINDOWS)
@@ -835,15 +864,38 @@ public class PreferencesWindow
 
                if(wfsm.ErrorStr != "")
                {
+                       /*
                        new DialogMessage("Chronojump - Modes of this webcam",
                                        Constants.MessageTypes.WARNING, wfsm.ErrorStr);
+                       */
+                       label_camera_error.Text = wfsm.ErrorStr;
+                       label_camera_error.Visible = true;
+
                        return;
                }
 
+               /*
                //display the result (if any)
                if(wfsm.ModesStr != "")
                        new DialogMessage("Chronojump - Modes of this webcam",
                                        Constants.MessageTypes.INFO, wfsm.ModesStr, true); 
//showScrolledWinBar
+               */
+
+               bool fillCombos = true;
+               if(fillCombos)
+               {
+                       UtilGtk.ComboUpdate(combo_camera_resolution, wfsm.PopulateFirstList());
+                       combo_camera_resolution.Active = 0;
+
+                       //TODO: framerates
+
+                       UtilGtk.ComboUpdate(combo_camera_pixel_format, wfsm.GetPixelFormats());
+                       combo_camera_pixel_format.Active = 0;
+                       hbox_combo_camera_pixel_format.ShowAll();
+
+                       label_camera_pixel_format.Visible = true;
+                       hbox_combo_camera_pixel_format.Visible = true;
+               }
        }
 
        private void on_button_video_preview_clicked (object o, EventArgs args)
@@ -852,11 +904,16 @@ public class PreferencesWindow
                if(cameraCode == "")
                        return;
 
-               Webcam webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(),
-                               cameraCode, getSelectedResolution(), getSelectedFramerate());
+               Webcam webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), 
cameraCode,
+                               getSelectedPixelFormat(), getSelectedResolution(), getSelectedFramerate());
                Webcam.Result result = webcamPlay.PlayPreviewNoBackground ();
        }
 
+       private string getSelectedPixelFormat()
+       {
+               string selected = UtilGtk.ComboGetActive(combo_camera_pixel_format);
+               return selected;
+       }
        private string getSelectedResolution()
        {
                string selected = UtilGtk.ComboGetActive(combo_camera_resolution);
@@ -1765,6 +1822,12 @@ public class PreferencesWindow
                        preferences.videoDevice = cameraCode;
                }
 
+               string pixelFormat = getSelectedPixelFormat();
+               if( preferences.videoDevicePixelFormat != pixelFormat ) {
+                       SqlitePreferences.Update("videoDevicePixelFormat", pixelFormat, true);
+                       preferences.videoDevicePixelFormat = pixelFormat;
+               }
+
                string resolution = getSelectedResolution();
                if( preferences.videoDeviceResolution != resolution ) {
                        SqlitePreferences.Update("videoDeviceResolution", resolution, true);
diff --git a/src/gui/webcam.cs b/src/gui/webcam.cs
index 8f6f8708..807c7125 100644
--- a/src/gui/webcam.cs
+++ b/src/gui/webcam.cs
@@ -119,7 +119,8 @@ public partial class ChronoJumpWindow
                string errorMessage = "";
                if(ncams == 1)
                {
-                       if(! webcamManage.RecordPrepare(preferences.videoDevice, 
preferences.videoDeviceResolution, preferences.videoDeviceFramerate).success)
+                       if(! webcamManage.RecordPrepare(preferences.videoDevice, 
preferences.videoDevicePixelFormat,
+                                               preferences.videoDeviceResolution, 
preferences.videoDeviceFramerate).success)
                                return false;
 
                        if(! webcamManage.RecordStart(1))
@@ -655,7 +656,8 @@ public partial class ChronoJumpWindow
        private void playPreview ()
        {
                //constructor for playpreview
-               webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), 
preferences.videoDevice, preferences.videoDeviceResolution, preferences.videoDeviceFramerate);
+               webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYPREVIEW, UtilAll.GetOSEnum(), 
preferences.videoDevice,
+                               preferences.videoDevicePixelFormat, preferences.videoDeviceResolution, 
preferences.videoDeviceFramerate);
                Webcam.Result result = webcamPlay.PlayPreviewNoBackground ();
        }
 
@@ -674,7 +676,7 @@ public partial class ChronoJumpWindow
        private void playVideo (string fileName)
        {
                //constructor for playpreview
-               webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYFILE, UtilAll.GetOSEnum(), "", "", "");
+               webcamPlay = new WebcamFfmpeg (Webcam.Action.PLAYFILE, UtilAll.GetOSEnum(), "", "", "", "");
                Webcam.Result result = webcamPlay.PlayFile (fileName);
 
                /*
diff --git a/src/preferences.cs b/src/preferences.cs
index 52a1fbb2..fdeee4b3 100644
--- a/src/preferences.cs
+++ b/src/preferences.cs
@@ -76,6 +76,7 @@ public class Preferences
        public Constants.Encoder1RMMethod encoder1RMMethod;
        
        public string videoDevice;
+       public string videoDevicePixelFormat;
        public string videoDeviceResolution;
        public string videoDeviceFramerate; //cannot be a double because decimals seem exactly important on 
mac. if decimal will have always a '.' as needed by ffmpeg
        public int videoStopAfter;
diff --git a/src/sqlite/main.cs b/src/sqlite/main.cs
index bd660a02..27aec3d3 100644
--- a/src/sqlite/main.cs
+++ b/src/sqlite/main.cs
@@ -125,7 +125,7 @@ class Sqlite
        /*
         * Important, change this if there's any update to database
         */
-       static string lastChronojumpDatabaseVersion = "1.63";
+       static string lastChronojumpDatabaseVersion = "1.64";
 
        public Sqlite() {
        }
@@ -2395,6 +2395,14 @@ class Sqlite
 
                                currentVersion = updateVersion("1.63");
                        }
+                       if(currentVersion == "1.63")
+                       {
+                               LogB.SQL("Added to preferences: videoDevicePixelFormat");
+
+                               SqlitePreferences.Insert ("videoDevicePixelFormat", "");
+
+                               currentVersion = updateVersion("1.64");
+                       }
 
 
 
@@ -2584,6 +2592,7 @@ class Sqlite
                SqliteJson.createTableUploadExhibitionTestTemp ();
 
                //changes [from - to - desc]
+               //1.63 - 1.64 Converted DB to 1.64 Added to preferences: videoDevicePixelFormat
                //1.62 - 1.63 Converted DB to 1.63 Added to preferences: encoderCaptureInertialDiscardFirstN
                //1.61 - 1.62 Converted DB to 1.62 Added to preferences: videoStopAfter
                //1.60 - 1.61 Converted DB to 1.61 Added to preferences: videoDeviceResolution, 
videoDeviceFramerate
diff --git a/src/sqlite/preferences.cs b/src/sqlite/preferences.cs
index e1275b80..ac029d3b 100644
--- a/src/sqlite/preferences.cs
+++ b/src/sqlite/preferences.cs
@@ -172,6 +172,7 @@ class SqlitePreferences : Sqlite
 
 
                                Insert ("videoDevice", "", dbcmdTr); //first
+                               Insert ("videoDevicePixelFormat", "", dbcmdTr);
                                Insert ("videoDeviceResolution", "", dbcmdTr);
                                Insert ("videoDeviceFramerate", "", dbcmdTr);
                                Insert ("videoStopAfter", "2", dbcmdTr);
@@ -375,6 +376,8 @@ class SqlitePreferences : Sqlite
                        //video... other
                        else if(reader[0].ToString() == "videoDevice")
                                preferences.videoDevice = reader[1].ToString();
+                       else if(reader[0].ToString() == "videoDevicePixelFormat")
+                               preferences.videoDevicePixelFormat = reader[1].ToString();
                        else if(reader[0].ToString() == "videoDeviceResolution")
                                preferences.videoDeviceResolution = reader[1].ToString();
                        else if(reader[0].ToString() == "videoDeviceFramerate")
diff --git a/src/webcam/webcam.cs b/src/webcam/webcam.cs
index ba95a9f5..f395c855 100644
--- a/src/webcam/webcam.cs
+++ b/src/webcam/webcam.cs
@@ -113,6 +113,7 @@ public abstract class Webcam
 
        protected Process process;
        protected string videoDevice;
+       protected string videoDevicePixelFormat;
        protected string videoDeviceResolution;
        protected string videoDeviceFramerate;
        protected StreamWriter streamWriter;
@@ -193,15 +194,16 @@ public class WebcamManage
        }
 
        // 1 camera
-       public Webcam.Result RecordPrepare (string videoDevice, string videoDeviceResolution, string 
videoDeviceFramerate)
+       public Webcam.Result RecordPrepare (string videoDevice,
+                       string videoDevicePixelFormat, string videoDeviceResolution, string 
videoDeviceFramerate)
        {
-               return recordPrepareDo (ref webcam, videoDevice, videoDeviceResolution, videoDeviceFramerate);
+               return recordPrepareDo (ref webcam, videoDevice, videoDevicePixelFormat, 
videoDeviceResolution, videoDeviceFramerate);
        }
        // 2 cameras
-       public Webcam.Result RecordPrepare (string videoDevice, string videoDevice2, string 
videoDeviceResolution, string videoDeviceFramerate)
+       public Webcam.Result RecordPrepare (string videoDevicePixelFormat, string videoDevice, string 
videoDevice2, string videoDeviceResolution, string videoDeviceFramerate)
        {
-               Webcam.Result result1 = recordPrepareDo (ref webcam, videoDevice, videoDeviceResolution, 
videoDeviceFramerate);
-               Webcam.Result result2 = recordPrepareDo (ref webcam2, videoDevice2, videoDeviceResolution, 
videoDeviceFramerate);
+               Webcam.Result result1 = recordPrepareDo (ref webcam, videoDevice, videoDevicePixelFormat, 
videoDeviceResolution, videoDeviceFramerate);
+               Webcam.Result result2 = recordPrepareDo (ref webcam2, videoDevice2, videoDevicePixelFormat, 
videoDeviceResolution, videoDeviceFramerate);
 
                return new Webcam.Result (
                        result1.success && result2.success,
@@ -209,7 +211,8 @@ public class WebcamManage
                        result1.error + result2.error
                        );
        }
-       private Webcam.Result recordPrepareDo (ref Webcam w, string videoDevice, string 
videoDeviceResolution, string videoDeviceFramerate)
+       private Webcam.Result recordPrepareDo (ref Webcam w, string videoDevice,
+                       string videoDevicePixelFormat, string videoDeviceResolution, string 
videoDeviceFramerate)
        {
                if(videoDevice == "")
                {
@@ -221,7 +224,8 @@ public class WebcamManage
                LogB.Information("wRS at gui chronojump.cs 0, videoDevice: " + videoDevice);
 
                //w = new WebcamMplayer (videoDevice);
-               w = new WebcamFfmpeg (Webcam.Action.CAPTURE, os, videoDevice, videoDeviceResolution, 
videoDeviceFramerate);
+               w = new WebcamFfmpeg (Webcam.Action.CAPTURE, os, videoDevice,
+                               videoDevicePixelFormat, videoDeviceResolution, videoDeviceFramerate);
                Webcam.Result result = w.CapturePrepare (Webcam.CaptureTypes.VIDEO);
 
                LogB.Information("wRS at gui chronojump.cs 1, videoDevice: " + videoDevice);
diff --git a/src/webcam/webcamFfmpeg.cs b/src/webcam/webcamFfmpeg.cs
index 8abc4367..917240b8 100644
--- a/src/webcam/webcamFfmpeg.cs
+++ b/src/webcam/webcamFfmpeg.cs
@@ -33,11 +33,13 @@ public class WebcamFfmpeg : Webcam
 
        // constructor ----------------------------------
 
-       public WebcamFfmpeg (Webcam.Action action, UtilAll.OperatingSystems os, string videoDevice, string 
videoDeviceResolution, string videoDeviceFramerate)
+       public WebcamFfmpeg (Webcam.Action action, UtilAll.OperatingSystems os, string videoDevice,
+                       string videoDevicePixelFormat, string videoDeviceResolution, string 
videoDeviceFramerate)
        {
                this.action = action;
                this.os = os;
                this.videoDevice = videoDevice;
+               this.videoDevicePixelFormat = videoDevicePixelFormat;
                this.videoDeviceResolution = videoDeviceResolution;
                this.videoDeviceFramerate = videoDeviceFramerate;
 
@@ -230,6 +232,11 @@ public class WebcamFfmpeg : Webcam
                else
                        parameters.Insert (i ++, "640x480");
 
+               if(videoDevicePixelFormat != "" && os == UtilAll.OperatingSystems.LINUX) {
+                       parameters.Insert (i ++, "-input_format");
+                       parameters.Insert (i ++, videoDevicePixelFormat);
+               }
+
                if(os == UtilAll.OperatingSystems.LINUX)
                        parameters.Insert (i ++, videoDevice);
                else if (os == UtilAll.OperatingSystems.WINDOWS)
diff --git a/src/webcam/webcamFfmpegSupportedModes.cs b/src/webcam/webcamFfmpegSupportedModes.cs
index f599dffb..95d7d888 100644
--- a/src/webcam/webcamFfmpegSupportedModes.cs
+++ b/src/webcam/webcamFfmpegSupportedModes.cs
@@ -40,6 +40,62 @@ public abstract class WebcamFfmpegSupportedModes
                errorStr = "";
        }
 
+       // start of: used to populated list on combos .....
+
+       public List<string> GetPixelFormats()
+       {
+               if(wsmListOfLists == null || wsmListOfLists.Count == 0)
+                       return new List<string>();
+
+               List<string> pixelFormats = new List<string>();
+               foreach(WebcamSupportedModesList wsmList in wsmListOfLists)
+                       pixelFormats.Add(wsmList.PixelFormat);
+
+               return pixelFormats;
+       }
+
+       public List<string> PopulateFirstList() //TODO: remove this
+       {
+               if(wsmListOfLists == null || wsmListOfLists.Count == 0)
+                       return new List<string>();
+
+               //TODO: be able to choose the pixel format, not just use the first one
+               //return wsmList[0].ToStringList();
+               return wsmListOfLists[0].ResolutionsToStringList();
+       }
+
+       public List<string> PopulateListByPixelFormat(string pixelFormat)
+       {
+               if(pixelFormat == "")
+                       return new List<string>();
+
+               return getListByPixelFormat(pixelFormat).ResolutionsToStringList();
+       }
+
+       public List<string> GetFramerates (string pixelFormat, string resolution)
+       {
+               if(pixelFormat == "")
+                       return new List<string>();
+
+               WebcamSupportedModesList wsmList = getListByPixelFormat(pixelFormat);
+               WebcamSupportedMode wsm = wsmList.GetMode(resolution);
+               return wsm.FrameratesToStringList();
+       }
+
+       private WebcamSupportedModesList getListByPixelFormat(string pixelFormat)
+       {
+               if(pixelFormat == "" || wsmListOfLists == null || wsmListOfLists.Count == 0)
+                       return new WebcamSupportedModesList();
+
+               foreach(WebcamSupportedModesList wsmList in wsmListOfLists)
+                       if(wsmList.PixelFormat == pixelFormat)
+                               return wsmList;
+
+               return new WebcamSupportedModesList();
+       }
+
+       // ... end of: used to populated list on combos
+
        protected abstract string parseSupportedModes(string allOutput);
 
        protected string printListOfLists()
@@ -111,7 +167,9 @@ public class WebcamFfmpegSupportedModesLinux : WebcamFfmpegSupportedModes
                        LogB.Information("line: " + l);
                        if(l.Contains("Pixel Format:"))
                        {
-                               wsmList = new WebcamSupportedModesList(l);
+                               wsmList = new WebcamSupportedModesList(parsePixelFormat(l));
+
+
                                wsmListOfLists.Add(wsmList);
 
                                continue;
@@ -161,6 +219,34 @@ public class WebcamFfmpegSupportedModesLinux : WebcamFfmpegSupportedModes
 
                return "";
        }
+
+       private string parsePixelFormat(string l)
+       {
+               /*
+                  Pixel Format: 'YUYV'
+                  Name        : YUYV 4:2:2
+                  has to be: yuyv422
+
+                  Pixel Format: 'MJPG' (compressed)
+                  Name        : Motion-JPEG
+                  has to be: mjpeg
+
+                  so we need to parse "Name" line or right now return yuyv422 or mjpeg
+                  */
+
+               Match match = Regex.Match(l, @"Pixel Format: '(\S+)'");
+               if(match.Groups.Count == 2)
+               {
+                       if(match.Groups[1].Value == "YUYV")
+                               return "yuyv422";
+                       else if(match.Groups[1].Value == "MJPG")
+                               return "mjpeg";
+                       else
+                               return string.Format("{0}", match.Groups[1].Value);
+               }
+
+               return "";
+       }
 }
 
 public class WebcamFfmpegSupportedModesWindows : WebcamFfmpegSupportedModes
@@ -305,7 +391,7 @@ public class WebcamFfmpegSupportedModesMac : WebcamFfmpegSupportedModes
 
                //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");
+                               cameraCode, "", "8000x8000", "8000");
 
                Webcam.Result result = webcamPlay.PlayPreviewNoBackgroundWantStdoutAndStderr();
                modesStr = parseSupportedModes(result.output);
@@ -324,7 +410,7 @@ public class WebcamFfmpegSupportedModesMac : WebcamFfmpegSupportedModes
 
                bool started = false;
                //on mac seems there is only one pixel format
-               wsmList = new WebcamSupportedModesList("");
+               wsmList = new WebcamSupportedModesList("avfoundation");
                wsmListOfLists.Add(wsmList);
                foreach(string l in lines)
                {
@@ -469,21 +555,37 @@ public class WebcamSupportedModesList
                return (l.Count > 0);
        }
 
-       public void Sort()
+       public override string ToString()
+       {
+               sort();
+               string str = "";
+               foreach(WebcamSupportedMode wsm in l)
+                       str += wsm.ToString() + "\n";
+
+               return str;
+       }
+
+       private void sort()
        {
                WebcamSupportedModeSort wsms = new WebcamSupportedModeSort();
                l.Sort(wsms);
        }
 
-       public override string ToString()
+       // start of: used to populated list on combos .....
+
+       public List<string> ResolutionsToStringList()
        {
-               string str = "";
+               sort();
+               List<string> lRes = new List<string> ();
                foreach(WebcamSupportedMode wsm in l)
-                       str += wsm.ToString() + "\n";
+                       lRes.Add(wsm.ResolutionString);
 
-               return str;
+               return lRes;
        }
 
+       // ... end of: used to populated list on combos
+
+
        public string PixelFormat
        {
                get { return pixelFormat; }
@@ -548,8 +650,7 @@ public class WebcamSupportedMode
                */
 
                //"\nSorting:";
-               WebcamSupportedModeSortFramerates wsmsf = new WebcamSupportedModeSortFramerates();
-               framerates.Sort(wsmsf);
+               sort();
                string sepChar = "";
                foreach (string framerate in framerates)
                {
@@ -560,6 +661,18 @@ public class WebcamSupportedMode
                return str;
        }
 
+       public List<string> FrameratesToStringList()
+       {
+               sort();
+               return framerates;
+       }
+
+       private void sort()
+       {
+               WebcamSupportedModeSortFramerates wsmsf = new WebcamSupportedModeSortFramerates();
+               framerates.Sort(wsmsf);
+       }
+
        public int CompareTo( WebcamSupportedMode that )
        {
                if ( that == null ) return 1;
@@ -576,6 +689,10 @@ public class WebcamSupportedMode
        {
                get { return resolutionHeight; }
        }
+       public string ResolutionString
+       {
+               get { return string.Format("{0}x{1}", resolutionWidth, resolutionHeight); }
+       }
 
        public int Size
        {



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