[vlc-commits] gl: converters: return a vlc error code from init cbs
Thomas Guillem
git at videolan.org
Thu Jun 22 16:58:30 CEST 2017
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jun 22 11:52:09 2017 +0200| [f60f2576ed5b5798136212ec6e5412bed5b78aad] | committer: Thomas Guillem
gl: converters: return a vlc error code from init cbs
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f60f2576ed5b5798136212ec6e5412bed5b78aad
---
modules/video_output/opengl/converter_android.c | 9 ++--
modules/video_output/opengl/converter_cvpx.c | 13 ++---
modules/video_output/opengl/converter_vaapi.c | 72 +++++++++++--------------
modules/video_output/opengl/converters.c | 24 +++++----
modules/video_output/opengl/internal.h | 16 +++---
modules/video_output/opengl/vout_helper.c | 26 +++++----
6 files changed, 79 insertions(+), 81 deletions(-)
diff --git a/modules/video_output/opengl/converter_android.c b/modules/video_output/opengl/converter_android.c
index 95eea3b305..46bec5462a 100644
--- a/modules/video_output/opengl/converter_android.c
+++ b/modules/video_output/opengl/converter_android.c
@@ -191,16 +191,16 @@ tc_anop_release(const opengl_tex_converter_t *tc)
free(priv);
}
-GLuint
+int
opengl_tex_converter_anop_init(opengl_tex_converter_t *tc)
{
if (tc->fmt.i_chroma != VLC_CODEC_ANDROID_OPAQUE
|| !tc->gl->surface->handle.anativewindow)
- return 0;
+ return VLC_EGENERIC;
tc->priv = malloc(sizeof(struct priv));
if (unlikely(tc->priv == NULL))
- return 0;
+ return VLC_ENOMEM;
struct priv *priv = tc->priv;
priv->awh = tc->gl->surface->handle.anativewindow;
@@ -264,6 +264,7 @@ opengl_tex_converter_anop_init(opengl_tex_converter_t *tc)
GLuint fragment_shader = tc->api->CreateShader(GL_FRAGMENT_SHADER);
tc->api->ShaderSource(fragment_shader, 1, &code, NULL);
tc->api->CompileShader(fragment_shader);
+ tc->fshader = fragment_shader;
- return fragment_shader;
+ return VLC_SUCCESS;
}
diff --git a/modules/video_output/opengl/converter_cvpx.c b/modules/video_output/opengl/converter_cvpx.c
index 0876094015..7864d3f25b 100644
--- a/modules/video_output/opengl/converter_cvpx.c
+++ b/modules/video_output/opengl/converter_cvpx.c
@@ -157,18 +157,18 @@ tc_cvpx_release(const opengl_tex_converter_t *tc)
free(tc->priv);
}
-GLuint
+int
opengl_tex_converter_cvpx_init(opengl_tex_converter_t *tc)
{
if (tc->fmt.i_chroma != VLC_CODEC_CVPX_UYVY
&& tc->fmt.i_chroma != VLC_CODEC_CVPX_NV12
&& tc->fmt.i_chroma != VLC_CODEC_CVPX_I420
&& tc->fmt.i_chroma != VLC_CODEC_CVPX_BGRA)
- return 0;
+ return VLC_EGENERIC;
struct priv *priv = calloc(1, sizeof(struct priv));
if (unlikely(priv == NULL))
- return 0;
+ return VLC_ENOMEM;
#if TARGET_OS_IPHONE
const GLenum tex_target = GL_TEXTURE_2D;
@@ -182,7 +182,7 @@ opengl_tex_converter_cvpx_init(opengl_tex_converter_t *tc)
{
msg_Err(tc->gl, "CVOpenGLESTextureCacheCreate failed: %d", err);
free(priv);
- return 0;
+ return VLC_EGENERIC;
}
}
tc->handle_texs_gen = true;
@@ -232,12 +232,13 @@ opengl_tex_converter_cvpx_init(opengl_tex_converter_t *tc)
if (fragment_shader == 0)
{
free(priv);
- return 0;
+ return VLC_EGENERIC;
}
tc->priv = priv;
tc->pf_update = tc_cvpx_update;
tc->pf_release = tc_cvpx_release;
+ tc->fshader = fragment_shader;
- return fragment_shader;
+ return VLC_SUCCESS;
}
diff --git a/modules/video_output/opengl/converter_vaapi.c b/modules/video_output/opengl/converter_vaapi.c
index 72232f1494..665da25f09 100644
--- a/modules/video_output/opengl/converter_vaapi.c
+++ b/modules/video_output/opengl/converter_vaapi.c
@@ -231,48 +231,58 @@ tc_vaegl_release(const opengl_tex_converter_t *tc)
free(tc->priv);
}
-static GLuint
+static int
tc_vaegl_init(opengl_tex_converter_t *tc, VADisplay *vadpy)
{
if (vadpy == NULL)
- return 0;
- struct priv *priv = tc->priv;
+ return VLC_EGENERIC;
+
+ struct priv *priv = tc->priv = calloc(1, sizeof(struct priv));
+ if (unlikely(tc->priv == NULL))
+ return VLC_ENOMEM;
+
priv->vadpy = vadpy;
priv->fourcc = 0;
if (!HasExtension(tc->glexts, "GL_OES_EGL_image"))
- return 0;
+ goto error;
const char *eglexts = tc->gl->egl.queryString(tc->gl, EGL_EXTENSIONS);
if (eglexts == NULL || !HasExtension(eglexts, "EGL_EXT_image_dma_buf_import"))
- return 0;
+ goto error;
if (vaegl_init_fourcc(tc, priv, VA_FOURCC_NV12))
- return 0;
+ goto error;
priv->glEGLImageTargetTexture2DOES =
vlc_gl_GetProcAddress(tc->gl, "glEGLImageTargetTexture2DOES");
if (priv->glEGLImageTargetTexture2DOES == NULL)
- return 0;
+ goto error;
tc->pf_update = tc_vaegl_update;
tc->pf_release = tc_vaegl_release;
if (vlc_vaapi_Initialize(VLC_OBJECT(tc->gl), priv->vadpy))
- return 0;
+ goto error;
if (vlc_vaapi_SetInstance(priv->vadpy))
{
msg_Err(tc->gl, "VAAPI instance already in use");
- return 0;
+ goto error;
}
- GLuint fshader =
- opengl_fragment_shader_init(tc, GL_TEXTURE_2D, VLC_CODEC_NV12,
- tc->fmt.space);
- if (fshader == 0)
+ tc->fshader = opengl_fragment_shader_init(tc, GL_TEXTURE_2D, VLC_CODEC_NV12,
+ tc->fmt.space);
+ if (tc->fshader == 0)
+ {
vlc_vaapi_ReleaseInstance(priv->vadpy);
- return fshader;
+ goto error;
+ }
+ return VLC_SUCCESS;
+
+error:
+ free(tc->priv);
+ return VLC_EGENERIC;
}
static picture_pool_t *
@@ -290,15 +300,14 @@ tc_va_get_pool(const opengl_tex_converter_t *tc, unsigned requested_count)
return pool;
}
-GLuint
+int
opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc)
{
if (tc->fmt.i_chroma != VLC_CODEC_VAAPI_420 || tc->gl->ext != VLC_GL_EXT_EGL
|| tc->gl->egl.createImageKHR == NULL
|| tc->gl->egl.destroyImageKHR == NULL)
- return 0;
+ return VLC_EGENERIC;
- GLuint fshader = 0;
switch (tc->gl->surface->type)
{
#ifdef HAVE_VA_X11
@@ -310,37 +319,20 @@ opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc)
if (x11dpy == NULL)
return VLC_EGENERIC;
- struct priv *priv = tc->priv = calloc(1, sizeof(struct priv));
- if (unlikely(tc->priv == NULL))
+ if (tc_vaegl_init(tc, vaGetDisplay(x11dpy)))
{
XCloseDisplay(x11dpy);
- return VLC_ENOMEM;
- }
-
- fshader = tc_vaegl_init(tc, vaGetDisplay(x11dpy));
- if (fshader == 0)
- {
- XCloseDisplay(x11dpy);
- free(tc->priv);
- return 0;
+ return VLC_EGENERIC;
}
+ struct priv *priv = tc->priv;
priv->x11dpy = x11dpy;
break;
}
#endif
#ifdef HAVE_VA_WL
case VOUT_WINDOW_TYPE_WAYLAND:
- tc->priv = calloc(1, sizeof(struct priv));
- if (unlikely(tc->priv == NULL))
- return VLC_ENOMEM;
-
- fshader = tc_vaegl_init(tc,
- vaGetDisplayWl(tc->gl->surface->display.wl));
- if (fshader == 0)
- {
- free(tc->priv);
- return 0;
- }
+ if (tc_vaegl_init(tc, vaGetDisplayWl(tc->gl->surface->display.wl)))
+ return VLC_EGENERIC;
break;
#endif
default:
@@ -348,5 +340,5 @@ opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc)
}
tc->pf_get_pool = tc_va_get_pool;
- return fshader;
+ return VLC_SUCCESS;
}
diff --git a/modules/video_output/opengl/converters.c b/modules/video_output/opengl/converters.c
index 1c02152f25..4176899929 100644
--- a/modules/video_output/opengl/converters.c
+++ b/modules/video_output/opengl/converters.c
@@ -1039,14 +1039,14 @@ xyz12_shader_init(opengl_tex_converter_t *tc)
return fragment_shader;
}
-static GLuint
+static int
generic_init(opengl_tex_converter_t *tc, bool allow_dr)
{
const vlc_chroma_description_t *desc =
vlc_fourcc_GetChromaDescription(tc->fmt.i_chroma);
assert(desc);
if (!desc)
- return 0;
+ return VLC_EGENERIC;
GLuint fragment_shader = 0;
if (tc->fmt.i_chroma == VLC_CODEC_XYZ12)
@@ -1061,7 +1061,7 @@ generic_init(opengl_tex_converter_t *tc, bool allow_dr)
GLint max_texture_units = 0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &max_texture_units);
if (max_texture_units < 3)
- return 0;
+ return VLC_EGENERIC;
get_fallback = vlc_fourcc_GetYUVFallback;
space = tc->fmt.space;
@@ -1100,11 +1100,14 @@ generic_init(opengl_tex_converter_t *tc, bool allow_dr)
}
}
if (fragment_shader == 0)
- return 0;
+ return VLC_EGENERIC;
struct priv *priv = tc->priv = calloc(1, sizeof(struct priv));
if (unlikely(priv == NULL))
- goto error;
+ {
+ tc->api->DeleteShader(fragment_shader);
+ return VLC_ENOMEM;
+ }
tc->pf_update = tc_common_update;
tc->pf_release = tc_common_release;
@@ -1156,20 +1159,19 @@ generic_init(opengl_tex_converter_t *tc, bool allow_dr)
priv->has_unpack_subimage = true;
#endif
- return fragment_shader;
-error:
- tc->api->DeleteShader(fragment_shader);
- return 0;
+ tc->fshader = fragment_shader;
+
+ return VLC_SUCCESS;
}
-GLuint
+int
opengl_tex_converter_subpictures_init(opengl_tex_converter_t *tc)
{
tc->fmt.i_chroma = VLC_CODEC_RGB32;
return generic_init(tc, false);
}
-GLuint
+int
opengl_tex_converter_generic_init(opengl_tex_converter_t *tc)
{
return generic_init(tc, true);
diff --git a/modules/video_output/opengl/internal.h b/modules/video_output/opengl/internal.h
index 1a50a11ceb..9d5639a107 100644
--- a/modules/video_output/opengl/internal.h
+++ b/modules/video_output/opengl/internal.h
@@ -164,7 +164,7 @@ typedef struct opengl_tex_converter_t opengl_tex_converter_t;
* \param fc OpenGL tex converter that needs to be filled on success
* \return VLC_SUCCESS or a VLC error
*/
-typedef GLuint (*opengl_tex_converter_init_cb)(opengl_tex_converter_t *fc);
+typedef int (*opengl_tex_converter_init_cb)(opengl_tex_converter_t *fc);
/*
* Structure that is filled by an opengl_tex_converter_init_cb function
@@ -181,6 +181,10 @@ struct opengl_tex_converter_t
/* Can only be changed from the module open function */
video_format_t fmt;
+ /* Fragment shader, must be set from the module open function. It will be
+ * deleted by the caller. */
+ GLuint fshader;
+
/* Number of textures, cannot be 0 */
unsigned tex_count;
@@ -321,24 +325,24 @@ GLuint
opengl_fragment_shader_init(opengl_tex_converter_t *tc, GLenum tex_target,
vlc_fourcc_t chroma, video_color_space_t yuv_space);
-GLuint
+int
opengl_tex_converter_subpictures_init(opengl_tex_converter_t *);
-GLuint
+int
opengl_tex_converter_generic_init(opengl_tex_converter_t *);
#ifdef __ANDROID__
-GLuint
+int
opengl_tex_converter_anop_init(opengl_tex_converter_t *);
#endif
#ifdef VLCGL_CONV_CVPX
-GLuint
+int
opengl_tex_converter_cvpx_init(opengl_tex_converter_t *tc);
#endif
#ifdef VLCGL_CONV_VA
-GLuint
+int
opengl_tex_converter_vaapi_init(opengl_tex_converter_t *tc);
#endif
diff --git a/modules/video_output/opengl/vout_helper.c b/modules/video_output/opengl/vout_helper.c
index 1784a97dde..9bc45fd550 100644
--- a/modules/video_output/opengl/vout_helper.c
+++ b/modules/video_output/opengl/vout_helper.c
@@ -433,17 +433,14 @@ DelTextures(const opengl_tex_converter_t *tc, GLuint *textures)
}
static int
-opengl_link_program(struct prgm *prgm, GLuint fragment_shader)
+opengl_link_program(struct prgm *prgm)
{
- if (fragment_shader == 0)
- return VLC_EGENERIC;
-
opengl_tex_converter_t *tc = &prgm->tc;
- assert(tc->tex_target != 0 && tc->tex_count > 0);
+ assert(tc->fshader != 0 && tc->tex_target != 0 && tc->tex_count > 0);
GLuint vertex_shader = BuildVertexShader(tc, tc->tex_count);
- GLuint shaders[] = { fragment_shader, vertex_shader };
+ GLuint shaders[] = { tc->fshader, vertex_shader };
/* Check shaders messages */
for (unsigned i = 0; i < 2; i++) {
@@ -464,12 +461,12 @@ opengl_link_program(struct prgm *prgm, GLuint fragment_shader)
}
prgm->id = tc->api->CreateProgram();
- tc->api->AttachShader(prgm->id, fragment_shader);
+ tc->api->AttachShader(prgm->id, tc->fshader);
tc->api->AttachShader(prgm->id, vertex_shader);
tc->api->LinkProgram(prgm->id);
tc->api->DeleteShader(vertex_shader);
- tc->api->DeleteShader(fragment_shader);
+ tc->api->DeleteShader(tc->fshader);
/* Check program messages */
int infoLength = 0;
@@ -662,8 +659,9 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
};
/* RGBA is needed for subpictures or for non YUV pictures */
- GLuint fshader = opengl_tex_converter_subpictures_init(&vgl->sub_prgm->tc);
- int ret = opengl_link_program(vgl->sub_prgm, fshader);
+ int ret = opengl_tex_converter_subpictures_init(&vgl->sub_prgm->tc);
+ if (ret == VLC_SUCCESS)
+ ret = opengl_link_program(vgl->sub_prgm);
if (ret != VLC_SUCCESS)
{
msg_Err(gl, "RGBA shader failed");
@@ -680,12 +678,12 @@ vout_display_opengl_t *vout_display_opengl_New(video_format_t *fmt,
.glexts = extensions,
.fmt = *fmt,
};
- fshader = opengl_tex_converter_init_cbs[j](&vgl->prgm->tc);
- ret = opengl_link_program(vgl->prgm, fshader);
+ ret = opengl_tex_converter_init_cbs[j](&vgl->prgm->tc);
+ if (ret == VLC_SUCCESS)
+ ret = opengl_link_program(vgl->prgm);
if (ret == VLC_SUCCESS)
{
- assert(vgl->prgm->tc.tex_target != 0 &&
- vgl->prgm->tc.tex_count > 0 && vgl->prgm->tc.pf_update != NULL &&
+ assert(vgl->prgm->tc.pf_update != NULL &&
vgl->prgm->tc.pf_fetch_locations != NULL &&
vgl->prgm->tc.pf_prepare_shader != NULL);
More information about the vlc-commits
mailing list