tests: add support for render-to-pixmap.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 22 Jul 2013 07:03:30 +0000 (09:03 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 22 Jul 2013 13:45:10 +0000 (15:45 +0200)
Add --pixmap option to test-decode so that to allow copies of VA
surface to an intermediate pixmap and rendering from that pixmap.

Only X11 backends are supported for now.

tests/output.c
tests/output.h
tests/test-decode.c

index 5fa7e5a..6a54f3b 100644 (file)
@@ -29,6 +29,7 @@
 #if USE_X11
 # include <gst/vaapi/gstvaapidisplay_x11.h>
 # include <gst/vaapi/gstvaapiwindow_x11.h>
+# include <gst/vaapi/gstvaapipixmap_x11.h>
 #endif
 #if USE_GLX
 # include <gst/vaapi/gstvaapidisplay_glx.h>
@@ -52,13 +53,15 @@ static const VideoOutputInfo g_video_outputs[] = {
 #if USE_X11
     { "x11",
       gst_vaapi_display_x11_new,
-      gst_vaapi_window_x11_new
+      gst_vaapi_window_x11_new,
+      gst_vaapi_pixmap_x11_new
     },
 #endif
 #if USE_GLX
     { "glx",
       gst_vaapi_display_glx_new,
-      gst_vaapi_window_glx_new
+      gst_vaapi_window_glx_new,
+      gst_vaapi_pixmap_x11_new
     },
 #endif
 #if USE_DRM
@@ -200,3 +203,12 @@ video_output_create_window(GstVaapiDisplay *display, guint width, guint height)
         gst_vaapi_window_set_fullscreen(window, TRUE);
     return window;
 }
+
+GstVaapiPixmap *
+video_output_create_pixmap(GstVaapiDisplay *display, GstVideoFormat format,
+    guint width, guint height)
+{
+    if (!g_video_output || !g_video_output->create_pixmap)
+        return NULL;
+    return g_video_output->create_pixmap(display, format, width, height);
+}
index 3377915..29339c5 100644 (file)
 #include <glib.h>
 #include <gst/vaapi/gstvaapidisplay.h>
 #include <gst/vaapi/gstvaapiwindow.h>
+#include <gst/vaapi/gstvaapipixmap.h>
 
 typedef GstVaapiDisplay *(*CreateDisplayFunc)(const gchar *display_name);
 typedef GstVaapiWindow *(*CreateWindowFunc)(GstVaapiDisplay *display,
                                             guint width, guint height);
+typedef GstVaapiPixmap *(*CreatePixmapFunc)(GstVaapiDisplay *display,
+    GstVideoFormat format, guint width, guint height);
+
 
 typedef struct _VideoOutputInfo VideoOutputInfo;
 struct _VideoOutputInfo {
     const gchar        *name;
     CreateDisplayFunc   create_display;
     CreateWindowFunc    create_window;
+    CreatePixmapFunc    create_pixmap;
 };
 
 gboolean
@@ -52,4 +57,8 @@ video_output_create_display(const gchar *display_name);
 GstVaapiWindow *
 video_output_create_window(GstVaapiDisplay *display, guint width, guint height);
 
+GstVaapiPixmap *
+video_output_create_pixmap(GstVaapiDisplay *display, GstVideoFormat format,
+    guint width, guint height);
+
 #endif /* OUTPUT_H */
index cff7612..8790a6e 100644 (file)
@@ -36,12 +36,17 @@ static inline void pause(void)
 }
 
 static gchar *g_codec_str;
+static gboolean g_use_pixmap;
 
 static GOptionEntry g_options[] = {
     { "codec", 'c',
       0,
       G_OPTION_ARG_STRING, &g_codec_str,
       "codec to test", NULL },
+    { "pixmap", 0,
+      0,
+      G_OPTION_ARG_NONE, &g_use_pixmap,
+      "use render-to-pixmap", NULL },
     { NULL, }
 };
 
@@ -50,6 +55,7 @@ main(int argc, char *argv[])
 {
     GstVaapiDisplay      *display, *display2;
     GstVaapiWindow       *window;
+    GstVaapiPixmap       *pixmap = NULL;
     GstVaapiDecoder      *decoder;
     GstVaapiSurfaceProxy *proxy;
     GstVaapiSurface      *surface;
@@ -96,12 +102,36 @@ main(int argc, char *argv[])
 
     gst_vaapi_window_show(window);
 
-    if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
+    if (g_use_pixmap) {
+        guint width, height;
+
+        if (crop_rect) {
+            width  = crop_rect->width;
+            height = crop_rect->height;
+        }
+        else
+            gst_vaapi_surface_get_size(surface, &width, &height);
+
+        pixmap = video_output_create_pixmap(display, GST_VIDEO_FORMAT_xRGB,
+            width, height);
+        if (!pixmap)
+            g_error("could not create pixmap");
+
+        if (!gst_vaapi_pixmap_put_surface(pixmap, surface, crop_rect,
+                GST_VAAPI_PICTURE_STRUCTURE_FRAME))
+            g_error("could not render to pixmap");
+
+        if (!gst_vaapi_window_put_pixmap(window, pixmap, NULL, NULL))
+            g_error("could not render pixmap");
+    }
+    else if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
             GST_VAAPI_PICTURE_STRUCTURE_FRAME))
         g_error("could not render surface");
 
     pause();
 
+    if (pixmap)
+        gst_vaapi_pixmap_unref(pixmap);
     gst_vaapi_surface_proxy_unref(proxy);
     gst_vaapi_decoder_unref(decoder);
     gst_vaapi_window_unref(window);