Commit graph

160 commits

Author SHA1 Message Date
Matthew Waters 32b71bd48d glcolorconvert: perform better negotiation
1. Correctly describe what we can caps we can transform to/from.
   i.e. no YUV->YUV or GRAY->YUV or YUV->GRAY (except for passthrough).
2. Prefer similar formats and ignore incompatible formats on fixation.
2017-12-09 19:32:16 +00:00
Sebastian Dröge f05da0fef7 glcolorconvert: Caps passed to fixate_caps() are not owned by us and guaranteed to be fixed
So don't try to fixate them, which takes ownership and steals them from
basetransform.

https://bugzilla.gnome.org/show_bug.cgi?id=760696
2017-12-09 19:32:15 +00:00
Alessandro Decina c2a6c97a1d glcolorconvert: try harder to passthrough
This makes a pipeline like:

... ! video/x-raw(memory:GLMemory),format=UYVY ! glcolorconvert !
video/x-raw(memory:GLMemory),format={UYVY, NV12} ! ...

passthrough instead of converting UYVY => NV12. The conversion would happen
before this change since the element (and basetransform) transform the src caps
to format={NV12, UYVY} (since NV12 comes first in the glcolorconvert:src
template) and then the default caps fixate func would fixate to NV12. Blah.

Also there's no need to intersect against the template caps in ::transform_caps
since basetransform does that right after calling the vfunc.
2017-12-09 19:32:14 +00:00
Matthew Waters a0a0e51249 glcolorconvert: implement usage of a buffer pool
Saves unnecessary glGenTextures and glDeleteTextures which may have a
non-trivial cost.
2017-12-09 19:32:14 +00:00
Matthew Waters 86110c4765 glupload: always add texture-target field to GL caps
1. Various elements/base classes only perform a subset check on accept-caps
2. Some GL elements have texture-target in their pad template
3. When checking subsets, only the caps to check are allowed to contain extra
   fields.  If the 'template' caps have extra fields, the subset fails.
Thus without texture-target on the caps, various accept-caps implementations
were failing.

Also, add some convenience functions for setting and retrieving
texture targets to/from GValue.

https://bugzilla.gnome.org/show_bug.cgi?id=759860
2017-12-09 19:32:14 +00:00
Nicolas Dufresne 35075fcb78 glconvert: Fix compilation of GRAY16_LE/BE shader 2017-12-09 19:32:13 +00:00
Matthew Waters 1673a6192f glmemorypbo: remove our own alloc()/wrapped()/etc functions
replaced by equivalent functionality within gst_gl_base_memory_alloc()
2017-12-09 19:32:13 +00:00
Matthew Waters 76a38dd66a glmemory: base classify and add the pbo memory on top
The base class is useful for having multiple backing memory types other
than the default.  e.g. IOSurface, EGLImage, dmabuf?

The PBO transfer logic is now inside GstGLMemoryPBO which uses GstGLBuffer
to manage the PBO memory.

This also moves the format utility functions into their own file.
2017-12-09 19:32:12 +00:00
Matthew Waters 953be21a22 glcolorconvert: improve the YUY2/UYVY->RGBA conversion shader
Don't offset the y-axis.  We only need to offset on the x-axis.

Removes a sawtooth pattern on horizontal and vertical edges.

https://bugzilla.gnome.org/show_bug.cgi?id=755486
2017-12-09 19:32:11 +00:00
Matthew Waters bb7422e91b glcolorconvert: improve RGBA->YUY2/UYVY conversion shader
We should only average the chroma samples not the luma sample.

https://bugzilla.gnome.org/show_bug.cgi?id=758904
2017-12-09 19:32:11 +00:00
Vineeth TM 7b0125ab11 glcolorconvert: remove unnecessary free
version_str is already being freed. So no need to call again

https://bugzilla.gnome.org/show_bug.cgi?id=757974
2017-12-09 19:32:11 +00:00
Vineeth TM 07901d8eed glcolorconvert: Fix string leak
String got using gst_glsl_version_profile_to_string, is allocated
memory and should be freed

