glimagesink: resize the viewport correctly on a caps change
authorMatthew Waters <matthew@centricular.com>
Fri, 31 Oct 2014 01:52:50 +0000 (12:52 +1100)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:49 +0000 (19:31 +0000)
with force-aspect-ratio=true, if the width or height changed, the
viewport wasn't being updated to respect the new video width and height
until a resize occured.

ext/gl/gstglimagesink.c
ext/gl/gstglimagesink.h

index 7d38a53..7367f29 100644 (file)
@@ -806,6 +806,7 @@ gst_glimage_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
   glimage_sink->upload = gst_gl_upload_new (glimage_sink->context);
 
   gst_gl_upload_set_format (glimage_sink->upload, &vinfo);
+  glimage_sink->caps_change = TRUE;
 
   return TRUE;
 }
@@ -1102,6 +1103,9 @@ gst_glimage_sink_on_resize (GstGLImageSink * gl_sink, gint width, gint height)
   g_signal_emit (gl_sink, gst_glimage_sink_signals[CLIENT_RESHAPE_SIGNAL], 0,
       gl_sink->context, width, height, &do_reshape);
 
+  gl_sink->window_width = width;
+  gl_sink->window_height = height;
+
   /* default reshape */
   if (!do_reshape) {
     if (gl_sink->keep_aspect_ratio) {
@@ -1165,6 +1169,14 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
   /* opengl scene */
   GST_TRACE ("redrawing texture:%u", gl_sink->redisplay_texture);
 
+  if (gl_sink->caps_change) {
+    GST_GLIMAGE_SINK_UNLOCK (gl_sink);
+    gst_glimage_sink_on_resize (gl_sink, gl_sink->window_width,
+        gl_sink->window_height);
+    GST_GLIMAGE_SINK_LOCK (gl_sink);
+    gl_sink->caps_change = FALSE;
+  }
+
   /* make sure that the environnement is clean */
   gst_gl_context_clear_shader (gl_sink->context);
 
index c5bc2ec..45d9515 100644 (file)
@@ -81,6 +81,10 @@ struct _GstGLImageSink
     GstBuffer *stored_buffer;
     GLuint redisplay_texture;
 
+    gboolean caps_change;
+    guint window_width;
+    guint window_height;
+
 #if GST_GL_HAVE_GLES2
   GstGLShader *redisplay_shader;
   GLint redisplay_attr_position_loc;