mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
gl: add gst_egl_image_check_dmabuf_direct_with_dma_drm()
It internally uses gst_gl_context_egl_get_dma_formats() instead of fetching modifiers by itself. Thus gst_egl_image_check_dmabuf_direct() is a decorator of this new function. Co-authored-by: He Junyan <junyan.he@intel.com> Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4680>
This commit is contained in:
parent
1477ed1ae5
commit
9f7f54174a
2 changed files with 59 additions and 85 deletions
|
@ -696,7 +696,7 @@ gst_egl_image_from_dmabuf (GstGLContext * context,
|
||||||
* @target: a #GstGLTextureTarget
|
* @target: a #GstGLTextureTarget
|
||||||
*
|
*
|
||||||
* Checks whether the video format specified by the given #GstVideoInfo is a
|
* Checks whether the video format specified by the given #GstVideoInfo is a
|
||||||
* supported texture format for the given target.
|
* supported texture format for the given @target.
|
||||||
*
|
*
|
||||||
* Returns: %TRUE if the format is supported.
|
* Returns: %TRUE if the format is supported.
|
||||||
*/
|
*/
|
||||||
|
@ -704,107 +704,76 @@ gboolean
|
||||||
gst_egl_image_check_dmabuf_direct (GstGLContext * context,
|
gst_egl_image_check_dmabuf_direct (GstGLContext * context,
|
||||||
const GstVideoInfo * in_info, GstGLTextureTarget target)
|
const GstVideoInfo * in_info, GstGLTextureTarget target)
|
||||||
{
|
{
|
||||||
EGLDisplay egl_display = EGL_DEFAULT_DISPLAY;
|
GstVideoInfoDmaDrm in_info_dma;
|
||||||
GstGLDisplayEGL *display_egl;
|
|
||||||
EGLint *formats;
|
if (!gst_video_info_dma_drm_from_video_info (&in_info_dma, in_info,
|
||||||
EGLint num_formats;
|
DRM_FORMAT_MOD_LINEAR))
|
||||||
EGLuint64KHR *modifiers;
|
return FALSE;
|
||||||
EGLBoolean *external_only;
|
|
||||||
int num_modifiers;
|
return gst_egl_image_check_dmabuf_direct_with_dma_drm (context, &in_info_dma,
|
||||||
gboolean ret;
|
target);
|
||||||
guint32 fourcc;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_egl_image_check_dmabuf_direct_with_dma_drm:
|
||||||
|
* @context: a #GstGLContext (must be an EGL context)
|
||||||
|
* @in_info_dma: a #GstVideoInfoDmaDrm
|
||||||
|
* @target: a #GstGLTextureTarget
|
||||||
|
*
|
||||||
|
* Checks whether the video format specified by the given #GstVideoInfoDmaDrm is
|
||||||
|
* a supported texture format for the given @target.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the format is supported.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_egl_image_check_dmabuf_direct_with_dma_drm (GstGLContext * context,
|
||||||
|
const GstVideoInfoDmaDrm * in_info_dma, GstGLTextureTarget target)
|
||||||
|
{
|
||||||
|
GstGLDmaModifier *mods, linear_modifier = { 0, FALSE };
|
||||||
|
gsize len;
|
||||||
|
const GArray *modifiers = NULL;
|
||||||
|
gint32 fourcc;
|
||||||
int i;
|
int i;
|
||||||
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
EGLBoolean (*gst_eglQueryDmaBufFormatsEXT) (EGLDisplay dpy,
|
fourcc = in_info_dma->drm_fourcc;
|
||||||
EGLint max_formats, EGLint * formats, EGLint * num_formats);
|
if (fourcc == DRM_FORMAT_INVALID) {
|
||||||
EGLBoolean (*gst_eglQueryDmaBufModifiersEXT) (EGLDisplay dpy,
|
GST_INFO ("Unsupported format for direct DMABuf.");
|
||||||
int format, int max_modifiers, EGLuint64KHR * modifiers,
|
|
||||||
EGLBoolean * external_only, int *num_modifiers);
|
|
||||||
|
|
||||||
fourcc =
|
|
||||||
gst_video_dma_drm_fourcc_from_format (GST_VIDEO_INFO_FORMAT (in_info));
|
|
||||||
if (fourcc == DRM_FORMAT_INVALID)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
gst_eglQueryDmaBufFormatsEXT =
|
|
||||||
gst_gl_context_get_proc_address (context, "eglQueryDmaBufFormatsEXT");
|
|
||||||
gst_eglQueryDmaBufModifiersEXT =
|
|
||||||
gst_gl_context_get_proc_address (context, "eglQueryDmaBufModifiersEXT");
|
|
||||||
|
|
||||||
if (!gst_eglQueryDmaBufFormatsEXT || !gst_eglQueryDmaBufModifiersEXT)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
display_egl = gst_gl_display_egl_from_gl_display (context->display);
|
|
||||||
if (!display_egl) {
|
|
||||||
GST_WARNING_OBJECT (context,
|
|
||||||
"Failed to retrieve GstGLDisplayEGL from %" GST_PTR_FORMAT,
|
|
||||||
context->display);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
egl_display =
|
|
||||||
(EGLDisplay) gst_gl_display_get_handle (GST_GL_DISPLAY (display_egl));
|
|
||||||
gst_object_unref (display_egl);
|
|
||||||
|
|
||||||
ret = gst_eglQueryDmaBufFormatsEXT (egl_display, 0, NULL, &num_formats);
|
|
||||||
if (!ret || num_formats == 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
formats = g_new (EGLint, num_formats);
|
|
||||||
|
|
||||||
ret = gst_eglQueryDmaBufFormatsEXT (egl_display, num_formats, formats,
|
|
||||||
&num_formats);
|
|
||||||
if (!ret || num_formats == 0) {
|
|
||||||
g_free (formats);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < num_formats; i++) {
|
if (!gst_gl_context_egl_get_format_modifiers (context, fourcc, &modifiers)) {
|
||||||
if (formats[i] == fourcc)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_free (formats);
|
|
||||||
if (i == num_formats) {
|
|
||||||
GST_DEBUG ("driver does not support importing fourcc %" GST_FOURCC_FORMAT,
|
GST_DEBUG ("driver does not support importing fourcc %" GST_FOURCC_FORMAT,
|
||||||
GST_FOURCC_ARGS (fourcc));
|
GST_FOURCC_ARGS (fourcc));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gst_eglQueryDmaBufModifiersEXT (egl_display, fourcc, 0, NULL, NULL,
|
if (modifiers) {
|
||||||
&num_modifiers);
|
mods = (GstGLDmaModifier *) modifiers->data;
|
||||||
if (!ret || num_modifiers == 0) {
|
len = modifiers->len;
|
||||||
GST_DEBUG ("driver does not report modifiers for fourcc %"
|
} else {
|
||||||
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
mods = &linear_modifier;
|
||||||
return FALSE;
|
len = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifiers = g_new (EGLuint64KHR, num_modifiers);
|
for (i = 0; i < len; ++i) {
|
||||||
external_only = g_new (EGLBoolean, num_modifiers);
|
GstGLDmaModifier *modifier = &mods[i];
|
||||||
|
if (modifier->modifier == in_info_dma->drm_modifier) {
|
||||||
ret = gst_eglQueryDmaBufModifiersEXT (egl_display, fourcc, num_modifiers,
|
if (modifier->external_only) {
|
||||||
modifiers, external_only, &num_modifiers);
|
|
||||||
if (!ret || num_modifiers == 0) {
|
|
||||||
g_free (modifiers);
|
|
||||||
g_free (external_only);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num_modifiers; ++i) {
|
|
||||||
if (modifiers[i] == DRM_FORMAT_MOD_LINEAR) {
|
|
||||||
if (external_only[i]) {
|
|
||||||
GST_DEBUG ("driver only supports external import of fourcc %"
|
GST_DEBUG ("driver only supports external import of fourcc %"
|
||||||
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
||||||
}
|
}
|
||||||
ret = !external_only[i] || (target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES);
|
ret = !modifier->external_only
|
||||||
g_free (modifiers);
|
|| (target == GST_GL_TEXTURE_TARGET_EXTERNAL_OES);
|
||||||
g_free (external_only);
|
break;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
GST_DEBUG ("driver only supports non-linear import of fourcc %"
|
GST_DEBUG ("driver only supports non-linear import of fourcc %"
|
||||||
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
|
||||||
g_free (modifiers);
|
}
|
||||||
g_free (external_only);
|
return ret;
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,11 @@ gboolean gst_egl_image_check_dmabuf_direct (GstGLContext *
|
||||||
const GstVideoInfo * in_info,
|
const GstVideoInfo * in_info,
|
||||||
GstGLTextureTarget target);
|
GstGLTextureTarget target);
|
||||||
|
|
||||||
|
G_GNUC_INTERNAL
|
||||||
|
gboolean gst_egl_image_check_dmabuf_direct_with_dma_drm
|
||||||
|
(GstGLContext * context,
|
||||||
|
const GstVideoInfoDmaDrm * in_info_dma,
|
||||||
|
GstGLTextureTarget target);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue