display: validate display types.

This commit is contained in:
Gwenole Beauchesne 2013-05-27 17:18:40 +02:00
parent b40cd3b382
commit b1e5dfab96
13 changed files with 49 additions and 8 deletions

View file

@ -391,7 +391,7 @@ gst_vaapi_display_drm_new_with_device(gint device)
gint gint
gst_vaapi_display_drm_get_device(GstVaapiDisplayDRM *display) gst_vaapi_display_drm_get_device(GstVaapiDisplayDRM *display)
{ {
g_return_val_if_fail(display != NULL, -1); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_DRM(display), -1);
return GST_VAAPI_DISPLAY_DRM_DEVICE(display); return GST_VAAPI_DISPLAY_DRM_DEVICE(display);
} }
@ -412,7 +412,7 @@ gst_vaapi_display_drm_get_device(GstVaapiDisplayDRM *display)
const gchar * const gchar *
gst_vaapi_display_drm_get_device_path(GstVaapiDisplayDRM *display) gst_vaapi_display_drm_get_device_path(GstVaapiDisplayDRM *display)
{ {
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_DRM(display), NULL);
return get_device_path(GST_VAAPI_DISPLAY_CAST(display)); return get_device_path(GST_VAAPI_DISPLAY_CAST(display));
} }

View file

@ -23,9 +23,14 @@
#define GST_VAAPI_DISPLAY_DRM_PRIV_H #define GST_VAAPI_DISPLAY_DRM_PRIV_H
#include <gst/vaapi/gstvaapidisplay_drm.h> #include <gst/vaapi/gstvaapidisplay_drm.h>
#include "gstvaapidisplay_priv.h"
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_IS_DISPLAY_DRM(display) \
((display) != NULL && \
GST_VAAPI_DISPLAY_TYPE(display) == GST_VAAPI_DISPLAY_TYPE_DRM)
#define GST_VAAPI_DISPLAY_DRM_CAST(display) \ #define GST_VAAPI_DISPLAY_DRM_CAST(display) \
((GstVaapiDisplayDRM *)(display)) ((GstVaapiDisplayDRM *)(display))

View file

@ -28,6 +28,10 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_IS_DISPLAY_GLX(display) \
((display) != NULL && \
GST_VAAPI_DISPLAY_TYPE(display) == GST_VAAPI_DISPLAY_TYPE_GLX)
#define GST_VAAPI_DISPLAY_GLX_CAST(display) \ #define GST_VAAPI_DISPLAY_GLX_CAST(display) \
((GstVaapiDisplayGLX *)(display)) ((GstVaapiDisplayGLX *)(display))

View file

@ -96,6 +96,16 @@ typedef void (*GstVaapiDisplayGetSizeMFunc)(GstVaapiDisplay *display,
#define GST_VAAPI_DISPLAY_UNLOCK(display) \ #define GST_VAAPI_DISPLAY_UNLOCK(display) \
gst_vaapi_display_unlock(GST_VAAPI_DISPLAY_CAST(display)) gst_vaapi_display_unlock(GST_VAAPI_DISPLAY_CAST(display))
/**
* GST_VAAPI_DISPLAY_TYPE:
* @display: a #GstVaapiDisplay
*
* Returns the @display type
*/
#undef GST_VAAPI_DISPLAY_TYPE
#define GST_VAAPI_DISPLAY_TYPE(display) \
GST_VAAPI_DISPLAY_GET_PRIVATE(display)->display_type
/** /**
* GST_VAAPI_DISPLAY_TYPES: * GST_VAAPI_DISPLAY_TYPES:
* @display: a #GstVaapiDisplay * @display: a #GstVaapiDisplay

View file

@ -420,7 +420,7 @@ gst_vaapi_display_wayland_new_with_display(struct wl_display *wl_display)
struct wl_display * struct wl_display *
gst_vaapi_display_wayland_get_display(GstVaapiDisplayWayland *display) gst_vaapi_display_wayland_get_display(GstVaapiDisplayWayland *display)
{ {
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_WAYLAND(display), NULL);
return GST_VAAPI_DISPLAY_WL_DISPLAY(display); return GST_VAAPI_DISPLAY_WL_DISPLAY(display);
} }

View file

@ -27,6 +27,10 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_IS_DISPLAY_WAYLAND(display) \
((display) != NULL && \
GST_VAAPI_DISPLAY_TYPE(display) == GST_VAAPI_DISPLAY_TYPE_WAYLAND)
#define GST_VAAPI_DISPLAY_WAYLAND_CAST(display) \ #define GST_VAAPI_DISPLAY_WAYLAND_CAST(display) \
((GstVaapiDisplayWayland *)(display)) ((GstVaapiDisplayWayland *)(display))

View file

@ -436,7 +436,7 @@ gst_vaapi_display_x11_new_with_display(Display *x11_display)
Display * Display *
gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display) gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
{ {
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
return GST_VAAPI_DISPLAY_XDISPLAY(display); return GST_VAAPI_DISPLAY_XDISPLAY(display);
} }
@ -454,7 +454,7 @@ gst_vaapi_display_x11_get_display(GstVaapiDisplayX11 *display)
int int
gst_vaapi_display_x11_get_screen(GstVaapiDisplayX11 *display) gst_vaapi_display_x11_get_screen(GstVaapiDisplayX11 *display)
{ {
g_return_val_if_fail(display != NULL, -1); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), -1);
return GST_VAAPI_DISPLAY_XSCREEN(display); return GST_VAAPI_DISPLAY_XSCREEN(display);
} }
@ -474,7 +474,7 @@ void
gst_vaapi_display_x11_set_synchronous(GstVaapiDisplayX11 *display, gst_vaapi_display_x11_set_synchronous(GstVaapiDisplayX11 *display,
gboolean synchronous) gboolean synchronous)
{ {
g_return_if_fail(display != NULL); g_return_if_fail(GST_VAAPI_IS_DISPLAY_X11(display));
set_synchronous(display, synchronous); set_synchronous(display, synchronous);
} }

View file

@ -29,6 +29,11 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define GST_VAAPI_IS_DISPLAY_X11(display) \
((display) != NULL && \
(GST_VAAPI_DISPLAY_TYPE(display) == GST_VAAPI_DISPLAY_TYPE_X11 || \
GST_VAAPI_DISPLAY_TYPE(display) == GST_VAAPI_DISPLAY_TYPE_GLX))
#define GST_VAAPI_DISPLAY_X11_CAST(display) \ #define GST_VAAPI_DISPLAY_X11_CAST(display) \
((GstVaapiDisplayX11 *)(display)) ((GstVaapiDisplayX11 *)(display))

View file

@ -32,6 +32,7 @@
#include "gstvaapiutils_glx.h" #include "gstvaapiutils_glx.h"
#include "gstvaapidisplay_glx.h" #include "gstvaapidisplay_glx.h"
#include "gstvaapidisplay_x11_priv.h" #include "gstvaapidisplay_x11_priv.h"
#include "gstvaapidisplay_glx_priv.h"
#include "gstvaapiobject_priv.h" #include "gstvaapiobject_priv.h"
#define DEBUG 1 #define DEBUG 1
@ -245,7 +246,7 @@ gst_vaapi_texture_new(
{ {
GstVaapiTexture *texture; GstVaapiTexture *texture;
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_GLX(display), NULL);
g_return_val_if_fail(target != GL_NONE, NULL); g_return_val_if_fail(target != GL_NONE, NULL);
g_return_val_if_fail(format != GL_NONE, NULL); g_return_val_if_fail(format != GL_NONE, NULL);
g_return_val_if_fail(width > 0, NULL); g_return_val_if_fail(width > 0, NULL);
@ -297,7 +298,7 @@ gst_vaapi_texture_new_with_texture(
GLTextureState ts; GLTextureState ts;
gboolean success; gboolean success;
g_return_val_if_fail(display != NULL, NULL); g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_GLX(display), NULL);
g_return_val_if_fail(target != GL_NONE, NULL); g_return_val_if_fail(target != GL_NONE, NULL);
g_return_val_if_fail(format != GL_NONE, NULL); g_return_val_if_fail(format != GL_NONE, NULL);

View file

@ -27,6 +27,7 @@
#include "sysdeps.h" #include "sysdeps.h"
#include "gstvaapiwindow_drm.h" #include "gstvaapiwindow_drm.h"
#include "gstvaapiwindow_priv.h" #include "gstvaapiwindow_priv.h"
#include "gstvaapidisplay_drm_priv.h"
#define DEBUG 1 #define DEBUG 1
#include "gstvaapidebug.h" #include "gstvaapidebug.h"
@ -147,6 +148,8 @@ gst_vaapi_window_drm_new(
{ {
GST_DEBUG("new window, size %ux%u", width, height); GST_DEBUG("new window, size %ux%u", width, height);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_DRM(display), NULL);
return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS( return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS(
gst_vaapi_window_drm_class()), display, width, height); gst_vaapi_window_drm_class()), display, width, height);
} }

View file

@ -30,6 +30,7 @@
#include "gstvaapiwindow_x11_priv.h" #include "gstvaapiwindow_x11_priv.h"
#include "gstvaapidisplay_x11.h" #include "gstvaapidisplay_x11.h"
#include "gstvaapidisplay_x11_priv.h" #include "gstvaapidisplay_x11_priv.h"
#include "gstvaapidisplay_glx_priv.h"
#include "gstvaapiutils_x11.h" #include "gstvaapiutils_x11.h"
#include "gstvaapiutils_glx.h" #include "gstvaapiutils_glx.h"
@ -362,6 +363,8 @@ GST_VAAPI_OBJECT_DEFINE_CLASS_WITH_CODE(
GstVaapiWindow * GstVaapiWindow *
gst_vaapi_window_glx_new(GstVaapiDisplay *display, guint width, guint height) gst_vaapi_window_glx_new(GstVaapiDisplay *display, guint width, guint height)
{ {
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_GLX(display), NULL);
return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS( return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS(
gst_vaapi_window_glx_class()), display, width, height); gst_vaapi_window_glx_class()), display, width, height);
} }
@ -383,6 +386,7 @@ gst_vaapi_window_glx_new_with_xid(GstVaapiDisplay *display, Window xid)
{ {
GST_DEBUG("new window from xid 0x%08x", xid); GST_DEBUG("new window from xid 0x%08x", xid);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_GLX(display), NULL);
g_return_val_if_fail(xid != None, NULL); g_return_val_if_fail(xid != None, NULL);
return gst_vaapi_window_new_from_native(GST_VAAPI_WINDOW_CLASS( return gst_vaapi_window_new_from_native(GST_VAAPI_WINDOW_CLASS(

View file

@ -411,6 +411,8 @@ gst_vaapi_window_wayland_new(
{ {
GST_DEBUG("new window, size %ux%u", width, height); GST_DEBUG("new window, size %ux%u", width, height);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_WAYLAND(display), NULL);
return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS( return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS(
gst_vaapi_window_wayland_class()), display, width, height); gst_vaapi_window_wayland_class()), display, width, height);
} }

View file

@ -479,6 +479,8 @@ gst_vaapi_window_x11_new(GstVaapiDisplay *display, guint width, guint height)
{ {
GST_DEBUG("new window, size %ux%u", width, height); GST_DEBUG("new window, size %ux%u", width, height);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS( return gst_vaapi_window_new(GST_VAAPI_WINDOW_CLASS(
gst_vaapi_window_x11_class()), display, width, height); gst_vaapi_window_x11_class()), display, width, height);
} }
@ -500,6 +502,7 @@ gst_vaapi_window_x11_new_with_xid(GstVaapiDisplay *display, Window xid)
{ {
GST_DEBUG("new window from xid 0x%08x", xid); GST_DEBUG("new window from xid 0x%08x", xid);
g_return_val_if_fail(GST_VAAPI_IS_DISPLAY_X11(display), NULL);
g_return_val_if_fail(xid != None, NULL); g_return_val_if_fail(xid != None, NULL);
return gst_vaapi_window_new_from_native(GST_VAAPI_WINDOW_CLASS( return gst_vaapi_window_new_from_native(GST_VAAPI_WINDOW_CLASS(