2 * decoder.h - Decoder utilities for the tests
4 * Copyright (C) 2013 Intel Corporation
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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
23 #include "gst/vaapi/sysdeps.h"
25 #include <gst/vaapi/gstvaapidecoder_h264.h>
26 #include <gst/vaapi/gstvaapidecoder_jpeg.h>
27 #include <gst/vaapi/gstvaapidecoder_mpeg2.h>
28 #include <gst/vaapi/gstvaapidecoder_mpeg4.h>
29 #include <gst/vaapi/gstvaapidecoder_vc1.h>
31 #include "test-jpeg.h"
32 #include "test-mpeg2.h"
33 #include "test-mpeg4.h"
34 #include "test-h264.h"
37 typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
39 typedef struct _CodecDefs CodecDefs;
41 const gchar *codec_str;
42 GetVideoInfoFunc get_video_info;
45 static const CodecDefs g_codec_defs[] = {
46 #define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
56 static const CodecDefs *
57 find_codec_defs(const gchar *codec_str)
60 for (c = g_codec_defs; c->codec_str; c++)
61 if (strcmp(codec_str, c->codec_str) == 0)
66 static inline const CodecDefs *
67 get_codec_defs(GstVaapiDecoder *decoder)
69 return gst_vaapi_decoder_get_user_data(decoder);
73 set_codec_defs(GstVaapiDecoder *decoder, const CodecDefs *c)
75 gst_vaapi_decoder_set_user_data(decoder, (gpointer)c);
79 decoder_new(GstVaapiDisplay *display, const gchar *codec_name)
81 GstVaapiDecoder *decoder;
82 const CodecDefs *codec;
89 codec = find_codec_defs(codec_name);
91 GST_ERROR("failed to find %s codec data", codec_name);
95 codec->get_video_info(&info);
96 caps = gst_vaapi_profile_get_caps(info.profile);
98 GST_ERROR("failed to create decoder caps");
102 if (info.width > 0 && info.height > 0)
103 gst_caps_set_simple(caps,
104 "width", G_TYPE_INT, info.width,
105 "height", G_TYPE_INT, info.height,
108 switch (gst_vaapi_profile_get_codec(info.profile)) {
109 case GST_VAAPI_CODEC_H264:
110 decoder = gst_vaapi_decoder_h264_new(display, caps);
113 case GST_VAAPI_CODEC_JPEG:
114 decoder = gst_vaapi_decoder_jpeg_new(display, caps);
117 case GST_VAAPI_CODEC_MPEG2:
118 decoder = gst_vaapi_decoder_mpeg2_new(display, caps);
120 case GST_VAAPI_CODEC_MPEG4:
121 decoder = gst_vaapi_decoder_mpeg4_new(display, caps);
123 case GST_VAAPI_CODEC_VC1:
124 decoder = gst_vaapi_decoder_vc1_new(display, caps);
130 gst_caps_unref(caps);
132 GST_ERROR("failed to create %s decoder", codec->codec_str);
136 set_codec_defs(decoder, codec);
141 decoder_put_buffers(GstVaapiDecoder *decoder)
143 const CodecDefs *codec;
144 VideoDecodeInfo info;
148 g_return_val_if_fail(decoder != NULL, FALSE);
150 codec = get_codec_defs(decoder);
151 g_return_val_if_fail(codec != NULL, FALSE);
153 codec->get_video_info(&info);
154 buffer = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY,
155 (guchar *)info.data, info.data_size, 0, info.data_size, NULL, NULL);
157 GST_ERROR("failed to create encoded data buffer");
161 success = gst_vaapi_decoder_put_buffer(decoder, buffer);
162 gst_buffer_unref(buffer);
164 GST_ERROR("failed to send video data to the decoder");
168 if (!gst_vaapi_decoder_put_buffer(decoder, NULL)) {
169 GST_ERROR("failed to submit <end-of-stream> to the decoder");
175 GstVaapiSurfaceProxy *
176 decoder_get_surface(GstVaapiDecoder *decoder)
178 GstVaapiSurfaceProxy *proxy;
179 GstVaapiDecoderStatus status;
181 g_return_val_if_fail(decoder != NULL, NULL);
183 status = gst_vaapi_decoder_get_surface(decoder, &proxy);
184 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
185 GST_ERROR("failed to get decoded surface (decoder status %d)", status);
192 decoder_get_codec_name(GstVaapiDecoder *decoder)
194 const CodecDefs *codec;
196 g_return_val_if_fail(decoder != NULL, NULL);
198 codec = get_codec_defs(decoder);
199 g_return_val_if_fail(codec != NULL, FALSE);
201 return codec->codec_str;