2 * decoder.h - Decoder utilities for the tests
4 * Copyright (C) 2013 Intel Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #include "gst/vaapi/sysdeps.h"
24 #include <gst/vaapi/gstvaapidecoder_h264.h>
25 #include <gst/vaapi/gstvaapidecoder_jpeg.h>
26 #include <gst/vaapi/gstvaapidecoder_mpeg2.h>
27 #include <gst/vaapi/gstvaapidecoder_mpeg4.h>
28 #include <gst/vaapi/gstvaapidecoder_vc1.h>
30 #include "test-jpeg.h"
31 #include "test-mpeg2.h"
32 #include "test-mpeg4.h"
33 #include "test-h264.h"
36 typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
38 typedef struct _CodecDefs CodecDefs;
40 const gchar *codec_str;
41 GetVideoInfoFunc get_video_info;
44 static const CodecDefs g_codec_defs[] = {
45 #define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
55 static const CodecDefs *
56 find_codec_defs(const gchar *codec_str)
59 for (c = g_codec_defs; c->codec_str; c++)
60 if (strcmp(codec_str, c->codec_str) == 0)
65 static inline const CodecDefs *
66 get_codec_defs(GstVaapiDecoder *decoder)
68 return gst_vaapi_decoder_get_user_data(decoder);
72 set_codec_defs(GstVaapiDecoder *decoder, const CodecDefs *c)
74 gst_vaapi_decoder_set_user_data(decoder, (gpointer)c);
78 decoder_new(GstVaapiDisplay *display, const gchar *codec_name)
80 GstVaapiDecoder *decoder;
81 const CodecDefs *codec;
88 codec = find_codec_defs(codec_name);
90 GST_ERROR("failed to find %s codec data", codec_name);
94 codec->get_video_info(&info);
95 caps = gst_vaapi_profile_get_caps(info.profile);
97 GST_ERROR("failed to create decoder caps");
101 if (info.width > 0 && info.height > 0)
102 gst_caps_set_simple(caps,
103 "width", G_TYPE_INT, info.width,
104 "height", G_TYPE_INT, info.height,
107 switch (gst_vaapi_profile_get_codec(info.profile)) {
108 case GST_VAAPI_CODEC_H264:
109 decoder = gst_vaapi_decoder_h264_new(display, caps);
112 case GST_VAAPI_CODEC_JPEG:
113 decoder = gst_vaapi_decoder_jpeg_new(display, caps);
116 case GST_VAAPI_CODEC_MPEG2:
117 decoder = gst_vaapi_decoder_mpeg2_new(display, caps);
119 case GST_VAAPI_CODEC_MPEG4:
120 decoder = gst_vaapi_decoder_mpeg4_new(display, caps);
122 case GST_VAAPI_CODEC_VC1:
123 decoder = gst_vaapi_decoder_vc1_new(display, caps);
129 gst_caps_unref(caps);
131 GST_ERROR("failed to create %s decoder", codec->codec_str);
135 set_codec_defs(decoder, codec);
140 decoder_put_buffers(GstVaapiDecoder *decoder)
142 const CodecDefs *codec;
143 VideoDecodeInfo info;
147 g_return_val_if_fail(decoder != NULL, FALSE);
149 codec = get_codec_defs(decoder);
150 g_return_val_if_fail(codec != NULL, FALSE);
152 codec->get_video_info(&info);
153 buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY,
154 (guchar *)info.data, info.data_size, 0, info.data_size, NULL, NULL);
156 GST_ERROR("failed to create encoded data buffer");
160 success = gst_vaapi_decoder_put_buffer(decoder, buffer);
161 gst_buffer_unref(buffer);
163 GST_ERROR("failed to send video data to the decoder");
167 if (!gst_vaapi_decoder_put_buffer(decoder, NULL)) {
168 GST_ERROR("failed to submit <end-of-stream> to the decoder");
174 GstVaapiSurfaceProxy *
175 decoder_get_surface(GstVaapiDecoder *decoder)
177 GstVaapiSurfaceProxy *proxy;
178 GstVaapiDecoderStatus status;
180 g_return_val_if_fail(decoder != NULL, NULL);
182 status = gst_vaapi_decoder_get_surface(decoder, &proxy);
183 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
184 GST_ERROR("failed to get decoded surface (decoder status %d)", status);
191 decoder_get_codec_name(GstVaapiDecoder *decoder)
193 const CodecDefs *codec;
195 g_return_val_if_fail(decoder != NULL, NULL);
197 codec = get_codec_defs(decoder);
198 g_return_val_if_fail(codec != NULL, FALSE);
200 return codec->codec_str;