2
* test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
4
* Copyright (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
GST_VAAPI_SURFACE_CAPS_NAME,
70
"type", G_TYPE_STRING, "vaapi",
71
"width", G_TYPE_INT, width,
72
"height", G_TYPE_INT, height,
76
g_error("cound not create Gst/VA surface caps");
78
pool = gst_vaapi_surface_pool_new(display, caps);
80
g_error("could not create Gst/VA surface pool");
82
for (i = 0; i < MAX_SURFACES; i++) {
83
surface = gst_vaapi_video_pool_get_object(pool);
85
g_error("could not allocate Gst/VA surface from pool");
86
g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
87
GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surface)));
88
surfaces[i] = surface;
91
/* Check the pool doesn't return the last free'd surface */
92
surface = g_object_ref(surfaces[1]);
94
for (i = 0; i < 2; i++)
95
gst_vaapi_video_pool_put_object(pool, surfaces[i]);
97
for (i = 0; i < 2; i++) {
98
surfaces[i] = gst_vaapi_video_pool_get_object(pool);
100
g_error("could not re-allocate Gst/VA surface%d from pool", i);
101
g_print("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
102
GST_VAAPI_ID_ARGS(gst_vaapi_surface_get_id(surfaces[i])));
105
if (surface == surfaces[0])
106
g_error("Gst/VA pool doesn't queue free surfaces");
108
for (i = MAX_SURFACES - 1; i >= 0; i--) {
111
gst_vaapi_video_pool_put_object(pool, surfaces[i]);
118
G_CALLBACK(gst_vaapi_object_destroy_cb), NULL
121
/* Unref in random order to check objects are correctly refcounted */
122
g_print("unref display\n");
123
g_object_unref(display);
124
gst_caps_unref(caps);
125
g_print("unref pool\n");
126
g_object_unref(pool);
127
g_print("unref surface\n");
128
g_object_unref(surface);