https://bugzilla.gnome.org/show_bug.cgi?id=757974
2017-12-09 19:32:11 +00:00
Vineeth TM 1f245c3d2e glcolorconvert: Fix frag_prog and frag_body memory leak
https://bugzilla.gnome.org/show_bug.cgi?id=757974
2017-12-09 19:32:11 +00:00
Matthew Waters b30deff7e1 glcolorconvert: mangle gl_FragColor for GL3
Some drivers don't provide the compatibility definition and we need to provide
our own 'out vec4' variable to put the results of the fragment shader into.

https://bugzilla.gnome.org/show_bug.cgi?id=757938
2017-12-09 19:32:11 +00:00
Matthew Waters 105497de60 glcolorconvert: try to keep the same texture-target if possible
Fixes issues attempting to passthrough external-oes textures
2017-12-09 19:32:10 +00:00
Matthew Waters 46b84c6035 glcolorconvert: fix rendering rectangular textures with GL3
Rectangular textures are unavailable in unextended
GLES2 #version 100 shaders.

Fixes
texture-target=rectangle ! glcolorconvert ! texture-target=2D

There's a couple of differences between GL3 and GLES2/GL

- varying -> in or out depending on the stage (vertex/fragment)
- attribute -> in
- filtered texture access is a single function, texture()
2017-12-09 19:32:10 +00:00
Matthew Waters e32fcfbf3c glcolorconvert: properly use the other texture-target on fixation 2017-12-09 19:32:10 +00:00
Matthew Waters 6a75a07815 glcolorconvert: wait on the sync meta for input buffers 2017-12-09 19:32:10 +00:00
Matthew Waters 2595f73fd0 glcolorconvert: follow the correct texture target names 2017-12-09 19:32:10 +00:00
Matthew Waters 6141d3fc7e glcolorconvert: add support for converting texture targets
Solved with a simple shader templating mechanism and string replacements
of the necessary sampler types/texture accesses and texture coordinate
mangling for rectangular and external-oes textures.
2017-12-09 19:32:10 +00:00
Matthew Waters 681cb5b16d glmemory: add support for rectangle textures
Add the various tokens/strings for the differnet texture types (2D, rect, oes)

Changes the GLmemory api to include the GstGLTextureTarget in all relevant
functions.

Update the relevant caps/templates for 2D only textures.
2017-12-09 19:32:10 +00:00
Matthew Waters ad49a39e5b glcolorconvert: allow outputting multiple textures for gles3 contexts
the USING_GLES2 includes all GLES3 contexts as well which does support
drawing to multiple buffers.  Instead make or decision solely based on
whether glDrawBuffers is available or not.
2017-12-09 19:32:10 +00:00
Matthew Waters 764c4a33bc gl: fix usage of string.h and stdio.h functions without including the headers
e.g:
gstglcontext_egl.c:613:7: error: implicit declaration of function 'strcmp'
[-Werror=implicit-function-declaration]
   if (strcmp (G_MODULE_SUFFIX, "so") == 0)
2017-12-09 19:32:09 +00:00
Matthew Waters bf98930546 gl: sprinkle some debug markers to ease debugging 2017-12-09 19:32:08 +00:00
Matthew Waters 41aeadc36e glcolorconvert: add RGB to NV12/NV21 conversion 2017-12-09 19:32:06 +00:00
Lubosz Sarnecki 26e6be8fad 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.

https://bugzilla.gnome.org/show_bug.cgi?id=745107
2017-12-09 19:32:06 +00:00
Lubosz Sarnecki dc47e6d3c0 glimagesinkbin: Add GstVideoOverlayCompositionMeta caps features
https://bugzilla.gnome.org/show_bug.cgi?id=745107
2017-12-09 19:32:06 +00:00
Julien Isorce 9b1eb32c49 gl: initialize output params to 0 before calling gl functions
The client side API of the Chromium's GPU Process has asserts
in debug mode that check that output params are initialized to 0.
2017-12-09 19:32:05 +00:00
Jan Schmidt 8a1fc4ab4e gl: Add support for multiple views in upload, colour convert and download
Support multiple attached views on input/output buffers
by processing each one, not just the first.
2017-12-09 19:32:04 +00:00
Matthew Waters 1e9f7b6303 gl: consolidate internal_rgba_format into glmemory
Expose some useful value format conversion functions available in
GstGLMemory.
2017-12-09 19:32:03 +00:00
Jan Schmidt 0f6b04c91d gl: Don't leak temp strings in _RGB_pixel_order()
Fix a memory leak of temporary strings when computing
swizzling of RGB formats.
2017-12-09 19:32:03 +00:00
Julien Isorce fce0e0ba3c gl: add and use gst_gl_internal_format_rgba
Previously when compiling GstGL with both GL and GLES2,
GL_RGBA8 was picked from GL/gl.h. But a clash may happen at
runtime when one is selecting GLES2.

