tracer: use the new flags to create the optional field in the format string

This spares us explicitly listing the field in the spec. and thus hide this
implementation detail.
This commit is contained in:
Stefan Sauer 2016-01-16 18:55:07 +01:00
parent 8cd76a918a
commit af91d23204
3 changed files with 21 additions and 7 deletions

View file

@ -32,6 +32,7 @@
#define GST_USE_UNSTABLE_API
#include "gst_private.h"
#include "gstenumtypes.h"
#include "gstinfo.h"
#include "gststructure.h"
#include "gsttracerrecord.h"
@ -73,14 +74,28 @@ build_field_template (GQuark field_id, const GValue * value, gpointer user_data)
const GstStructure *sub;
GValue template_value = { 0, };
GType type;
GstTracerValueFlags flags;
gboolean res;
g_return_val_if_fail (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE, FALSE);
sub = gst_value_get_structure (value);
type = g_value_get_gtype (gst_structure_get_value (sub, "type"));
g_value_init (&template_value, type);
gst_structure_get (sub, "type", G_TYPE_GTYPE, &type, "flags",
GST_TYPE_TRACER_VALUE_FLAGS, &flags, NULL);
if (flags & GST_TRACER_VALUE_FLAGS_OPTIONAL) {
gchar *opt_name = g_strconcat ("have-", g_quark_to_string (field_id), NULL);
/* add a boolean field, that indicates the presence of the next field */
g_value_init (&template_value, G_TYPE_BOOLEAN);
res =
priv__gst_structure_append_template_to_gstring (g_quark_from_string
(opt_name), &template_value, s);
g_value_unset (&template_value);
g_free (opt_name);
}
g_value_init (&template_value, type);
res = priv__gst_structure_append_template_to_gstring (field_id,
&template_value, s);
g_value_unset (&template_value);

View file

@ -70,7 +70,9 @@ typedef enum
/**
* GstTracerValueFlags:
* @GST_TRACER_VALUE_FLAGS_NONE: no flags
* @GST_TRACER_VALUE_FLAGS_OPTIONAL: the value is optional
* @GST_TRACER_VALUE_FLAGS_OPTIONAL: the value is optional. When using this flag
* one need to have an additional boolean arg before this value in the
* var-args list passed to gst_tracer_record_log().
* @GST_TRACER_VALUE_FLAGS_AGGREGATED: the value is combined since the start of
* tracing
*

View file

@ -657,13 +657,10 @@ gst_stats_tracer_class_init (GstStatsTracerClass * klass)
"type", G_TYPE_GTYPE, GST_TYPE_STRUCTURE,
"description", G_TYPE_STRING, "query structure",
NULL),
"have-res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
"type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
"description", G_TYPE_STRING, "have query result",
NULL),
"res", GST_TYPE_STRUCTURE, gst_structure_new ("value",
"type", G_TYPE_GTYPE, G_TYPE_BOOLEAN,
"description", G_TYPE_STRING, "query result",
"flags", GST_TYPE_TRACER_VALUE_FLAGS, GST_TRACER_VALUE_FLAGS_OPTIONAL,
NULL),
/* TODO(ensonic): "buffer-flags" */
NULL));