diff --git a/gst-libs/gst/gl/gstglapi.c b/gst-libs/gst/gl/gstglapi.c index c86b398d9e..9b3aefe234 100644 --- a/gst-libs/gst/gl/gstglapi.c +++ b/gst-libs/gst/gl/gstglapi.c @@ -129,3 +129,90 @@ gst_gl_api_from_string (const gchar * apis_s) return ret; } + +/** + * gst_gl_platform_to_string(): + * + * @api: a #GstGLPlatform to stringify + * + * Returns: A space seperated string of the OpenGL platforms enabled in @api + */ +gchar * +gst_gl_platform_to_string (GstGLPlatform platform) +{ + GString *str = NULL; + gchar *ret; + + if (platform == GST_GL_PLATFORM_NONE) { + str = g_string_new ("none"); + goto out; + } else if (platform == GST_GL_PLATFORM_ANY) { + str = g_string_new ("any"); + goto out; + } + + str = g_string_new (""); + + if (platform & GST_GL_PLATFORM_GLX) { + str = g_string_append (str, "glx "); + } + if (platform & GST_GL_PLATFORM_EGL) { + str = g_string_append (str, "egl "); + } + if (platform & GST_GL_PLATFORM_WGL) { + str = g_string_append (str, "wgl "); + } + if (platform & GST_GL_PLATFORM_CGL) { + str = g_string_append (str, "cgl "); + } + +out: + if (!str) + return "unknown"; + + ret = g_string_free (str, FALSE); + return ret; +} + +/** + * gst_gl_platform_from_string(): + * + * @platform_s: a space seperated string of OpenGL platformss + * + * Returns: The #GstGLPlatform represented by @platform_s + */ +GstGLPlatform +gst_gl_platform_from_string (const gchar * platform_s) +{ + GstGLPlatform ret = GST_GL_PLATFORM_NONE; + gchar *platform = (gchar *) platform_s; + + if (!platform || platform[0] == '\0') { + ret = GST_GL_PLATFORM_ANY; + } else { + while (platform) { + if (platform[0] == '\0') { + break; + } else if (platform[0] == ' ' || platform[0] == ',') { + platform = &platform[1]; + } else if (g_strstr_len (platform, 3, "glx")) { + ret |= GST_GL_PLATFORM_GLX; + platform = &platform[3]; + } else if (g_strstr_len (platform, 3, "egl")) { + ret |= GST_GL_PLATFORM_EGL; + platform = &platform[3]; + } else if (g_strstr_len (platform, 3, "wgl")) { + ret |= GST_GL_PLATFORM_WGL; + platform = &platform[3]; + } else if (g_strstr_len (platform, 3, "cgl")) { + ret |= GST_GL_PLATFORM_CGL; + platform = &platform[3]; + } else { + GST_ERROR ("Error parsing \'%s\'", platform); + break; + } + } + } + + return ret; +} diff --git a/gst-libs/gst/gl/gstglapi.h b/gst-libs/gst/gl/gstglapi.h index 6c6fdbb917..ba84958ce9 100644 --- a/gst-libs/gst/gl/gstglapi.h +++ b/gst-libs/gst/gl/gstglapi.h @@ -78,7 +78,7 @@ typedef enum { typedef enum { - GST_GL_PLATFORM_UNKNOWN = 0, + GST_GL_PLATFORM_NONE = 0, GST_GL_PLATFORM_EGL = (1 << 0), GST_GL_PLATFORM_GLX = (1 << 1), GST_GL_PLATFORM_WGL = (1 << 2), @@ -119,6 +119,9 @@ typedef struct _GstGLFuncs gchar * gst_gl_api_to_string (GstGLAPI api); GstGLAPI gst_gl_api_from_string (const gchar * api_s); +gchar * gst_gl_platform_to_string (GstGLPlatform api); +GstGLPlatform gst_gl_platform_from_string (const gchar * platform_s); + G_END_DECLS #endif /* __GST_GL_API_H__ */