2010-03-12 23:50:09 +00:00
|
|
|
/*
|
|
|
|
* test-surfaces.c - Test GstVaapiSurface and GstVaapiSurfacePool
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2013-11-22 05:37:12 +00:00
|
|
|
* Copyright (C) 2012-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-03-12 23:50:09 +00:00
|
|
|
*
|
2011-10-18 07:18:20 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-03-12 23:50:09 +00:00
|
|
|
*
|
2011-10-18 07:18:20 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-12 23:50:09 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-10-18 07:18:20 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-12 23:50:09 +00:00
|
|
|
*
|
2011-10-18 07:18:20 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-03-12 23:50:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gst/vaapi/gstvaapisurface.h>
|
|
|
|
#include <gst/vaapi/gstvaapisurfacepool.h>
|
2012-07-23 13:17:03 +00:00
|
|
|
#include "output.h"
|
2010-03-12 23:50:09 +00:00
|
|
|
|
|
|
|
#define MAX_SURFACES 4
|
|
|
|
|
|
|
|
int
|
2016-04-29 10:48:44 +00:00
|
|
|
main (int argc, char *argv[])
|
2010-03-12 23:50:09 +00:00
|
|
|
{
|
2016-04-29 10:48:44 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
GstVaapiSurface *surface;
|
|
|
|
GstVaapiID surface_id;
|
|
|
|
GstVaapiSurface *surfaces[MAX_SURFACES];
|
|
|
|
GstVaapiVideoPool *pool;
|
|
|
|
gint i;
|
2010-03-12 23:50:09 +00:00
|
|
|
|
2016-04-29 10:48:44 +00:00
|
|
|
static const GstVaapiChromaType chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
|
|
|
|
static const guint width = 320;
|
|
|
|
static const guint height = 240;
|
2010-03-12 23:50:09 +00:00
|
|
|
|
2016-04-29 10:48:44 +00:00
|
|
|
if (!video_output_init (&argc, argv, NULL))
|
|
|
|
g_error ("failed to initialize video output subsystem");
|
2010-03-12 23:50:09 +00:00
|
|
|
|
2016-04-29 10:48:44 +00:00
|
|
|
display = video_output_create_display (NULL);
|
|
|
|
if (!display)
|
|
|
|
g_error ("could not create Gst/VA display");
|
2010-03-12 23:50:09 +00:00
|
|
|
|
2016-04-29 10:48:44 +00:00
|
|
|
surface = gst_vaapi_surface_new (display, chroma_type, width, height);
|
|
|
|
if (!surface)
|
|
|
|
g_error ("could not create Gst/VA surface");
|
|
|
|
|
|
|
|
surface_id = gst_vaapi_surface_get_id (surface);
|
|
|
|
g_print ("created surface %" GST_VAAPI_ID_FORMAT "\n",
|
|
|
|
GST_VAAPI_ID_ARGS (surface_id));
|
|
|
|
|
|
|
|
gst_vaapi_object_unref (surface);
|
|
|
|
|
|
|
|
pool = gst_vaapi_surface_pool_new (display, GST_VIDEO_FORMAT_ENCODED,
|
|
|
|
width, height);
|
|
|
|
if (!pool)
|
|
|
|
g_error ("could not create Gst/VA surface pool");
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_SURFACES; i++) {
|
|
|
|
surface = gst_vaapi_video_pool_get_object (pool);
|
2010-03-12 23:50:09 +00:00
|
|
|
if (!surface)
|
2016-04-29 10:48:44 +00:00
|
|
|
g_error ("could not allocate Gst/VA surface from pool");
|
|
|
|
g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool\n",
|
|
|
|
GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surface)));
|
|
|
|
surfaces[i] = surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the pool doesn't return the last free'd surface */
|
|
|
|
surface = gst_vaapi_object_ref (surfaces[1]);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
gst_vaapi_video_pool_put_object (pool, surfaces[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
surfaces[i] = gst_vaapi_video_pool_get_object (pool);
|
|
|
|
if (!surfaces[i])
|
|
|
|
g_error ("could not re-allocate Gst/VA surface%d from pool", i);
|
|
|
|
g_print ("created surface %" GST_VAAPI_ID_FORMAT " from pool (realloc)\n",
|
|
|
|
GST_VAAPI_ID_ARGS (gst_vaapi_surface_get_id (surfaces[i])));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface == surfaces[0])
|
|
|
|
g_error ("Gst/VA pool doesn't queue free surfaces");
|
|
|
|
|
|
|
|
for (i = MAX_SURFACES - 1; i >= 0; i--) {
|
|
|
|
if (!surfaces[i])
|
|
|
|
continue;
|
|
|
|
gst_vaapi_video_pool_put_object (pool, surfaces[i]);
|
|
|
|
surfaces[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unref in random order to check objects are correctly refcounted */
|
2018-06-13 15:54:23 +00:00
|
|
|
gst_object_unref (display);
|
2016-04-29 10:48:44 +00:00
|
|
|
gst_vaapi_video_pool_unref (pool);
|
|
|
|
gst_vaapi_object_unref (surface);
|
|
|
|
video_output_exit ();
|
|
|
|
return 0;
|
2010-03-12 23:50:09 +00:00
|
|
|
}
|