gst_gl_internal_format_rgba allows to check at runtime
if it should use GL_RGBA or GL_RGBA8.
2017-12-09 19:32:02 +00:00
Xavier Claessens 80fab54c0a gl: fix crash on windows with intel driver
https://bugzilla.gnome.org/show_bug.cgi?id=749430
2017-12-09 19:32:01 +00:00
Matthew Waters 65c57b77ff gl: element buffers are part of vao state
Use them as such.  They are also required for GL3 core profile support
with glDrawElements on OS X.
2017-12-09 19:32:01 +00:00
Sebastian Dröge 51d3a0a059 Revert "gl: readd glupload/download onto element pads"
This reverts commit 87d8270f30.
2017-12-09 19:32:00 +00:00
Jan Schmidt c2450a28f5 glcolorconvert: Improve passthrough check when no conversion is needed.
Make the passthrough check contingent on only the fields we
can modify being unchanged, and pre-compute it when caps
change instead of checking on each buffer. Makes the passthrough
more lenient if consumers are lax about making input and output
caps complete.
2017-12-09 19:32:00 +00:00
Matthew Waters 343947f383 gl: readd glupload/download onto element pads
Allows insertion of gl elements into non-gl pipelines without converter
(upload/download) elements.

https://bugzilla.gnome.org/show_bug.cgi?id=743974
2017-12-09 19:32:00 +00:00
Sebastian Dröge 659477c7c7 glcolorconvert: Fix last commit 2017-12-09 19:31:59 +00:00
Sebastian Dröge 4a8001e683 gl: Remove iOS/EAGL workaround for R/RG textures
This should be unneeded now after https://bugzilla.gnome.org/show_bug.cgi?id=732507
2017-12-09 19:31:58 +00:00
Sebastian Dröge bd2821982f glcolorconvert: Add correct check for RG/R textures in glcolorconvert too
https://bugzilla.gnome.org/show_bug.cgi?id=732507
2017-12-09 19:31:58 +00:00
Matthew Waters 0b5c7e8b49 gl/docs: update some doc comments 2017-12-09 19:31:58 +00:00
Julien Isorce d6e460095f glcolorconvert: cache indices in a buffer object 2017-12-09 19:31:57 +00:00
Matthew Waters 1d4b82d5f8 glcolorconvert: we don't do resizing of the video frames
As we cannot do accurate texel sampling then due to the texture
coordinates being interpolated based on the output frame size.
2017-12-09 19:31:56 +00:00
Sebastian Dröge cb59ace574 gl: Remove format info in glcolorconvert's transform_caps function instead of on every caller
... and let glmixer actually transform the caps it is supposed to transform
instead of inventing new caps.
2017-12-09 19:31:56 +00:00
Nicolas Dufresne de79830b05 glmemory: Add GstAllocationParams and alignment support
This implements support for GstAllocationParams and memory alignments.
The parameters where simply ignored which could lead to crash on
certain platform when used with libav and no luck.

https://bugzilla.gnome.org/show_bug.cgi?id=744246
2017-12-09 19:31:55 +00:00
Edward Hervey f56c4c541a gl: Add/Update more debug statements
Where possible, use the _OBJECT variants in order to track better from
which object the debug statement is coming from

Define (and use) GST_CAT_DEFAULT where applicable

