After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 745107 - glimagesink: implement GstVideoOverlayCompositionMeta
glimagesink: implement GstVideoOverlayCompositionMeta
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
unspecified
Other Linux
: Normal blocker
: 1.5.90
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2015-02-24 18:03 UTC by Xavier Claessens
Modified: 2015-08-16 13:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
export GstVideoOverlayComposition and GstVideoOverlayRectangle structure (8.72 KB, patch)
2015-03-05 04:30 UTC, Mingke Wang
rejected Details | Review
Add class for managing GstVideoOverlayCompositionOverlay buffers (17.67 KB, patch)
2015-06-18 13:00 UTC, Lubosz Sarnecki
none Details | Review
glcolorconvert: Apply GstVideoOverlayCompositionMeta buffer to converted buffer (1.51 KB, patch)
2015-06-18 13:00 UTC, Lubosz Sarnecki
none Details | Review
glimagesink: Add window size event for upstream text overlays (2.36 KB, patch)
2015-06-18 13:01 UTC, Lubosz Sarnecki
none Details | Review
glimagesink: Upload and draw overlays (5.59 KB, patch)
2015-06-18 13:01 UTC, Lubosz Sarnecki
none Details | Review
glimagesinkbin: Add allocation query for GstVideoOverlayComposition (7.02 KB, patch)
2015-06-18 13:02 UTC, Lubosz Sarnecki
none Details | Review
glimagesinkbin: Add static GstVideoOverlayCompositionMeta caps features (3.43 KB, patch)
2015-06-18 13:02 UTC, Lubosz Sarnecki
none Details | Review
glupload: Move debug init to top of the file (1.81 KB, patch)
2015-06-18 13:02 UTC, Lubosz Sarnecki
committed Details | Review
glimagesinkbin: Add dynamic caps for GstVideoOverlayComposition (2.61 KB, patch)
2015-06-18 13:03 UTC, Lubosz Sarnecki
none Details | Review
glupload: Detect overlay meta buffers correctly (1.98 KB, patch)
2015-06-18 13:03 UTC, Lubosz Sarnecki
none Details | Review
glcompositionoverlay: Add compatibility for GL contexts without glGenVertexArrays (2.89 KB, patch)
2015-06-18 13:03 UTC, Lubosz Sarnecki
none Details | Review
glimagesink: uint is undefined on windows, use guint instead. (932 bytes, patch)
2015-06-26 00:23 UTC, Xavier Claessens
accepted-commit_now Details | Review
GstGLCompositionOverlay: Fix leaked gl context (1.10 KB, patch)
2015-06-26 19:57 UTC, Xavier Claessens
accepted-commit_now Details | Review
glcompositionoverlay: Add class for managing GstVideoOverlayCompositionOverlay buffers (15.98 KB, patch)
2015-07-01 13:58 UTC, Lubosz Sarnecki
committed Details | Review
glcompositionoverlay: Add compatibility for GL contexts without glGenVertexArrays (2.87 KB, patch)
2015-07-01 13:59 UTC, Lubosz Sarnecki
committed Details | Review
gloverlaycompositor: Add GstGLOverlayCompositor class (12.45 KB, patch)
2015-07-01 13:59 UTC, Lubosz Sarnecki
committed Details | Review
glimagesink: Upload and draw overlays with GstGLOverlayCompositor (3.17 KB, patch)
2015-07-01 13:59 UTC, Lubosz Sarnecki
committed Details | Review
glimagesinkbin: Add GstVideoOverlayCompositionMeta caps features (5.49 KB, patch)
2015-07-01 14:00 UTC, Lubosz Sarnecki
committed Details | Review
glupload: Detect overlay meta buffers correctly (1.98 KB, patch)
2015-07-01 14:00 UTC, Lubosz Sarnecki
committed Details | Review
glcolorconvert: Apply GstVideoOverlayCompositionMeta buffer to converted buffer (1.50 KB, patch)
2015-07-01 14:01 UTC, Lubosz Sarnecki
committed Details | Review
glimagesinkbin: Add allocation query for GstVideoOverlayComposition (3.03 KB, patch)
2015-07-01 14:02 UTC, Lubosz Sarnecki
committed Details | Review
glimagesink: Send reconfigure event when window size changes (1.49 KB, patch)
2015-07-01 14:02 UTC, Lubosz Sarnecki
committed Details | Review
gloverlaycompositor: Create own shader object (6.29 KB, patch)
2015-07-21 14:49 UTC, Lubosz Sarnecki
none Details | Review
glimagesink: Properly handle compsositor life time (3.07 KB, patch)
2015-07-21 22:49 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
gloverlaycompositor: Create own shader object (6.36 KB, patch)
2015-07-22 01:28 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review
composition-overlay: Positions are relative to texture (7.50 KB, patch)
2015-07-22 04:50 UTC, Nicolas Dufresne (ndufresne)
committed Details | Review

Description Xavier Claessens 2015-02-24 18:03:16 UTC
When using this pipeline on android device, I get really bad performance:
  playbin ! gltransformation ! textoverlay ! glimagesink

If I remove the textoverlay the video plays perfectly.

As far as I can tell, the problem is that the video buffers are going gpu->cpu->gpu instead of composing the overlay on gpu.

