2 * test-decode.c - Test GstVaapiDecoder
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011-2013 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/sysdeps.h"
25 #include <gst/vaapi/gstvaapisurface.h>
29 /* Set to 1 to check display cache works (shared VA display) */
30 #define CHECK_DISPLAY_CACHE 1
32 static inline void pause(void)
34 g_print("Press any key to continue...\n");
38 static gchar *g_codec_str;
39 static gboolean g_use_pixmap;
41 static GOptionEntry g_options[] = {
44 G_OPTION_ARG_STRING, &g_codec_str,
45 "codec to test", NULL },
48 G_OPTION_ARG_NONE, &g_use_pixmap,
49 "use render-to-pixmap", NULL },
54 main(int argc, char *argv[])
56 GstVaapiDisplay *display, *display2;
57 GstVaapiWindow *window;
58 GstVaapiPixmap *pixmap = NULL;
59 GstVaapiDecoder *decoder;
60 GstVaapiSurfaceProxy *proxy;
61 GstVaapiSurface *surface;
62 const GstVaapiRectangle *crop_rect;
64 static const guint win_width = 640;
65 static const guint win_height = 480;
67 if (!video_output_init(&argc, argv, g_options))
68 g_error("failed to initialize video output subsystem");
70 g_print("Test decode\n");
72 display = video_output_create_display(NULL);
74 g_error("could not create VA display");
76 if (CHECK_DISPLAY_CACHE)
77 display2 = video_output_create_display(NULL);
79 display2 = gst_vaapi_display_ref(display);
81 g_error("could not create second VA display");
83 window = video_output_create_window(display, win_width, win_height);
85 g_error("could not create window");
87 decoder = decoder_new(display, g_codec_str);
89 g_error("could not create decoder");
91 g_print("Decode %s sample frame\n", decoder_get_codec_name(decoder));
93 if (!decoder_put_buffers(decoder))
94 g_error("could not fill decoder with sample data");
96 proxy = decoder_get_surface(decoder);
98 g_error("could not get decoded surface");
100 surface = gst_vaapi_surface_proxy_get_surface(proxy);
101 crop_rect = gst_vaapi_surface_proxy_get_crop_rect(proxy);
103 gst_vaapi_window_show(window);
109 width = crop_rect->width;
110 height = crop_rect->height;
113 gst_vaapi_surface_get_size(surface, &width, &height);
115 pixmap = video_output_create_pixmap(display, GST_VIDEO_FORMAT_xRGB,
118 g_error("could not create pixmap");
120 if (!gst_vaapi_pixmap_put_surface(pixmap, surface, crop_rect,
121 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
122 g_error("could not render to pixmap");
124 if (!gst_vaapi_window_put_pixmap(window, pixmap, NULL, NULL))
125 g_error("could not render pixmap");
127 else if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
128 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
129 g_error("could not render surface");
134 gst_vaapi_pixmap_unref(pixmap);
135 gst_vaapi_surface_proxy_unref(proxy);
136 gst_vaapi_decoder_unref(decoder);
137 gst_vaapi_window_unref(window);
138 gst_vaapi_display_unref(display);
139 gst_vaapi_display_unref(display2);