2 * test-decode.c - Test GstVaapiDecoder
4 * gstreamer-vaapi (C) 2010 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 (*GetVideoDataFunc)(const guchar **data, guint *size);
33 typedef struct _CodecDefs CodecDefs;
35 const gchar *codec_str;
37 GetVideoDataFunc get_video_data;
40 static const CodecDefs g_codec_defs[] = {
41 { "mpeg2", GST_VAAPI_CODEC_MPEG2, mpeg2_get_video_data },
42 { "h264", GST_VAAPI_CODEC_H264, h264_get_video_data },
43 { "vc1", GST_VAAPI_CODEC_VC1, vc1_get_video_data },
47 static const CodecDefs *
48 get_codec_defs(const gchar *codec_str)
51 for (c = g_codec_defs; c->codec_str; c++)
52 if (strcmp(codec_str, c->codec_str) == 0)
57 static inline void pause(void)
59 g_print("Press any key to continue...\n");
63 static gchar *g_codec_str;
65 static GOptionEntry g_options[] = {
68 G_OPTION_ARG_STRING, &g_codec_str,
69 "codec to test", NULL },
74 main(int argc, char *argv[])
76 GOptionContext *options;
77 GstVaapiDisplay *display;
78 GstVaapiWindow *window;
79 GstVaapiDecoder *decoder;
80 GstVaapiDecoderStatus status;
81 const CodecDefs *codec;
82 GstVaapiSurfaceProxy *proxy;
86 static const guint win_width = 640;
87 static const guint win_height = 480;
89 gst_init(&argc, &argv);
91 options = g_option_context_new(" - test-decode options");
92 g_option_context_add_main_entries(options, g_options, NULL);
93 g_option_context_parse(options, &argc, &argv, NULL);
94 g_option_context_free(options);
97 g_codec_str = g_strdup("h264");
99 g_print("Test %s decode\n", g_codec_str);
100 codec = get_codec_defs(g_codec_str);
102 g_error("no %s codec data found", g_codec_str);
104 display = gst_vaapi_display_x11_new(NULL);
106 g_error("could not create VA display");
108 window = gst_vaapi_window_x11_new(display, win_width, win_height);
110 g_error("could not create window");
112 codec->get_video_data(&vdata, &vdata_size);
113 decoder = gst_vaapi_decoder_ffmpeg_new(display, codec->codec, NULL);
115 g_error("could not create FFmpeg decoder");
117 if (!gst_vaapi_decoder_put_buffer_data(decoder, vdata, vdata_size))
118 g_error("could not send video data to the decoder");
119 if (!gst_vaapi_decoder_put_buffer(decoder, NULL))
120 g_error("could not send EOS to the decoder");
122 proxy = gst_vaapi_decoder_get_surface(decoder, &status);
124 g_error("could not get decoded surface (decoder status %d)", status);
126 gst_vaapi_window_show(window);
128 if (!gst_vaapi_window_put_surface(window,
129 GST_VAAPI_SURFACE_PROXY_SURFACE(proxy),
132 GST_VAAPI_PICTURE_STRUCTURE_FRAME))
133 g_error("could not render surface");
137 g_object_unref(proxy);
138 g_object_unref(decoder);
139 g_object_unref(window);
140 g_object_unref(display);