[Libva] [PATCH] vaapisink: Allow scaling to ignore aspect ratio

Simon Farnsworth simon.farnsworth at onelan.co.uk
Fri Aug 16 08:58:58 PDT 2013


Other GStreamer sinks, like xvimagesink, have a force-aspect-ratio property,
which allows you to say that you don't want the sink to respect aspect
ratio. Add the same property to vaapisink.

Signed-off-by: Simon Farnsworth <simon.farnsworth at onelan.co.uk>
---

We use this for material (mostly MPEG-2, but we're seeing some H.264 like
this, too) where the display aspect ratio in the media does not match the
content.

There's no way for software to detect this, so we simply make it possible
for a human to intervene.

 gst/vaapi/gstvaapisink.c | 36 ++++++++++++++++++++++++++++++++++++
 gst/vaapi/gstvaapisink.h | 1 + 2 files changed, 37 insertions(+)

diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c
index b0061cb..f9bee76 100644
--- a/gst/vaapi/gstvaapisink.c
+++ b/gst/vaapi/gstvaapisink.c
@@ -158,6 +158,7 @@ enum {
     PROP_USE_GLX,
     PROP_USE_REFLECTION,
     PROP_ROTATION,
+    PROP_FORCE_ASPECT_RATIO,
 };
 
 #define DEFAULT_DISPLAY_TYPE            GST_VAAPI_DISPLAY_TYPE_ANY
@@ -381,6 +382,19 @@ gst_vaapisink_ensure_render_rect(GstVaapiSink *sink, guint width, guint height)
     if (!sink->caps)
         return TRUE;
 
+    if (!sink->keep_aspect) {
+        display_rect->width = width;
+        display_rect->height = height;
+        display_rect->x = 0;
+        display_rect->y = 0;
+
+        GST_DEBUG("force-aspect-ratio is false; distorting while scaling video");
+        GST_DEBUG("render rect (%d,%d):%ux%u",
+                  display_rect->x, display_rect->y,
+                  display_rect->width, display_rect->height);
+        return TRUE;
+    }
+
     GST_DEBUG("ensure render rect within %ux%u bounds", width, height);
 
     gst_vaapi_display_get_pixel_aspect_ratio(
@@ -1251,6 +1265,9 @@ gst_vaapisink_set_property(
     case PROP_ROTATION:
         sink->rotation_req = g_value_get_enum(value);
         break;
+    case PROP_FORCE_ASPECT_RATIO:
+        sink->keep_aspect = g_value_get_boolean(value);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -1286,6 +1303,9 @@ gst_vaapisink_get_property(
     case PROP_ROTATION:
         g_value_set_enum(value, sink->rotation);
         break;
+    case PROP_FORCE_ASPECT_RATIO:
+        g_value_set_boolean(value, sink->keep_aspect);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -1397,6 +1417,21 @@ gst_vaapisink_class_init(GstVaapiSinkClass *klass)
                            GST_VAAPI_TYPE_ROTATION,
                            DEFAULT_ROTATION,
                            G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+    /**
+     * GstVaapiSink:force-aspect-ratio:
+     *
+     * When enabled, scaling respects video aspect ratio; when disabled, the
+     * video is distorted to fit the window.
+     */
+    g_object_class_install_property
+        (object_class,
+         PROP_FORCE_ASPECT_RATIO,
+         g_param_spec_boolean("force-aspect-ratio",
+                              "Force aspect ratio",
+                              "When enabled, scaling will respect original aspect ratio",
+                              TRUE,
+                              G_PARAM_READWRITE));
 }
 
 static void
@@ -1422,4 +1457,5 @@ gst_vaapisink_init(GstVaapiSink *sink)
     sink->use_reflection = FALSE;
     sink->use_overlay    = FALSE;
     sink->use_rotation   = FALSE;
+    sink->keep_aspect    = TRUE;
 }
diff --git a/gst/vaapi/gstvaapisink.h b/gst/vaapi/gstvaapisink.h
index b73065e..c60258a 100644
--- a/gst/vaapi/gstvaapisink.h
+++ b/gst/vaapi/gstvaapisink.h
@@ -95,6 +95,7 @@ struct _GstVaapiSink {
     guint               use_reflection  : 1;
     guint               use_overlay     : 1;
     guint               use_rotation    : 1;
+    guint               keep_aspect     : 1;
     guint               use_video_raw   : 1;
 };
 
-- 
1.7.11.7



More information about the Libva mailing list