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/gstvaapidisplay_x11.h>
26
#include <gst/vaapi/gstvaapiwindow_x11.h>
27
#include <gst/vaapi/gstvaapidecoder.h>
28
#include <gst/vaapi/gstvaapisurface.h>
29
#include "test-mpeg2.h"
30
#include "test-h264.h"
34
# include <gst/vaapi/gstvaapidecoder_ffmpeg.h>
37
# include <gst/vaapi/gstvaapidecoder_h264.h>
38
# include <gst/vaapi/gstvaapidecoder_mpeg2.h>
39
# include <gst/vaapi/gstvaapidecoder_vc1.h>
42
/* Set to 1 to check display cache works (shared VA display) */
43
#define CHECK_DISPLAY_CACHE 1
45
typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
47
typedef struct _CodecDefs CodecDefs;
49
const gchar *codec_str;
50
GetVideoInfoFunc get_video_info;
53
static const CodecDefs g_codec_defs[] = {
54
#define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
62
static const CodecDefs *
63
get_codec_defs(const gchar *codec_str)
66
for (c = g_codec_defs; c->codec_str; c++)
67
if (strcmp(codec_str, c->codec_str) == 0)
72
static inline void pause(void)
74
g_print("Press any key to continue...\n");
78
static gchar *g_codec_str;
79
static gboolean g_use_ffmpeg = FALSE;
81
static GOptionEntry g_options[] = {
84
G_OPTION_ARG_STRING, &g_codec_str,
85
"codec to test", NULL },
88
G_OPTION_ARG_NONE, &g_use_ffmpeg,
91
G_OPTION_FLAG_REVERSE,
92
G_OPTION_ARG_NONE, &g_use_ffmpeg,
93
"use codec parsers", NULL },
98
main(int argc, char *argv[])
100
GOptionContext *options;
101
GstVaapiDisplay *display, *display2;
102
GstVaapiWindow *window;
103
GstVaapiDecoder *decoder;
104
GstCaps *decoder_caps;
105
GstStructure *structure;
106
GstVaapiDecoderStatus status;
107
const CodecDefs *codec;
109
GstVaapiSurfaceProxy *proxy;
110
VideoDecodeInfo info;
112
static const guint win_width = 640;
113
static const guint win_height = 480;
115
gst_init(&argc, &argv);
117
options = g_option_context_new(" - test-decode options");
118
g_option_context_add_main_entries(options, g_options, NULL);
119
g_option_context_parse(options, &argc, &argv, NULL);
120
g_option_context_free(options);
123
g_codec_str = g_strdup("h264");
125
g_print("Test %s decode\n", g_codec_str);
126
codec = get_codec_defs(g_codec_str);
128
g_error("no %s codec data found", g_codec_str);
130
display = gst_vaapi_display_x11_new(NULL);
132
g_error("could not create VA display");
134
if (CHECK_DISPLAY_CACHE)
135
display2 = gst_vaapi_display_x11_new(NULL);
137
display2 = g_object_ref(display);
139
g_error("could not create second VA display");
141
window = gst_vaapi_window_x11_new(display, win_width, win_height);
143
g_error("could not create window");
145
codec->get_video_info(&info);
146
decoder_caps = gst_vaapi_profile_get_caps(info.profile);
148
g_error("could not create decoder caps");
150
structure = gst_caps_get_structure(decoder_caps, 0);
151
if (info.width > 0 && info.height > 0)
154
"width", G_TYPE_INT, info.width,
155
"height", G_TYPE_INT, info.height,
161
decoder = gst_vaapi_decoder_ffmpeg_new(display, decoder_caps);
163
g_error("FFmpeg-based decoders are not supported");
167
#if USE_CODEC_PARSERS
168
switch (gst_vaapi_profile_get_codec(info.profile)) {
169
case GST_VAAPI_CODEC_H264:
170
decoder = gst_vaapi_decoder_h264_new(display, decoder_caps);
172
case GST_VAAPI_CODEC_MPEG2:
173
decoder = gst_vaapi_decoder_mpeg2_new(display, decoder_caps);
175
case GST_VAAPI_CODEC_VC1:
176
decoder = gst_vaapi_decoder_vc1_new(display, decoder_caps);
183
g_error("codecparsers-based decoders are not supported");
187
g_error("could not create decoder");
188
gst_caps_unref(decoder_caps);
190
buffer = gst_buffer_new();
192
g_error("could not create encoded data buffer");
193
gst_buffer_set_data(buffer, (guchar *)info.data, info.data_size);
195
if (!gst_vaapi_decoder_put_buffer(decoder, buffer))
196
g_error("could not send video data to the decoder");
197
gst_buffer_unref(buffer);
199
if (!gst_vaapi_decoder_put_buffer(decoder, NULL))
200
g_error("could not send EOS to the decoder");
202
proxy = gst_vaapi_decoder_get_surface(decoder, &status);
204
g_error("could not get decoded surface (decoder status %d)", status);
206
gst_vaapi_window_show(window);
208
if (!gst_vaapi_window_put_surface(window,
209
GST_VAAPI_SURFACE_PROXY_SURFACE(proxy),
212
GST_VAAPI_PICTURE_STRUCTURE_FRAME))
213
g_error("could not render surface");
217
g_object_unref(proxy);
218
g_object_unref(decoder);
219
g_object_unref(window);
220
g_object_unref(display);
221
g_object_unref(display2);