2013-07-10 17:03:49 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2013 Thiago Santos <thiago.sousa.santos@collabora.com>
|
|
|
|
*
|
|
|
|
* gst-qa-element-monitor.c - QA Monitor class
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gst-qa-monitor.h"
|
2013-07-22 23:17:53 +00:00
|
|
|
#include "gst-qa-reporter.h"
|
2013-07-10 17:03:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gst-qa-monitor
|
|
|
|
* @short_description: Base class that wraps a #GObject for QA checks
|
|
|
|
*
|
|
|
|
* TODO
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_OBJECT,
|
2013-07-12 03:41:43 +00:00
|
|
|
PROP_RUNNER,
|
2013-07-12 19:02:25 +00:00
|
|
|
PROP_QA_PARENT,
|
2013-07-10 17:03:49 +00:00
|
|
|
PROP_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_qa_monitor_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_qa_monitor_debug
|
|
|
|
|
|
|
|
#define _do_init \
|
2013-07-22 23:17:53 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_qa_monitor_debug, "qa_monitor", 0, "QA Monitor");\
|
|
|
|
G_IMPLEMENT_INTERFACE (GST_TYPE_QA_REPORTER, NULL)
|
|
|
|
|
|
|
|
|
2013-07-10 17:03:49 +00:00
|
|
|
#define gst_qa_monitor_parent_class parent_class
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstQaMonitor, gst_qa_monitor,
|
|
|
|
G_TYPE_OBJECT, _do_init);
|
|
|
|
|
|
|
|
static gboolean gst_qa_monitor_do_setup (GstQaMonitor * monitor);
|
|
|
|
static void
|
|
|
|
gst_qa_monitor_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
static void
|
|
|
|
gst_qa_monitor_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2013-07-12 05:10:06 +00:00
|
|
|
static GObject *gst_qa_monitor_constructor (GType type,
|
|
|
|
guint n_construct_params, GObjectConstructParam * construct_params);
|
|
|
|
|
|
|
|
gboolean gst_qa_monitor_setup (GstQaMonitor * monitor);
|
2013-07-10 17:03:49 +00:00
|
|
|
|
2013-07-18 15:49:25 +00:00
|
|
|
void
|
|
|
|
_target_freed_cb (GstQaMonitor * monitor, GObject * where_the_object_was)
|
|
|
|
{
|
|
|
|
GST_DEBUG_OBJECT (monitor, "Target was freed");
|
|
|
|
monitor->target = NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:03:49 +00:00
|
|
|
static void
|
|
|
|
gst_qa_monitor_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstQaMonitor *monitor = GST_QA_MONITOR_CAST (object);
|
|
|
|
|
|
|
|
g_mutex_clear (&monitor->mutex);
|
|
|
|
|
2013-07-12 19:02:25 +00:00
|
|
|
if (monitor->target)
|
2013-07-18 15:49:25 +00:00
|
|
|
g_object_weak_unref (G_OBJECT (monitor->target),
|
|
|
|
(GWeakNotify) _target_freed_cb, monitor);
|
2013-07-10 17:03:49 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2013-07-18 15:49:54 +00:00
|
|
|
static void
|
|
|
|
gst_qa_monitor_finalize (GObject * object)
|
|
|
|
{
|
2013-07-22 23:17:53 +00:00
|
|
|
gst_qa_reporter_set_name (GST_QA_REPORTER (object), NULL);
|
2013-07-18 15:49:54 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2013-07-10 17:03:49 +00:00
|
|
|
static void
|
|
|
|
gst_qa_monitor_class_init (GstQaMonitorClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->get_property = gst_qa_monitor_get_property;
|
|
|
|
gobject_class->set_property = gst_qa_monitor_set_property;
|
|
|
|
gobject_class->dispose = gst_qa_monitor_dispose;
|
2013-07-18 15:49:54 +00:00
|
|
|
gobject_class->finalize = gst_qa_monitor_finalize;
|
2013-07-12 05:10:06 +00:00
|
|
|
gobject_class->constructor = gst_qa_monitor_constructor;
|
2013-07-10 17:03:49 +00:00
|
|
|
|
|
|
|
klass->setup = gst_qa_monitor_do_setup;
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_OBJECT,
|
|
|
|
g_param_spec_object ("object", "Object", "The object to be monitored",
|
2013-07-12 05:10:06 +00:00
|
|
|
GST_TYPE_OBJECT, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
|
2013-07-12 03:41:43 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RUNNER,
|
|
|
|
g_param_spec_object ("qa-runner", "QA Runner", "The QA runner to "
|
2013-07-12 05:10:06 +00:00
|
|
|
"report errors to", GST_TYPE_QA_RUNNER,
|
|
|
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
|
2013-07-12 19:02:25 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_QA_PARENT,
|
|
|
|
g_param_spec_object ("qa-parent", "QA parent monitor", "The QA monitor "
|
|
|
|
"that is the parent of this one", GST_TYPE_QA_MONITOR,
|
|
|
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
|
2013-07-12 05:10:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
|
|
|
gst_qa_monitor_constructor (GType type, guint n_construct_params,
|
|
|
|
GObjectConstructParam * construct_params)
|
|
|
|
{
|
|
|
|
GstQaMonitor *monitor =
|
|
|
|
GST_QA_MONITOR_CAST (G_OBJECT_CLASS (parent_class)->constructor (type,
|
|
|
|
n_construct_params,
|
|
|
|
construct_params));
|
|
|
|
gst_qa_monitor_setup (monitor);
|
|
|
|
return (GObject *) monitor;
|
2013-07-10 17:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qa_monitor_init (GstQaMonitor * monitor)
|
|
|
|
{
|
|
|
|
g_mutex_init (&monitor->mutex);
|
2013-07-18 21:49:44 +00:00
|
|
|
|
2013-07-10 17:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_qa_monitor_new:
|
|
|
|
* @element: (transfer-none): a #GObject to run QA on
|
|
|
|
*/
|
|
|
|
GstQaMonitor *
|
|
|
|
gst_qa_monitor_new (GObject * object)
|
|
|
|
{
|
|
|
|
GstQaMonitor *monitor = g_object_new (GST_TYPE_QA_MONITOR, "object",
|
|
|
|
G_TYPE_OBJECT, object, NULL);
|
|
|
|
|
|
|
|
if (GST_QA_MONITOR_GET_OBJECT (monitor) == NULL) {
|
|
|
|
/* setup failed, no use on returning this monitor */
|
|
|
|
g_object_unref (monitor);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_qa_monitor_do_setup (GstQaMonitor * monitor)
|
|
|
|
{
|
|
|
|
/* NOP */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_qa_monitor_setup (GstQaMonitor * monitor)
|
|
|
|
{
|
2013-07-12 03:41:43 +00:00
|
|
|
GST_DEBUG_OBJECT (monitor, "Starting monitor setup");
|
2013-07-10 17:03:49 +00:00
|
|
|
return GST_QA_MONITOR_GET_CLASS (monitor)->setup (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qa_monitor_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstQaMonitor *monitor;
|
|
|
|
|
|
|
|
monitor = GST_QA_MONITOR_CAST (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_OBJECT:
|
2013-07-12 19:02:25 +00:00
|
|
|
g_assert (monitor->target == NULL);
|
2013-07-18 15:49:25 +00:00
|
|
|
monitor->target = g_value_get_object (value);
|
|
|
|
g_object_weak_ref (G_OBJECT (monitor->target),
|
|
|
|
(GWeakNotify) _target_freed_cb, monitor);
|
2013-07-18 15:49:54 +00:00
|
|
|
|
|
|
|
if (monitor->target)
|
2013-07-22 23:17:53 +00:00
|
|
|
gst_qa_reporter_set_name (GST_QA_REPORTER (monitor), g_strdup
|
2013-07-18 15:49:54 +00:00
|
|
|
(GST_OBJECT_NAME (monitor->target)));
|
2013-07-10 17:03:49 +00:00
|
|
|
break;
|
2013-07-12 03:41:43 +00:00
|
|
|
case PROP_RUNNER:
|
|
|
|
/* we assume the runner is valid as long as this monitor is,
|
|
|
|
* no ref taken */
|
|
|
|
monitor->runner = g_value_get_object (value);
|
|
|
|
break;
|
2013-07-12 19:02:25 +00:00
|
|
|
case PROP_QA_PARENT:
|
|
|
|
monitor->parent = g_value_get_object (value);
|
|
|
|
break;
|
2013-07-10 17:03:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_qa_monitor_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstQaMonitor *monitor;
|
|
|
|
|
|
|
|
monitor = GST_QA_MONITOR_CAST (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_OBJECT:
|
|
|
|
g_value_set_object (value, GST_QA_MONITOR_GET_OBJECT (monitor));
|
|
|
|
break;
|
2013-07-12 03:41:43 +00:00
|
|
|
case PROP_RUNNER:
|
2013-07-12 19:02:25 +00:00
|
|
|
g_value_set_object (value, GST_QA_MONITOR_GET_RUNNER (monitor));
|
|
|
|
break;
|
|
|
|
case PROP_QA_PARENT:
|
|
|
|
g_value_set_object (value, GST_QA_MONITOR_GET_PARENT (monitor));
|
2013-07-12 03:41:43 +00:00
|
|
|
break;
|
2013-07-10 17:03:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|