2 * test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2012-2013 Intel Corporation
7 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA
25 #include <gst/vaapi/gstvaapisurface.h>
26 #include <gst/vaapi/gstvaapisurfacepool.h>
29 #define MAX_SURFACES 4
32 main(int argc, char *argv[])
34 GstVaapiDisplay *display;
35 GstVaapiSurface *surface;
36 GstVaapiID surface_id;
37 GstVaapiSurface *surfaces[MAX_SURFACES];
38 GstVaapiVideoPool *pool;
42 static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
43 static const guint width = 320;
44 static const guint height = 240;
46 if (!video_output_init(&argc, argv, NULL))
47 g_error("failed to initialize video output subsystem");
49 display = video_output_create_display(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");
57 surface_id = gst_vaapi_surface_get_id(surface);
58 g_print("created surface %" GST_VAAPI_ID_FORMAT "\n",
59 GST_VAAPI_ID_ARGS(surface_id));
61 gst_vaapi_object_unref(surface);
63 gst_video_info_set_format(&vi, GST_VIDEO_FORMAT_ENCODED, width, height);
65 pool = gst_vaapi_surface_pool_new(display, &vi);
67 g_error("could not create Gst/VA surface pool");
69 for (i = 0; i < MAX_SURFACES; i++) {
70 surface = gst_vaapi_video_pool_get_object(pool);
72 g_error("could not allocate Gst/VA surface from pool");
73 g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
74 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
75 surfaces[i] = surface;
78 /* Check the pool doesn't return the last free'd surface */
79 surface = gst_vaapi_object_ref(surfaces[1]);
81 for (i = 0; i < 2; i++)
82 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
84 for (i = 0; i < 2; i++) {
85 surfaces[i] = gst_vaapi_video_pool_get_object(pool);
87 g_error("could not re-allocate Gst/VA surface%d from pool", i);
88 g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
89 GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surfaces[i])));
92 if (surface == surfaces[0])
93 g_error("Gst/VA pool doesn't queue free surfaces");
95 for (i = MAX_SURFACES - 1; i >= 0; i--) {
98 gst_vaapi_video_pool_put_object(pool, surfaces[i]);
102 /* Unref in random order to check objects are correctly refcounted */
103 gst_vaapi_display_unref(display);
104 gst_vaapi_video_pool_unref(pool);
105 gst_vaapi_object_unref(surface);