mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 00:31:13 +00:00
composition-overlay: Positions are relative to texture
The coordinate are relative to the texture dimension and not the window dimension now. There is no need to pass the window dimension or to update the overlay if the dimension changes. https://bugzilla.gnome.org/show_bug.cgi?id=745107
This commit is contained in:
parent
8abd2bbe35
commit
1812c19291
5 changed files with 13 additions and 39 deletions
|
@ -1287,7 +1287,7 @@ prepare_next_buffer (GstGLImageSink * glimage_sink)
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor,
|
gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor,
|
||||||
next_buffer, glimage_sink->window_width, glimage_sink->window_height);
|
next_buffer);
|
||||||
|
|
||||||
/* in_buffer invalid now */
|
/* in_buffer invalid now */
|
||||||
if (!gst_video_frame_map (&gl_frame, info, next_buffer,
|
if (!gst_video_frame_map (&gl_frame, info, next_buffer,
|
||||||
|
|
|
@ -42,7 +42,7 @@ G_DEFINE_TYPE_WITH_CODE (GstGLCompositionOverlay, gst_gl_composition_overlay,
|
||||||
static void gst_gl_composition_overlay_finalize (GObject * object);
|
static void gst_gl_composition_overlay_finalize (GObject * object);
|
||||||
static void
|
static void
|
||||||
gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
||||||
overlay, GstBuffer * video_buffer, guint window_width, guint window_height);
|
overlay, GstBuffer * video_buffer);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_composition_overlay_class_init (GstGLCompositionOverlayClass * klass)
|
gst_gl_composition_overlay_class_init (GstGLCompositionOverlayClass * klass)
|
||||||
|
@ -204,7 +204,7 @@ gst_gl_composition_overlay_init_vertex_buffer (GstGLContext * context,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
||||||
overlay, GstBuffer * video_buffer, guint window_width, guint window_height)
|
overlay, GstBuffer * video_buffer)
|
||||||
{
|
{
|
||||||
gint comp_x, comp_y;
|
gint comp_x, comp_y;
|
||||||
guint comp_width, comp_height;
|
guint comp_width, comp_height;
|
||||||
|
@ -213,19 +213,13 @@ gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
||||||
|
|
||||||
float rel_x, rel_y, rel_w, rel_h;
|
float rel_x, rel_y, rel_w, rel_h;
|
||||||
|
|
||||||
gfloat window_aspect = 1.0;
|
|
||||||
gfloat video_aspect = 1.0;
|
|
||||||
|
|
||||||
meta = gst_buffer_get_video_meta (video_buffer);
|
meta = gst_buffer_get_video_meta (video_buffer);
|
||||||
|
|
||||||
gst_video_overlay_rectangle_get_render_rectangle (overlay->rectangle,
|
gst_video_overlay_rectangle_get_render_rectangle (overlay->rectangle,
|
||||||
&comp_x, &comp_y, &comp_width, &comp_height);
|
&comp_x, &comp_y, &comp_width, &comp_height);
|
||||||
|
|
||||||
width = window_width;
|
width = meta->width;
|
||||||
height = window_height;
|
height = meta->height;
|
||||||
|
|
||||||
window_aspect = (float) width / (float) height;
|
|
||||||
video_aspect = (float) meta->width / (float) meta->height;
|
|
||||||
|
|
||||||
/* calculate relative position */
|
/* calculate relative position */
|
||||||
rel_x = (float) comp_x / (float) width;
|
rel_x = (float) comp_x / (float) width;
|
||||||
|
@ -234,15 +228,6 @@ gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
||||||
rel_w = (float) comp_width / (float) width;
|
rel_w = (float) comp_width / (float) width;
|
||||||
rel_h = (float) comp_height / (float) height;
|
rel_h = (float) comp_height / (float) height;
|
||||||
|
|
||||||
/* transform to window aspect ratio */
|
|
||||||
if (window_aspect <= video_aspect) {
|
|
||||||
rel_y *= video_aspect / window_aspect;
|
|
||||||
rel_h *= video_aspect / window_aspect;
|
|
||||||
} else {
|
|
||||||
rel_x *= window_aspect / video_aspect;
|
|
||||||
rel_w *= window_aspect / video_aspect;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* transform from [0,1] to [-1,1], invert y axis */
|
/* transform from [0,1] to [-1,1], invert y axis */
|
||||||
rel_x = rel_x * 2.0 - 1.0;
|
rel_x = rel_x * 2.0 - 1.0;
|
||||||
rel_y = (1.0 - rel_y) * 2.0 - 1.0;
|
rel_y = (1.0 - rel_y) * 2.0 - 1.0;
|
||||||
|
@ -274,14 +259,13 @@ gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *
|
||||||
gst_gl_composition_overlay_init_vertex_buffer, overlay);
|
gst_gl_composition_overlay_init_vertex_buffer, overlay);
|
||||||
|
|
||||||
GST_DEBUG
|
GST_DEBUG
|
||||||
("overlay position: (%d,%d) size: %dx%d video size: %dx%d, sink window %dx%d",
|
("overlay position: (%d,%d) size: %dx%d video size: %dx%d",
|
||||||
comp_x, comp_y, comp_width, comp_height, meta->width, meta->height,
|
comp_x, comp_y, comp_width, comp_height, meta->width, meta->height);
|
||||||
window_width, window_height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
|
gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
|
||||||
GstBuffer * buf, guint window_width, guint window_height)
|
GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstMapInfo info;
|
GstMapInfo info;
|
||||||
GstVideoMeta *vmeta;
|
GstVideoMeta *vmeta;
|
||||||
|
@ -306,8 +290,7 @@ gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
|
||||||
|
|
||||||
meta = gst_buffer_get_video_meta (comp_buffer);
|
meta = gst_buffer_get_video_meta (comp_buffer);
|
||||||
|
|
||||||
gst_gl_composition_overlay_add_transformation (overlay, buf, window_width,
|
gst_gl_composition_overlay_add_transformation (overlay, buf);
|
||||||
window_height);
|
|
||||||
|
|
||||||
gst_video_info_init (&text_info);
|
gst_video_info_init (&text_info);
|
||||||
gst_video_info_set_format (&text_info, meta->format, meta->width,
|
gst_video_info_set_format (&text_info, meta->format, meta->width,
|
||||||
|
|
|
@ -74,7 +74,7 @@ GstGLCompositionOverlay *gst_gl_composition_overlay_new (GstGLContext * context,
|
||||||
GLint texcoord_attrib);
|
GLint texcoord_attrib);
|
||||||
|
|
||||||
void gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
|
void gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay,
|
||||||
GstBuffer * buf, guint window_width, guint window_height);
|
GstBuffer * buf);
|
||||||
|
|
||||||
void gst_gl_composition_overlay_draw (GstGLCompositionOverlay * overlay,
|
void gst_gl_composition_overlay_draw (GstGLCompositionOverlay * overlay,
|
||||||
GstGLShader * shader);
|
GstGLShader * shader);
|
||||||
|
|
|
@ -153,18 +153,10 @@ gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor)
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
||||||
GstBuffer * buf, guint window_width, guint window_height)
|
GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstVideoOverlayCompositionMeta *composition_meta;
|
GstVideoOverlayCompositionMeta *composition_meta;
|
||||||
|
|
||||||
if (compositor->last_window_width != window_width ||
|
|
||||||
compositor->last_window_height != window_height) {
|
|
||||||
gst_gl_overlay_compositor_free_overlays (compositor);
|
|
||||||
compositor->last_window_width = window_width;
|
|
||||||
compositor->last_window_height = window_height;
|
|
||||||
GST_DEBUG ("window size changed, freeing overlays");
|
|
||||||
}
|
|
||||||
|
|
||||||
composition_meta = gst_buffer_get_video_overlay_composition_meta (buf);
|
composition_meta = gst_buffer_get_video_overlay_composition_meta (buf);
|
||||||
if (composition_meta) {
|
if (composition_meta) {
|
||||||
GstVideoOverlayComposition *composition = NULL;
|
GstVideoOverlayComposition *composition = NULL;
|
||||||
|
@ -186,8 +178,7 @@ gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
||||||
gst_gl_composition_overlay_new (compositor->context, rectangle,
|
gst_gl_composition_overlay_new (compositor->context, rectangle,
|
||||||
compositor->position_attrib, compositor->texcoord_attrib);
|
compositor->position_attrib, compositor->texcoord_attrib);
|
||||||
|
|
||||||
gst_gl_composition_overlay_upload (overlay, buf, window_width,
|
gst_gl_composition_overlay_upload (overlay, buf);
|
||||||
window_height);
|
|
||||||
|
|
||||||
compositor->overlays = g_list_append (compositor->overlays, overlay);
|
compositor->overlays = g_list_append (compositor->overlays, overlay);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ GstGLOverlayCompositor *gst_gl_overlay_compositor_new (GstGLContext * context);
|
||||||
void gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor);
|
void gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor);
|
||||||
|
|
||||||
void gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
void gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor,
|
||||||
GstBuffer * buf, guint window_width, guint window_height);
|
GstBuffer * buf);
|
||||||
|
|
||||||
void gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor);
|
void gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue