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_mpeg4.h>
31 #include <gst/vaapi/gstvaapidecoder_vc1.h>
32 #include "test-jpeg.h"
33 #include "test-mpeg2.h"
34 #include "test-mpeg4.h"
35 #include "test-h264.h"
39 /* Set to 1 to check display cache works (shared VA display) */
40 #define CHECK_DISPLAY_CACHE 1
42 typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
44 typedef struct _CodecDefs CodecDefs;
46 const gchar *codec_str;
47 GetVideoInfoFunc get_video_info;
50 static const CodecDefs g_codec_defs[] = {
51 #define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
61 static const CodecDefs *
62 get_codec_defs(const gchar *codec_str)
65 for (c = g_codec_defs; c->codec_str; c++)
66 if (strcmp(codec_str, c->codec_str) == 0)
71 static inline void pause(void)
73 g_print("Press any key to continue...\n");
77 static gchar *g_codec_str;
79 static GOptionEntry g_options[] = {
82 G_OPTION_ARG_STRING, &g_codec_str,
83 "codec to test", NULL },
88 main(int argc, char *argv[])
90 GstVaapiDisplay *display, *display2;
91 GstVaapiWindow *window;
92 GstVaapiDecoder *decoder;
93 GstCaps *decoder_caps;
94 GstStructure *structure;
95 GstVaapiDecoderStatus status;
96 const CodecDefs *codec;
98 GstVaapiSurfaceProxy *proxy;
101 static const guint win_width = 640;
102 static const guint win_height = 480;
104 if (!video_output_init(&argc, argv, g_options))
105 g_error("failed to initialize video output subsystem");
108 g_codec_str = g_strdup("h264");
110 g_print("Test %s decode\n", g_codec_str);
111 codec = get_codec_defs(g_codec_str);
113 g_error("no %s codec data found", g_codec_str);
115 display = video_output_create_display(NULL);
117 g_error("could not create VA display");
119 if (CHECK_DISPLAY_CACHE)
120 display2 = video_output_create_display(NULL);
122 display2 = g_object_ref(display);
124 g_error("could not create second VA display");
126 window = video_output_create_window(display, win_width, win_height);
128 g_error("could not create window");
130 codec->get_video_info(&info);
131 decoder_caps = gst_vaapi_profile_get_caps(info.profile);
133 g_error("could not create decoder caps");
135 structure = gst_caps_get_structure(decoder_caps, 0);
136 if (info.width > 0 && info.height > 0)
139 "width", G_TYPE_INT, info.width,
140 "height", G_TYPE_INT, info.height,
144 switch (gst_vaapi_profile_get_codec(info.profile)) {
145 case GST_VAAPI_CODEC_H264:
146 decoder = gst_vaapi_decoder_h264_new(display, decoder_caps);
149 case GST_VAAPI_CODEC_JPEG:
150 decoder = gst_vaapi_decoder_jpeg_new(display, decoder_caps);
153 case GST_VAAPI_CODEC_MPEG2:
154 decoder = gst_vaapi_decoder_mpeg2_new(display, decoder_caps);
156 case GST_VAAPI_CODEC_MPEG4:
157 decoder = gst_vaapi_decoder_mpeg4_new(display, decoder_caps);
159 case GST_VAAPI_CODEC_VC1:
160 decoder = gst_vaapi_decoder_vc1_new(display, decoder_caps);
167 g_error("could not create decoder");
168 gst_caps_unref(decoder_caps);
170 buffer = gst_buffer_new();
172 g_error("could not create encoded data buffer");
173 gst_buffer_set_data(buffer, (guchar *)info.data, info.data_size);
175 if (!gst_vaapi_decoder_put_buffer(decoder, buffer))
176 g_error("could not send video data to the decoder");
177 gst_buffer_unref(buffer);
179 if (!gst_vaapi_decoder_put_buffer(decoder, NULL))
180 g_error("could not send EOS to the decoder");
182 proxy = gst_vaapi_decoder_get_surface(decoder, &status);
184 g_error("could not get decoded surface (decoder status %d)", status);
186 gst_vaapi_window_show(window);
188 if (!gst_vaapi_window_put_surface(window,
189 GST_VAAPI_SURFACE_PROXY_SURFACE(proxy),
192 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
193 g_error("could not render surface");
197 g_object_unref(proxy);
198 g_object_unref(decoder);
199 g_object_unref(window);
200 g_object_unref(display);
201 g_object_unref(display2);