2 * test-decode.c - Test GstVaapiDecoder
4 * gstreamer-vaapi (C) 2010-2011 Splitted-Desktop Systems
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <gst/vaapi/gstvaapidisplay_x11.h>
23 #include <gst/vaapi/gstvaapiwindow_x11.h>
24 #include <gst/vaapi/gstvaapidecoder.h>
25 #include <gst/vaapi/gstvaapidecoder_ffmpeg.h>
26 #include <gst/vaapi/gstvaapisurface.h>
27 #include "test-mpeg2.h"
28 #include "test-h264.h"
31 typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
33 typedef struct _CodecDefs CodecDefs;
35 const gchar *codec_str;
36 GetVideoInfoFunc get_video_info;
39 static const CodecDefs g_codec_defs[] = {
40 #define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
48 static const CodecDefs *
49 get_codec_defs(const gchar *codec_str)
52 for (c = g_codec_defs; c->codec_str; c++)
53 if (strcmp(codec_str, c->codec_str) == 0)
58 static inline void pause(void)
60 g_print("Press any key to continue...\n");
64 static gchar *g_codec_str;
66 static GOptionEntry g_options[] = {
69 G_OPTION_ARG_STRING, &g_codec_str,
70 "codec to test", NULL },
75 main(int argc, char *argv[])
77 GOptionContext *options;
78 GstVaapiDisplay *display;
79 GstVaapiWindow *window;
80 GstVaapiDecoder *decoder;
81 GstCaps *decoder_caps;
82 GstStructure *structure;
83 GstVaapiDecoderStatus status;
84 const CodecDefs *codec;
86 GstVaapiSurfaceProxy *proxy;
89 static const guint win_width = 640;
90 static const guint win_height = 480;
92 gst_init(&argc, &argv);
94 options = g_option_context_new(" - test-decode options");
95 g_option_context_add_main_entries(options, g_options, NULL);
96 g_option_context_parse(options, &argc, &argv, NULL);
97 g_option_context_free(options);
100 g_codec_str = g_strdup("h264");
102 g_print("Test %s decode\n", g_codec_str);
103 codec = get_codec_defs(g_codec_str);
105 g_error("no %s codec data found", g_codec_str);
107 display = gst_vaapi_display_x11_new(NULL);
109 g_error("could not create VA display");
111 window = gst_vaapi_window_x11_new(display, win_width, win_height);
113 g_error("could not create window");
115 codec->get_video_info(&info);
116 decoder_caps = gst_vaapi_profile_get_caps(info.profile);
118 g_error("could not create decoder caps");
120 structure = gst_caps_get_structure(decoder_caps, 0);
121 if (info.width > 0 && info.height > 0)
124 "width", G_TYPE_INT, info.width,
125 "height", G_TYPE_INT, info.height,
129 decoder = gst_vaapi_decoder_ffmpeg_new(display, decoder_caps);
131 g_error("could not create FFmpeg decoder");
132 gst_caps_unref(decoder_caps);
134 buffer = gst_buffer_new();
136 g_error("could not create encoded data buffer");
137 gst_buffer_set_data(buffer, (guchar *)info.data, info.data_size);
139 if (!gst_vaapi_decoder_put_buffer(decoder, buffer))
140 g_error("could not send video data to the decoder");
141 gst_buffer_unref(buffer);
143 if (!gst_vaapi_decoder_put_buffer(decoder, NULL))
144 g_error("could not send EOS to the decoder");
146 proxy = gst_vaapi_decoder_get_surface(decoder, &status);
148 g_error("could not get decoded surface (decoder status %d)", status);
150 gst_vaapi_window_show(window);
152 if (!gst_vaapi_window_put_surface(window,
153 GST_VAAPI_SURFACE_PROXY_SURFACE(proxy),
156 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
157 g_error("could not render surface");
161 g_object_unref(proxy);
162 g_object_unref(decoder);
163 g_object_unref(window);
164 g_object_unref(display);