2 * test-decode.c - Test GstVaapiDecoder
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2011-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/sysdeps.h"
27 #include <gst/vaapi/gstvaapisurface.h>
31 /* Set to 1 to check display cache works (shared VA display) */
32 #define CHECK_DISPLAY_CACHE 1
34 static inline void pause(void)
36 g_print("Press any key to continue...\n");
40 static gchar *g_codec_str;
41 static gboolean g_use_pixmap;
43 static GOptionEntry g_options[] = {
46 G_OPTION_ARG_STRING, &g_codec_str,
47 "codec to test", NULL },
50 G_OPTION_ARG_NONE, &g_use_pixmap,
51 "use render-to-pixmap", NULL },
56 main(int argc, char *argv[])
58 GstVaapiDisplay *display, *display2;
59 GstVaapiWindow *window;
60 GstVaapiPixmap *pixmap = NULL;
61 GstVaapiDecoder *decoder;
62 GstVaapiSurfaceProxy *proxy;
63 GstVaapiSurface *surface;
64 const GstVaapiRectangle *crop_rect;
66 static const guint win_width = 640;
67 static const guint win_height = 480;
69 if (!video_output_init(&argc, argv, g_options))
70 g_error("failed to initialize video output subsystem");
72 g_print("Test decode\n");
74 display = video_output_create_display(NULL);
76 g_error("could not create VA display");
78 if (CHECK_DISPLAY_CACHE)
79 display2 = video_output_create_display(NULL);
81 display2 = gst_vaapi_display_ref(display);
83 g_error("could not create second VA display");
85 window = video_output_create_window(display, win_width, win_height);
87 g_error("could not create window");
89 decoder = decoder_new(display, g_codec_str);
91 g_error("could not create decoder");
93 g_print("Decode %s sample frame\n", decoder_get_codec_name(decoder));
95 if (!decoder_put_buffers(decoder))
96 g_error("could not fill decoder with sample data");
98 proxy = decoder_get_surface(decoder);
100 g_error("could not get decoded surface");
102 surface = gst_vaapi_surface_proxy_get_surface(proxy);
103 crop_rect = gst_vaapi_surface_proxy_get_crop_rect(proxy);
105 gst_vaapi_window_show(window);
111 width = crop_rect->width;
112 height = crop_rect->height;
115 gst_vaapi_surface_get_size(surface, &width, &height);
117 pixmap = video_output_create_pixmap(display, GST_VIDEO_FORMAT_xRGB,
120 g_error("could not create pixmap");
122 if (!gst_vaapi_pixmap_put_surface(pixmap, surface, crop_rect,
123 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
124 g_error("could not render to pixmap");
126 if (!gst_vaapi_window_put_pixmap(window, pixmap, NULL, NULL))
127 g_error("could not render pixmap");
129 else if (!gst_vaapi_window_put_surface(window, surface, crop_rect, NULL,
130 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
131 g_error("could not render surface");
136 gst_vaapi_pixmap_unref(pixmap);
137 gst_vaapi_surface_proxy_unref(proxy);
138 gst_vaapi_decoder_unref(decoder);
139 gst_vaapi_window_unref(window);
140 gst_vaapi_display_unref(display);
141 gst_vaapi_display_unref(display2);