Use GST_PTR_FORMAT where applicable
2017-12-09 19:31:54 +00:00
Matthew Waters ae14797982 glcolorconvert: don't intersect with the input caps
that limits our formats to whatever is in the input caps
2017-12-09 19:31:54 +00:00
Matthew Waters 68dc0fef6d glcolorconvert: put GstGLSyncMeta on output buffers
allows thread safely using the provided output buffer in a separate
thread
2017-12-09 19:31:54 +00:00
Matthew Waters 530ae2cbb0 glupload/download/convert: provide transform_caps functions
Allows finer grain decisions about formats and features at each
stage of the pipeline.
Also provide propose_allocation for glupload besed on the supported
methods.
2017-12-09 19:31:54 +00:00
Sebastian Dröge 78aaa6b1de glcolorconvert: Add FIXME comment about possibility of non-Apple YCbCr422 rectangular textures 2017-12-09 19:31:53 +00:00
Sebastian Dröge 46086ac1fe glcolorconvert: Only use GL_TEXTURE_RECTANGLE with OpenGL
It's not defined for GLES.
2017-12-09 19:31:53 +00:00
Alessandro Decina 9f1cb84523 libgstgl: run a custom shader to convert YUV to RGB on mac and ios
When GL_APPLE_ycbcr_422 is available, run a custom shader to convert
GL_TEXTURE_RECTANGLE textures from YUV to RGB.

See https://www.opengl.org/registry/specs/APPLE/ycbcr_422.txt
2017-12-09 19:31:53 +00:00
Alessandro Decina 966cad27d7 gl: initial support for texture targets other than GL_TEXTURE_2D
Make GstGLMemory hold the texture target (tex_target) the texture it represents
(tex_id) is bound to. Modify gst_gl_memory_wrapped_texture and
gst_gl_download_perform_with_data to take the texture target as an argument.

This change is needed to support wrapping textures created outside libgstgl,
which might be bound to a target other than GL_TEXTURE_2D. For example on OSX
textures coming from VideoToolbox have target GL_TEXTURE_RECTANGLE.

With this change we still keep (and sometimes imply) GL_TEXTURE_2D as the
target of textures created with libgstgl.

API: modify GstGLMemory
API: modify gst_gl_memory_wrapped_texture
API: gst_gl_download_perform_with_data
2017-12-09 19:31:53 +00:00
Alessandro Decina f31ba88835 gstglcolorconvert: micro optimization
Don't call glClear && glClearColor at each draw since we're going to draw the
whole viewport anyway. Gets rid of a glFlush triggered by glClear on OSX.
2017-12-09 19:31:53 +00:00
Alessandro Decina 5c81a68eb1 gstglcolorconvert: relax caps features check
Require caps to have the GST_CAPS_FEATURE_MEMORY_GL_MEMORY feature but allow
them to have more features.
2017-12-09 19:31:53 +00:00
Matthew Waters 1dfeae2c42 gl: split glcolorconvert usage from glupload
the separation allows the transfer operation to occur in a separate
thread/time which may increase performance in specific circumstances.
2017-12-09 19:31:52 +00:00
Nicola Murino ef987be337 glcolorconvert: fix memleak
https://bugzilla.gnome.org/show_bug.cgi?id=741943
2017-12-09 19:31:52 +00:00
Nicolas Dufresne a1e02726ee gl: Add support for GstVideoAlignment
This allow saving a copy with libav video decoders or decoders with
similar padding requirement.

https://bugzilla.gnome.org/show_bug.cgi?id=740900
2017-12-09 19:31:52 +00:00
Matthew Waters 6bb113f685 gl: add a sync meta for synchronizing across GL contexts
A context can create a GLsync object that can be waited on in order
to ensure that GL resources created in one context are able to be
used in another shared context without any chance of reading invalid
data.

This meta would be placed on buffers that are known to cross from
one context to another.  The receiving element would then wait
on the sync object to ensure that the data to be used is complete.
2017-12-09 19:31:51 +00:00
Matthew Waters b6fc74c9b8 glcolorconvert: add support for gl3 2017-12-09 19:31:50 +00:00
Matthew Waters 86c084f1af glx: ask for a GL3 core context 2017-12-09 19:31:50 +00:00
Sebastian Dröge a6f02d4b29 glcolorconvert: Unref buffer with the correct function 2017-12-09 19:31:50 +00:00
Wang Xin-yu (王昕宇) 45db2931c8 glcolorconvert: support RGB16/BGR16 video format download
https://bugzilla.gnome.org/show_bug.cgi?id=740801
2017-12-09 19:31:50 +00:00
Luis de Bethencourt eabcf66f2f glcolorconvert: fix comments that confuse gtk-doc
GTK-Doc uses a special syntax for code documentation. A multiline comment that
starts with an additional '*' marks a documentation block that will be processed
by the GTK-Doc tools. So GTK-Doc is confused if a comment block starts with that
additional '*' but isn't meant to be processed. Removing this additional '*'.

