display: fix display aspect ratio when display is rotated.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Thu, 6 Sep 2012 09:51:41 +0000 (11:51 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Thu, 6 Sep 2012 11:39:50 +0000 (13:39 +0200)
gst-libs/gst/vaapi/gstvaapidisplay.c

index a52339d..8876643 100644 (file)
@@ -382,7 +382,7 @@ gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
 {
     GstVaapiDisplayPrivate * const priv = display->priv;
     gdouble ratio, delta;
-    gint i, index;
+    gint i, j, index, windex;
 
     static const gint par[][2] = {
         {1, 1},         /* regular screen            */
@@ -405,21 +405,25 @@ gst_vaapi_display_calculate_pixel_aspect_ratio(GstVaapiDisplay *display)
     GST_DEBUG("calculated pixel aspect ratio: %f", ratio);
 
     /* Now, find the one from par[][2] with the lowest delta to the real one */
-#define DELTA(idx) (ABS(ratio - ((gdouble)par[idx][0] / par[idx][1])))
-    delta = DELTA(0);
-    index = 0;
+#define DELTA(idx, w) (ABS(ratio - ((gdouble)par[idx][w] / par[idx][!(w)])))
+    delta  = DELTA(0, 0);
+    index  = 0;
+    windex = 0;
 
     for (i = 1; i < G_N_ELEMENTS(par); i++) {
-        const gdouble this_delta = DELTA(i);
-        if (this_delta < delta) {
-            index = i;
-            delta = this_delta;
+        for (j = 0; j < 2; j++) {
+            const gdouble this_delta = DELTA(i, j);
+            if (this_delta < delta) {
+                index  = i;
+                windex = j;
+                delta  = this_delta;
+            }
         }
     }
 #undef DELTA
 
-    priv->par_n = par[index][0];
-    priv->par_d = par[index][1];
+    priv->par_n = par[index][windex];
+    priv->par_d = par[index][windex ^ 1];
 }
 
 static void