Update
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
if dl.found()
|
||||
shared_library('gstvalidatefaultinjection',
|
||||
'socket_interposer.c',
|
||||
include_directories : inc_dirs,
|
||||
link_with: [gstvalidate],
|
||||
dependencies : [gst_dep, glib_dep, dl],
|
||||
c_args: ['-DHAVE_CONFIG_H'],
|
||||
install : true,
|
||||
install_dir : validate_plugins_install_dir,
|
||||
)
|
||||
endif
|
||||
@@ -0,0 +1,388 @@
|
||||
/* GStreamer
|
||||
*
|
||||
* Copyright (C) 2014 YouView TV Ltd
|
||||
* Authors: Mariusz Buras <mariusz.buras@youview.com>
|
||||
* Mathieu Duponchelle <mathieu.duponchelle@collabora.com>
|
||||
*
|
||||
* socket_interposer.c : overrides for standard socket functions
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include "../../gst/validate/gst-validate-scenario.h"
|
||||
|
||||
#if defined(__gnu_linux__) && !defined(__ANDROID__) && !defined (ANDROID)
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <dlfcn.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define MAX_CALLBACKS (16)
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
/* Return 0 to remove the callback immediately */
|
||||
typedef int (*socket_interposer_callback) (void *, const void *, size_t);
|
||||
|
||||
struct
|
||||
{
|
||||
socket_interposer_callback callback;
|
||||
void *userdata;
|
||||
struct sockaddr_in sockaddr;
|
||||
int fd;
|
||||
} callbacks[MAX_CALLBACKS];
|
||||
|
||||
static int
|
||||
socket_interposer_remove_callback_unlocked (struct sockaddr_in *addrin,
|
||||
socket_interposer_callback callback, void *userdata)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < MAX_CALLBACKS; i++) {
|
||||
if (callbacks[i].callback == callback
|
||||
&& callbacks[i].userdata == userdata
|
||||
&& callbacks[i].sockaddr.sin_addr.s_addr == addrin->sin_addr.s_addr
|
||||
&& callbacks[i].sockaddr.sin_port == addrin->sin_port) {
|
||||
memset (&callbacks[i], 0, sizeof (callbacks[0]));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
socket_interposer_set_callback (struct sockaddr_in *addrin,
|
||||
socket_interposer_callback callback, void *userdata)
|
||||
{
|
||||
size_t i;
|
||||
pthread_mutex_lock (&mutex);
|
||||
|
||||
|
||||
socket_interposer_remove_callback_unlocked (addrin, callback, userdata);
|
||||
for (i = 0; i < MAX_CALLBACKS; i++) {
|
||||
if (callbacks[i].callback == NULL) {
|
||||
callbacks[i].callback = callback;
|
||||
callbacks[i].userdata = userdata;
|
||||
memcpy (&callbacks[i].sockaddr, addrin, sizeof (struct sockaddr_in));
|
||||
callbacks[i].fd = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock (&mutex);
|
||||
}
|
||||
|
||||
int
|
||||
connect (int socket, const struct sockaddr_in *addrin, socklen_t address_len)
|
||||
{
|
||||
size_t i;
|
||||
int override_errno = 0;
|
||||
typedef ssize_t (*real_connect_fn) (int, const struct sockaddr_in *,
|
||||
socklen_t);
|
||||
static real_connect_fn real_connect = 0;
|
||||
ssize_t ret = 0;
|
||||
|
||||
pthread_mutex_lock (&mutex);
|
||||
|
||||
for (i = 0; i < MAX_CALLBACKS; i++) {
|
||||
if (callbacks[i].sockaddr.sin_addr.s_addr == addrin->sin_addr.s_addr
|
||||
&& callbacks[i].sockaddr.sin_port == addrin->sin_port) {
|
||||
|
||||
callbacks[i].fd = socket;
|
||||
|
||||
if (callbacks[i].callback) {
|
||||
int ret = callbacks[i].callback (callbacks[i].userdata, NULL,
|
||||
0);
|
||||
if (ret != 0)
|
||||
override_errno = ret;
|
||||
else /* Remove the callback */
|
||||
memset (&callbacks[i], 0, sizeof (callbacks[0]));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock (&mutex);
|
||||
|
||||
if (!real_connect) {
|
||||
real_connect = (real_connect_fn) dlsym (RTLD_NEXT, "connect");
|
||||
}
|
||||
|
||||
if (!override_errno) {
|
||||
ret = real_connect (socket, addrin, address_len);
|
||||
} else {
|
||||
// override errno
|
||||
errno = override_errno;
|
||||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
send (int socket, const void *buffer, size_t len, int flags)
|
||||
{
|
||||
size_t i;
|
||||
int override_errno = 0;
|
||||
typedef ssize_t (*real_send_fn) (int, const void *, size_t, int);
|
||||
ssize_t ret;
|
||||
static real_send_fn real_send = 0;
|
||||
|
||||
pthread_mutex_lock (&mutex);
|
||||
for (i = 0; i < MAX_CALLBACKS; i++) {
|
||||
if (callbacks[i].fd != 0 && callbacks[i].fd == socket) {
|
||||
int ret = callbacks[i].callback (callbacks[i].userdata, buffer,
|
||||
len);
|
||||
|
||||
if (ret != 0)
|
||||
override_errno = ret;
|
||||
else /* Remove the callback */
|
||||
memset (&callbacks[i], 0, sizeof (callbacks[0]));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock (&mutex);
|
||||
|
||||
if (!real_send) {
|
||||
real_send = (real_send_fn) dlsym (RTLD_NEXT, "send");
|
||||
}
|
||||
|
||||
ret = real_send (socket, buffer, len, flags);
|
||||
|
||||
// override errno
|
||||
if (override_errno != 0) {
|
||||
errno = override_errno;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
ssize_t
|
||||
recv (int socket, void *buffer, size_t length, int flags)
|
||||
{
|
||||
size_t i;
|
||||
int old_errno;
|
||||
typedef ssize_t (*real_recv_fn) (int, void *, size_t, int);
|
||||
ssize_t ret;
|
||||
static real_recv_fn real_recv = 0;
|
||||
|
||||
if (!real_recv) {
|
||||
real_recv = (real_recv_fn) dlsym (RTLD_NEXT, "recv");
|
||||
}
|
||||
|
||||
ret = real_recv (socket, buffer, length, flags);
|
||||
old_errno = errno;
|
||||
|
||||
pthread_mutex_lock (&mutex);
|
||||
for (i = 0; i < MAX_CALLBACKS; i++) {
|
||||
if (callbacks[i].fd != 0 && callbacks[i].fd == socket) {
|
||||
int newerrno = callbacks[i].callback (callbacks[i].userdata, buffer,
|
||||
ret);
|
||||
|
||||
// override errno
|
||||
if (newerrno != 0) {
|
||||
old_errno = newerrno;
|
||||
ret = -1;
|
||||
} else { /* Remove the callback */
|
||||
memset (&callbacks[i], 0, sizeof (callbacks[0]));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock (&mutex);
|
||||
|
||||
errno = old_errno;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct errno_entry
|
||||
{
|
||||
const gchar *str;
|
||||
int _errno;
|
||||
};
|
||||
|
||||
static struct errno_entry errno_map[] = {
|
||||
{"ECONNABORTED", ECONNABORTED},
|
||||
{"ECONNRESET", ECONNRESET},
|
||||
{"ENETRESET", ENETRESET},
|
||||
{"ECONNREFUSED", ECONNREFUSED},
|
||||
{"EHOSTUNREACH", EHOSTUNREACH},
|
||||
{"EHOSTDOWN", EHOSTDOWN},
|
||||
{NULL, 0},
|
||||
};
|
||||
|
||||
static int
|
||||
socket_callback_ (GstValidateAction * action, const void *buff, size_t len)
|
||||
{
|
||||
gint times;
|
||||
gint real_errno;
|
||||
|
||||
gst_structure_get_int (action->structure, "times", ×);
|
||||
gst_structure_get_int (action->structure, "real_errno", &real_errno);
|
||||
|
||||
times -= 1;
|
||||
gst_structure_set (action->structure, "times", G_TYPE_INT, times, NULL);
|
||||
if (times <= 0) {
|
||||
gst_validate_action_set_done (action);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return real_errno;
|
||||
}
|
||||
|
||||
static gint
|
||||
errno_string_to_int (const gchar * errno_str)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; errno_map[i]._errno; i += 1) {
|
||||
if (!g_ascii_strcasecmp (errno_map[i].str, errno_str))
|
||||
return errno_map[i]._errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_fault_injector_loaded (void)
|
||||
{
|
||||
const gchar *ld_preload = g_getenv ("LD_PRELOAD");
|
||||
|
||||
|
||||
return (ld_preload && strstr (ld_preload, "libfaultinjection-1.0.so"));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_execute_corrupt_socket_recv (GstValidateScenario * scenario,
|
||||
GstValidateAction * action)
|
||||
{
|
||||
struct sockaddr_in addr =
|
||||
{ AF_INET, htons (42), {htonl (INADDR_LOOPBACK)}, {0} };
|
||||
gint server_port, times;
|
||||
const gchar *errno_str;
|
||||
gint real_errno;
|
||||
|
||||
if (!_fault_injector_loaded ()) {
|
||||
GST_ERROR
|
||||
("The fault injector wasn't preloaded, can't execute socket recv corruption\n"
|
||||
"You should set LD_PRELOAD to the path of libfaultinjection.so");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_structure_get_int (action->structure, "port", &server_port)) {
|
||||
GST_ERROR ("could not get port to corrupt recv on.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_structure_get_int (action->structure, "times", ×)) {
|
||||
gst_structure_set (action->structure, "times", G_TYPE_INT, 1, NULL);
|
||||
}
|
||||
|
||||
errno_str = gst_structure_get_string (action->structure, "errno");
|
||||
if (!errno_str) {
|
||||
GST_ERROR ("Could not get errno string");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
real_errno = errno_string_to_int (errno_str);
|
||||
|
||||
if (real_errno == 0) {
|
||||
GST_ERROR ("unrecognized errno");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gst_structure_set (action->structure, "real_errno", G_TYPE_INT, real_errno,
|
||||
NULL);
|
||||
|
||||
addr.sin_port = htons (server_port);
|
||||
|
||||
socket_interposer_set_callback (&addr,
|
||||
(socket_interposer_callback) socket_callback_, action);
|
||||
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ASYNC;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
socket_interposer_init (GstPlugin * plugin)
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
gst_validate_register_action_type_dynamic (plugin, "corrupt-socket-recv",
|
||||
GST_RANK_PRIMARY,
|
||||
_execute_corrupt_socket_recv, ((GstValidateActionParameter[]) {
|
||||
{
|
||||
.name = "port",
|
||||
.description = "The port the socket to be corrupted listens on",
|
||||
.mandatory = TRUE,
|
||||
.types = "int",
|
||||
.possible_variables = NULL,
|
||||
},
|
||||
{
|
||||
.name = "errno",
|
||||
.description = "errno to set when failing",
|
||||
.mandatory = TRUE,
|
||||
.types = "string",
|
||||
},
|
||||
{
|
||||
.name = "times",
|
||||
.description = "Number of times to corrupt recv, default is one",
|
||||
.mandatory = FALSE,
|
||||
.types = "int",
|
||||
.possible_variables = NULL,
|
||||
.def = "1",
|
||||
},
|
||||
{NULL}
|
||||
}),
|
||||
"corrupt the next socket receive", GST_VALIDATE_ACTION_TYPE_ASYNC);
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#else /* No LD_PRELOAD tricks on Windows */
|
||||
|
||||
static gboolean
|
||||
socket_interposer_init (GstPlugin * plugin)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
validatefaultinjection,
|
||||
"Fault injector plugin for GstValidate",
|
||||
socket_interposer_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
||||
@@ -0,0 +1,80 @@
|
||||
/* GStreamer
|
||||
*
|
||||
* Copyright (C) 2015 Raspberry Pi Foundation
|
||||
* Author: Thibault Saunier <thibault.saunier@collabora.com>
|
||||
*
|
||||
* gstvalidategapplication.c: GstValidateAction overrides for gapplication
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "../../gst/validate/validate.h"
|
||||
#include "../../gst/validate/gst-validate-scenario.h"
|
||||
#include "../../gst/validate/gst-validate-utils.h"
|
||||
|
||||
|
||||
static gboolean
|
||||
_execute_stop (GstValidateScenario * scenario, GstValidateAction * action)
|
||||
{
|
||||
g_application_quit (g_application_get_default ());
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_validate_gapplication_init (GstPlugin * plugin)
|
||||
{
|
||||
GList *config, *tmp;
|
||||
const gchar *appname;
|
||||
|
||||
config = gst_validate_plugin_get_config (plugin);
|
||||
|
||||
if (!config)
|
||||
return TRUE;
|
||||
|
||||
for (tmp = config; tmp; tmp = tmp->next) {
|
||||
appname = gst_structure_get_string (tmp->data, "application-name");
|
||||
}
|
||||
|
||||
if (appname && g_strcmp0 (g_get_prgname (), appname)) {
|
||||
GST_INFO_OBJECT (plugin, "App: %s is not %s", g_get_prgname (), appname);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gst_validate_register_action_type_dynamic (plugin, "stop",
|
||||
GST_RANK_PRIMARY, _execute_stop, NULL,
|
||||
"Sets the pipeline state to NULL",
|
||||
GST_VALIDATE_ACTION_TYPE_NO_EXECUTION_NOT_FATAL |
|
||||
GST_VALIDATE_ACTION_TYPE_DOESNT_NEED_PIPELINE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
validategapplication,
|
||||
"GstValidate plugin to run validate on gapplication",
|
||||
gst_validate_gapplication_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
||||
@@ -0,0 +1,9 @@
|
||||
shared_library('gstvalidategapplication',
|
||||
'gstvalidategapplication.c',
|
||||
include_directories : inc_dirs,
|
||||
c_args: ['-DHAVE_CONFIG_H'],
|
||||
install: true,
|
||||
install_dir: validate_plugins_install_dir,
|
||||
dependencies : [gst_dep, glib_dep, gst_pbutils_dep, gio_dep],
|
||||
link_with : [gstvalidate]
|
||||
)
|
||||
@@ -0,0 +1,544 @@
|
||||
/* GStreamer
|
||||
*
|
||||
* Copyright (C) 2015 Raspberry Pi Foundation
|
||||
* Author: Thibault Saunier <thibault.saunier@collabora.com>
|
||||
*
|
||||
* gstvalidategtk.c: GstValidateActionTypes to use with gtk applications
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "../../gst/validate/gst-validate-report.h"
|
||||
#include "../../gst/validate/gst-validate-reporter.h"
|
||||
#include "../../gst/validate/validate.h"
|
||||
#include "../../gst/validate/gst-validate-scenario.h"
|
||||
#include "../../gst/validate/gst-validate-utils.h"
|
||||
|
||||
#define ACTION_GDKEVENTS_QUARK g_quark_from_static_string("ACTION_GDKEVENTS_QUARK")
|
||||
static GList *awaited_actions = NULL; /* A list of GstValidateAction to be executed */
|
||||
|
||||
static const gchar *
|
||||
get_widget_name (GtkWidget * widget)
|
||||
{
|
||||
const gchar *name = NULL;
|
||||
|
||||
if (GTK_IS_BUILDABLE (widget))
|
||||
name = gtk_buildable_get_name (GTK_BUILDABLE (widget));
|
||||
|
||||
if (!name) {
|
||||
name = gtk_widget_get_name (widget);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static GdkEventType
|
||||
get_event_type (GstValidateScenario * scenario, GstValidateAction * action)
|
||||
{
|
||||
guint type;
|
||||
const gchar *etype_str = gst_structure_get_string (action->structure, "type");
|
||||
|
||||
if (!etype_str)
|
||||
return GDK_NOTHING;
|
||||
|
||||
if (gst_validate_utils_enum_from_str (GDK_TYPE_EVENT_TYPE, etype_str, &type))
|
||||
return type;
|
||||
|
||||
GST_VALIDATE_REPORT (scenario,
|
||||
g_quark_from_static_string ("scenario::execution-error"),
|
||||
"Uknown event type %s, the string should look like the ones defined in "
|
||||
"gdk_event_type_get_type", etype_str);
|
||||
|
||||
return -2;
|
||||
}
|
||||
|
||||
#if ! GTK_CHECK_VERSION(3,20,0)
|
||||
static GdkDevice *
|
||||
get_device (GstValidateAction * action, GdkInputSource input_source)
|
||||
{
|
||||
GList *tmp, *devices;
|
||||
GdkDevice *device = NULL;
|
||||
GdkDeviceManager *dev_manager;
|
||||
|
||||
dev_manager = gdk_display_get_device_manager (gdk_display_get_default ());
|
||||
devices =
|
||||
gdk_device_manager_list_devices (dev_manager, GDK_DEVICE_TYPE_MASTER);
|
||||
|
||||
for (tmp = devices; tmp; tmp = tmp->next) {
|
||||
if (gdk_device_get_source (tmp->data) == input_source) {
|
||||
device = tmp->data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free (devices);
|
||||
|
||||
return device;
|
||||
}
|
||||
#endif
|
||||
|
||||
static GdkEvent *
|
||||
_create_key_event (GdkWindow * window, GdkEventType etype, guint keyval,
|
||||
guint hw_keycode, guint state, GdkDevice * device)
|
||||
{
|
||||
GdkEvent *event = gdk_event_new (etype);
|
||||
GdkEventKey *kevent = (GdkEventKey *) event;
|
||||
|
||||
kevent->window = g_object_ref (window);
|
||||
kevent->send_event = TRUE;
|
||||
kevent->time = GDK_CURRENT_TIME;
|
||||
kevent->keyval = keyval;
|
||||
kevent->hardware_keycode = hw_keycode;
|
||||
kevent->state = state;
|
||||
|
||||
gdk_event_set_device (event, device);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
static GList *
|
||||
_create_keyboard_events (GstValidateAction * action,
|
||||
GdkWindow * window, const gchar * keyname, const gchar * string,
|
||||
GdkEventType etype)
|
||||
{
|
||||
guint *keys;
|
||||
#if GTK_CHECK_VERSION(3,20,0)
|
||||
GdkDisplay *display;
|
||||
GdkSeat *seat;
|
||||
#endif
|
||||
GList *events = NULL;
|
||||
GdkDevice *device = NULL;
|
||||
GstValidateScenario *scenario = gst_validate_action_get_scenario (action);
|
||||
|
||||
if (etype == GDK_NOTHING) {
|
||||
etype = GDK_KEY_PRESS;
|
||||
} else if (etype != GDK_KEY_PRESS && etype != GDK_KEY_RELEASE) {
|
||||
GST_VALIDATE_REPORT (scenario,
|
||||
g_quark_from_static_string ("scenario::execution-error"),
|
||||
"GdkEvent type %s does not work with the 'keys' parameter",
|
||||
gst_structure_get_string (action->structure, "type"));
|
||||
|
||||
goto fail;
|
||||
}
|
||||
#if GTK_CHECK_VERSION(3,20,0)
|
||||
display = gdk_display_get_default ();
|
||||
if (display == NULL) {
|
||||
GST_VALIDATE_REPORT (scenario,
|
||||
g_quark_from_static_string ("scenario::execution-error"),
|
||||
"Could not find a display");
|
||||
|
||||
goto fail;
|
||||
}
|
||||
|
||||
seat = gdk_display_get_default_seat (display);
|
||||
device = gdk_seat_get_keyboard (seat);
|
||||
#else
|
||||
device = get_device (action, GDK_SOURCE_KEYBOARD);
|
||||
#endif
|
||||
if (device == NULL) {
|
||||
GST_VALIDATE_REPORT (scenario,
|
||||
g_quark_from_static_string ("scenario::execution-error"),
|
||||
"Could not find a keyboard device");
|
||||
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (keyname) {
|
||||
guint keyval, state;
|
||||
|
||||
gtk_accelerator_parse_with_keycode (keyname, &keyval, &keys, &state);
|
||||
events =
|
||||
g_list_append (events, _create_key_event (window, etype, keyval,
|
||||
keys ? keys[0] : 0, state, device));
|
||||
} else if (string) {
|
||||
gint i;
|
||||
|
||||
for (i = 0; string[i]; i++) {
|
||||
gint n_keys;
|
||||
GdkKeymapKey *kmaps;
|
||||
guint keyval = gdk_unicode_to_keyval (string[i]);
|
||||
|
||||
gdk_keymap_get_entries_for_keyval (gdk_keymap_get_for_display
|
||||
(gdk_display_get_default ()), keyval, &kmaps, &n_keys);
|
||||
|
||||
events =
|
||||
g_list_append (events, _create_key_event (window, etype, keyval,
|
||||
kmaps[0].keycode, 0, device));
|
||||
}
|
||||
}
|
||||
|
||||
gst_object_unref (scenario);
|
||||
return events;
|
||||
|
||||
fail:
|
||||
gst_object_unref (scenario);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar **widget_paths;
|
||||
gint current_index;
|
||||
GtkWidget *widget;
|
||||
gboolean found;
|
||||
} WidgetNameWidget;
|
||||
|
||||
static GtkWidget *_find_widget (GtkContainer * container,
|
||||
WidgetNameWidget * res);
|
||||
|
||||
static gboolean
|
||||
_widget_has_name (GtkWidget * widget, gchar * name)
|
||||
{
|
||||
if (g_strcmp0 (get_widget_name (GTK_WIDGET (widget)), name) == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
_find_widget_cb (GtkWidget * child, WidgetNameWidget * res)
|
||||
{
|
||||
if (res->found) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_widget_has_name (child, res->widget_paths[res->current_index])) {
|
||||
res->current_index++;
|
||||
|
||||
if (res->widget_paths[res->current_index] == NULL) {
|
||||
res->widget = child;
|
||||
res->found = TRUE;
|
||||
GST_ERROR ("%p GOT IT!!! %s", child,
|
||||
gtk_buildable_get_name (GTK_BUILDABLE (child)));
|
||||
} else if (GTK_CONTAINER (child)) {
|
||||
res->widget = _find_widget (GTK_CONTAINER (child), res);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (GTK_IS_CONTAINER (child)) {
|
||||
res->widget = _find_widget (GTK_CONTAINER (child), res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
_find_widget (GtkContainer * container, WidgetNameWidget * res)
|
||||
{
|
||||
if (res->found)
|
||||
return res->widget;
|
||||
|
||||
if (_widget_has_name (GTK_WIDGET (container),
|
||||
res->widget_paths[res->current_index])) {
|
||||
res->current_index++;
|
||||
|
||||
if (res->widget_paths[res->current_index] == NULL)
|
||||
return GTK_WIDGET (container);
|
||||
}
|
||||
|
||||
gtk_container_forall (container, (GtkCallback) _find_widget_cb, res);
|
||||
|
||||
if (res->widget) {
|
||||
res->current_index++;
|
||||
|
||||
if (res->widget_paths[res->current_index + 1] == NULL)
|
||||
return res->widget;
|
||||
|
||||
if (GTK_IS_CONTAINER (res->widget))
|
||||
_find_widget (GTK_CONTAINER (res->widget), res);
|
||||
}
|
||||
|
||||
return res->widget;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_find_button (GtkWidget * widget, GtkWidget ** button)
|
||||
{
|
||||
if (GTK_IS_BUTTON (widget))
|
||||
*button = widget;
|
||||
}
|
||||
|
||||
/* Copy pasted from gtk+/gtk/gtktestutils.c */
|
||||
static GSList *
|
||||
test_find_widget_input_windows (GtkWidget * widget, gboolean input_only)
|
||||
{
|
||||
GdkWindow *window;
|
||||
GList *node, *children;
|
||||
GSList *matches = NULL;
|
||||
gpointer udata;
|
||||
|
||||
window = gtk_widget_get_window (widget);
|
||||
|
||||
gdk_window_get_user_data (window, &udata);
|
||||
if (udata == widget && (!input_only || (GDK_IS_WINDOW (window)
|
||||
&& gdk_window_is_input_only (GDK_WINDOW (window)))))
|
||||
matches = g_slist_prepend (matches, window);
|
||||
children = gdk_window_get_children (gtk_widget_get_parent_window (widget));
|
||||
for (node = children; node; node = node->next) {
|
||||
gdk_window_get_user_data (node->data, &udata);
|
||||
if (udata == widget && (!input_only || (GDK_IS_WINDOW (node->data)
|
||||
&& gdk_window_is_input_only (GDK_WINDOW (node->data)))))
|
||||
matches = g_slist_prepend (matches, node->data);
|
||||
}
|
||||
return g_slist_reverse (matches);
|
||||
}
|
||||
|
||||
static GdkWindow *
|
||||
widget_get_window (GtkWidget * widget)
|
||||
{
|
||||
GdkWindow *res = NULL;
|
||||
GSList *iwindows = test_find_widget_input_windows (widget, FALSE);
|
||||
|
||||
if (!iwindows)
|
||||
iwindows = test_find_widget_input_windows (widget, TRUE);
|
||||
|
||||
if (iwindows)
|
||||
res = iwindows->data;
|
||||
|
||||
g_slist_free (iwindows);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static GdkWindow *
|
||||
get_window (GstValidateScenario * scenario, GstValidateAction * action,
|
||||
const gchar * widget_name)
|
||||
{
|
||||
GList *tmptoplevel;
|
||||
GdkWindow *res = NULL;
|
||||
gchar **widget_paths = NULL;
|
||||
|
||||
GList *toplevels = gtk_window_list_toplevels ();
|
||||
|
||||
if (!widget_name)
|
||||
widget_name = gst_structure_get_string (action->structure, "widget-name");
|
||||
|
||||
if (!toplevels) {
|
||||
GST_VALIDATE_REPORT (scenario,
|
||||
g_quark_from_static_string ("scenario::execution-error"),
|
||||
"No Gtk topelevel window found, can not sent GdkEvent");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!widget_name) {
|
||||
res = gtk_widget_get_window (toplevels->data);
|
||||
|
||||
goto done;
|
||||
}
|
||||
|
||||
widget_paths = g_strsplit (widget_name, "/", -1);
|
||||
|
||||
for (tmptoplevel = toplevels; tmptoplevel; tmptoplevel = tmptoplevel->next) {
|
||||
GtkWidget *widget;
|
||||
WidgetNameWidget wn;
|
||||
|
||||
wn.widget_paths = widget_paths;
|
||||
wn.current_index = 0;
|
||||
wn.found = FALSE;
|
||||
wn.widget = NULL;
|
||||
|
||||
widget = _find_widget (tmptoplevel->data, &wn);
|
||||
if (widget) {
|
||||
if (GTK_IS_TOOL_BUTTON (widget)) {
|
||||
GST_ERROR ("IS TOOL BUTTON");
|
||||
gtk_container_forall (GTK_CONTAINER (widget),
|
||||
(GtkCallback) _find_button, &widget);
|
||||
}
|
||||
|
||||
res = widget_get_window (widget);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
g_list_free (toplevels);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static GstValidateActionReturn
|
||||
_put_events (GstValidateAction * action, GList * events)
|
||||
{
|
||||
GList *tmp;
|
||||
|
||||
if (events == NULL)
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
|
||||
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT (action), ACTION_GDKEVENTS_QUARK,
|
||||
events, NULL);
|
||||
awaited_actions = g_list_append (awaited_actions, action);
|
||||
|
||||
for (tmp = events; tmp; tmp = tmp->next) {
|
||||
gdk_event_put (tmp->data);
|
||||
}
|
||||
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ASYNC;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_execute_put_events (GstValidateScenario * scenario, GstValidateAction * action)
|
||||
{
|
||||
GdkEventType etype;
|
||||
const gchar *keys, *string;
|
||||
|
||||
GList *events = NULL;
|
||||
GdkWindow *window = get_window (scenario, action, NULL);
|
||||
|
||||
if (!window)
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
|
||||
|
||||
etype = get_event_type (scenario, action);
|
||||
if (etype == -2)
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
|
||||
|
||||
keys = gst_structure_get_string (action->structure, "keys");
|
||||
string = gst_structure_get_string (action->structure, "string");
|
||||
if (keys || string) {
|
||||
events = _create_keyboard_events (action, window, keys, string, etype);
|
||||
|
||||
return _put_events (action, events);
|
||||
}
|
||||
|
||||
GST_VALIDATE_REPORT (scenario,
|
||||
g_quark_from_static_string ("scenario::execution-error"),
|
||||
"Action parameters not supported yet");
|
||||
|
||||
return GST_VALIDATE_EXECUTE_ACTION_ERROR_REPORTED;
|
||||
}
|
||||
|
||||
static void
|
||||
_process_event (GdkEvent * event, gpointer data)
|
||||
{
|
||||
GList *tmp;
|
||||
GdkEvent *done_event = NULL;
|
||||
GstValidateAction *action = NULL;
|
||||
|
||||
for (tmp = awaited_actions; tmp; tmp = tmp->next) {
|
||||
GstValidateAction *tmp_action = tmp->data;
|
||||
GdkEvent *awaited_event =
|
||||
((GList *) gst_mini_object_get_qdata (GST_MINI_OBJECT (tmp_action),
|
||||
ACTION_GDKEVENTS_QUARK))->data;
|
||||
|
||||
if (awaited_event->type == event->type
|
||||
&& ((GdkEventAny *) event)->window ==
|
||||
((GdkEventAny *) awaited_event)->window) {
|
||||
|
||||
switch (awaited_event->type) {
|
||||
case GDK_KEY_PRESS:
|
||||
case GDK_KEY_RELEASE:
|
||||
if (event->key.keyval == awaited_event->key.keyval) {
|
||||
done_event = awaited_event;
|
||||
action = tmp_action;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (done_event) {
|
||||
GList *awaited_events = gst_mini_object_get_qdata (GST_MINI_OBJECT (action),
|
||||
ACTION_GDKEVENTS_QUARK);
|
||||
|
||||
awaited_events = g_list_remove (awaited_events, done_event);
|
||||
gdk_event_free (done_event);
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT (action), ACTION_GDKEVENTS_QUARK,
|
||||
awaited_events, NULL);
|
||||
|
||||
if (awaited_events == NULL) {
|
||||
awaited_actions = g_list_remove (awaited_actions, action);
|
||||
gst_validate_action_set_done (action);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_main_do_event (event);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_validate_gtk_init (GstPlugin * plugin)
|
||||
{
|
||||
gdk_event_handler_set (_process_event, NULL, NULL);
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
gst_validate_register_action_type_dynamic (plugin, "gtk-put-event",
|
||||
GST_RANK_PRIMARY, _execute_put_events, ((GstValidateActionParameter[]) {
|
||||
{
|
||||
.name = "keys",
|
||||
.description = "The keyboard keys to be used for the event, parsed"
|
||||
" with gtk_accelerator_parse_with_keycode, so refer to its documentation"
|
||||
" for more information",
|
||||
.mandatory = FALSE,
|
||||
.types = "string",
|
||||
.possible_variables = NULL,
|
||||
},
|
||||
{
|
||||
.name = "string",
|
||||
.description = "The string to be 'written' by the keyboard"
|
||||
" sending KEY_PRESS GdkEvents",
|
||||
.mandatory = FALSE,
|
||||
.types = "string",
|
||||
.possible_variables = NULL,
|
||||
},
|
||||
{
|
||||
.name = "type",
|
||||
.description = "The event type to get executed. "
|
||||
"the string should look like the ones in GdkEventType but without"
|
||||
" the leading 'GDK_'. It is not mandatory as it can be computed from"
|
||||
" other present fields (e.g, an action with 'keys' will consider the type"
|
||||
" as 'key_pressed' by default).",
|
||||
.mandatory = FALSE,
|
||||
.types = "string",
|
||||
},
|
||||
{
|
||||
.name = "widget-name",
|
||||
.description = "The name of the target GdkWidget of the GdkEvent"
|
||||
". That widget has to contain a GdkWindow. If not specified,"
|
||||
" the event will be sent to the first toplevel window",
|
||||
.mandatory = FALSE,
|
||||
.types = "string",
|
||||
.possible_variables = NULL,
|
||||
},
|
||||
{NULL}
|
||||
}),
|
||||
"Put a GdkEvent on the event list using gdk_put_event",
|
||||
GST_VALIDATE_ACTION_TYPE_NO_EXECUTION_NOT_FATAL |
|
||||
GST_VALIDATE_ACTION_TYPE_DOESNT_NEED_PIPELINE);
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
validategtk,
|
||||
"GstValidate plugin to execute action specific to the Gtk toolkit",
|
||||
gst_validate_gtk_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
||||
@@ -0,0 +1,7 @@
|
||||
shared_library('gstvalidategtk', 'gstvalidategtk.c',
|
||||
include_directories : inc_dirs,
|
||||
dependencies : [gst_dep, glib_dep, gst_pbutils_dep, gtk_dep],
|
||||
c_args: ['-DHAVE_CONFIG_H'],
|
||||
install : true,
|
||||
install_dir : validate_plugins_install_dir,
|
||||
link_with : [gstvalidate])
|
||||
@@ -0,0 +1,7 @@
|
||||
subdir('fault_injection')
|
||||
subdir('gapplication')
|
||||
subdir('ssim')
|
||||
|
||||
if gtk_dep.found()
|
||||
subdir('gtk')
|
||||
endif
|
||||
@@ -0,0 +1,817 @@
|
||||
/* GStreamer
|
||||
*
|
||||
* Copyright (C) 2015 Raspberry Pi Foundation
|
||||
* Author: Thibault Saunier <thibault.saunier@collabora.com>
|
||||
*
|
||||
* gstvalidatessim.c: GstValidateActionTypes to use with ssim applications
|
||||
*
|
||||
* 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., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <cairo.h>
|
||||
|
||||
#include <glib/gstdio.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include "../../gst-libs/gst/video/gstvalidatessim.h"
|
||||
#include "../../gst/validate/gst-validate-report.h"
|
||||
#include "../../gst/validate/gst-validate-pad-monitor.h"
|
||||
#include "../../gst/validate/gst-validate-reporter.h"
|
||||
#include "../../gst/validate/validate.h"
|
||||
#include "../../gst/validate/gst-validate-scenario.h"
|
||||
#include "../../gst/validate/gst-validate-utils.h"
|
||||
|
||||
#define SSIM_WRONG_FORMAT g_quark_from_static_string ("validatessim::wrong-format")
|
||||
#define SSIM_CONVERSION_ERROR g_quark_from_static_string ("validatessim::conversion-error")
|
||||
#define SSIM_SAVING_ERROR g_quark_from_static_string ("validatessim::saving-error")
|
||||
#define MONITOR_DATA g_quark_from_static_string ("validate-ssim-monitor-data")
|
||||
#define NOT_ATTACHED g_quark_from_static_string ("validatessim::not-attached")
|
||||
|
||||
typedef struct _ValidateSsimOverridePrivate ValidateSsimOverridePrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstValidateOverride parent;
|
||||
|
||||
ValidateSsimOverridePrivate *priv;
|
||||
|
||||
} ValidateSsimOverride;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstValidateOverrideClass parent;
|
||||
|
||||
} ValidateSsimOverrideClass;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gchar *path;
|
||||
GstClockTime position;
|
||||
guint width, height;
|
||||
} Frame;
|
||||
|
||||
static void
|
||||
free_frame (Frame * frame)
|
||||
{
|
||||
g_free (frame->path);
|
||||
}
|
||||
|
||||
struct _ValidateSsimOverridePrivate
|
||||
{
|
||||
gchar *outdir;
|
||||
gchar *result_outdir;
|
||||
GstStructure *config;
|
||||
|
||||
gboolean is_attached;
|
||||
|
||||
GstVideoConverter *converter;
|
||||
GstCaps *last_caps;
|
||||
GstVideoInfo in_info;
|
||||
GstVideoInfo out_info;
|
||||
|
||||
GArray *frames;
|
||||
GstClockTime recurrence;
|
||||
GstClockTime last_dump_position;
|
||||
|
||||
/* Always used in the streaming thread */
|
||||
gboolean needs_reconfigure;
|
||||
GstVideoFormat save_format;
|
||||
const gchar *ext;
|
||||
GstVideoFormat ref_format;
|
||||
const gchar *ref_ext;
|
||||
};
|
||||
|
||||
|
||||
|
||||
static GType validate_ssim_override_get_type (void);
|
||||
|
||||
#define VALIDATE_SSIM_OVERRIDE_TYPE (validate_ssim_override_get_type ())
|
||||
#define VALIDATE_SSIM_OVERRIDE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VALIDATE_SSIM_OVERRIDE_TYPE, ValidateSsimOverride))
|
||||
#define VALIDATE_SSIM_OVERRIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VALIDATE_SSIM_OVERRIDE_TYPE, ValidateSsimOverrideClass))
|
||||
#define IS_VALIDATE_SSIM_OVERRIDE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VALIDATE_SSIM_OVERRIDE_TYPE))
|
||||
#define IS_VALIDATE_SSIM_OVERRIDE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VALIDATE_SSIM_OVERRIDE_TYPE))
|
||||
#define VALIDATE_SSIM_OVERRIDE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VALIDATE_SSIM_OVERRIDE_TYPE, ValidateSsimOverrideClass))
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (ValidateSsimOverride, validate_ssim_override,
|
||||
GST_TYPE_VALIDATE_OVERRIDE)
|
||||
/* *INDENT-ON* */
|
||||
|
||||
static void
|
||||
runner_stopping (GstValidateRunner * runner, ValidateSsimOverride * self)
|
||||
{
|
||||
GstValidateSsim *ssim;
|
||||
|
||||
guint i, nfiles;
|
||||
gfloat mssim = 0, lowest = 1, highest = -1, total_avg = 0;
|
||||
gint npassed = 0, nfailures = 0;
|
||||
gdouble min_avg_similarity = 0.95, min_lowest_similarity = -1.0,
|
||||
min_avg = 1.0, min_min = 1.0;
|
||||
const gchar *compared_files_dir =
|
||||
gst_structure_get_string (self->priv->config,
|
||||
"reference-images-dir");
|
||||
gint fps_n = 0, fps_d = 1;
|
||||
|
||||
if (!self->priv->is_attached) {
|
||||
gchar *config_str = gst_structure_to_string (self->priv->config);
|
||||
GST_VALIDATE_REPORT (self, NOT_ATTACHED,
|
||||
"The test ended without SSIM being attached for config %s", config_str);
|
||||
g_free (config_str);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compared_files_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
gst_validate_printf (self,
|
||||
"Running frame comparison between images from '%s' and '%s' %s%s.\n",
|
||||
compared_files_dir, self->priv->outdir,
|
||||
self->priv->result_outdir ? ". Issues can be visialized in " :
|
||||
" (set 'result-output-dir' in the config file to visualize the result)",
|
||||
self->priv->result_outdir ? self->priv->result_outdir : "");
|
||||
|
||||
gst_structure_get_double (self->priv->config, "min-avg-priority",
|
||||
&min_avg_similarity);
|
||||
gst_structure_get_double (self->priv->config, "min-lowest-priority",
|
||||
&min_lowest_similarity);
|
||||
|
||||
gst_structure_get_fraction (self->priv->config, "framerate", &fps_n, &fps_d);
|
||||
ssim =
|
||||
gst_validate_ssim_new (runner, min_avg_similarity, min_lowest_similarity,
|
||||
fps_n, fps_d);
|
||||
|
||||
nfiles = self->priv->frames->len;
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
Frame *frame = &g_array_index (self->priv->frames, Frame, i);
|
||||
gchar *refname, *ref_path, *bname = g_path_get_basename (frame->path);
|
||||
|
||||
if (self->priv->ref_format == GST_VIDEO_FORMAT_ENCODED)
|
||||
refname = g_strdup_printf ("*.%s", self->priv->ref_ext);
|
||||
else
|
||||
refname = g_strdup_printf ("*.%dx%d.%s", frame->width, frame->height,
|
||||
self->priv->ref_ext);
|
||||
|
||||
ref_path = g_build_path (G_DIR_SEPARATOR_S, compared_files_dir,
|
||||
refname, NULL);
|
||||
|
||||
if (!gst_validate_ssim_compare_image_files (ssim, ref_path, frame->path,
|
||||
&mssim, &lowest, &highest, self->priv->result_outdir))
|
||||
nfailures++;
|
||||
else
|
||||
npassed++;
|
||||
|
||||
min_avg = MIN (min_avg, mssim);
|
||||
min_min = MIN (lowest, min_min);
|
||||
total_avg += mssim;
|
||||
gst_validate_print_position (frame->position, GST_CLOCK_TIME_NONE, 1.0,
|
||||
g_strdup_printf (" %d / %d avg: %f min: %f (Passed: %d failed: %d)",
|
||||
i + 1, nfiles, mssim, lowest, npassed, nfailures));
|
||||
g_free (bname);
|
||||
}
|
||||
|
||||
gst_validate_printf (NULL,
|
||||
"\nAverage similarity: %f, min_avg: %f, min_min: %f\n",
|
||||
total_avg / nfiles, min_avg, min_min);
|
||||
}
|
||||
|
||||
static void
|
||||
_runner_set (GObject * object, GParamSpec * pspec, gpointer user_data)
|
||||
{
|
||||
ValidateSsimOverride *self = VALIDATE_SSIM_OVERRIDE (object);
|
||||
GstValidateRunner *runner =
|
||||
gst_validate_reporter_get_runner (GST_VALIDATE_REPORTER (self));
|
||||
|
||||
g_signal_connect (runner, "stopping", G_CALLBACK (runner_stopping), self);
|
||||
gst_object_unref (runner);
|
||||
}
|
||||
|
||||
static ValidateSsimOverride *
|
||||
validate_ssim_override_new (GstStructure * config)
|
||||
{
|
||||
const gchar *format;
|
||||
ValidateSsimOverride *self = g_object_new (VALIDATE_SSIM_OVERRIDE_TYPE, NULL);
|
||||
|
||||
self->priv->outdir =
|
||||
g_strdup (gst_structure_get_string (config, "output-dir"));
|
||||
|
||||
if (self->priv->outdir == NULL) {
|
||||
gchar *template = g_build_filename (g_get_tmp_dir (),
|
||||
"validatessim-XXXXXX", NULL);
|
||||
self->priv->outdir = g_mkdtemp (template);
|
||||
}
|
||||
|
||||
if (!g_file_test (self->priv->outdir, G_FILE_TEST_IS_DIR)) {
|
||||
if (g_mkdir_with_parents (self->priv->outdir, 0755) != 0) {
|
||||
|
||||
GST_ERROR ("Could not create directory %s", self->priv->outdir);
|
||||
|
||||
g_object_unref (self);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
self->priv->config = gst_structure_copy (config);
|
||||
self->priv->result_outdir =
|
||||
g_strdup (gst_structure_get_string (config, "result-output-dir"));
|
||||
|
||||
format = gst_structure_get_string (config, "output-video-format");
|
||||
if (!format) {
|
||||
self->priv->save_format = GST_VIDEO_FORMAT_ENCODED;
|
||||
self->priv->ext = "png";
|
||||
} else {
|
||||
self->priv->save_format = gst_video_format_from_string (format);
|
||||
self->priv->ext = format;
|
||||
}
|
||||
|
||||
if (self->priv->save_format == GST_VIDEO_FORMAT_UNKNOWN) {
|
||||
GST_ERROR ("Uknown video format: %s", format);
|
||||
|
||||
gst_object_unref (self);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
format = gst_structure_get_string (config, "reference-video-format");
|
||||
if (!format) {
|
||||
self->priv->ref_ext = "png";
|
||||
self->priv->ref_format = GST_VIDEO_FORMAT_ENCODED;
|
||||
} else {
|
||||
self->priv->ref_format = gst_video_format_from_string (format);
|
||||
if (self->priv->ref_format == GST_VIDEO_FORMAT_UNKNOWN) {
|
||||
GST_ERROR ("Uknown video format: %s", format);
|
||||
|
||||
gst_object_unref (self);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->priv->ref_ext = format;
|
||||
}
|
||||
|
||||
gst_validate_utils_get_clocktime (config, "check-recurrence",
|
||||
&self->priv->recurrence);
|
||||
|
||||
g_signal_connect (self, "notify::validate-runner", G_CALLBACK (_runner_set),
|
||||
NULL);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
_can_attach (GstValidateOverride * override, GstValidateMonitor * monitor)
|
||||
{
|
||||
guint i;
|
||||
GstPad *pad = NULL;
|
||||
GstCaps *template_caps;
|
||||
GstElement *element = NULL;
|
||||
GstStructure *structure;
|
||||
gboolean res = FALSE;
|
||||
ValidateSsimOverride *self = VALIDATE_SSIM_OVERRIDE (override);
|
||||
|
||||
if (self->priv->is_attached) {
|
||||
GST_ERROR_OBJECT (override, "Already attached");
|
||||
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!GST_IS_VALIDATE_PAD_MONITOR (monitor)) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pad = GST_PAD (gst_validate_monitor_get_target (monitor));
|
||||
element = gst_validate_monitor_get_element (monitor);
|
||||
|
||||
if (!element) {
|
||||
GST_INFO_OBJECT (monitor, "Not in an element yet, can't attach");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((gst_validate_element_has_klass (element, "Converter") ||
|
||||
gst_validate_element_has_klass (element, "Filter") ||
|
||||
gst_validate_element_has_klass (element, "Decoder")) &&
|
||||
GST_PAD_IS_SINK (pad)) {
|
||||
GST_INFO_OBJECT (override, "Not attaching on filter or decoder sinkpads");
|
||||
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!GST_PAD_PAD_TEMPLATE (pad)) {
|
||||
GST_INFO_OBJECT (pad,
|
||||
"Doesn't have template, can't use it %" GST_PTR_FORMAT,
|
||||
gst_pad_query_caps (pad, NULL));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
template_caps = GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
|
||||
if (gst_caps_is_any (template_caps)) {
|
||||
res = TRUE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < gst_caps_get_size (template_caps); i++) {
|
||||
structure = gst_caps_get_structure (template_caps, i);
|
||||
if (gst_structure_has_name (structure, "video/x-raw")) {
|
||||
res = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (res) {
|
||||
gchar *path = gst_object_get_path_string (GST_OBJECT (pad));
|
||||
GST_INFO_OBJECT (override, "Wrapping %" GST_PTR_FORMAT, pad);
|
||||
|
||||
gst_validate_reporter_set_name (GST_VALIDATE_REPORTER (override),
|
||||
g_strdup_printf ("ssim-override-%s", path));
|
||||
gst_validate_printf (self, "Using %s as output directory\n",
|
||||
self->priv->outdir);
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
if (pad)
|
||||
gst_object_unref (pad);
|
||||
if (element)
|
||||
gst_object_unref (element);
|
||||
return res;
|
||||
|
||||
fail:
|
||||
res = FALSE;
|
||||
goto done;
|
||||
}
|
||||
|
||||
static void
|
||||
validate_ssim_override_attached (GstValidateOverride * override)
|
||||
{
|
||||
ValidateSsimOverride *self = VALIDATE_SSIM_OVERRIDE (override);
|
||||
|
||||
self->priv->is_attached = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
_finalize (GObject * object)
|
||||
{
|
||||
ValidateSsimOverridePrivate *priv = VALIDATE_SSIM_OVERRIDE (object)->priv;
|
||||
GDir *outdir_handle = NULL;
|
||||
const gchar *filename = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (priv->converter)
|
||||
gst_video_converter_free (priv->converter);
|
||||
|
||||
if (priv->last_caps)
|
||||
gst_caps_unref (priv->last_caps);
|
||||
|
||||
if (priv->config && !gst_structure_has_field (priv->config, "output-dir")) {
|
||||
/* Remove temporary directory contents (expected to be files, no sub-directories). */
|
||||
outdir_handle = g_dir_open (priv->outdir, 0, &error);
|
||||
if (outdir_handle != NULL) {
|
||||
while ((filename = g_dir_read_name (outdir_handle))) {
|
||||
gchar *path =
|
||||
g_build_path (G_DIR_SEPARATOR_S, priv->outdir, filename, NULL);
|
||||
g_remove (path);
|
||||
g_free (path);
|
||||
}
|
||||
g_dir_close (outdir_handle);
|
||||
} else {
|
||||
GST_ERROR ("Unable to cleanup temporary directory %s: %s", priv->outdir,
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
g_rmdir (priv->outdir);
|
||||
}
|
||||
|
||||
g_free (priv->outdir);
|
||||
g_free (priv->result_outdir);
|
||||
g_array_unref (priv->frames);
|
||||
|
||||
if (priv->config)
|
||||
gst_structure_free (priv->config);
|
||||
}
|
||||
|
||||
static void
|
||||
validate_ssim_override_class_init (ValidateSsimOverrideClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstValidateOverrideClass *override_class =
|
||||
GST_VALIDATE_OVERRIDE_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = _finalize;
|
||||
override_class->attached = validate_ssim_override_attached;
|
||||
|
||||
if (!gst_validate_is_initialized ())
|
||||
return;
|
||||
|
||||
GST_VALIDATE_OVERRIDE_CLASS (klass)->can_attach = _can_attach;
|
||||
|
||||
gst_validate_issue_register (gst_validate_issue_new (SSIM_WRONG_FORMAT,
|
||||
"The ValidateSSim plugin can not work with a video format",
|
||||
"The GstValidate ssim plugin was not able to work"
|
||||
" with a video format that flowed in the pipeline."
|
||||
" Make sure you properly configured the plugin",
|
||||
GST_VALIDATE_REPORT_LEVEL_CRITICAL));
|
||||
|
||||
gst_validate_issue_register (gst_validate_issue_new (SSIM_CONVERSION_ERROR,
|
||||
"The ValidateSSim plugin could not convert a frame in the needed format",
|
||||
"The GstValidate ssim plugin needs to convert the frame in a colorspace"
|
||||
" it can handle, but it was not possible.",
|
||||
GST_VALIDATE_REPORT_LEVEL_CRITICAL));
|
||||
|
||||
gst_validate_issue_register (gst_validate_issue_new (SSIM_SAVING_ERROR,
|
||||
"The ValidateSSim plugin could not save PNG file",
|
||||
"The ValidateSSim plugin could not save PNG file",
|
||||
GST_VALIDATE_REPORT_LEVEL_CRITICAL));
|
||||
|
||||
gst_validate_issue_register (gst_validate_issue_new
|
||||
(NOT_ATTACHED,
|
||||
"The ssim override was never attached.",
|
||||
"The ssim override was never attached.",
|
||||
GST_VALIDATE_REPORT_LEVEL_CRITICAL));
|
||||
}
|
||||
|
||||
static void
|
||||
validate_ssim_override_init (ValidateSsimOverride * self)
|
||||
{
|
||||
self->priv = validate_ssim_override_get_instance_private (self);
|
||||
|
||||
self->priv->needs_reconfigure = TRUE;
|
||||
self->priv->frames = g_array_new (TRUE, TRUE, sizeof (Frame));
|
||||
g_array_set_clear_func (self->priv->frames, (GDestroyNotify) free_frame);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_set_videoconvert (ValidateSsimOverride * o,
|
||||
GstValidatePadMonitor * pad_monitor)
|
||||
{
|
||||
GstCaps *caps;
|
||||
GstVideoFormat format;
|
||||
ValidateSsimOverridePrivate *priv = o->priv;
|
||||
GstPad *pad =
|
||||
GST_PAD (gst_validate_monitor_get_target (GST_VALIDATE_MONITOR
|
||||
(pad_monitor)));
|
||||
|
||||
caps = gst_pad_get_current_caps (pad);
|
||||
gst_object_unref (pad);
|
||||
gst_caps_replace (&priv->last_caps, caps);
|
||||
|
||||
gst_video_info_init (&priv->in_info);
|
||||
gst_video_info_init (&priv->out_info);
|
||||
if (priv->converter) {
|
||||
gst_video_converter_free (priv->converter);
|
||||
priv->converter = NULL;
|
||||
}
|
||||
|
||||
if (!gst_video_info_from_caps (&priv->in_info, priv->last_caps)) {
|
||||
GST_VALIDATE_REPORT (o, SSIM_WRONG_FORMAT,
|
||||
"The format %" GST_PTR_FORMAT " is not supported"
|
||||
" by the plugin", pad_monitor->last_caps);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (GST_VIDEO_INFO_HAS_ALPHA (&priv->in_info))
|
||||
format = GST_VIDEO_FORMAT_BGRA;
|
||||
else
|
||||
format = GST_VIDEO_FORMAT_BGRx;
|
||||
|
||||
if (priv->in_info.finfo->format == format) {
|
||||
GST_INFO_OBJECT (o, "No conversion needed");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (priv->save_format != GST_VIDEO_FORMAT_ENCODED)
|
||||
format = priv->save_format;
|
||||
|
||||
gst_video_info_set_format (&priv->out_info, format,
|
||||
priv->in_info.width, priv->in_info.height);
|
||||
priv->out_info.fps_d = priv->in_info.fps_d;
|
||||
priv->out_info.fps_n = priv->in_info.fps_n;
|
||||
|
||||
priv->converter = gst_video_converter_new (&priv->in_info,
|
||||
&priv->out_info, NULL);
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
static gboolean
|
||||
has_frame (ValidateSsimOverride * self, gchar * name)
|
||||
{
|
||||
guint i;
|
||||
GArray *frames = self->priv->frames;
|
||||
|
||||
for (i = 0; i < frames->len; ++i) {
|
||||
if (g_strcmp0 (g_array_index (frames, Frame, i).path, name) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
static gchar *
|
||||
_get_filename (ValidateSsimOverride * self, GstValidatePadMonitor * monitor,
|
||||
GstClockTime position)
|
||||
{
|
||||
gint i = 0;
|
||||
gchar *outname = NULL, *s;
|
||||
|
||||
if (self->priv->save_format == GST_VIDEO_FORMAT_ENCODED)
|
||||
s = g_strdup_printf ("%" GST_VALIDATE_SSIM_TIME_FORMAT ".%s",
|
||||
GST_TIME_ARGS (position), self->priv->ext);
|
||||
else
|
||||
s = g_strdup_printf ("%" GST_VALIDATE_SSIM_TIME_FORMAT ".%dx%d.%s",
|
||||
GST_TIME_ARGS (position),
|
||||
self->priv->out_info.width,
|
||||
self->priv->out_info.height, self->priv->ext);
|
||||
|
||||
outname = g_build_path (G_DIR_SEPARATOR_S, self->priv->outdir, s, NULL);
|
||||
|
||||
g_free (s);
|
||||
while (has_frame (self, outname)) {
|
||||
g_free (outname);
|
||||
if (self->priv->save_format == GST_VIDEO_FORMAT_ENCODED)
|
||||
s = g_strdup_printf ("%" GST_VALIDATE_SSIM_TIME_FORMAT "-%d.%s",
|
||||
GST_TIME_ARGS (position), i++, self->priv->ext);
|
||||
else
|
||||
s = g_strdup_printf ("%" GST_VALIDATE_SSIM_TIME_FORMAT "-%d.%dx%d.%s",
|
||||
GST_TIME_ARGS (position), i++, self->priv->out_info.width,
|
||||
self->priv->out_info.height, self->priv->ext);
|
||||
|
||||
outname = g_build_path (G_DIR_SEPARATOR_S, self->priv->outdir, s, NULL);
|
||||
g_free (s);
|
||||
}
|
||||
|
||||
return outname;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_should_dump_buffer (ValidateSsimOverride * self,
|
||||
GstValidatePadMonitor * pad_monitor, GstClockTime position)
|
||||
{
|
||||
ValidateSsimOverridePrivate *priv = self->priv;
|
||||
|
||||
if (!GST_CLOCK_TIME_IS_VALID (priv->recurrence))
|
||||
return TRUE;
|
||||
|
||||
if (priv->needs_reconfigure)
|
||||
return TRUE;
|
||||
|
||||
/* recurence 0 means, dump exclusively on reconfiguration */
|
||||
if (priv->recurrence == 0)
|
||||
return FALSE;
|
||||
|
||||
if (position > priv->last_dump_position ?
|
||||
position - priv->last_dump_position : 0 >= priv->recurrence)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_save_frame (ValidateSsimOverride * self, GstVideoFrame * frame,
|
||||
const gchar * outname)
|
||||
{
|
||||
gboolean res = TRUE;
|
||||
cairo_status_t status;
|
||||
cairo_surface_t *surface;
|
||||
GError *error = NULL;
|
||||
|
||||
if (self->priv->save_format == GST_VIDEO_FORMAT_ENCODED) {
|
||||
surface =
|
||||
cairo_image_surface_create_for_data (GST_VIDEO_FRAME_PLANE_DATA (frame,
|
||||
0), CAIRO_FORMAT_RGB24, GST_VIDEO_FRAME_WIDTH (frame),
|
||||
GST_VIDEO_FRAME_HEIGHT (frame), GST_VIDEO_FRAME_PLANE_STRIDE (frame,
|
||||
0));
|
||||
|
||||
if ((status = cairo_surface_write_to_png (surface, outname)) !=
|
||||
CAIRO_STATUS_SUCCESS) {
|
||||
GST_VALIDATE_REPORT (self, SSIM_SAVING_ERROR,
|
||||
"Could not save '%s', cairo status is '%s'", outname,
|
||||
cairo_status_to_string (status));
|
||||
|
||||
res = FALSE;
|
||||
}
|
||||
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
if (!g_file_set_contents (outname,
|
||||
GST_VIDEO_FRAME_PLANE_DATA (frame, 0),
|
||||
GST_VIDEO_FRAME_SIZE (frame), &error)) {
|
||||
GST_VALIDATE_REPORT (self, SSIM_SAVING_ERROR,
|
||||
"Could not save %s error: %s", outname, error->message);
|
||||
res = FALSE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
_handle_buffer (GstValidateOverride * override,
|
||||
GstValidatePadMonitor * pad_monitor, GstBuffer * buffer)
|
||||
{
|
||||
gchar *outname = NULL;
|
||||
GstVideoFrame frame;
|
||||
Frame iframe;
|
||||
|
||||
ValidateSsimOverride *o = VALIDATE_SSIM_OVERRIDE (override);
|
||||
ValidateSsimOverridePrivate *priv = o->priv;
|
||||
|
||||
GstClockTime position;
|
||||
|
||||
position = gst_segment_to_stream_time (&pad_monitor->segment,
|
||||
GST_FORMAT_TIME, GST_BUFFER_PTS (buffer));
|
||||
|
||||
if (!_should_dump_buffer (o, pad_monitor, position)) {
|
||||
GST_LOG_OBJECT (override, "Not dumping buffer: %" GST_TIME_FORMAT,
|
||||
GST_TIME_ARGS (position));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (priv->needs_reconfigure) {
|
||||
priv->needs_reconfigure = !_set_videoconvert (o, pad_monitor);
|
||||
}
|
||||
|
||||
if (priv->converter) {
|
||||
GstVideoFrame inframe;
|
||||
GstBuffer *outbuf;
|
||||
|
||||
if (!gst_video_frame_map (&inframe, &priv->in_info, buffer, GST_MAP_READ)) {
|
||||
GST_VALIDATE_REPORT (o, SSIM_CONVERSION_ERROR,
|
||||
"Could not map the videoframe %p", buffer);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
outbuf = gst_buffer_new_allocate (NULL, priv->out_info.size, NULL);
|
||||
if (!gst_video_frame_map (&frame, &priv->out_info, outbuf, GST_MAP_WRITE)) {
|
||||
GST_VALIDATE_REPORT (o, SSIM_CONVERSION_ERROR,
|
||||
"Could not map the outbuffer %p", outbuf);
|
||||
|
||||
gst_buffer_unref (outbuf);
|
||||
return;
|
||||
}
|
||||
gst_buffer_unref (outbuf);
|
||||
gst_video_converter_frame (priv->converter, &inframe, &frame);
|
||||
gst_video_frame_unmap (&inframe);
|
||||
} else {
|
||||
if (!gst_video_frame_map (&frame, &priv->in_info, buffer, GST_MAP_WRITE)) {
|
||||
GST_VALIDATE_REPORT (o, SSIM_CONVERSION_ERROR,
|
||||
"Could not map the buffer %p", buffer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
outname = _get_filename (o, pad_monitor, position);
|
||||
if (_save_frame (o, &frame, outname)) {
|
||||
priv->last_dump_position = position;
|
||||
|
||||
iframe.position = position;
|
||||
iframe.path = outname;
|
||||
iframe.width = priv->in_info.width;
|
||||
iframe.height = priv->in_info.height;
|
||||
g_array_append_val (priv->frames, iframe);
|
||||
}
|
||||
|
||||
gst_video_frame_unmap (&frame);
|
||||
}
|
||||
|
||||
static void
|
||||
_handle_event (GstValidateOverride * override,
|
||||
GstValidateMonitor * pad_monitor, GstEvent * event)
|
||||
{
|
||||
ValidateSsimOverride *self = VALIDATE_SSIM_OVERRIDE (override);
|
||||
|
||||
switch (GST_EVENT_TYPE (event)) {
|
||||
case GST_EVENT_FLUSH_STOP:
|
||||
self->priv->needs_reconfigure = TRUE;
|
||||
break;
|
||||
case GST_EVENT_CAPS:
|
||||
self->priv->needs_reconfigure = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_map_confg (GQuark field_id, GValue * value, GstStructure * structure)
|
||||
{
|
||||
if (!gst_structure_id_has_field (structure, field_id))
|
||||
gst_structure_id_set_value (structure, field_id, value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_validate_ssim_init (GstPlugin * plugin)
|
||||
{
|
||||
GList *tmp, *config;
|
||||
GstStructure *config_structure = NULL;
|
||||
|
||||
if (!gst_validate_is_initialized ())
|
||||
return FALSE;
|
||||
|
||||
config = gst_validate_plugin_get_config (plugin);
|
||||
for (tmp = config; tmp; tmp = tmp->next) {
|
||||
gboolean is_config;
|
||||
|
||||
if (gst_structure_get_boolean (tmp->data, "is-config", &is_config)) {
|
||||
if (is_config) {
|
||||
config_structure = tmp->data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (tmp = config; tmp; tmp = tmp->next) {
|
||||
const gchar *name = gst_structure_get_string (tmp->data, "element-name");
|
||||
const gchar *target_element_classification =
|
||||
gst_structure_get_string (tmp->data, "element-classification");
|
||||
|
||||
if (tmp->data == config_structure)
|
||||
continue;
|
||||
|
||||
if (config_structure) {
|
||||
gst_structure_map_in_place (config_structure,
|
||||
(GstStructureMapFunc) _map_confg, tmp->data);
|
||||
}
|
||||
if ((name || target_element_classification)) {
|
||||
GstValidateOverride *override =
|
||||
GST_VALIDATE_OVERRIDE (validate_ssim_override_new (tmp->data));
|
||||
|
||||
if (override == NULL) {
|
||||
GST_ERROR ("Could not create override with config %"
|
||||
GST_PTR_FORMAT, tmp->data);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
override->buffer_probe_handler =
|
||||
(GstValidateOverrideBufferHandler) _handle_buffer;
|
||||
override->buffer_handler =
|
||||
(GstValidateOverrideBufferHandler) _handle_buffer;
|
||||
override->event_handler = (GstValidateOverrideEventHandler) _handle_event;
|
||||
|
||||
if (target_element_classification)
|
||||
gst_validate_override_register_by_klass (target_element_classification,
|
||||
override);
|
||||
else if (name)
|
||||
gst_validate_override_register_by_name (name, override);
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
g_object_unref (override);
|
||||
} else {
|
||||
GST_ERROR ("Wrong configuration '%" GST_PTR_FORMAT
|
||||
"'element-classification' and output-dir are mandatory fields",
|
||||
tmp->data);
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
GST_VERSION_MINOR,
|
||||
validatessim,
|
||||
"GstValidate plugin to run the ssim algorithm on raw"
|
||||
" video buffers. It allows you to generate png files"
|
||||
"\n "
|
||||
" and then check them against pre generated, reference images."
|
||||
"\n "
|
||||
" The following parameters can be passed in the configuration file:"
|
||||
"\n "
|
||||
" 'element-classification': The target element classification as define in gst_element_class_set_metadata"
|
||||
"\n "
|
||||
" 'output-dir': The directory in which the image files will be saved'"
|
||||
"\n",
|
||||
gst_validate_ssim_init, VERSION, "LGPL", GST_PACKAGE_NAME,
|
||||
GST_PACKAGE_ORIGIN)
|
||||
@@ -0,0 +1,12 @@
|
||||
if validate_video_dep.found()
|
||||
shared_library('gstvalidatessim',
|
||||
'gstvalidatessim.c',
|
||||
include_directories : inc_dirs,
|
||||
link_with: [gstvalidate],
|
||||
dependencies : [gst_dep, gst_video_dep, glib_dep, validate_video_dep,
|
||||
gst_pbutils_dep],
|
||||
install : true,
|
||||
install_dir : validate_plugins_install_dir,
|
||||
c_args: ['-DHAVE_CONFIG_H'],
|
||||
)
|
||||
endif
|
||||
Reference in New Issue
Block a user