https://bugzilla.gnome.org/show_bug.cgi?id=739444
2017-12-09 19:31:49 +00:00
Wang Xin-yu (王昕宇) 77682a51e6 glcolorconvert: support RGB16/BGR16 video format upload
https://bugzilla.gnome.org/show_bug.cgi?id=738842
2017-12-09 19:31:48 +00:00
Matthew Waters 3439402164 glcolorconvert: output why we cannot convert a buffer 2017-12-09 19:31:48 +00:00
Matthew Waters df6967c274 glcolorconvert: fix planar YUV download
- sample the u and v planes properly
- output the correctly scaled u and v planes for different chroma block sizes
2017-12-09 19:31:48 +00:00
Matthew Waters a771b40474 glcolorconvert: fix UYVY download green screen 2017-12-09 19:31:47 +00:00
Matthew Waters ea711807d8 glcolrconvert: fix YUY2 download
- The shader was outputing the wrong values compared with raw
  videotestsrc.
- deal with the texture edge properly.
- properly sample the 2x1 rectangle for the u and v values
- don't double sample the y value
2017-12-09 19:31:47 +00:00
Matthew Waters e6bd70d580 glcolorconvert: convert xRGB into ARGB properly
The alpha channel might not be the last component so check which one
it is in and clobber that one instead.
2017-12-09 19:31:47 +00:00
Matthew Waters c216799b20 glmemory: use GstVideoInfo everywhere
Simplifies a lot of the calling code

https://bugzilla.gnome.org/show_bug.cgi?id=733717
2017-12-09 19:31:45 +00:00
Matthew Waters 2b82b78ef5 glmemory: reenable the texture_rg support for !eagl
The GST_GL_HAVE_PLATFORM_EAGL is always defined we need to compare
against the value instead.
2017-12-09 19:31:44 +00:00
Wang Xin-yu (王昕宇) 2ce11e4bac gl: fix multi gl object leaks
1. fix FBO leaks in decide_allocation
2. fix texture leaks in decide_allocation and reset
3. fix texture leaks in FBO incomplete error path
2017-12-09 19:31:44 +00:00
Sebastian Dröge f6ae4ab243 eagl: Disable usage of R and RG textures on iOS
They don't work currently and just render zeroes, while the
fallback code path with LUM and LUM_ALPHA textures still works.

https://bugzilla.gnome.org/show_bug.cgi?id=732390
2017-12-09 19:31:44 +00:00
Matthew Waters 216b5ec9a8 glcolorconvert: free pixel swizzling information 2017-12-09 19:31:44 +00:00
Matthew Waters 4a8b31afd6 glfeature: remove GST_GL_API_GLES3
instead check the gl version using gst_gl_context_check_gl_version()
2017-12-09 19:31:42 +00:00
Matthew Waters 5009338a50 gl/colorconvert: keep our private pointer
again, avoid to much trigger
2017-12-09 19:31:42 +00:00
Matthew Waters 04b2144ff1 gl/colorconvert: use GstObject's lock instead of our own 2017-12-09 19:31:42 +00:00
Matthew Waters 1544f66f26 gl/colorconvert: remove unnecassary pointer inderection 2017-12-09 19:31:42 +00:00
Matthew Waters 8cf3a3a4f4 gl/colorconvert: optimise the same format case
simply return the input buffer unchanged
2017-12-09 19:31:41 +00:00
Matthew Waters 4fe67d48be gl/colorconvert: fix YUY2/UYVY download for RG/LA textures 2017-12-09 19:31:41 +00:00
Matthew Waters 8ac92cd90d gl/colorconvert: allocate output buffers
Allows the nop optimisation by simply reffing the input buffer.
2017-12-09 19:31:41 +00:00
Tim-Philipp Müller 06351d4d9b glcolorconvert: fix compiler warning
gstglcolorconvert.c:1133:11: error: 'j' may be used uninitialized in this function

