qa-runner: simplify runner to not hold refs to monitor/pipeline

The GstQaRunner is now a simple aggregator of reports that it receives
from monitors and filechecker. This allows it to be used in both
scenarios without  APIs that expect GstElement or Monitors, that are
only used on the pipeline monitoring QA tests.
This commit is contained in:
Thiago Santos 2013-08-07 16:10:57 -03:00
parent 61d39d6e74
commit 08aae8336b
8 changed files with 28 additions and 71 deletions

View file

@ -22,10 +22,13 @@
#include <gst/gst.h>
#include <string.h>
#include "gst-qa-runner.h"
#include "gst-qa-monitor-factory.h"
#define __USE_GNU
#include <dlfcn.h>
static GstQaRunner *runner = NULL;
/*
* Functions that wrap object creation so gst-qa can be used
* to monitor 'standard' applications
@ -34,15 +37,11 @@
static void
gst_qa_preload_wrap (GstElement * element)
{
GstQaRunner *runner;
if (runner == NULL)
runner = gst_qa_runner_new ();
runner = gst_qa_runner_new (element);
/* TODO this will actually never unref the runner as it holds a ref
* to the element */
if (runner)
g_object_set_data_full ((GObject *) element, "qa-runner", runner,
g_object_unref);
/* the reference to the monitor is lost */
gst_qa_monitor_factory_create (GST_OBJECT_CAST (element), runner, NULL);
}
GstElement *

View file

