diff --git a/gst-libs/gst/gl/gstgldisplay.c b/gst-libs/gst/gl/gstgldisplay.c index f339f0c482..9c3cce9a13 100644 --- a/gst-libs/gst/gl/gstgldisplay.c +++ b/gst-libs/gst/gl/gstgldisplay.c @@ -24,6 +24,7 @@ #include "config.h" #endif +#include #include "gstgldisplay.h" /* @@ -125,6 +126,7 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass) display->redisplay_texture = 0; display->redisplay_texture_width = 0; display->redisplay_texture_height = 0; + display->keep_aspect_ratio = FALSE; #ifdef OPENGL_ES2 display->redisplay_shader = NULL; display->redisplay_attr_position_loc = 0; @@ -1747,7 +1749,24 @@ gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height) //default reshape else { - glViewport (0, 0, width, height); + if (display->keep_aspect_ratio) { + GstVideoRectangle src, dst, result; + + src.x = 0; + src.y = 0; + src.w = display->redisplay_texture_width; + src.h = display->redisplay_texture_height; + + dst.x = 0; + dst.y = 0; + dst.w = width; + dst.h = height; + + gst_video_sink_center_rect (src, dst, &result, TRUE); + glViewport (result.x, result.y, result.w, result.h); + } else { + glViewport (0, 0, width, height); + } #ifndef OPENGL_ES2 glMatrixMode (GL_PROJECTION); glLoadIdentity (); @@ -2091,7 +2110,7 @@ gst_gl_display_create_context (GstGLDisplay * display, /* Called by the glimagesink element */ gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width, - gint height) + gint height, gboolean keep_aspect_ratio) { gboolean isAlive = TRUE; @@ -2111,6 +2130,7 @@ gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width, display->redisplay_texture_width = width; display->redisplay_texture_height = height; } + display->keep_aspect_ratio = keep_aspect_ratio; if (display->gl_window) gst_gl_window_draw (display->gl_window); } diff --git a/gst-libs/gst/gl/gstgldisplay.h b/gst-libs/gst/gl/gstgldisplay.h index 25370b5b22..74a72e6878 100644 --- a/gst-libs/gst/gl/gstgldisplay.h +++ b/gst-libs/gst/gl/gstgldisplay.h @@ -100,6 +100,7 @@ struct _GstGLDisplay GLuint redisplay_texture; GLuint redisplay_texture_width; GLuint redisplay_texture_height; + gboolean keep_aspect_ratio; #ifdef OPENGL_ES2 GstGLShader *redisplay_shader; gchar *redisplay_vertex_shader_str; @@ -241,7 +242,7 @@ GstGLDisplay *gst_gl_display_new (void); void gst_gl_display_create_context (GstGLDisplay * display, GLint width, GLint height, guint64 external_gl_context); gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, - gint width, gint height); + gint width, gint height, gboolean keep_aspect_ratio); void gst_gl_display_thread_add (GstGLDisplay * display, GstGLDisplayThreadFunc func, gpointer data);