2 * test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
4 * gstreamer-vaapi (C) 2010-2011 Splitted-Desktop Systems
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #include <gst/vaapi/gstvaapisurface.h>
23 #include <gst/vaapi/gstvaapisurfacepool.h>
24 #include <gst/vaapi/gstvaapidisplay_x11.h>
26 #define MAX_SURFACES 4
29 gst_vaapi_object_destroy_cb(gpointer object, gpointer user_data)
31 g_print("destroying GstVaapiObject %p\n", object);
35 main(int argc, char *argv[])
37 GstVaapiDisplay *display;
38 GstVaapiSurface *surface;
39 GstVaapiID surface_id;
40 GstVaapiSurface *surfaces[MAX_SURFACES];
41 GstVaapiVideoPool *pool;
45 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
46 static const guint width = 320;
47 static const guint height = 240;
49 gst_init(&argc, &argv);
51 display = gst_vaapi_display_x11_new(NULL);
53 g_error("could not create Gst/VA display");
55 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
57 g_error("could not create Gst/VA surface");
59 /* This also tests for the GstVaapiParamSpecID */
60 g_object_get(G_OBJECT(surface), "id", &surface_id, NULL);
61 if (surface_id != gst_vaapi_surface_get_id(surface))
62 g_error("could not retrieve the native surface ID");
63 g_print("created surface %" GST_VAAPI_ID_FORMAT "\n",
64 GST_VAAPI_ID_ARGS(surface_id));
66 g_object_unref(surface);
68 caps = gst_caps_new_simple(
69 "video/x-vaapi-surface",
70 "width", G_TYPE_INT, width,
71 "height", G_TYPE_INT, height,
75 g_error("cound not create Gst/VA surface caps");
77 pool = gst_vaapi_surface_pool_new(display, caps);
79 g_error("could not create Gst/VA surface pool");
81 for (i = 0; i < MAX_SURFACES; i++) {
82 surface = gst_vaapi_video_pool_get_object(pool);
84 g_error("could not allocate Gst/VA surface from pool");
85 g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
86 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
87 surfaces[i] = surface;
90 /* Check the pool doesn't return the last free'd surface */
91 surface = g_object_ref(surfaces[1]);
93 for (i = 0; i < 2; i++)
94 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
96 for (i = 0; i < 2; i++) {
97 surfaces[i] = gst_vaapi_video_pool_get_object(pool);
99 g_error("could not re-allocate Gst/VA surface%d from pool", i);
100 g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
101 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surfaces[i])));
104 if (surface == surfaces[0])
105 g_error("Gst/VA pool doesn't queue free surfaces");
107 for (i = MAX_SURFACES - 1; i >= 0; i--) {
110 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
117 G_CALLBACK(gst_vaapi_object_destroy_cb), NULL
120 /* Unref in random order to check objects are correctly refcounted */
121 g_print("unref display\n");
122 g_object_unref(display);
123 gst_caps_unref(caps);
124 g_print("unref pool\n");
125 g_object_unref(pool);
126 g_print("unref surface\n");
127 g_object_unref(surface);