tests: inforce gstreamer code-style

parent 018ea8b2
......@@ -24,170 +24,172 @@
#include <gst/vaapi/gstvaapidisplay.h>
#include "codec.h"
typedef struct {
const gchar *codec_str;
GstVaapiCodec codec;
const gchar *caps_str;
typedef struct
{
const gchar *codec_str;
GstVaapiCodec codec;
const gchar *caps_str;
} CodecMap;
static const CodecMap g_codec_map[] = {
{ "h264", GST_VAAPI_CODEC_H264,
"video/x-h264" },
{ "jpeg", GST_VAAPI_CODEC_JPEG,
"image/jpeg" },
{ "mpeg2", GST_VAAPI_CODEC_MPEG2,
"video/mpeg, mpegversion=2" },
{ "mpeg4", GST_VAAPI_CODEC_MPEG4,
"video/mpeg, mpegversion=4" },
{ "wmv3", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3" },
{ "vc1", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3, format=(string)WVC1" },
{ NULL, }
{"h264", GST_VAAPI_CODEC_H264,
"video/x-h264"},
{"jpeg", GST_VAAPI_CODEC_JPEG,
"image/jpeg"},
{"mpeg2", GST_VAAPI_CODEC_MPEG2,
"video/mpeg, mpegversion=2"},
{"mpeg4", GST_VAAPI_CODEC_MPEG4,
"video/mpeg, mpegversion=4"},
{"wmv3", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3"},
{"vc1", GST_VAAPI_CODEC_VC1,
"video/x-wmv, wmvversion=3, format=(string)WVC1"},
{NULL,}
};
static const CodecMap *
get_codec_map(GstVaapiCodec codec)
get_codec_map (GstVaapiCodec codec)
{
const CodecMap *m;
const CodecMap *m;
if (codec) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (m->codec == codec)
return m;
}
if (codec) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (m->codec == codec)
return m;
}
return NULL;
}
return NULL;
}
const gchar *
string_from_codec(GstVaapiCodec codec)
string_from_codec (GstVaapiCodec codec)
{
const CodecMap * const m = get_codec_map(codec);
const CodecMap *const m = get_codec_map (codec);
return m ? m->codec_str : NULL;
return m ? m->codec_str : NULL;
}
GstCaps *
caps_from_codec(GstVaapiCodec codec)
caps_from_codec (GstVaapiCodec codec)
{
const CodecMap * const m = get_codec_map(codec);
const CodecMap *const m = get_codec_map (codec);
return m ? gst_caps_from_string(m->caps_str) : NULL;
return m ? gst_caps_from_string (m->caps_str) : NULL;
}
GstVaapiCodec
identify_codec_from_string(const gchar *codec_str)
identify_codec_from_string (const gchar * codec_str)
{
const CodecMap *m;
const CodecMap *m;
if (codec_str) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (g_ascii_strcasecmp(m->codec_str, codec_str) == 0)
return m->codec;
}
if (codec_str) {
for (m = g_codec_map; m->codec_str != NULL; m++) {
if (g_ascii_strcasecmp (m->codec_str, codec_str) == 0)
return m->codec;
}
return 0;
}
return 0;
}
typedef struct {
GMappedFile *file;
guint8 *data;
guint size;
guint probability;
GstCaps *caps;
GstTypeFind type_find;
typedef struct
{
GMappedFile *file;
guint8 *data;
guint size;
guint probability;
GstCaps *caps;
GstTypeFind type_find;
} CodecIdentifier;
static const guint8 *
codec_identifier_peek(gpointer data, gint64 offset, guint size)
codec_identifier_peek (gpointer data, gint64 offset, guint size)
{
CodecIdentifier * const cip = data;
CodecIdentifier *const cip = data;
if (offset >= 0 && offset + size <= cip->size)
return cip->data + offset;
if (offset < 0 && ((gint)cip->size + offset) >= 0)
return &cip->data[cip->size + offset];
return NULL;
if (offset >= 0 && offset + size <= cip->size)
return cip->data + offset;
if (offset < 0 && ((gint) cip->size + offset) >= 0)
return &cip->data[cip->size + offset];
return NULL;
}
static void
codec_identifier_suggest(gpointer data, guint probability, GstCaps *caps)
codec_identifier_suggest (gpointer data, guint probability, GstCaps * caps)
{
CodecIdentifier * const cip = data;
CodecIdentifier *const cip = data;
if (cip->probability < probability) {
cip->probability = probability;
gst_caps_replace(&cip->caps, caps);
}
if (cip->probability < probability) {
cip->probability = probability;
gst_caps_replace (&cip->caps, caps);
}
}
static void
codec_identifier_free(CodecIdentifier *cip)
codec_identifier_free (CodecIdentifier * cip)
{
if (!cip)
return;
if (cip->file) {
g_mapped_file_unref(cip->file);
cip->file = NULL;
}
gst_caps_replace(&cip->caps, NULL);
g_slice_free(CodecIdentifier, cip);
if (!cip)
return;
if (cip->file) {
g_mapped_file_unref (cip->file);
cip->file = NULL;
}
gst_caps_replace (&cip->caps, NULL);
g_slice_free (CodecIdentifier, cip);
}
static CodecIdentifier *
codec_identifier_new(const gchar *filename)
codec_identifier_new (const gchar * filename)
{
CodecIdentifier *cip;
GstTypeFind *tfp;
CodecIdentifier *cip;
GstTypeFind *tfp;
cip = g_slice_new0(CodecIdentifier);
if (!cip)
return NULL;
cip = g_slice_new0 (CodecIdentifier);
if (!cip)
return NULL;
cip->file = g_mapped_file_new(filename, FALSE, NULL);
if (!cip->file)
goto error;
cip->file = g_mapped_file_new (filename, FALSE, NULL);
if (!cip->file)
goto error;
cip->size = g_mapped_file_get_length(cip->file);
cip->data = (guint8 *)g_mapped_file_get_contents(cip->file);
if (!cip->data)
goto error;
cip->size = g_mapped_file_get_length (cip->file);
cip->data = (guint8 *) g_mapped_file_get_contents (cip->file);
if (!cip->data)
goto error;
tfp = &cip->type_find;
tfp->peek = codec_identifier_peek;
tfp->suggest = codec_identifier_suggest;
tfp->data = cip;
return cip;
tfp = &cip->type_find;
tfp->peek = codec_identifier_peek;
tfp->suggest = codec_identifier_suggest;
tfp->data = cip;
return cip;
error:
codec_identifier_free(cip);
return NULL;
codec_identifier_free (cip);
return NULL;
}
GstVaapiCodec
identify_codec(const gchar *filename)
identify_codec (const gchar * filename)
{
CodecIdentifier *cip;
GList *type_list, *l;
guint32 codec = 0;
cip = codec_identifier_new(filename);
if (!cip)
return 0;
type_list = gst_type_find_factory_get_list();
for (l = type_list; l != NULL; l = l->next) {
GstTypeFindFactory * const factory = GST_TYPE_FIND_FACTORY(l->data);
gst_type_find_factory_call_function(factory, &cip->type_find);
}
g_list_free(type_list);
CodecIdentifier *cip;
GList *type_list, *l;
guint32 codec = 0;
cip = codec_identifier_new (filename);
if (!cip)
return 0;
type_list = gst_type_find_factory_get_list ();
for (l = type_list; l != NULL; l = l->next) {
GstTypeFindFactory *const factory = GST_TYPE_FIND_FACTORY (l->data);
gst_type_find_factory_call_function (factory, &cip->type_find);
}
g_list_free (type_list);
if (cip->probability >= GST_TYPE_FIND_LIKELY)
codec = gst_vaapi_profile_get_codec(
gst_vaapi_profile_from_caps(cip->caps));
if (cip->probability >= GST_TYPE_FIND_LIKELY)
codec =
gst_vaapi_profile_get_codec (gst_vaapi_profile_from_caps (cip->caps));
codec_identifier_free(cip);
return codec;
codec_identifier_free (cip);
return codec;
}
......@@ -34,169 +34,169 @@
#include "test-h264.h"
#include "test-vc1.h"
typedef void (*GetVideoInfoFunc)(VideoDecodeInfo *info);
typedef void (*GetVideoInfoFunc) (VideoDecodeInfo * info);
typedef struct _CodecDefs CodecDefs;
struct _CodecDefs {
const gchar *codec_str;
GetVideoInfoFunc get_video_info;
struct _CodecDefs
{
const gchar *codec_str;
GetVideoInfoFunc get_video_info;
};
static const CodecDefs g_codec_defs[] = {
#define INIT_FUNCS(CODEC) { #CODEC, CODEC##_get_video_info }
INIT_FUNCS(jpeg),
INIT_FUNCS(mpeg2),
INIT_FUNCS(mpeg4),
INIT_FUNCS(h264),
INIT_FUNCS(vc1),
INIT_FUNCS (jpeg),
INIT_FUNCS (mpeg2),
INIT_FUNCS (mpeg4),
INIT_FUNCS (h264),
INIT_FUNCS (vc1),
#undef INIT_FUNCS
{ NULL, }
{NULL,}
};
static const CodecDefs *
find_codec_defs(const gchar *codec_str)
find_codec_defs (const gchar * codec_str)
{
const CodecDefs *c;
for (c = g_codec_defs; c->codec_str; c++)
if (strcmp(codec_str, c->codec_str) == 0)
return c;
return NULL;
const CodecDefs *c;
for (c = g_codec_defs; c->codec_str; c++)
if (strcmp (codec_str, c->codec_str) == 0)
return c;
return NULL;
}
static inline const CodecDefs *
get_codec_defs(GstVaapiDecoder *decoder)
get_codec_defs (GstVaapiDecoder * decoder)
{
return gst_vaapi_decoder_get_user_data(decoder);
return gst_vaapi_decoder_get_user_data (decoder);
}
static inline void
set_codec_defs(GstVaapiDecoder *decoder, const CodecDefs *c)
set_codec_defs (GstVaapiDecoder * decoder, const CodecDefs * c)
{
gst_vaapi_decoder_set_user_data(decoder, (gpointer)c);
gst_vaapi_decoder_set_user_data (decoder, (gpointer) c);
}
GstVaapiDecoder *
decoder_new(GstVaapiDisplay *display, const gchar *codec_name)
decoder_new (GstVaapiDisplay * display, const gchar * codec_name)
{
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)) {
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)) {
case GST_VAAPI_CODEC_H264:
decoder = gst_vaapi_decoder_h264_new(display, caps);
break;
decoder = gst_vaapi_decoder_h264_new (display, caps);
break;
#if USE_JPEG_DECODER
case GST_VAAPI_CODEC_JPEG:
decoder = gst_vaapi_decoder_jpeg_new(display, caps);
break;
decoder = gst_vaapi_decoder_jpeg_new (display, caps);
break;
#endif
case GST_VAAPI_CODEC_MPEG2:
decoder = gst_vaapi_decoder_mpeg2_new(display, caps);
break;
decoder = gst_vaapi_decoder_mpeg2_new (display, caps);
break;
case GST_VAAPI_CODEC_MPEG4:
decoder = gst_vaapi_decoder_mpeg4_new(display, caps);
break;
decoder = gst_vaapi_decoder_mpeg4_new (display, caps);
break;
case GST_VAAPI_CODEC_VC1:
decoder = gst_vaapi_decoder_vc1_new(display, caps);
break;
decoder = gst_vaapi_decoder_vc1_new (display, caps);
break;
default:
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;
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;
}
gboolean
decoder_put_buffers(GstVaapiDecoder *decoder)
decoder_put_buffers (GstVaapiDecoder * decoder)
{
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;
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;
}
GstVaapiSurfaceProxy *
decoder_get_surface(GstVaapiDecoder *decoder)
decoder_get_surface (GstVaapiDecoder * decoder)
{
GstVaapiSurfaceProxy *proxy;
GstVaapiDecoderStatus status;
GstVaapiSurfaceProxy *proxy;
GstVaapiDecoderStatus status;
g_return_val_if_fail(decoder != NULL, NULL);
g_return_val_if_fail (decoder != NULL, NULL);
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;
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;
}
const gchar *
decoder_get_codec_name(GstVaapiDecoder *decoder)
decoder_get_codec_name (GstVaapiDecoder * decoder)
{
const CodecDefs *codec;
const CodecDefs *codec;
g_return_val_if_fail(decoder != NULL, NULL);
g_return_val_if_fail (decoder != NULL, NULL);
codec = get_codec_defs(decoder);
g_return_val_if_fail(codec != NULL, FALSE);
codec = get_codec_defs (decoder);
g_return_val_if_fail (codec != NULL, FALSE);
return codec->codec_str;
return codec->codec_str;
}
This diff is collapsed.
......@@ -48,34 +48,30 @@
static const VideoOutputInfo *g_video_output;
static const VideoOutputInfo g_video_outputs[] = {
/* Video outputs are sorted in test order for automatic characterisation */
/* Video outputs are sorted in test order for automatic characterisation */
#if USE_WAYLAND
{ "wayland",
gst_vaapi_display_wayland_new,
gst_vaapi_window_wayland_new
},
{"wayland",
gst_vaapi_display_wayland_new,
gst_vaapi_window_wayland_new},
#endif
#if USE_X11
{ "x11",
gst_vaapi_display_x11_new,
gst_vaapi_window_x11_new,
gst_vaapi_pixmap_x11_new
},
{"x11",
gst_vaapi_display_x11_new,
gst_vaapi_window_x11_new,
gst_vaapi_pixmap_x11_new},
#endif
#if USE_GLX
{ "glx",
gst_vaapi_display_glx_new,
gst_vaapi_window_glx_new,
gst_vaapi_pixmap_x11_new
},
{"glx",
gst_vaapi_display_glx_new,
gst_vaapi_window_glx_new,
gst_vaapi_pixmap_x11_new},
#endif
#if USE_DRM
{ "drm",
gst_vaapi_display_drm_new,
gst_vaapi_window_drm_new
},
{"drm",
gst_vaapi_display_drm_new,
gst_vaapi_window_drm_new},
#endif
{ NULL, }
{NULL,}
};
static gchar *g_output_name;
......@@ -86,163 +82,164 @@ static gboolean g_egl_mode = FALSE;
static guint g_gles_version;
static GOptionEntry g_options[] = {
{ "list-outputs", 0,
0,
G_OPTION_ARG_NONE, &g_list_outputs,
"list video outputs", NULL },
{ "output", 'o',
0,
G_OPTION_ARG_STRING, &g_output_name,
"video output name", NULL },
{ "fullscreen", 'f',
0,
G_OPTION_ARG_NONE, &g_fullscreen,
"fullscreen mode", NULL },
{ "egl", 0,
0,
G_OPTION_ARG_NONE, &g_egl_mode,
"enable EGL rendering", NULL },
{ "gles-version", 0,
0,
G_OPTION_ARG_INT, &g_gles_version,
"OpenGL|ES version (in --egl mode)", NULL },
{ NULL, }
{"list-outputs", 0,
0,
G_OPTION_ARG_NONE, &g_list_outputs,
"list video outputs", NULL},
{"output", 'o',
0,
G_OPTION_ARG_STRING, &g_output_name,
"video output name", NULL},
{"fullscreen", 'f',
0,
G_OPTION_ARG_NONE, &g_fullscreen,
"fullscreen mode", NULL},
{"egl", 0,
0,
G_OPTION_ARG_NONE, &g_egl_mode,
"enable EGL rendering", NULL},
{"gles-version", 0,
0,
G_OPTION_ARG_INT, &g_gles_version,
"OpenGL|ES version (in --egl mode)", NULL},
{NULL,}
};
static void
list_outputs(void)
list_outputs (void)
{
const VideoOutputInfo *o;
const VideoOutputInfo *o;
g_print("Video outputs:");
for (o = g_video_outputs; o->name != NULL; o++)
g_print(" %s", o->name);
g_print("\n");
g_print ("Video outputs:");
for (o = g_video_outputs; o->name != NULL; o++)
g_print (" %s", o->name);
g_print ("\n");
}
gboolean
video_output_init(int *argc, char *argv[], GOptionEntry *options)
video_output_init (int *argc, char *argv[], GOptionEntry * options)
{
GOptionContext *ctx;
gboolean success;
GOptionContext *ctx;
gboolean success;
#if !GLIB_CHECK_VERSION(2,31,0)
if (!g_thread_supported())
g_thread_init(NULL);
if (!g_thread_supported ())
g_thread_init (NULL);
#endif
ctx = g_option_context_new("- test options");
if (!ctx)
return FALSE;
g_option_context_add_group(ctx, gst_init_get_option_group());
g_option_context_add_main_entries(ctx, g_options, NULL);
if (options)
g_option_context_add_main_entries(ctx, options, NULL);
success = g_option_context_parse(ctx, argc, &argv, NULL);
g_option_context_free(ctx);
if (g_list_outputs) {
list_outputs();
exit(0);
}
return success;
ctx = g_option_context_new ("- test options");
if (!ctx)