mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-30 20:59:44 +00:00
[333/906] add force-aspect-ratio support
This commit is contained in:
parent
80e114860e
commit
bcc33ab716
4 changed files with 47 additions and 6 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/video/gstvideosink.h>
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -156,7 +156,8 @@ enum
|
|||
ARG_0,
|
||||
ARG_DISPLAY,
|
||||
PROP_CLIENT_RESHAPE_CALLBACK,
|
||||
PROP_CLIENT_DRAW_CALLBACK
|
||||
PROP_CLIENT_DRAW_CALLBACK,
|
||||
PROP_FORCE_ASPECT_RATIO
|
||||
};
|
||||
|
||||
GST_BOILERPLATE_FULL (GstGLImageSink, gst_glimage_sink, GstVideoSink,
|
||||
|
@ -226,6 +227,12 @@ gst_glimage_sink_class_init (GstGLImageSinkClass * klass)
|
|||
g_param_spec_pointer ("client_draw_callback", "Client draw callback",
|
||||
"Define a custom draw callback in a client code", G_PARAM_WRITABLE));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
|
||||
g_param_spec_boolean ("force-aspect-ratio",
|
||||
"Force aspect ratio",
|
||||
"When enabled, scaling will respect original aspect ratio", FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
gobject_class->finalize = gst_glimage_sink_finalize;
|
||||
|
||||
gstelement_class->change_state = gst_glimage_sink_change_state;
|
||||
|
@ -248,6 +255,7 @@ gst_glimage_sink_init (GstGLImageSink * glimage_sink,
|
|||
glimage_sink->stored_buffer = NULL;
|
||||
glimage_sink->clientReshapeCallback = NULL;
|
||||
glimage_sink->clientDrawCallback = NULL;
|
||||
glimage_sink->keep_aspect_ratio = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -277,6 +285,11 @@ gst_glimage_sink_set_property (GObject * object, guint prop_id,
|
|||
glimage_sink->clientDrawCallback = g_value_get_pointer (value);
|
||||
break;
|
||||
}
|
||||
case PROP_FORCE_ASPECT_RATIO:
|
||||
{
|
||||
glimage_sink->keep_aspect_ratio = g_value_get_boolean (value);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -314,6 +327,9 @@ gst_glimage_sink_get_property (GObject * object, guint prop_id,
|
|||
case ARG_DISPLAY:
|
||||
g_value_set_string (value, glimage_sink->display_name);
|
||||
break;
|
||||
case PROP_FORCE_ASPECT_RATIO:
|
||||
g_value_set_boolean (value, glimage_sink->keep_aspect_ratio);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -553,7 +569,8 @@ gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
|||
//redisplay opengl scene
|
||||
if (gl_buffer->texture &&
|
||||
gst_gl_display_redisplay (glimage_sink->display,
|
||||
gl_buffer->texture, gl_buffer->width, gl_buffer->height))
|
||||
gl_buffer->texture, gl_buffer->width, gl_buffer->height,
|
||||
glimage_sink->keep_aspect_ratio))
|
||||
return GST_FLOW_OK;
|
||||
else
|
||||
return GST_FLOW_UNEXPECTED;
|
||||
|
@ -592,7 +609,8 @@ gst_glimage_sink_expose (GstXOverlay * overlay)
|
|||
|
||||
//redisplay opengl scene
|
||||
if (glimage_sink->display && glimage_sink->window_id)
|
||||
gst_gl_display_redisplay (glimage_sink->display, 0, 0, 0);
|
||||
gst_gl_display_redisplay (glimage_sink->display, 0, 0, 0,
|
||||
glimage_sink->keep_aspect_ratio);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,8 @@ struct _GstGLImageSink
|
|||
|
||||
CRCB clientReshapeCallback;
|
||||
CDCB clientDrawCallback;
|
||||
|
||||
gboolean keep_aspect_ratio;
|
||||
};
|
||||
|
||||
struct _GstGLImageSinkClass
|
||||
|
|
Loading…
Reference in a new issue