2 * test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
4 * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <gst/vaapi/gstvaapisurface.h>
22 #include <gst/vaapi/gstvaapisurfacepool.h>
23 #include <gst/vaapi/gstvaapidisplay_x11.h>
25 #define MAX_SURFACES 4
28 gst_vaapi_object_destroy_cb(gpointer object, gpointer user_data)
30 g_print("Destroying GstVaapiObject %p\n", object);
34 main(int argc, char *argv[])
36 GstVaapiDisplay *display;
37 GstVaapiSurface *surface;
38 GstVaapiSurface *surfaces[MAX_SURFACES];
39 GstVaapiVideoPool *pool;
43 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
44 static const guint width = 320;
45 static const guint height = 240;
47 gst_init(&argc, &argv);
49 display = gst_vaapi_display_x11_new(NULL);
51 g_error("could not create Gst/VA display");
53 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
55 g_error("could not create Gst/VA surface");
56 g_object_unref(surface);
58 caps = gst_caps_new_simple(
59 "video/x-vaapi-surface",
60 "width", G_TYPE_INT, width,
61 "height", G_TYPE_INT, height,
65 g_error("cound not create Gst/VA surface caps");
67 pool = gst_vaapi_surface_pool_new(display, caps);
69 g_error("could not create Gst/VA surface pool");
71 for (i = 0; i < MAX_SURFACES; i++) {
72 surface = gst_vaapi_video_pool_get_object(pool);
74 g_error("could not allocate Gst/VA surface from pool");
75 g_print("created surface 0x%08x from pool\n",
76 gst_vaapi_surface_get_id(surface));
77 surfaces[i] = surface;
80 /* Check the pool doesn't return the last free'd surface */
81 surface = g_object_ref(surfaces[1]);
83 for (i = 0; i < 2; i++)
84 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
86 for (i = 0; i < 2; i++) {
87 surfaces[i] = gst_vaapi_video_pool_get_object(pool);
89 g_error("could not re-allocate Gst/VA surface%d from pool", i);
90 g_print("created surface 0x%08x from pool (realloc)\n",
91 gst_vaapi_surface_get_id(surfaces[i]));
94 if (surface == surfaces[0])
95 g_error("Gst/VA pool doesn't queue free surfaces");
97 for (i = MAX_SURFACES - 1; i >= 0; i--) {
100 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
107 G_CALLBACK(gst_vaapi_object_destroy_cb), NULL
110 /* Unref in random order to check objects are correctly refcounted */
111 g_print("unref display\n");
112 g_object_unref(display);
113 gst_caps_unref(caps);
114 g_print("unref pool\n");
115 g_object_unref(pool);
116 g_print("unref surface\n");
117 g_object_unref(surface);