2 * test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2012 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
23 #include <gst/vaapi/gstvaapisurface.h>
24 #include <gst/vaapi/gstvaapisurfacepool.h>
27 #define MAX_SURFACES 4
30 main(int argc, char *argv[])
32 GstVaapiDisplay *display;
33 GstVaapiSurface *surface;
34 GstVaapiID surface_id;
35 GstVaapiSurface *surfaces[MAX_SURFACES];
36 GstVaapiVideoPool *pool;
40 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
41 static const guint width = 320;
42 static const guint height = 240;
44 if (!video_output_init(&argc, argv, NULL))
45 g_error("failed to initialize video output subsystem");
47 display = video_output_create_display(NULL);
49 g_error("could not create Gst/VA display");
51 surface = gst_vaapi_surface_new(display, chroma_type, width, height);
53 g_error("could not create Gst/VA surface");
55 surface_id = gst_vaapi_surface_get_id(surface);
56 g_print("created surface %" GST_VAAPI_ID_FORMAT "\n",
57 GST_VAAPI_ID_ARGS(surface_id));
59 gst_vaapi_object_unref(surface);
61 gst_video_info_set_format(&vi, GST_VIDEO_FORMAT_ENCODED, width, height);
63 pool = gst_vaapi_surface_pool_new(display, &vi);
65 g_error("could not create Gst/VA surface pool");
67 for (i = 0; i < MAX_SURFACES; i++) {
68 surface = gst_vaapi_video_pool_get_object(pool);
70 g_error("could not allocate Gst/VA surface from pool");
71 g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
72 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
73 surfaces[i] = surface;
76 /* Check the pool doesn't return the last free'd surface */
77 surface = gst_vaapi_object_ref(surfaces[1]);
79 for (i = 0; i < 2; i++)
80 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
82 for (i = 0; i < 2; i++) {
83 surfaces[i] = gst_vaapi_video_pool_get_object(pool);
85 g_error("could not re-allocate Gst/VA surface%d from pool", i);
86 g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
87 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surfaces[i])));
90 if (surface == surfaces[0])
91 g_error("Gst/VA pool doesn't queue free surfaces");
93 for (i = MAX_SURFACES - 1; i >= 0; i--) {
96 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
100 /* Unref in random order to check objects are correctly refcounted */
101 gst_vaapi_display_unref(display);
102 gst_vaapi_video_pool_unref(pool);
103 gst_vaapi_object_unref(surface);