2 * test-decode.c - Test GstVaapiDecoder
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2011-2012 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
25 #include <gst/vaapi/gstvaapidecoder.h>
26 #include <gst/vaapi/gstvaapisurface.h>
27 #include <gst/vaapi/gstvaapidecoder_h264.h>
28 #include <gst/vaapi/gstvaapidecoder_jpeg.h>
29 #include <gst/vaapi/gstvaapidecoder_mpeg2.h>
30 #include <gst/vaapi/gstvaapidecoder_vc1.h>
31 #include "test-jpeg.h"
32 #include "test-mpeg2.h"
33 #include "test-h264.h"
37 /* Set to 1 to check display cache works (shared VA display) */
38 #define CHECK_DISPLAY_CACHE 1
40 typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
42 typedef struct _CodecDefs CodecDefs;
44 const gchar *codec_str;
45 GetVideoInfoFunc get_video_info;
48 static const CodecDefs g_codec_defs[] = {
49 #define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
58 static const CodecDefs *
59 get_codec_defs(const gchar *codec_str)
62 for (c = g_codec_defs; c->codec_str; c++)
63 if (strcmp(codec_str, c->codec_str) == 0)
68 static inline void pause(void)
70 g_print("Press any key to continue...\n");
74 static gchar *g_codec_str;
76 static GOptionEntry g_options[] = {
79 G_OPTION_ARG_STRING, &g_codec_str,
80 "codec to test", NULL },
85 main(int argc, char *argv[])
87 GstVaapiDisplay *display, *display2;
88 GstVaapiWindow *window;
89 GstVaapiDecoder *decoder;
90 GstCaps *decoder_caps;
91 GstStructure *structure;
92 GstVaapiDecoderStatus status;
93 const CodecDefs *codec;
95 GstVaapiSurfaceProxy *proxy;
98 static const guint win_width = 640;
99 static const guint win_height = 480;
101 if (!video_output_init(&argc, argv, g_options))
102 g_error("failed to initialize video output subsystem");
105 g_codec_str = g_strdup("h264");
107 g_print("Test %s decode\n", g_codec_str);
108 codec = get_codec_defs(g_codec_str);
110 g_error("no %s codec data found", g_codec_str);
112 display = video_output_create_display(NULL);
114 g_error("could not create VA display");
116 if (CHECK_DISPLAY_CACHE)
117 display2 = video_output_create_display(NULL);
119 display2 = g_object_ref(display);
121 g_error("could not create second VA display");
123 window = video_output_create_window(display, win_width, win_height);
125 g_error("could not create window");
127 codec->get_video_info(&info);
128 decoder_caps = gst_vaapi_profile_get_caps(info.profile);
130 g_error("could not create decoder caps");
132 structure = gst_caps_get_structure(decoder_caps, 0);
133 if (info.width > 0 && info.height > 0)
136 "width", G_TYPE_INT, info.width,
137 "height", G_TYPE_INT, info.height,
141 switch (gst_vaapi_profile_get_codec(info.profile)) {
142 case GST_VAAPI_CODEC_H264:
143 decoder = gst_vaapi_decoder_h264_new(display, decoder_caps);
146 case GST_VAAPI_CODEC_JPEG:
147 decoder = gst_vaapi_decoder_jpeg_new(display, decoder_caps);
150 case GST_VAAPI_CODEC_MPEG2:
151 decoder = gst_vaapi_decoder_mpeg2_new(display, decoder_caps);
153 case GST_VAAPI_CODEC_VC1:
154 decoder = gst_vaapi_decoder_vc1_new(display, decoder_caps);
161 g_error("could not create decoder");
162 gst_caps_unref(decoder_caps);
164 buffer = gst_buffer_new();
166 g_error("could not create encoded data buffer");
167 gst_buffer_set_data(buffer, (guchar *)info.data, info.data_size);
169 if (!gst_vaapi_decoder_put_buffer(decoder, buffer))
170 g_error("could not send video data to the decoder");
171 gst_buffer_unref(buffer);
173 if (!gst_vaapi_decoder_put_buffer(decoder, NULL))
174 g_error("could not send EOS to the decoder");
176 proxy = gst_vaapi_decoder_get_surface(decoder, &status);
178 g_error("could not get decoded surface (decoder status %d)", status);
180 gst_vaapi_window_show(window);
182 if (!gst_vaapi_window_put_surface(window,
183 GST_VAAPI_SURFACE_PROXY_SURFACE(proxy),
186 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
187 g_error("could not render surface");
191 g_object_unref(proxy);
192 g_object_unref(decoder);
193 g_object_unref(window);
194 g_object_unref(display);
195 g_object_unref(display2);