|
Packit Service |
963350 |
/* GStreamer
|
|
Packit Service |
963350 |
* Copyright (C) 2016 Stefan Sauer <ensonic@users.sf.net>
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* gsttracerrecord.c: tracer log record class
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
963350 |
* modify it under the terms of the GNU Library General Public
|
|
Packit Service |
963350 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
963350 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
963350 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
963350 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
963350 |
* Library General Public License for more details.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* You should have received a copy of the GNU Library General Public
|
|
Packit Service |
963350 |
* License along with this library; if not, write to the
|
|
Packit Service |
963350 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit Service |
963350 |
* Boston, MA 02110-1301, USA.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* SECTION:gsttracerrecord
|
|
Packit Service |
963350 |
* @title: GstTracerRecord
|
|
Packit Service |
963350 |
* @short_description: Trace log entry class
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Tracing modules will create instances of this class to announce the data they
|
|
Packit Service |
963350 |
* will log and create a log formatter.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Since: 1.8
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#define GST_USE_UNSTABLE_API
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#include "gst_private.h"
|
|
Packit Service |
963350 |
#include "gstenumtypes.h"
|
|
Packit Service |
963350 |
#include "gstinfo.h"
|
|
Packit Service |
963350 |
#include "gststructure.h"
|
|
Packit Service |
963350 |
#include "gsttracerrecord.h"
|
|
Packit Service |
963350 |
#include "gstvalue.h"
|
|
Packit Service |
963350 |
#include <gobject/gvaluecollector.h>
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GST_DEBUG_CATEGORY_EXTERN (tracer_debug);
|
|
Packit Service |
963350 |
#define GST_CAT_DEFAULT tracer_debug
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
struct _GstTracerRecord
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstObject parent;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
GstStructure *spec;
|
|
Packit Service |
963350 |
gchar *format;
|
|
Packit Service |
963350 |
};
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
struct _GstTracerRecordClass
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstObjectClass parent_class;
|
|
Packit Service |
963350 |
};
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#define gst_tracer_record_parent_class parent_class
|
|
Packit Service |
963350 |
G_DEFINE_TYPE (GstTracerRecord, gst_tracer_record, GST_TYPE_OBJECT);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static gboolean
|
|
Packit Service |
963350 |
build_field_template (GQuark field_id, const GValue * value, gpointer user_data)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GString *s = (GString *) user_data;
|
|
Packit Service |
963350 |
const GstStructure *sub;
|
|
Packit Service |
963350 |
GValue template_value = { 0, };
|
|
Packit Service |
963350 |
GType type = G_TYPE_INVALID;
|
|
Packit Service |
963350 |
GstTracerValueFlags flags = GST_TRACER_VALUE_FLAGS_NONE;
|
|
Packit Service |
963350 |
gboolean res;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (G_VALUE_TYPE (value) != GST_TYPE_STRUCTURE) {
|
|
Packit Service |
963350 |
GST_WARNING ("expected field of type GstStructure, but %s is %s",
|
|
Packit Service |
963350 |
g_quark_to_string (field_id), G_VALUE_TYPE_NAME (value));
|
|
Packit Service |
963350 |
return FALSE;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
sub = gst_value_get_structure (value);
|
|
Packit Service |
963350 |
gst_structure_get (sub, "type", G_TYPE_GTYPE, &type, "flags",
|
|
Packit Service |
963350 |
GST_TYPE_TRACER_VALUE_FLAGS, &flags, NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (flags & GST_TRACER_VALUE_FLAGS_OPTIONAL) {
|
|
Packit Service |
963350 |
gchar *opt_name = g_strconcat ("have-", g_quark_to_string (field_id), NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* add a boolean field, that indicates the presence of the next field */
|
|
Packit Service |
963350 |
g_value_init (&template_value, G_TYPE_BOOLEAN);
|
|
Packit Service |
963350 |
priv__gst_structure_append_template_to_gstring (g_quark_from_string
|
|
Packit Service |
963350 |
(opt_name), &template_value, s);
|
|
Packit Service |
963350 |
g_value_unset (&template_value);
|
|
Packit Service |
963350 |
g_free (opt_name);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
g_value_init (&template_value, type);
|
|
Packit Service |
963350 |
res = priv__gst_structure_append_template_to_gstring (field_id,
|
|
Packit Service |
963350 |
&template_value, s);
|
|
Packit Service |
963350 |
g_value_unset (&template_value);
|
|
Packit Service |
963350 |
return res;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_tracer_record_build_format (GstTracerRecord * self)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstStructure *structure = self->spec;
|
|
Packit Service |
963350 |
GString *s;
|
|
Packit Service |
963350 |
gchar *name = (gchar *) g_quark_to_string (structure->name);
|
|
Packit Service |
963350 |
gchar *p;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
g_return_if_fail (g_str_has_suffix (name, ".class"));
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* announce the format */
|
|
Packit Service |
963350 |
GST_TRACE ("%" GST_PTR_FORMAT, structure);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* cut off '.class' suffix */
|
|
Packit Service |
963350 |
name = g_strdup (name);
|
|
Packit Service |
963350 |
p = strrchr (name, '.');
|
|
Packit Service |
963350 |
g_assert (p != NULL);
|
|
Packit Service |
963350 |
*p = '\0';
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
s = g_string_sized_new (STRUCTURE_ESTIMATED_STRING_LEN (structure));
|
|
Packit Service |
963350 |
g_string_append (s, name);
|
|
Packit Service |
963350 |
gst_structure_foreach (structure, build_field_template, s);
|
|
Packit Service |
963350 |
g_string_append_c (s, ';');
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
self->format = g_string_free (s, FALSE);
|
|
Packit Service |
963350 |
GST_DEBUG ("new format string: %s", self->format);
|
|
Packit Service |
963350 |
g_free (name);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_tracer_record_dispose (GObject * object)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstTracerRecord *self = GST_TRACER_RECORD (object);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
if (self->spec) {
|
|
Packit Service |
963350 |
gst_structure_free (self->spec);
|
|
Packit Service |
963350 |
self->spec = NULL;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
g_free (self->format);
|
|
Packit Service |
963350 |
self->format = NULL;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_tracer_record_class_init (GstTracerRecordClass * klass)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
gobject_class->dispose = gst_tracer_record_dispose;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
static void
|
|
Packit Service |
963350 |
gst_tracer_record_init (GstTracerRecord * self)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_tracer_record_new:
|
|
Packit Service |
963350 |
* @name: name of new record, must end on ".class".
|
|
Packit Service |
963350 |
* @firstfield: name of first field to set
|
|
Packit Service |
963350 |
* @...: additional arguments
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Create a new tracer record. The record instance can be used to efficiently
|
|
Packit Service |
963350 |
* log entries using gst_tracer_record_log().
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* The @name without the ".class" suffix will be used for the log records.
|
|
Packit Service |
963350 |
* There must be fields for each value that gets logged where the field name is
|
|
Packit Service |
963350 |
* the value name. The field must be a #GstStructure describing the value. The
|
|
Packit Service |
963350 |
* sub structure must contain a field called 'type' of %G_TYPE_GTYPE that
|
|
Packit Service |
963350 |
* contains the GType of the value. The resulting #GstTracerRecord will take
|
|
Packit Service |
963350 |
* ownership of the field structures.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* The way to deal with optional values is to log an additional boolean before
|
|
Packit Service |
963350 |
* the optional field, that if %TRUE signals that the optional field is valid
|
|
Packit Service |
963350 |
* and %FALSE signals that the optional field should be ignored. One must still
|
|
Packit Service |
963350 |
* log a placeholder value for the optional field though. Please also note, that
|
|
Packit Service |
963350 |
* pointer type values must not be NULL - the underlying serialisation can not
|
|
Packit Service |
963350 |
* handle that right now.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* > Please note that this is still under discussion and subject to change.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Returns: (transfer full): a new #GstTracerRecord
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
GstTracerRecord *
|
|
Packit Service |
963350 |
gst_tracer_record_new (const gchar * name, const gchar * firstfield, ...)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
GstTracerRecord *self;
|
|
Packit Service |
963350 |
GstStructure *structure;
|
|
Packit Service |
963350 |
va_list varargs;
|
|
Packit Service |
963350 |
gchar *err = NULL;
|
|
Packit Service |
963350 |
GType type;
|
|
Packit Service |
963350 |
GQuark id;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
va_start (varargs, firstfield);
|
|
Packit Service |
963350 |
structure = gst_structure_new_empty (name);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
while (firstfield) {
|
|
Packit Service |
963350 |
GValue val = { 0, };
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
id = g_quark_from_string (firstfield);
|
|
Packit Service |
963350 |
type = va_arg (varargs, GType);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* all fields passed here must be GstStructures which we take over */
|
|
Packit Service |
963350 |
if (type != GST_TYPE_STRUCTURE) {
|
|
Packit Service |
963350 |
GST_WARNING ("expected field of type GstStructure, but %s is %s",
|
|
Packit Service |
963350 |
firstfield, g_type_name (type));
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
G_VALUE_COLLECT_INIT (&val, type, varargs, G_VALUE_NOCOPY_CONTENTS, &err;;
|
|
Packit Service |
963350 |
if (G_UNLIKELY (err)) {
|
|
Packit Service |
963350 |
g_critical ("%s", err);
|
|
Packit Service |
963350 |
break;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
/* see boxed_proxy_collect_value */
|
|
Packit Service |
963350 |
val.data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
|
|
Packit Service |
963350 |
gst_structure_id_take_value (structure, id, &val;;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
firstfield = va_arg (varargs, gchar *);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
va_end (varargs);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
self = g_object_new (GST_TYPE_TRACER_RECORD, NULL);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/* Clear floating flag */
|
|
Packit Service |
963350 |
gst_object_ref_sink (self);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
self->spec = structure;
|
|
Packit Service |
963350 |
gst_tracer_record_build_format (self);
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
return self;
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
#ifndef GST_DISABLE_GST_DEBUG
|
|
Packit Service |
963350 |
/**
|
|
Packit Service |
963350 |
* gst_tracer_record_log:
|
|
Packit Service |
963350 |
* @self: the tracer-record
|
|
Packit Service |
963350 |
* @...: the args as described in the spec-
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Serialzes the trace event into the log.
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* Right now this is using the gstreamer debug log with the level TRACE (7) and
|
|
Packit Service |
963350 |
* the category "GST_TRACER".
|
|
Packit Service |
963350 |
*
|
|
Packit Service |
963350 |
* > Please note that this is still under discussion and subject to change.
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
void
|
|
Packit Service |
963350 |
gst_tracer_record_log (GstTracerRecord * self, ...)
|
|
Packit Service |
963350 |
{
|
|
Packit Service |
963350 |
va_list var_args;
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
/*
|
|
Packit Service |
963350 |
* does it make sense to use the {file, line, func} from the tracer hook?
|
|
Packit Service |
963350 |
* a)
|
|
Packit Service |
963350 |
* - we'd need to pass them in the macros to gst_tracer_dispatch()
|
|
Packit Service |
963350 |
* - and each tracer needs to grab them from the va_list and pass them here
|
|
Packit Service |
963350 |
* b)
|
|
Packit Service |
963350 |
* - we create a context in dispatch, pass that to the tracer
|
|
Packit Service |
963350 |
* - and the tracer will pass that here
|
|
Packit Service |
963350 |
* ideally we also use *our* ts instead of the one that
|
|
Packit Service |
963350 |
* gst_debug_log_default() will pick
|
|
Packit Service |
963350 |
*/
|
|
Packit Service |
963350 |
|
|
Packit Service |
963350 |
va_start (var_args, self);
|
|
Packit Service |
963350 |
if (G_LIKELY (GST_LEVEL_TRACE <= _gst_debug_min)) {
|
|
Packit Service |
963350 |
gst_debug_log_valist (GST_CAT_DEFAULT, GST_LEVEL_TRACE, "", "", 0, NULL,
|
|
Packit Service |
963350 |
self->format, var_args);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
va_end (var_args);
|
|
Packit Service |
963350 |
}
|
|
Packit Service |
963350 |
#endif
|