Was used uninitialized when jumping to out label
in error case.
2017-12-09 19:31:41 +00:00
Matthew Waters 625efc1757 gl/colorconvert: operate on buffers instead of memories 2017-12-09 19:31:41 +00:00
Nicolas Dufresne 73c73470a0 glcolorconvert: Fix YUY2 and UYVY support with luminance_alpha
https://bugzilla.gnome.org/show_bug.cgi?id=730666
2017-12-09 19:31:41 +00:00
Matthew Waters 2279713aa0 gl/colorconvert: remove scratch texture for YUY2/UYVY
We can get all our data from the one RG/LA texture with some shader magic.

https://bugzilla.gnome.org/show_bug.cgi?id=728890
2017-12-09 19:31:41 +00:00
Matthew Waters 132a233f7b gl/memory: implement GL_EXT_texture_rg support
Which is used by default over the Luminance formats due to it
being color renderable with fbos (and deprecation/removal with
GL 3.x).

https://bugzilla.gnome.org/show_bug.cgi?id=729750
https://bugzilla.gnome.org/show_bug.cgi?id=704222
https://bugzilla.gnome.org/show_bug.cgi?id=728890
2017-12-09 19:31:41 +00:00
Matthew Waters 313dfbb500 gl/upload: switch the 'master' texture for YUY2, UYVY
From d4bcef3204 on, using a RGBA
texture to hold the data causes the glmemory to have half width
and a scaling of [2, 1].  Using a LA texture solves this problem
however cannot be attached to the framebuffer for copying into
a RGBA texture.  Which will be solved by moving to EXT_texture_rg.

https://bugzilla.gnome.org/show_bug.cgi?id=728890
2017-12-09 19:31:41 +00:00
Matthew Waters 5efb69304a gl/colorconvert: fix up alpha clobbering
Previously it would only work if the alpha value was in the last
component (RGBx, BGRx).  Now it works wherever the alpha value may
be (xRGB, xBGR, etc).
2017-12-09 19:31:40 +00:00
Matthew Waters 07b6bfeaa7 gl/colorconvert: use the texture scaling from the gl memory
The colorconvert values were not being used at all.

https://bugzilla.gnome.org/show_bug.cgi?id=729896
2017-12-09 19:31:40 +00:00
Matthew Waters 480784e368 gl/convert: clobber alpha channel when needed
Needed in the conversion from padded RGB formats to formats with an
alpha channel.  e.g. BGRx -> ABGR, etc

https://bugzilla.gnome.org/show_bug.cgi?id=729742
2017-12-09 19:31:40 +00:00
Matthew Waters ae283ec9da gl/colorconvert: choose the right alpha component for AYUV -> RGBA 2017-12-09 19:31:40 +00:00
Nicolas Dufresne 5c8acc21fe gl: Fix some of the error handling 2017-12-09 19:31:40 +00:00
Matthew Waters f213321083 gl/colorconvert: preserve alpha in AYUV <-> RGBA conversions
https://bugzilla.gnome.org/show_bug.cgi?id=729743
2017-12-09 19:31:40 +00:00
Matthew Waters 977c326c59 gl/colorconvert: implement lazy init 2017-12-09 19:31:40 +00:00
Matthew Waters 857200ff40 gl: make all GObjects inherit from GstObject
Aids memory leak debugging with GST_TRACE=mem-live
2017-12-09 19:31:39 +00:00
Julien Isorce 4b0e037fa4 gl: use gst_gl_context_gen_shader helper instead of duplicating code 2017-12-09 19:31:39 +00:00
Matthew Waters 33091ff6a5 gl/mem: implement texture copying between formats with strides properly
Previously, we used the width to determine the amount of data to be
copied using pbos.  This, makes it allocate enough data for the
the strides as well.
2017-12-09 19:31:38 +00:00
Julien Isorce 959aae65c0 gl: fix string literal warning
warning: format not a string literal, argument types not checked [-Wformat-nonliteral]
2017-12-09 19:31:38 +00:00
Jan Schmidt c891eedb79 glcolorconvert: Fix bt709 conversion matrices.
Fix the sign on one entry in the bt.709 YUV->RGB conversion
matrix, and the corresponding inverse matrix. Fixes really
wrong colouring of some videos.
2017-12-09 19:31:37 +00:00