According to what people said on #gstreamer, this can be fixed using GstVideoOverlayCompositionMeta.
Comment 1 Lubosz Sarnecki 2015-02-28 11:14:46 UTC
I can reproduce the performance issue when playing a 4k video. It runs noticeably smoother without the textoverlay.

How can a performance gain can be achieved by implementing GstVideoOverlayCompositionMeta? 

The only place I where this used is tests/check/elements/textoverlay.c.

According to the documentation, the raw buffer should be blended over the GL buffer in the sink. How should the pipeline look in this case?

As a side note, I would like to see a gl element rendering fonts using this:
https://code.google.com/p/glyphy/
Comment 2 Edward Hervey 2015-02-28 11:19:52 UTC
The idea being GstVideoOverlayCompositionMeta is to instruct downstream elements to do the overlaying operation.

In this case, glimagesink could state it can handle it (return it in the supported meta in the allocation query), and when it sees an incoming buffer with that meta on it upload the overlayed buffer and ask the gpu to blend it.

The pipeline wouldn't change (except that the pipeline xavier gave is wrong, I imagine it's s/playbin/decodebin/), textoverlay would figure out that glimagesink can do overlay, and therefore not "burn in" the overlay but instead attach the information in the meta.
Comment 3 kevin 2015-03-02 14:27:27 UTC
We are working on that. We will try to fix it.
Comment 4 Nicolas Dufresne (ndufresne) 2015-03-03 21:51:28 UTC

*** This bug has been marked as a duplicate of bug 723761 ***
Comment 5 Nicolas Dufresne (ndufresne) 2015-03-03 21:52:28 UTC
My bad.
Comment 6 kevin 2015-03-05 02:06:38 UTC
kevin_> so you focus on glimagesink implement video overlay composite?
<kevin_> do you sync with Julien Isorce? https://bugzilla.gnome.org/show_bug.cgi?id=723761
<kevin_> do you care about gltextoverlay.text_sink?
<kevin_> Use an external GL Font API to build a separate gltexture and attach it to the input buffer's GstVideoOverlayCompositionMeta. Then a downstream element could call gst_video_overlay_composition_blend to show up the subtitles.
<kevin_> So gltextoverlay still can do video composite with GL even if downstream element can't support GstVideoOverlayCompositionMeta? I also need this use case.
<kevin_> how about timeoverlay? do still need gltimeoverlay?
<kevin_> so GstBaseTextOverlay based on GL is really needed?
<lubosz> i was considering using glyphy for font rendering
<lubosz> but we prefer pango atm
<lubosz> the bug from julien isorce was marked as duplicate, and later unmarked
<lubosz> is there already a gltextoverlay element??
<lubosz> GstBaseTextOverlay won't be based on GL with my work
<lubosz> the sink will support compositing the buffers in hardware
<lubosz> the font will still be rendered on the cpiu
<lubosz> but the textoverlay won't do it's slow compositing anymore
Comment 7 kevin 2015-03-05 02:12:32 UTC
So video composite code based on GL in your work will location in one common fold. So GstBaseTextOverlay based on GL will reuse your code? We need gltextoverlay and gltimeoverlay, and can based on your video composite code?
Comment 8 Mingke Wang 2015-03-05 04:28:21 UTC
I'm trying to implement the GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION in another sink using G2D. 
I added features in static caps template, but besides the GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION feature, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY also need to be added, since gstbasetextoverlay will use them both for feature negotiation. 
we need two structure in caps, one is without feature, and one contains feature. if only has one structure with feature, somehow, element link will failed.
following if may code clip in my static caps function:
--------------------------------------------------------------
  caps = gst_caps_new_empty ();
  for(i=0; i<CAPS_NUM; i++) {
    GstStructure *structure = gst_structure_from_string(caps_str[i], NULL);
    gst_caps_append_structure (caps, structure);
  }

  for(i=0; i<CAPS_NUM; i++) {
    GstStructure *structure = gst_structure_from_string(caps_str[i], NULL);
    gst_caps_append_structure (caps, structure);
    GstCapsFeatures *f =
        gst_caps_features_new(GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY, NULL);
    gst_caps_features_add(f, GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION);
    gst_caps_set_features(caps, i+CAPS_NUM, f);
  }
---------------------------------------------------------------

and now I can get GstVideoOverlayCompositionMeta in may sink.and got the meta info like following:
Blending composition 0x71ac4cf8 with 1 rectangles onto video buffer 0x7290f0d8 (1920x1088, format 23)
rectangle 0 0x71aa7008: 833x53, format 12

but before all above can be work, we need change video-overlay-composition.c and video-overlay-composition.h a little bit to export GstVideoOverlayComposition and GstVideoOverlayRectangle structures, otherwise we can't get compiled.
the patch is attached.
Comment 9 Mingke Wang 2015-03-05 04:30:34 UTC
Created attachment 298601 [details] [review]
export GstVideoOverlayComposition and GstVideoOverlayRectangle structure

export GstVideoOverlayComposition and GstVideoOverlayRectangle structures so that other element can use them to implement a video overlay composition feature
Comment 10 Tim-Philipp Müller 2015-03-05 08:57:47 UTC
Comment on attachment 298601 [details] [review]
export GstVideoOverlayComposition and GstVideoOverlayRectangle structure

