[vlc-commits] v4l2: get aspect ratio from V4L2 crop capabilities (rather than user)

Rémi Denis-Courmont git at videolan.org
Sat Apr 7 20:37:39 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Apr  7 21:35:11 2012 +0300| [bf9da75bf5d7626ccc2b04bf7d214ef6cabd1572] | committer: Rémi Denis-Courmont

v4l2: get aspect ratio from V4L2 crop capabilities (rather than user)

Previously, VLC would assume 4/3 picture aspect ratio. That was quite
lame. This patch makes --v4l2-aspect-ratio redundant.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bf9da75bf5d7626ccc2b04bf7d214ef6cabd1572
---

 modules/access/v4l2/demux.c |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/modules/access/v4l2/demux.c b/modules/access/v4l2/demux.c
index 7aad23e..45ff4fc 100644
--- a/modules/access/v4l2/demux.c
+++ b/modules/access/v4l2/demux.c
@@ -239,6 +239,20 @@ static vlc_fourcc_t var_InheritFourCC (vlc_object_t *obj, const char *varname)
 }
 #define var_InheritFourCC(o, v) var_InheritFourCC(VLC_OBJECT(o), v)
 
+static void GetAR (int fd, unsigned *restrict num, unsigned *restrict den)
+{
+    struct v4l2_cropcap cropcap = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE };
+
+    /* TODO: get CROPCAP only once (see ResetCrop()). */
+    if (v4l2_ioctl (fd, VIDIOC_CROPCAP, &cropcap) < 0)
+    {
+        *num = *den = 1;
+        return;
+    }
+    *num = cropcap.pixelaspect.numerator;
+    *den = cropcap.pixelaspect.denominator;
+}
+
 static int InitVideo (demux_t *demux, int fd)
 {
     demux_sys_t *sys = demux->p_sys;
@@ -412,23 +426,14 @@ static int InitVideo (demux_t *demux, int fd)
     es_fmt.video.i_height = fmt.fmt.pix.height;
     es_fmt.video.i_frame_rate = parm.parm.capture.timeperframe.denominator;
     es_fmt.video.i_frame_rate_base = parm.parm.capture.timeperframe.numerator;
+    GetAR (fd, &es_fmt.video.i_sar_num, &es_fmt.video.i_sar_den);
 
-    int ar = 4 * VOUT_ASPECT_FACTOR / 3;
-    char *str = var_InheritString (demux, CFG_PREFIX"aspect-ratio");
-    if (likely(str != NULL))
-    {
-        const char *delim = strchr (str, ':');
-        if (delim != NULL)
-            ar = atoi (str) * VOUT_ASPECT_FACTOR / atoi (delim + 1);
-        free (str);
-    }
-    es_fmt.video.i_sar_num = ar * es_fmt.video.i_height;
-    es_fmt.video.i_sar_den = VOUT_ASPECT_FACTOR * es_fmt.video.i_width;
-
-    msg_Dbg (demux, "added new video es %4.4s %dx%d", (char *)&es_fmt.i_codec,
+    msg_Dbg (demux, "added new video ES %4.4s %ux%u", (char *)&es_fmt.i_codec,
              es_fmt.video.i_width, es_fmt.video.i_height);
     msg_Dbg (demux, " frame rate: %u/%u", es_fmt.video.i_frame_rate,
              es_fmt.video.i_frame_rate_base);
+    msg_Dbg (demux, " aspect ratio: %u/%u", es_fmt.video.i_sar_num,
+             es_fmt.video.i_sar_den);
     sys->p_es = es_out_Add (demux->out, &es_fmt);
 
     /* Init I/O method */



More information about the vlc-commits mailing list