@ -22,7 +22,6 @@
#include "gst-qa-runner.h"
#include "gst-qa-report.h"
#include "gst-qa-monitor-factory.h"
#include "gst-qa-element-monitor.h"
#include "gst-qa-override-registry.h"
#include "gst-qa-scenario.h"
@ -51,20 +50,13 @@ enum
static guint _signals[LAST_SIGNAL] = { 0 };
static gboolean gst_qa_runner_setup (GstQaRunner * runner);
static void
gst_qa_runner_dispose (GObject * object)
{
GstQaRunner *runner = GST_QA_RUNNER_CAST (object);
if (runner->pipeline)
gst_object_unref (runner->pipeline);
g_slist_free_full (runner->reports, (GDestroyNotify) gst_qa_report_unref);
if (runner->monitor)
g_object_unref (runner->monitor);
if (runner->scenario)
g_object_unref (runner->scenario);
@ -100,54 +92,11 @@ gst_qa_runner_init (GstQaRunner * runner)
/**
* gst_qa_runner_new:
* @pipeline: (transfer-none): a #GstElement to run QA on
*/
GstQaRunner *
gst_qa_runner_new (GstElement * pipeline)
gst_qa_runner_new (void)
{
const gchar *scenario_name;
GstQaRunner *runner;
g_return_val_if_fail (pipeline != NULL, NULL);
runner = g_object_get_data ((GObject *) pipeline, "qa-runner");
if (runner) {
GST_WARNING_OBJECT (pipeline,
"Pipeline already has a qa-runner associated, returning it");
return gst_object_ref (runner);
}
runner = g_object_new (GST_TYPE_QA_RUNNER, NULL);
runner->pipeline = gst_object_ref (pipeline);
if ((scenario_name = g_getenv ("GST_QA_SCENARIO")))
runner->scenario = gst_qa_scenario_factory_create (runner, scenario_name);
g_object_set_data ((GObject *) pipeline, "qa-runner", runner);
if (!gst_qa_runner_setup (runner)) {
gst_object_unref (runner);
runner = NULL;
}
return runner;
}
static gboolean
gst_qa_runner_setup (GstQaRunner * runner)
{
GST_INFO_OBJECT (runner, "Starting QA Runner setup");
runner->monitor =
gst_qa_monitor_factory_create (GST_OBJECT_CAST (runner->pipeline), runner,
NULL);
if (runner->monitor == NULL) {
GST_WARNING_OBJECT (runner, "Setup failed");
return FALSE;
}
GST_DEBUG_OBJECT (runner, "Setup successful");
return TRUE;
return g_object_new (GST_TYPE_QA_RUNNER, NULL);
}
void
@ -161,6 +110,7 @@ gst_qa_runner_add_report (GstQaRunner * runner, GstQaReport * report)
guint
gst_qa_runner_get_reports_count (GstQaRunner * runner)
{
g_return_val_if_fail (runner != NULL, 0);
return g_slist_length (runner->reports);
}

View file

@ -30,7 +30,6 @@
G_BEGIN_DECLS
/* forward declaration */
typedef struct _GstQaMonitor GstQaMonitor;
typedef struct _GstQaScenario GstQaScenario;
#define GST_TYPE_QA_RUNNER (gst_qa_runner_get_type ())
@ -59,8 +58,6 @@ struct _GstQaRunner {
gboolean setup;
/*< private >*/
GstElement *pipeline;
GstQaMonitor *monitor;
GstQaScenario *scenario;
GSList *reports;
@ -79,7 +76,7 @@ struct _GstQaRunnerClass {
/* normal GObject stuff */
GType gst_qa_runner_get_type (void);
GstQaRunner * gst_qa_runner_new (GstElement * pipeline);
GstQaRunner * gst_qa_runner_new (void);
void gst_qa_runner_add_report (GstQaRunner * runner, GstQaReport * report);

View file

@ -695,7 +695,7 @@ gst_qa_scenario_finalize (GObject * object)
}
GstQaScenario *
gst_qa_scenario_factory_create (GstQaRunner * runner,
gst_qa_scenario_factory_create (GstQaRunner * runner, GstElement * pipeline,
const gchar * scenario_name)
{
GstBus *bus;
@ -709,11 +709,11 @@ gst_qa_scenario_factory_create (GstQaRunner * runner,
return NULL;
}
scenario->priv->pipeline = gst_object_ref (runner->pipeline);
scenario->priv->pipeline = gst_object_ref (pipeline);
gst_qa_reporter_set_name (GST_QA_REPORTER (scenario),
g_strdup (scenario_name));
bus = gst_element_get_bus (runner->pipeline);
bus = gst_element_get_bus (pipeline);
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "message::async-done", (GCallback) async_done_cb,
scenario);
@ -724,7 +724,7 @@ gst_qa_scenario_factory_create (GstQaRunner * runner,
g_print ("\n=========================================\n"
"Running scenario %s on pipeline %s"
"\n=========================================\n", scenario_name,
GST_OBJECT_NAME (runner->pipeline));
GST_OBJECT_NAME (pipeline));
return scenario;
}

View file

@ -57,6 +57,7 @@ struct _GstQaScenario
GType gst_qa_scenario_get_type (void);
GstQaScenario * gst_qa_scenario_factory_create (GstQaRunner *runner,
GstElement *pipeline,
const gchar *scenario_name);
G_END_DECLS

View file

@ -244,6 +244,7 @@ main (int argc, gchar ** argv)
{
GstBus *bus;
GstQaRunner *runner;
GstQaMonitor *monitor;
GOptionContext *ctx;
GError *err = NULL;
@ -304,7 +305,9 @@ main (int argc, gchar ** argv)
/* Create the pipeline */
create_transcoding_pipeline (argv[1], argv[2]);
runner = gst_qa_runner_new (pipeline);
runner = gst_qa_runner_new ();
monitor =
gst_qa_monitor_factory_create (GST_OBJECT_CAST (pipeline), runner, NULL);
mainloop = g_main_loop_new (NULL, FALSE);
if (!runner) {
@ -328,6 +331,7 @@ main (int argc, gchar ** argv)
exit:
gst_element_set_state (pipeline, GST_STATE_NULL);
g_main_loop_unref (mainloop);
g_object_unref (monitor);
g_object_unref (runner);
g_object_unref (pipeline);

View file

@ -57,6 +57,7 @@ main (int argc, gchar ** argv)
GOptionContext *ctx;
gchar **argvn;
GstQaRunner *runner;
GstQaMonitor *monitor;
GstBus *bus;
ctx = g_option_context_new ("- runs QA tests for a pipeline.");
@ -87,7 +88,9 @@ main (int argc, gchar ** argv)
pipeline = (GstElement *) gst_parse_launchv ((const gchar **) argvn, &err);
g_free (argvn);
runner = gst_qa_runner_new (pipeline);
runner = gst_qa_runner_new ();
monitor =
gst_qa_monitor_factory_create (GST_OBJECT_CAST (pipeline), runner, NULL);
mainloop = g_main_loop_new (NULL, FALSE);
if (!runner) {
@ -111,6 +114,7 @@ main (int argc, gchar ** argv)
exit:
gst_element_set_state (pipeline, GST_STATE_NULL);
g_main_loop_unref (mainloop);
g_object_unref (monitor);
g_object_unref (runner);
g_object_unref (pipeline);
if (count)

View file

@ -3,4 +3,6 @@
*/
#include <gst/qa/gst-qa-runner.h>
#include <gst/qa/gst-qa-file-checker.h>
#include <gst/qa/gst-qa-monitor-factory.h>