I don't think that's needed. Why do you think these need to be made public? What can't you get to otherwise?
Comment 11 Mingke Wang 2015-03-05 10:29:56 UTC
(In reply to Tim-Philipp Müller from comment #10)
> Comment on attachment 298601 [details] [review] [review]
> export GstVideoOverlayComposition and GstVideoOverlayRectangle structure
> 
> I don't think that's needed. Why do you think these need to be made public?
> What can't you get to otherwise?

I have a sink need implement GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION feature, so I use gst_buffer_get_video_overlay_composition_meta() to get the composition meta like following:

  GstVideoOverlayCompositionMeta *compmeta =
      gst_buffer_get_video_overlay_composition_meta(buffer);

then I need access the data in GstVideoOverlayCompositionMeta.

this was defined in video-overlay-composition.h as following:
struct _GstVideoOverlayCompositionMeta
{
  GstMeta meta;
  GstVideoOverlayComposition *overlay;
};

then I need access the GstVideoOverlayComposition and rectangles in GstVideoOverlayComposition. but both of them are defined in video-overlay-composition.c, How can I use them in my sink source code?
Comment 13 Mingke Wang 2015-03-05 11:07:48 UTC
(In reply to Tim-Philipp Müller from comment #12)
> http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-
> libs/html/gst-plugins-base-libs-gstvideooverlaycomposition.html
> 
> See _get_rectangle() and _get_pixels_*().

Thanks a lot, 
I didn't notice those APIs.
Comment 14 Nicolas Dufresne (ndufresne) 2015-03-05 13:24:20 UTC
To Kevin: Text overlay are not frequently updated and are small. Rendering text in GL using vectorial data is slower then rendering to a buffer and uploading. 

So the idea is that we don't care at all about text rendering for this bug. textoverlay or other subtitled element (like assrender) will render to an RGBA buffer and attach it to the buffer to render. All we have to do is upload and compose the buffer in the glimagesink element (and a utility in libgstgl of course, at not everyone uses the sink).

This is fully implemented in cogl and clutter video sink.
Comment 15 kevin 2015-03-05 13:47:51 UTC
If only implement video composite in glimagesink, I still don't know how to implement my use case.

My use case is v4l2src ! timeoverlay ! videoencoder. How can I accelerate timeoverlay video composite?
Comment 16 Nicolas Dufresne (ndufresne) 2015-03-05 14:06:34 UTC
(In reply to kevin from comment #15)
> If only implement video composite in glimagesink, I still don't know how to
> implement my use case.
> 
> My use case is v4l2src ! timeoverlay ! videoencoder. How can I accelerate
> timeoverlay video composite?

It's a completely different use case, this bug is about glimagesink, and you don't have this element in your pipeline. Please move to the ML if you want to discuss this matter.
Comment 17 Lubosz Sarnecki 2015-06-18 12:59:30 UTC
These patches implement the GstOverlayComposition API in the glimagesink.

The required gst-plugins-base patches can be found here:
https://bugzilla.gnome.org/show_bug.cgi?id=751157
Comment 18 Lubosz Sarnecki 2015-06-18 13:00:09 UTC
Created attachment 305563 [details] [review]
Add class for managing GstVideoOverlayCompositionOverlay buffers

    Add a class to store and manage the OpenGL texture,
    vertex buffer and GstVideoOverlayRectangle.
    Transforms overlay coordinate space to vertex buffer space with aspect ratios in mind.
    Provides methods for caps manipulation and overlay caching.
    
    = Example Pipelines =
    
    Simple pipeline
    
    gst-launch-1.0 videotestsrc ! \
      textoverlay text="Hello World" font-desc="sans bold 30" ! \
      glimagesink
    
    Display 3 static overlays at different positions
    
    gst-launch-1.0 videotestsrc ! \
      textoverlay text="text1" valignment="top" font-desc="sans bold 30" ! \
      textoverlay text="text2" halignment="right" font-desc="sans bold 30" ! \
      textoverlay text="text3" halignment="left" font-desc="sans bold 30" ! \
      glimagesink
    
    Display subtitle file over testsrc
    
    gst-launch-1.0 videotestsrc ! \
      textoverlay name=foo filesrc location=foo.srt ! subparse ! queue ! foo. foo. ! \
      glimagesink
Comment 19 Lubosz Sarnecki 2015-06-18 13:00:48 UTC
Created attachment 305564 [details] [review]
glcolorconvert: Apply GstVideoOverlayCompositionMeta buffer to converted buffer

Since glcolorconvert creates a new GstBuffer, without the GstVideoOverlayCompositionMeta data, it needs to be copied to not be dropped.
Comment 20 Lubosz Sarnecki 2015-06-18 13:01:27 UTC
Created attachment 305566 [details] [review]
glimagesink: Add window size event for upstream text overlays

    This event will propagate the window size upstream,
    so the basetextoverlay can receive it to render an image buffer
    according to the devices screen size.
    This makes text overlays independent of the stream size and
    reading text over a 320x240 stream on a HiDPI display possible.
Comment 21 Lubosz Sarnecki 2015-06-18 13:01:56 UTC
Created attachment 305567 [details] [review]
glimagesink: Upload and draw overlays

    Receives the GstOverlayComposition buffer in the glimagesink,
    manages the GstGLCompositionOverlay objects,
    caches already uploaded overlays and draws them.
Comment 22 Lubosz Sarnecki 2015-06-18 13:02:20 UTC
Created attachment 305568 [details] [review]
glimagesinkbin: Add allocation query for GstVideoOverlayComposition

    Adds an GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE query
    to glupload, glcolorconvert and glimagesink.
    Detects the query from the downstream elements, so it is executed
    only when downstream supports the overlay API.
    This makes pipelines with textoverlay ! glupload ! gldownload ! xvimagesink possible.
Comment 23 Lubosz Sarnecki 2015-06-18 13:02:41 UTC
Created attachment 305569 [details] [review]
glimagesinkbin: Add static GstVideoOverlayCompositionMeta caps features
Comment 24 Lubosz Sarnecki 2015-06-18 13:02:59 UTC
Created attachment 305570 [details] [review]
glupload: Move debug init to top of the file
Comment 25 Lubosz Sarnecki 2015-06-18 13:03:14 UTC
Created attachment 305571 [details] [review]
glimagesinkbin: Add dynamic caps for GstVideoOverlayComposition
Comment 26 Lubosz Sarnecki 2015-06-18 13:03:30 UTC
Created attachment 305572 [details] [review]
glupload: Detect overlay meta buffers correctly
Comment 27 Lubosz Sarnecki 2015-06-18 13:03:46 UTC
Created attachment 305573 [details] [review]
glcompositionoverlay: Add compatibility for GL contexts without glGenVertexArrays
Comment 28 Tim-Philipp Müller 2015-06-18 13:12:16 UTC
Cool stuff.

I'm not so sure about this window-size event. I realise it's a quick'n'easy way to make this work, but I think this should be done via the extra GstStructure in the allocation query,which is done anyway to check for the overlay composition meta suppoert, no? glimagesink should then send a reconfigure event if the size changes, not sure that's done yet.
Comment 29 Xavier Claessens 2015-06-26 00:23:02 UTC
Created attachment 306133 [details] [review]
glimagesink: uint is undefined on windows, use guint instead.
Comment 30 Lubosz Sarnecki 2015-06-26 11:47:27 UTC
@Tim:

I managed to pass the window size in the allocation query structure. One challenging aspect is that it has to be passed through glcolorconvert, glupload to textoverlay. It does not need to be passed through the textoverlays weirdly. If I have multiple of them, they all receive the window size from glupload.

The major problem about this way of passing the window size is not only the amount of additional code required (why complicated if it can be done simple), but the bug that I receive 3 configure event old resolutions in the textoverlay.

So it requires 3 resize / reconfigure events to get the current resolution through all the elements, so the buffer is rendered with the resolution the window hat 3 resize events before. Any solution to this would be appreciated. Maybe reconfigure in the propose_allocation, but this does not sound right.

Enjoy:

https://git.collabora.com/cgit/user/lubosz/gst-plugins-bad.git/log/?h=videooverlaycomposition-alloc-query-size

https://git.collabora.com/cgit/user/lubosz/gst-plugins-base.git/log/?h=videooverlaycomposition-alloc-query-size
Comment 31 Xavier Claessens 2015-06-26 19:41:23 UTC
Testing your patchset with this pipeline:

gst-launch-1.0 videotestsrc ! glupload ! textoverlay text=plop ! glimagesink

And the glcontext is leaked when closing the window. If I remove the textoverlay it's not leaked (after the recent patch from Nicolas).
Comment 32 Nicolas Dufresne (ndufresne) 2015-06-26 19:51:51 UTC
Review of attachment 305563 [details] [review]:

::: gst-libs/gst/gl/gstglcompositionoverlay.c
@@ +113,3 @@
+  if (GST_GL_IS_CONTEXT (overlay->context)) {
+    gst_gl_context_thread_add (overlay->context,
+        gst_gl_composition_overlay_free_vertex_buffer, overlay);

The type check is suspicious. Also, what about unrefing the context ;-P
Comment 33 Xavier Claessens 2015-06-26 19:57:21 UTC
Created attachment 306187 [details] [review]
GstGLCompositionOverlay: Fix leaked gl context
Comment 34 Xavier Claessens 2015-06-26 19:58:23 UTC
That fix the leak I mentioned in comment #31
Comment 35 Nicolas Dufresne (ndufresne) 2015-06-26 19:58:56 UTC
Review of attachment 305563 [details] [review]:

::: gst-libs/gst/gl/gstglcompositionoverlay.c
@@ +299,3 @@
+  vmeta = gst_buffer_get_video_meta (comp_buffer);
+  gst_video_meta_map (vmeta, 0, &info, &raw_overlay_data, &stride,
+      GST_MAP_READ);

Here you map, then you unmap, and keep using the pointer after. Would be nice to explain how this can be is safe ?
Comment 36 Nicolas Dufresne (ndufresne) 2015-06-26 20:00:14 UTC
Review of attachment 305567 [details] [review]:

Any ways this could become a utlity. We need this in gtkglsink too.
Comment 37 Nicolas Dufresne (ndufresne) 2015-06-26 20:01:55 UTC
Review of attachment 305570 [details] [review]:

.
Comment 38 Sebastian Dröge (slomo) 2015-06-28 10:09:52 UTC
I also think that the window size stuff should be done via the ALLOCATION query. If there are problems with that currently, or if it's too inconvenient, then we should fix that first but don't introduce a new event that is just there to be dropped again in the near future.
Comment 39 Lubosz Sarnecki 2015-07-01 13:58:38 UTC
Created attachment 306511 [details] [review]
glcompositionoverlay: Add class for managing GstVideoOverlayCompositionOverlay buffers
Comment 40 Lubosz Sarnecki 2015-07-01 13:59:04 UTC
Created attachment 306514 [details] [review]
glcompositionoverlay: Add compatibility for GL contexts without glGenVertexArrays
Comment 41 Lubosz Sarnecki 2015-07-01 13:59:30 UTC
Created attachment 306515 [details] [review]
gloverlaycompositor: Add GstGLOverlayCompositor class
Comment 42 Lubosz Sarnecki 2015-07-01 13:59:58 UTC
Created attachment 306516 [details] [review]
glimagesink: Upload and draw overlays with GstGLOverlayCompositor
Comment 43 Lubosz Sarnecki 2015-07-01 14:00:29 UTC
Created attachment 306517 [details] [review]
glimagesinkbin: Add GstVideoOverlayCompositionMeta caps features
Comment 44 Lubosz Sarnecki 2015-07-01 14:00:52 UTC
Created attachment 306518 [details] [review]
glupload: Detect overlay meta buffers correctly
Comment 45 Lubosz Sarnecki 2015-07-01 14:01:22 UTC
Created attachment 306519 [details] [review]
glcolorconvert: Apply GstVideoOverlayCompositionMeta buffer to converted buffer
Comment 46 Lubosz Sarnecki 2015-07-01 14:02:17 UTC
Created attachment 306520 [details] [review]
glimagesinkbin: Add allocation query for GstVideoOverlayComposition
Comment 47 Lubosz Sarnecki 2015-07-01 14:02:37 UTC
Created attachment 306521 [details] [review]
glimagesink: Send reconfigure event when window size changes
Comment 48 Nicolas Dufresne (ndufresne) 2015-07-20 14:47:13 UTC
Review of attachment 306133 [details] [review]:

.
Comment 49 Nicolas Dufresne (ndufresne) 2015-07-20 14:57:10 UTC
Review of attachment 306187 [details] [review]:

.
Comment 50 Nicolas Dufresne (ndufresne) 2015-07-20 15:21:32 UTC
Review of attachment 306511 [details] [review]:

::: gst-libs/gst/gl/gstglcompositionoverlay.c
@@ +34,3 @@
+
+#define DEBUG_INIT \
+  GST_DEBUG_CATEGORY_INIT (gst_gl_composition_overlay_debug, "glcompositionoverlay", 0, "compositionoverlay");

I suspect this is larger then 80 characters.

@@ +41,3 @@
+
+void
+gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay *

Missing static, put the type on same line unless the gst-indent says otherwise.

@@ +279,3 @@
+      GST_MAP_READ);
+
+  if (raw_overlay_data != NULL) {

I would rather check the return value of gst_video_meta_map().

@@ +312,3 @@
+  }
+
+  gst_video_meta_unmap (vmeta, 0, &info);

Only unmap if map return TRUE.

@@ +323,3 @@
+  if (overlay->texture_id != -1)
+    gl->BindTexture (GL_TEXTURE_2D, overlay->texture_id);
+  gl->DrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);

If there is no texture to draw to, isn't it a better idea to simpy not do anything ?

::: gst-libs/gst/gl/gstglcompositionoverlay.h
@@ +26,3 @@
+#include <gst/gl/gstgl_fwd.h>
+
+G_BEGIN_DECLS GType gst_gl_composition_overlay_get_type (void);

This is uncommon syntax. I prefer when G_BEGIN_DECLS is on separate line.

@@ +40,3 @@
+ */
+struct _GstGLCompositionOverlay
+{

For documentation you need /*< private >*/ here for opaque type.
Comment 51 Nicolas Dufresne (ndufresne) 2015-07-20 15:23:02 UTC
Review of attachment 306514 [details] [review]:

When the otherone is fixed of course.
Comment 52 Nicolas Dufresne (ndufresne) 2015-07-20 15:24:04 UTC
I'll mark the one that are ok with commit-now, but read it as these are the ready to ship one, I'll merge everything when we got everything.
Comment 53 Nicolas Dufresne (ndufresne) 2015-07-20 15:30:10 UTC
Review of attachment 306515 [details] [review]:

This patch is duplicated. Same comment applies, could you pick one and cleanup (mark as obsolete) the one you don't want merge.
Comment 54 Nicolas Dufresne (ndufresne) 2015-07-20 15:36:30 UTC
Review of attachment 306517 [details] [review]:

::: ext/gl/gstglcolorconvertelement.c
@@ +54,2 @@
 static GstStaticPadTemplate gst_gl_color_convert_element_src_pad_template =
+    GST_STATIC_PAD_TEMPLATE ("src",

Was obviously more readable before, I support you could use INDENT-OFF mark.

::: gst-libs/gst/gl/gstglupload.c
@@ +967,2 @@
   for (i = 0; i < G_N_ELEMENTS (upload_methods); i++) {
+    tmp2 = upload_methods[i]->transform_caps (context, direction, caps);

You could have kept the tmp2 in the loop scope. I can't see any rational to change this.
Comment 55 Nicolas Dufresne (ndufresne) 2015-07-20 15:37:33 UTC
Review of attachment 306518 [details] [review]:

.
Comment 56 Nicolas Dufresne (ndufresne) 2015-07-20 15:38:04 UTC
Review of attachment 306519 [details] [review]:

.
Comment 57 Nicolas Dufresne (ndufresne) 2015-07-20 15:40:20 UTC
Review of attachment 306520 [details] [review]:

.
Comment 58 Nicolas Dufresne (ndufresne) 2015-07-20 15:41:07 UTC
Review of attachment 306521 [details] [review]:

.
Comment 59 Nicolas Dufresne (ndufresne) 2015-07-20 15:41:59 UTC
Review of attachment 306516 [details] [review]:

.
Comment 60 Nicolas Dufresne (ndufresne) 2015-07-20 15:43:34 UTC
I'm quite happy with this version. It's much cleaner then the previous ones. As you can see, all my comments are cosmetic, so I believe one more update and we'll be ready to merge this.
Comment 61 Nicolas Dufresne (ndufresne) 2015-07-20 18:11:18 UTC
Comment on attachment 306133 [details] [review]
glimagesink: uint is undefined on windows, use guint instead.

This has been squashed in fact.
Comment 62 Nicolas Dufresne (ndufresne) 2015-07-20 18:12:57 UTC
Comment on attachment 306187 [details] [review]
GstGLCompositionOverlay: Fix leaked gl context

Was squashed too.
Comment 63 Nicolas Dufresne (ndufresne) 2015-07-20 18:17:11 UTC
(In reply to Nicolas Dufresne (stormer) from comment #53)
> Review of attachment 306515 [details] [review] [review]:
> 
> This patch is duplicated. Same comment applies, could you pick one and
> cleanup (mark as obsolete) the one you don't want merge.

I was confused, never mind.
Comment 64 Nicolas Dufresne (ndufresne) 2015-07-20 20:34:20 UTC
Attachment 305570 [details] pushed as 60c8b73 - glupload: Move debug init to top of the file
Attachment 306511 [details] pushed as 7c7f84c - glcompositionoverlay: Add class for managing GstVideoOverlayCompositionOverlay buffers
Attachment 306514 [details] pushed as b4a4999 - glcompositionoverlay: Add compatibility for GL contexts without glGenVertexArrays
Attachment 306515 [details] pushed as b2601a7 - gloverlaycompositor: Add GstGLOverlayCompositor class
Attachment 306516 [details] pushed as 778ad10 - glimagesink: Upload and draw overlays with GstGLOverlayCompositor
Attachment 306517 [details] pushed as a7d1b7f - glimagesinkbin: Add GstVideoOverlayCompositionMeta caps features
Attachment 306518 [details] pushed as 6eaeefc - glupload: Detect overlay meta buffers correctly
Attachment 306519 [details] pushed as 5554288 - glcolorconvert: Apply GstVideoOverlayCompositionMeta buffer to converted buffer
Attachment 306520 [details] pushed as 2fb862b - glimagesinkbin: Add allocation query for GstVideoOverlayComposition
Attachment 306521 [details] pushed as 2b75424 - glimagesink: Send reconfigure event when window size changes
Comment 65 Nicolas Dufresne (ndufresne) 2015-07-20 20:35:21 UTC
Comment on attachment 306511 [details] [review]
glcompositionoverlay: Add class for managing GstVideoOverlayCompositionOverlay buffers

I fixed it before merging.
Comment 66 Nicolas Dufresne (ndufresne) 2015-07-20 20:35:44 UTC
Comment on attachment 306515 [details] [review]
gloverlaycompositor: Add GstGLOverlayCompositor class

I also fixed it before merging.
Comment 67 Matthew Waters (ystreet00) 2015-07-21 04:43:32 UTC
This was not ready to be merged for the following reasons.

1. gst-launch-1.0 videotestsrc ! textoverlay text=YAY ! glimagesink and resize the window.  The text does not stay in the same place relative to the video.
2. The inconsistent gloverlaycompositor/glcompositionoverlay naming
3. Point 2 should have really been a single file containing both objects, the overall compositor and the GstVideoOverlayComposition wrapper object.  Ideally the wrapper object should be entirely internal to the compositor.
4. Reliance on a passed in shader/attributes that we have no idea of the contents of.  The compositor should create it's own shader.
5. gst_video_meta_map instead of gst_video_frame_map usage?
6. Not ensuring that the data pointer passed to gst_gl_memory_wrapped is always valid as long the memory is (it may have disappeared at the time of _unmap()).
7. Stride paramater not passed between video_meta_map() and the wrapped GstVideoInfo.
Comment 68 Matthew Waters (ystreet00) 2015-07-21 04:55:34 UTC
(In reply to Matthew Waters from comment #67)
> 1. gst-launch-1.0 videotestsrc ! textoverlay text=YAY ! glimagesink and
> resize the window.  The text does not stay in the same place relative to the
> video.

A more correct description is that the overlay lags behind the window resize.
Comment 69 Lubosz Sarnecki 2015-07-21 08:03:26 UTC
1. The lag is due to the nature of the poorly performing allocation query propagation. It is a known issue. It worked very fluently with a custom upstream event, but the decision was to fix the performance of the allocation query.

2. Which naming do you suggest?

3. Why put 2 classes in 1 file?

4. This would mean more duplication of glimagesink code, but it is doable.

5. - 7. Sounds reasonable.
Comment 70 Lubosz Sarnecki 2015-07-21 08:14:58 UTC
1. In fact, it's my bad. I forgot to propose the hack for gst-plugins-base to make the negotation fnish every event cycle.

https://bugzilla.gnome.org/show_bug.cgi?id=751157

This fixes the lag. It's still slow but the resolution is correct in the same event cycle at least.
Comment 71 Matthew Waters (ystreet00) 2015-07-21 08:39:19 UTC
(In reply to Lubosz Sarnecki from comment #69)
> 1. The lag is due to the nature of the poorly performing allocation query
> propagation. It is a known issue. It worked very fluently with a custom
> upstream event, but the decision was to fix the performance of the
> allocation query.

Ok

> 2. Which naming do you suggest?

Pick one, but be consistent.  Moot point with 3).

> 3. Why put 2 classes in 1 file?

As I see the code use, the compositor directs the usage of the composition objects that is entirely internal to the compositor's operation and doesn't need to be public API.  Therefore, the composition object can go into gstgloverlaycompositor.c and not be exposed as public API removing the need for gstglcompositionoverlay.c/h to exist.

> 4. This would mean more duplication of glimagesink code, but it is doable.

The only thing you're not doing on top of glimagesink is creating/setting up the shader.
Comment 72 Nicolas Dufresne (ndufresne) 2015-07-21 13:44:54 UTC
2. Let's rename glcompositionoverlay -> gloverlaycompostion
3. We can simply not install the .h also
4. Is that cosmetic ? Or is there a real issue you can demonstrate ?
5. Is cosmetic. It's probably less code, more stack to change it.
7. Need to be looked at indeed.

About 1, it can be a bug, e.g. the meta should always be relative to the stream size (regardless of the size it was rendered), but if it's not such a bug, we should pass back the use window size so the sink can handle the difference.
Comment 73 Lubosz Sarnecki 2015-07-21 14:49:51 UTC
Created attachment 307835 [details] [review]
gloverlaycompositor: Create own shader object
Comment 74 Nicolas Dufresne (ndufresne) 2015-07-21 22:49:18 UTC
Created attachment 307872 [details] [review]
glimagesink: Properly handle compsositor life time

Should be created in READY_TO_PAUSED, not PAUSED_TO_PLAYING.
Should be cleared in PAUSED_TO_READY.
Comment 75 Nicolas Dufresne (ndufresne) 2015-07-21 22:51:12 UTC
The main issue is that the implementation seems to assume meta coordinate are window size relative, but in fact they should be stream size relative. This will fix the miss-placed overlay. The end result will be correctly placed overlay, with scale up or down overlay until the composition meta get updated. I think this will be fully acceptable (nearly not visible).
Comment 76 Nicolas Dufresne (ndufresne) 2015-07-22 01:28:27 UTC
Created attachment 307880 [details] [review]
gloverlaycompositor: Create own shader object

Make gloverlaycompositor independent of the shader used in the sink.
Comment 77 Nicolas Dufresne (ndufresne) 2015-07-22 01:29:49 UTC
(In reply to Nicolas Dufresne (stormer) from comment #76)
> Created attachment 307880 [details] [review] [review]
> gloverlaycompositor: Create own shader object
> 
> Make gloverlaycompositor independent of the shader used in the sink.

I simply rebased it on top of my patch.
Comment 78 Nicolas Dufresne (ndufresne) 2015-07-22 01:48:41 UTC
Note, here's few more thing that will need fixing (originally reported by Sebastien, and I didn't understood what he meant).

* Handle the case force-aspect-ratio == FALSE
* Handle the case where pixel-aspect-ratio != 1/1

This would be pretty much the same in the way to handle. Basically, we need to compute the resulting aspect ratio and use that when placing the overlay. Ideally, we'd pass this pixel-aspect-ratio along with the window width and height so we can get a pre-render that match the display.
Comment 79 Jan Schmidt 2015-07-22 04:11:24 UTC
(In reply to Nicolas Dufresne (stormer) from comment #78)
> Note, here's few more thing that will need fixing (originally reported by
> Sebastien, and I didn't understood what he meant).

Let me throw another thought in: frame-packed stereo outputs.

When rendering out to side-by-side or top-bottom frame packings, if we're blending subpictures, it'll need to be done twice - once for each eye view in the output video. Other frame packings (line-by-line,columns, etc) are probably worse.
Comment 80 Nicolas Dufresne (ndufresne) 2015-07-22 04:50:31 UTC
Created attachment 307884 [details] [review]
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.
Comment 81 Nicolas Dufresne (ndufresne) 2015-07-22 04:54:58 UTC
(In reply to Jan Schmidt from comment #79)
> When rendering out to side-by-side or top-bottom frame packings, if we're
> blending subpictures, it'll need to be done twice - once for each eye view
> in the output video. Other frame packings (line-by-line,columns, etc) are
> probably worse.

Do you have pipeline and streams, or do you mean you will implement this ?
Comment 82 Nicolas Dufresne (ndufresne) 2015-07-22 05:00:06 UTC
With the latest patch (and the latest basetextoverlay patch, see bug 751157), it's doing the right thing for the non-3D videos. There is a bug that initial negotiation does not see the overlay meta suppport initially. I'll work on that tomorrow.

For 3D support, note that it cannot be done if some combiner is in place. This should already negotiate the textoverlay to render directly. In general, I would not offer the meta if the caps are 3D, so we don't get rushed in figure-out what would be the right thing to do.
Comment 83 Nicolas Dufresne (ndufresne) 2015-07-22 05:01:19 UTC
Also, Matthew, please confirm the shader change from Lubosz reflects your request.
Comment 84 Jan Schmidt 2015-07-22 05:36:46 UTC
(In reply to Nicolas Dufresne (stormer) from comment #81)
> (In reply to Jan Schmidt from comment #79)
> > When rendering out to side-by-side or top-bottom frame packings, if we're
> > blending subpictures, it'll need to be done twice - once for each eye view
> > in the output video. Other frame packings (line-by-line,columns, etc) are
> > probably worse.
> 
> Do you have pipeline and streams, or do you mean you will implement this ?

I'll look for or create a usable stereo stream with a suitable subs track for testing. The only one I have isn't share-able.(In reply to Nicolas Dufresne (stormer) from comment #82)

> With the latest patch (and the latest basetextoverlay patch, see bug
> 751157), it's doing the right thing for the non-3D videos. There is a bug
> that initial negotiation does not see the overlay meta suppport initially.
> I'll work on that tomorrow.
> 
> For 3D support, note that it cannot be done if some combiner is in place.
> This should already negotiate the textoverlay to render directly. In
> general, I would not offer the meta if the caps are 3D, so we don't get
> rushed in figure-out what would be the right thing to do.

Yep - at the moment it gets it horribly wrong there. It'll render over the top of a frame-packed video frame, and then when it gets converted you end up with half the subtitle showing in the wrong place to each eye.
Comment 85 Matthew Waters (ystreet00) 2015-07-22 06:11:03 UTC
Review of attachment 307880 [details] [review]:

Looks good.
Comment 86 Nicolas Dufresne (ndufresne) 2015-07-22 17:28:20 UTC
This address issue 1 and 4.

Attachment 307872 [details] pushed as e8c3161 - glimagesink: Properly handle compsositor life time
Attachment 307880 [details] pushed as b155f5d - gloverlaycompositor: Create own shader object
Attachment 307884 [details] pushed as 1778815 - composition-overlay: Positions are relative to texture
Comment 87 Nicolas Dufresne (ndufresne) 2015-07-22 18:09:52 UTC
This address 2 and 3. I believe the naming isn't a big issue now that it's fully private and hidden from the API.

commit d92375eaaeff98e267c37c0e9c260f276f2c8289
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Wed Jul 22 14:05:34 2015 -0400

    gloverlaycompositor: Hide GstCompsitionOverlay object
    
    This object is only used inside the compositor and does not
    need to be expose in libgstgl API.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745107
Comment 88 Nicolas Dufresne (ndufresne) 2015-07-22 21:10:05 UTC
This fixes concern 5, 6 and 7. And fixes a regression in Lubosz branch when he added meta parameter.

About the 3D stuff, gstglviewconvert, which I believe is needed, does not forward the composition meta, which should lead to textoverlay not attaching it. That's what I expected, please confirm me if I'm wrong. So the bad result is because textoverlay does not support (and does not fail) in presence of 3D view. Sink support for that seems like the step after fixing the software renderer.

About the window pixel-aspect-ratio. It would be a nice to have, but not passing it does not result in bug of any kind. The only side, is that the overlay is being scaled, which arguable is something we try to avoid to produce perfect quality subtitle. I'll file a separate bug for that one.

commit 4f4aedecf37830e95676cfbb407540e654de9527
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Wed Jul 22 16:58:12 2015 -0400

    glupload: Forward composition meta even without params
    
    When the sink does not know the window size (e.g not created yet)
    it will not add any param to the the composition meta. This is no
    reason not to forward this meta API. Fixes issue where it could not
    attach until we resize the window.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745107

commit e310e6d5403d703c241fb1fa84977113cb828651
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Wed Jul 22 15:56:34 2015 -0400

    gloverlaycompositor: Keep memory pointer alive
    
    Keep the composition memory pointer alive while it's being
    wrapped inside a GstGLMemory object.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745107

commit 9c020443e6959b7c710e6de2ddbee36e9e2a3aab
Author: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Date:   Wed Jul 22 14:17:42 2015 -0400

    gloverlaycompositor: Pass buffer stride
    
    The overlay pixel buffer stride was not given back
    to the GL image.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745107