]> git.sesse.net Git - vlc/blobdiff - modules/access/v4l2.c
Fix parsing of float-typed variables
[vlc] / modules / access / v4l2.c
index f88d914df0e5385253cdefc25fa5358f5869fa69..864333b7042b374256a603404a5f9a97071ca613 100644 (file)
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_access.h>
+#include <vlc_charset.h>
 #include <vlc_demux.h>
 #include <vlc_input.h>
 
 #include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
@@ -789,8 +791,8 @@ static void ParseMRL( demux_sys_t *p_sys, char *psz_path, vlc_object_t *p_obj )
             }
             else if( !strncmp( psz_parser, "fps=", strlen( "fps=" ) ) )
             {
-                p_sys->f_fps = strtof( psz_parser + strlen( "fps=" ),
-                                       &psz_parser );
+                p_sys->f_fps = us_strtof( psz_parser + strlen( "fps=" ),
+                                          &psz_parser );
             }
             else if( !strncmp( psz_parser, "io=", strlen( "io=" ) ) )
             {
@@ -1999,12 +2001,22 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux )
                                                         fmt.fmt.pix.pixelformat );
                 msg_Dbg( p_demux, "Found maximum framerate of %f", p_sys->f_fps );
             }
+            uint32_t i_width, i_height;
             GetMaxDimensions( p_demux, i_fd,
                               fmt.fmt.pix.pixelformat, p_sys->f_fps,
-                              &fmt.fmt.pix.width, &fmt.fmt.pix.height );
-            msg_Dbg( p_demux, "Found optimal dimensions for framerate %f of %dx%d",
-                     p_sys->f_fps, fmt.fmt.pix.width, fmt.fmt.pix.height );
-            if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) {;}
+                              &i_width, &i_height );
+            if( i_width || i_height )
+            {
+                msg_Dbg( p_demux, "Found optimal dimensions for framerate %f of %dx%d",
+                         p_sys->f_fps, i_width, i_height );
+                fmt.fmt.pix.width = i_width;
+                fmt.fmt.pix.height = i_height;
+                if( v4l2_ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) {;}
+            }
+            else
+            {
+                msg_Warn( p_obj, "Could not find optimal width and height." );
+            }
         }
 
         /* Reassign width, height and chroma incase driver override */