gstreamer/subprojects/gstreamer-vaapi/tests/internal/decoder.c

200 lines
5.2 KiB
C
Raw Normal View History

2013-01-10 10:22:38 +00:00
/*
* decoder.h - Decoder utilities for the tests
*
* Copyright (C) 2013 Intel Corporation
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
2013-01-10 10:22:38 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "gst/vaapi/sysdeps.h"
2013-01-10 10:22:38 +00:00
#include <gst/vaapi/gstvaapidecoder_h264.h>
#include <gst/vaapi/gstvaapidecoder_jpeg.h>
#include <gst/vaapi/gstvaapidecoder_mpeg2.h>
#include <gst/vaapi/gstvaapidecoder_mpeg4.h>
#include <gst/vaapi/gstvaapidecoder_vc1.h>
#include "decoder.h"
#include "test-jpeg.h"
#include "test-mpeg2.h"
#include "test-mpeg4.h"
#include "test-h264.h"
#include "test-vc1.h"
2016-04-29 10:48:44 +00:00
typedef void (*GetVideoInfoFunc) (VideoDecodeInfo * info);
2013-01-10 10:22:38 +00:00
typedef struct _CodecDefs CodecDefs;
2016-04-29 10:48:44 +00:00
struct _CodecDefs
{
const gchar *codec_str;
GetVideoInfoFunc get_video_info;
2013-01-10 10:22:38 +00:00
};
static const CodecDefs g_codec_defs[] = {
#define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
2016-04-29 10:48:44 +00:00
INIT_FUNCS (jpeg),
INIT_FUNCS (mpeg2),
INIT_FUNCS (mpeg4),
INIT_FUNCS (h264),
INIT_FUNCS (vc1),
2013-01-10 10:22:38 +00:00
#undef INIT_FUNCS
2016-04-29 10:48:44 +00:00
{NULL,}
2013-01-10 10:22:38 +00:00
};
static const CodecDefs *
2016-04-29 10:48:44 +00:00
find_codec_defs (const gchar * codec_str)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
const CodecDefs *c;
for (c = g_codec_defs; c->codec_str; c++)
if (strcmp (codec_str, c->codec_str) == 0)
return c;
return NULL;
2013-01-10 10:22:38 +00:00
}
static inline const CodecDefs *
2016-04-29 10:48:44 +00:00
get_codec_defs (GstVaapiDecoder * decoder)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
return gst_vaapi_decoder_get_user_data (decoder);
2013-01-10 10:22:38 +00:00
}
static inline void
2016-04-29 10:48:44 +00:00
set_codec_defs (GstVaapiDecoder * decoder, const CodecDefs * c)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
gst_vaapi_decoder_set_user_data (decoder, (gpointer) c);
2013-01-10 10:22:38 +00:00
}
GstVaapiDecoder *
2016-04-29 10:48:44 +00:00
decoder_new (GstVaapiDisplay * display, const gchar * codec_name)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
GstVaapiDecoder *decoder;
const CodecDefs *codec;
GstCaps *caps;
VideoDecodeInfo info;
if (!codec_name)
codec_name = "h264";
codec = find_codec_defs (codec_name);
if (!codec) {
GST_ERROR ("failed to find %s codec data", codec_name);
return NULL;
}
codec->get_video_info (&info);
caps = gst_vaapi_profile_get_caps (info.profile);
if (!caps) {
GST_ERROR ("failed to create decoder caps");
return NULL;
}
if (info.width > 0 && info.height > 0)
gst_caps_set_simple (caps,
"width", G_TYPE_INT, info.width,
"height", G_TYPE_INT, info.height, NULL);
switch (gst_vaapi_profile_get_codec (info.profile)) {
2013-01-10 10:22:38 +00:00
case GST_VAAPI_CODEC_H264:
2016-04-29 10:48:44 +00:00
decoder = gst_vaapi_decoder_h264_new (display, caps);
break;
2013-01-10 10:22:38 +00:00
case GST_VAAPI_CODEC_JPEG:
2016-04-29 10:48:44 +00:00
decoder = gst_vaapi_decoder_jpeg_new (display, caps);
break;
2013-01-10 10:22:38 +00:00
case GST_VAAPI_CODEC_MPEG2:
2016-04-29 10:48:44 +00:00
decoder = gst_vaapi_decoder_mpeg2_new (display, caps);
break;
2013-01-10 10:22:38 +00:00
case GST_VAAPI_CODEC_MPEG4:
2016-04-29 10:48:44 +00:00
decoder = gst_vaapi_decoder_mpeg4_new (display, caps);
break;
2013-01-10 10:22:38 +00:00
case GST_VAAPI_CODEC_VC1:
2016-04-29 10:48:44 +00:00
decoder = gst_vaapi_decoder_vc1_new (display, caps);
break;
2013-01-10 10:22:38 +00:00
default:
2016-04-29 10:48:44 +00:00
decoder = NULL;
break;
}
gst_caps_unref (caps);
if (!decoder) {
GST_ERROR ("failed to create %s decoder", codec->codec_str);
return NULL;
}
set_codec_defs (decoder, codec);
return decoder;
2013-01-10 10:22:38 +00:00
}
gboolean
2016-04-29 10:48:44 +00:00
decoder_put_buffers (GstVaapiDecoder * decoder)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
const CodecDefs *codec;
VideoDecodeInfo info;
GstBuffer *buffer;
gboolean success;
g_return_val_if_fail (decoder != NULL, FALSE);
codec = get_codec_defs (decoder);
g_return_val_if_fail (codec != NULL, FALSE);
codec->get_video_info (&info);
buffer = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY,
(guchar *) info.data, info.data_size, 0, info.data_size, NULL, NULL);
if (!buffer) {
GST_ERROR ("failed to create encoded data buffer");
return FALSE;
}
success = gst_vaapi_decoder_put_buffer (decoder, buffer);
gst_buffer_unref (buffer);
if (!success) {
GST_ERROR ("failed to send video data to the decoder");
return FALSE;
}
if (!gst_vaapi_decoder_put_buffer (decoder, NULL)) {
GST_ERROR ("failed to submit <end-of-stream> to the decoder");
return FALSE;
}
return TRUE;
2013-01-10 10:22:38 +00:00
}
GstVaapiSurfaceProxy *
2016-04-29 10:48:44 +00:00
decoder_get_surface (GstVaapiDecoder * decoder)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
GstVaapiSurfaceProxy *proxy;
GstVaapiDecoderStatus status;
2013-01-10 10:22:38 +00:00
2016-04-29 10:48:44 +00:00
g_return_val_if_fail (decoder != NULL, NULL);
2013-01-10 10:22:38 +00:00
2016-04-29 10:48:44 +00:00
status = gst_vaapi_decoder_get_surface (decoder, &proxy);
if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
GST_ERROR ("failed to get decoded surface (decoder status %d)", status);
return NULL;
}
return proxy;
2013-01-10 10:22:38 +00:00
}
const gchar *
2016-04-29 10:48:44 +00:00
decoder_get_codec_name (GstVaapiDecoder * decoder)
2013-01-10 10:22:38 +00:00
{
2016-04-29 10:48:44 +00:00
const CodecDefs *codec;
2013-01-10 10:22:38 +00:00
2016-04-29 10:48:44 +00:00
g_return_val_if_fail (decoder != NULL, NULL);
2013-01-10 10:22:38 +00:00
2016-04-29 10:48:44 +00:00
codec = get_codec_defs (decoder);
g_return_val_if_fail (codec != NULL, FALSE);
2013-01-10 10:22:38 +00:00
2016-04-29 10:48:44 +00:00
return codec->codec_str;
2013-01-10 10:22:38 +00:00
}