2010-04-23 16:11:55 +00:00
|
|
|
/*
|
|
|
|
* test-decode.c - Test GstVaapiDecoder
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-01-29 13:14:45 +00:00
|
|
|
* Copyright (C) 2011-2013 Intel Corporation
|
2010-04-23 16:11:55 +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-04-23 16:11:55 +00:00
|
|
|
*
|
2011-10-18 07:18:20 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-04-23 16:11:55 +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-04-23 16:11:55 +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
|
2013-03-20 10:57:57 +00:00
|
|
|
*/
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2013-03-20 10:50:15 +00:00
|
|
|
#include "gst/vaapi/sysdeps.h"
|
2010-04-23 16:11:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gst/vaapi/gstvaapisurface.h>
|
2013-01-10 10:22:38 +00:00
|
|
|
#include "decoder.h"
|
2012-07-23 13:17:03 +00:00
|
|
|
#include "output.h"
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2012-01-12 14:34:59 +00:00
|
|
|
/* Set to 1 to check display cache works (shared VA display) */
|
|
|
|
#define CHECK_DISPLAY_CACHE 1
|
|
|
|
|
2010-04-23 16:11:55 +00:00
|
|
|
static inline void pause(void)
|
|
|
|
{
|
|
|
|
g_print("Press any key to continue...\n");
|
|
|
|
getchar();
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *g_codec_str;
|
2013-07-22 07:03:30 +00:00
|
|
|
static gboolean g_use_pixmap;
|
2010-04-23 16:11:55 +00:00
|
|
|
|
|
|
|
static GOptionEntry g_options[] = {
|
|
|
|
{ "codec", 'c',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_STRING, &g_codec_str,
|
|
|
|
"codec to test", NULL },
|
2013-07-22 07:03:30 +00:00
|
|
|
{ "pixmap", 0,
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_NONE, &g_use_pixmap,
|
|
|
|
"use render-to-pixmap", NULL },
|
2010-04-23 16:11:55 +00:00
|
|
|
{ NULL, }
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2012-01-12 14:34:59 +00:00
|
|
|
GstVaapiDisplay *display, *display2;
|
2010-04-23 16:11:55 +00:00
|
|
|
GstVaapiWindow *window;
|
2013-07-22 07:03:30 +00:00
|
|
|
GstVaapiPixmap *pixmap = NULL;
|
2010-04-23 16:11:55 +00:00
|
|
|
GstVaapiDecoder *decoder;
|
2013-07-08 15:01:21 +00:00
|
|
|
GstVaapiSurfaceProxy *proxy;
|
2013-01-10 10:22:38 +00:00
|
|
|
GstVaapiSurface *surface;
|
2013-07-08 15:01:21 +00:00
|
|
|
const GstVaapiRectangle *crop_rect;
|
2010-04-23 16:11:55 +00:00
|
|
|
|
|
|
|
static const guint win_width = 640;
|
|
|
|
static const guint win_height = 480;
|
|
|
|
|
2012-07-23 13:17:03 +00:00
|
|
|
if (!video_output_init(&argc, argv, g_options))
|
|
|
|
g_error("failed to initialize video output subsystem");
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2013-01-10 10:22:38 +00:00
|
|
|
g_print("Test decode\n");
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2012-07-23 13:17:03 +00:00
|
|
|
display = video_output_create_display(NULL);
|
2010-04-23 16:11:55 +00:00
|
|
|
if (!display)
|
|
|
|
g_error("could not create VA display");
|
|
|
|
|
2012-01-12 14:34:59 +00:00
|
|
|
if (CHECK_DISPLAY_CACHE)
|
2012-07-23 13:17:03 +00:00
|
|
|
display2 = video_output_create_display(NULL);
|
2012-01-12 14:34:59 +00:00
|
|
|
else
|
2013-05-07 09:45:10 +00:00
|
|
|
display2 = gst_vaapi_display_ref(display);
|
2012-01-12 14:34:59 +00:00
|
|
|
if (!display2)
|
|
|
|
g_error("could not create second VA display");
|
|
|
|
|
2012-07-23 13:17:03 +00:00
|
|
|
window = video_output_create_window(display, win_width, win_height);
|
2010-04-23 16:11:55 +00:00
|
|
|
if (!window)
|
|
|
|
g_error("could not create window");
|
|
|
|
|
2013-01-10 10:22:38 +00:00
|
|
|
decoder = decoder_new(display, g_codec_str);
|
2010-04-23 16:11:55 +00:00
|
|
|
if (!decoder)
|
2011-08-12 08:21:19 +00:00
|
|
|
g_error("could not create decoder");
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2013-01-10 10:22:38 +00:00
|
|
|
g_print("Decode %s sample frame\n", decoder_get_codec_name(decoder));
|
2010-05-03 20:55:17 +00:00
|
|
|
|
2013-01-10 10:22:38 +00:00
|
|
|
if (!decoder_put_buffers(decoder))
|
|
|
|
g_error("could not fill decoder with sample data");
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2013-07-08 15:01:21 +00:00
|
|
|
proxy = decoder_get_surface(decoder);
|
|
|
|
if (!proxy)
|
2013-01-10 10:22:38 +00:00
|
|
|
g_error("could not get decoded surface");
|
2010-04-23 16:11:55 +00:00
|
|
|
|
2013-07-08 15:01:21 +00:00
|
|
|
surface = gst_vaapi_surface_proxy_get_surface(proxy);
|
|
|
|
crop_rect = gst_vaapi_surface_proxy_get_crop_rect(proxy);
|
|
|
|
|
2010-04-23 16:11:55 +00:00
|
|
|
gst_vaapi_window_show(window);
|
|
|
|
|
2013-07-22 07:03:30 +00:00
|
|
|
if (g_use_pixmap) {
|
|
|
|
guint width, height;
|
|
|
|
|
|
|
|
if (crop_rect) {
|
|
|
|
width = crop_rect->width;
|
|
|
|
height = crop_rect->height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gst_vaapi_surface_get_size(surface, &width, &height);
|
|
|
|
|
|
|
|
pixmap = video_output_create_pixmap(display, GST_VIDEO_FORMAT_xRGB,
|
|
|
|
width, height);
|
|
|
|
if (!pixmap)
|
|
|
|
g_error("could not create pixmap");
|
|
|
|
|
|
|
|
if (!gst_vaapi_pixmap_put_surface(pixmap, surface, crop_rect,
|
|
|
|
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
|
|
|
|
g_error("could not render to pixmap");
|
|
|
|
|
|
|
|
if (!gst_vaapi_window_put_pixmap(window, pixmap, NULL, NULL))
|
|
|
|
g_error("could not render pixmap");
|
|
|
|
}
|
|
|
|
else if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
|
2013-01-10 10:22:38 +00:00
|
|
|
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
|
2010-04-23 16:11:55 +00:00
|
|
|
g_error("could not render surface");
|
|
|
|
|
|
|
|
pause();
|
|
|
|
|
2013-07-22 07:03:30 +00:00
|
|
|
if (pixmap)
|
|
|
|
gst_vaapi_pixmap_unref(pixmap);
|
2013-07-08 15:01:21 +00:00
|
|
|
gst_vaapi_surface_proxy_unref(proxy);
|
2013-05-07 09:45:10 +00:00
|
|
|
gst_vaapi_decoder_unref(decoder);
|
|
|
|
gst_vaapi_window_unref(window);
|
|
|
|
gst_vaapi_display_unref(display);
|
|
|
|
gst_vaapi_display_unref(display2);
|
2010-04-23 16:11:55 +00:00
|
|
|
g_free(g_codec_str);
|
2012-07-23 13:17:03 +00:00
|
|
|
video_output_exit();
|
2010-04-23 16:11:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|