mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-15 08:56:38 -05:00
Debug: remove logger
Make a default logger and mapper in a .h file to be used by examples Remove logger and mapper from libs Make method to set the default mapper for the debug methods
This commit is contained in:
parent
4433203d5f
commit
b4fdcbd322
40 changed files with 508 additions and 494 deletions
205
spa/lib/debug.c
205
spa/lib/debug.c
|
|
@ -20,13 +20,21 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
#include <lib/mapper.h>
|
||||
#include <spa/format-utils.h>
|
||||
#include <spa/loop.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
int spa_debug_port_info(const struct spa_port_info *info, const struct spa_type_map *map)
|
||||
static const struct spa_type_map *map;
|
||||
|
||||
void spa_debug_set_type_map(const struct spa_type_map *m)
|
||||
{
|
||||
map = m;
|
||||
}
|
||||
|
||||
int spa_debug_port_info(const struct spa_port_info *info)
|
||||
{
|
||||
if (info == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -37,7 +45,7 @@ int spa_debug_port_info(const struct spa_port_info *info, const struct spa_type_
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
int spa_debug_buffer(const struct spa_buffer *buffer, const struct spa_type_map *map)
|
||||
int spa_debug_buffer(const struct spa_buffer *buffer)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -130,45 +138,42 @@ int spa_debug_dump_mem(const void *mem, size_t size)
|
|||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
int spa_debug_props(const struct spa_props *props, const struct spa_type_map *map)
|
||||
int spa_debug_props(const struct spa_props *props)
|
||||
{
|
||||
spa_debug_pod(&props->object.pod, map);
|
||||
spa_debug_pod(&props->object.pod);
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
int spa_debug_param(const struct spa_param *param, const struct spa_type_map *map)
|
||||
int spa_debug_param(const struct spa_param *param)
|
||||
{
|
||||
spa_debug_pod(¶m->object.pod, map);
|
||||
spa_debug_pod(¶m->object.pod);
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
struct pod_type_name {
|
||||
const char *name;
|
||||
const char *CCName;
|
||||
} pod_type_names[] = {
|
||||
{ "invalid", "*Invalid*"},
|
||||
{ "none", "None"},
|
||||
{ "bool", "Bool"},
|
||||
{ "id", "Id"},
|
||||
{ "int", "Int"},
|
||||
{ "long", "Long"},
|
||||
{ "float", "Float"},
|
||||
{ "double", "Double"},
|
||||
{ "string", "String"},
|
||||
{ "bytes", "Bytes"},
|
||||
{ "pointer", "Pointer"},
|
||||
{ "rectangle", "Rectangle"},
|
||||
{ "fraction", "Fraction"},
|
||||
{ "bitmask", "Bitmask"},
|
||||
{ "array", "Array"},
|
||||
{ "struct", "Struct"},
|
||||
{ "object", "Object"},
|
||||
{ "prop", "Prop"},
|
||||
static const char *pod_type_names[] = {
|
||||
"invalid",
|
||||
"none",
|
||||
"bool",
|
||||
"id",
|
||||
"int",
|
||||
"long",
|
||||
"float",
|
||||
"double",
|
||||
"string",
|
||||
"bytes",
|
||||
"pointer",
|
||||
"rectangle",
|
||||
"fraction",
|
||||
"bitmask",
|
||||
"array",
|
||||
"struct",
|
||||
"object",
|
||||
"prop",
|
||||
"pod"
|
||||
};
|
||||
|
||||
static void
|
||||
print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, void *body,
|
||||
int prefix)
|
||||
print_pod_value(uint32_t size, uint32_t type, void *body, int prefix)
|
||||
{
|
||||
switch (type) {
|
||||
case SPA_POD_TYPE_BOOL:
|
||||
|
|
@ -223,7 +228,7 @@ print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, vo
|
|||
b->child.size, b->child.type);
|
||||
|
||||
SPA_POD_ARRAY_BODY_FOREACH(b, size, p)
|
||||
print_pod_value(map, b->child.size, b->child.type, p, prefix + 2);
|
||||
print_pod_value(b->child.size, b->child.type, p, prefix + 2);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_STRUCT:
|
||||
|
|
@ -231,7 +236,7 @@ print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, vo
|
|||
struct spa_pod *b = body, *p;
|
||||
printf("%-*sStruct: size %d\n", prefix, "", size);
|
||||
SPA_POD_FOREACH(b, size, p)
|
||||
print_pod_value(map, p->size, p->type, SPA_POD_BODY(p), prefix + 2);
|
||||
print_pod_value(p->size, p->type, SPA_POD_BODY(p), prefix + 2);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_OBJECT:
|
||||
|
|
@ -242,7 +247,7 @@ print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, vo
|
|||
printf("%-*sObject: size %d, id %d, type %s\n", prefix, "", size, b->id,
|
||||
spa_type_map_get_type(map, b->type));
|
||||
SPA_POD_OBJECT_BODY_FOREACH(b, size, p)
|
||||
print_pod_value(map, p->size, p->type, SPA_POD_BODY(p), prefix + 2);
|
||||
print_pod_value(p->size, p->type, SPA_POD_BODY(p), prefix + 2);
|
||||
break;
|
||||
}
|
||||
case SPA_POD_TYPE_PROP:
|
||||
|
|
@ -257,14 +262,14 @@ print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, vo
|
|||
printf("%-*sUnset (Default):\n", prefix + 2, "");
|
||||
else
|
||||
printf("%-*sValue: size %u\n", prefix + 2, "", b->value.size);
|
||||
print_pod_value(map, b->value.size, b->value.type, SPA_POD_BODY(&b->value),
|
||||
print_pod_value(b->value.size, b->value.type, SPA_POD_BODY(&b->value),
|
||||
prefix + 4);
|
||||
|
||||
i = 0;
|
||||
SPA_POD_PROP_ALTERNATIVE_FOREACH(b, size, alt) {
|
||||
if (i == 0)
|
||||
printf("%-*sAlternatives:\n", prefix + 2, "");
|
||||
print_pod_value(map, b->value.size, b->value.type, alt, prefix + 4);
|
||||
print_pod_value(b->value.size, b->value.type, alt, prefix + 4);
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
|
|
@ -283,15 +288,14 @@ print_pod_value(const struct spa_type_map *map, uint32_t size, uint32_t type, vo
|
|||
}
|
||||
}
|
||||
|
||||
int spa_debug_pod(const struct spa_pod *pod, const struct spa_type_map *map)
|
||||
int spa_debug_pod(const struct spa_pod *pod)
|
||||
{
|
||||
map = map ? map : spa_type_map_get_default();
|
||||
print_pod_value(map, pod->size, pod->type, SPA_POD_BODY(pod), 0);
|
||||
print_pod_value(pod->size, pod->type, SPA_POD_BODY(pod), 0);
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
print_format_value(const struct spa_type_map *map, uint32_t size, uint32_t type, void *body)
|
||||
print_format_value(uint32_t size, uint32_t type, void *body)
|
||||
{
|
||||
switch (type) {
|
||||
case SPA_POD_TYPE_BOOL:
|
||||
|
|
@ -348,7 +352,7 @@ print_format_value(const struct spa_type_map *map, uint32_t size, uint32_t type,
|
|||
}
|
||||
}
|
||||
|
||||
int spa_debug_format(const struct spa_format *format, const struct spa_type_map *map)
|
||||
int spa_debug_format(const struct spa_format *format)
|
||||
{
|
||||
int i;
|
||||
const char *media_type;
|
||||
|
|
@ -359,8 +363,6 @@ int spa_debug_format(const struct spa_format *format, const struct spa_type_map
|
|||
if (format == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
map = map ? map : spa_type_map_get_default();
|
||||
|
||||
mtype = format->body.media_type.value;
|
||||
mstype = format->body.media_subtype.value;
|
||||
|
||||
|
|
@ -380,10 +382,10 @@ int spa_debug_format(const struct spa_format *format, const struct spa_type_map
|
|||
key = spa_type_map_get_type(map, prop->body.key);
|
||||
|
||||
fprintf(stderr, " %20s : (%s) ", rindex(key, ':') + 1,
|
||||
pod_type_names[prop->body.value.type].name);
|
||||
pod_type_names[prop->body.value.type]);
|
||||
|
||||
if (!(prop->body.flags & SPA_POD_PROP_FLAG_UNSET)) {
|
||||
print_format_value(map, prop->body.value.size,
|
||||
print_format_value(prop->body.value.size,
|
||||
prop->body.value.type, SPA_POD_BODY(&prop->body.value));
|
||||
} else {
|
||||
const char *ssep, *esep, *sep;
|
||||
|
|
@ -411,7 +413,7 @@ int spa_debug_format(const struct spa_format *format, const struct spa_type_map
|
|||
SPA_POD_PROP_ALTERNATIVE_FOREACH(&prop->body, prop->pod.size, alt) {
|
||||
if (i > 0)
|
||||
fprintf(stderr, "%s", sep);
|
||||
print_format_value(map, prop->body.value.size,
|
||||
print_format_value(prop->body.value.size,
|
||||
prop->body.value.type, alt);
|
||||
i++;
|
||||
}
|
||||
|
|
@ -435,114 +437,3 @@ int spa_debug_dict(const struct spa_dict *dict)
|
|||
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_INFO
|
||||
|
||||
#define TRACE_BUFFER 4096
|
||||
|
||||
struct debug_log {
|
||||
struct spa_log log;
|
||||
struct spa_ringbuffer trace_rb;
|
||||
uint8_t trace_data[TRACE_BUFFER];
|
||||
struct spa_source *source;
|
||||
};
|
||||
|
||||
static void
|
||||
do_logv(struct spa_log *log,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt,
|
||||
va_list args)
|
||||
{
|
||||
struct debug_log *l = SPA_CONTAINER_OF(log, struct debug_log, log);
|
||||
char text[512], location[1024];
|
||||
static const char *levels[] = { "-", "E", "W", "I", "D", "T", "*T*" };
|
||||
int size;
|
||||
bool do_trace;
|
||||
|
||||
if ((do_trace = (level == SPA_LOG_LEVEL_TRACE && l->source)))
|
||||
level++;
|
||||
|
||||
vsnprintf(text, sizeof(text), fmt, args);
|
||||
size = snprintf(location, sizeof(location), "[%s][%s:%i %s()] %s\n",
|
||||
levels[level], strrchr(file, '/') + 1, line, func, text);
|
||||
|
||||
if (SPA_UNLIKELY(do_trace)) {
|
||||
uint32_t index;
|
||||
uint64_t count = 1;
|
||||
|
||||
spa_ringbuffer_get_write_index(&l->trace_rb, &index);
|
||||
spa_ringbuffer_write_data(&l->trace_rb, l->trace_data,
|
||||
index & l->trace_rb.mask, location, size);
|
||||
spa_ringbuffer_write_update(&l->trace_rb, index + size);
|
||||
|
||||
write(l->source->fd, &count, sizeof(uint64_t));
|
||||
} else
|
||||
fputs(location, stderr);
|
||||
}
|
||||
|
||||
static void
|
||||
do_log(struct spa_log *log,
|
||||
enum spa_log_level level,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
do_logv(log, level, file, line, func, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static struct debug_log log = {
|
||||
{sizeof(struct spa_log),
|
||||
NULL,
|
||||
DEFAULT_LOG_LEVEL,
|
||||
do_log,
|
||||
do_logv,
|
||||
},
|
||||
{0, 0, TRACE_BUFFER, TRACE_BUFFER - 1},
|
||||
};
|
||||
|
||||
struct spa_log *spa_log_get_default(void)
|
||||
{
|
||||
return &log.log;
|
||||
}
|
||||
|
||||
static void on_trace_event(struct spa_source *source)
|
||||
{
|
||||
int32_t avail;
|
||||
uint32_t index;
|
||||
uint64_t count;
|
||||
|
||||
if (read(source->fd, &count, sizeof(uint64_t)) != sizeof(uint64_t))
|
||||
fprintf(stderr, "failed to read event fd: %s", strerror(errno));
|
||||
|
||||
while ((avail = spa_ringbuffer_get_read_index(&log.trace_rb, &index)) > 0) {
|
||||
uint32_t offset, first;
|
||||
|
||||
if (avail > log.trace_rb.size) {
|
||||
index += avail - log.trace_rb.size;
|
||||
avail = log.trace_rb.size;
|
||||
}
|
||||
offset = index & log.trace_rb.mask;
|
||||
first = SPA_MIN(avail, log.trace_rb.size - offset);
|
||||
|
||||
fwrite(log.trace_data + offset, first, 1, stderr);
|
||||
if (SPA_UNLIKELY(avail > first)) {
|
||||
fwrite(log.trace_data, avail - first, 1, stderr);
|
||||
}
|
||||
spa_ringbuffer_read_update(&log.trace_rb, index + avail);
|
||||
}
|
||||
}
|
||||
|
||||
void spa_log_default_set_trace_event(struct spa_source *source)
|
||||
{
|
||||
log.source = source;
|
||||
log.source->func = on_trace_event;
|
||||
log.source->data = &log;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,17 +33,17 @@ extern "C" {
|
|||
#include <spa/dict.h>
|
||||
#include <spa/log.h>
|
||||
|
||||
int spa_debug_port_info(const struct spa_port_info *info, const struct spa_type_map *map);
|
||||
int spa_debug_buffer(const struct spa_buffer *buffer, const struct spa_type_map *map);
|
||||
int spa_debug_props(const struct spa_props *props, const struct spa_type_map *map);
|
||||
int spa_debug_param(const struct spa_param *param, const struct spa_type_map *map);
|
||||
int spa_debug_pod(const struct spa_pod *pod, const struct spa_type_map *map);
|
||||
int spa_debug_format(const struct spa_format *format, const struct spa_type_map *map);
|
||||
void spa_debug_set_type_map(const struct spa_type_map *map);
|
||||
|
||||
int spa_debug_port_info(const struct spa_port_info *info);
|
||||
int spa_debug_buffer(const struct spa_buffer *buffer);
|
||||
int spa_debug_props(const struct spa_props *props);
|
||||
int spa_debug_param(const struct spa_param *param);
|
||||
int spa_debug_pod(const struct spa_pod *pod);
|
||||
int spa_debug_format(const struct spa_format *format);
|
||||
int spa_debug_dump_mem(const void *data, size_t size);
|
||||
int spa_debug_dict(const struct spa_dict *dict);
|
||||
|
||||
struct spa_log *spa_log_get_default(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
#include <spa/format-builder.h>
|
||||
#include <spa/video/format-utils.h>
|
||||
|
||||
#include <lib/props.h>
|
||||
#include <lib/mapper.h>
|
||||
|
||||
int
|
||||
spa_format_filter(const struct spa_format *format,
|
||||
|
|
|
|||
|
|
@ -1,90 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* 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 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spa/type-map.h>
|
||||
|
||||
#include <lib/debug.h>
|
||||
|
||||
#define MAX_TYPES 4096
|
||||
|
||||
struct type_map {
|
||||
struct spa_type_map map;
|
||||
char *types[MAX_TYPES];
|
||||
unsigned int n_types;
|
||||
};
|
||||
|
||||
static uint32_t type_map_get_id(struct spa_type_map *map, const char *type)
|
||||
{
|
||||
struct type_map *this = SPA_CONTAINER_OF(map, struct type_map, map);
|
||||
unsigned int i = 0;
|
||||
|
||||
if (type != NULL) {
|
||||
for (i = 1; i <= this->n_types; i++) {
|
||||
if (strcmp(this->types[i], type) == 0)
|
||||
return i;
|
||||
}
|
||||
this->types[i] = (char *) type;
|
||||
this->n_types++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static const char *type_map_get_type(const struct spa_type_map *map, uint32_t id)
|
||||
{
|
||||
struct type_map *this = SPA_CONTAINER_OF(map, struct type_map, map);
|
||||
|
||||
if (id <= this->n_types)
|
||||
return this->types[id];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static size_t type_map_get_size(const struct spa_type_map *map)
|
||||
{
|
||||
struct type_map *this = SPA_CONTAINER_OF(map, struct type_map, map);
|
||||
return this->n_types;
|
||||
}
|
||||
|
||||
static struct type_map default_type_map = {
|
||||
{sizeof(struct spa_type_map),
|
||||
NULL,
|
||||
type_map_get_id,
|
||||
type_map_get_type,
|
||||
type_map_get_size,
|
||||
},
|
||||
{NULL,},
|
||||
0
|
||||
};
|
||||
|
||||
static struct spa_type_map *default_map = &default_type_map.map;
|
||||
|
||||
struct spa_type_map *spa_type_map_get_default(void)
|
||||
{
|
||||
return default_map;
|
||||
}
|
||||
|
||||
void spa_type_map_set_default(struct spa_type_map *map)
|
||||
{
|
||||
default_map = map;
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/* Simple Plugin API
|
||||
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* 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 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __SPA_LIBMAPPER_H__
|
||||
#define __SPA_LIBMAPPER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/type-map.h>
|
||||
|
||||
void spa_type_map_set_default(struct spa_type_map *map);
|
||||
struct spa_type_map *spa_type_map_get_default(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __SPA_LIBMAPPER_H__ */
|
||||
|
|
@ -1,13 +1,11 @@
|
|||
spalib_headers = [
|
||||
'debug.h',
|
||||
'mapper.h',
|
||||
'props.h',
|
||||
]
|
||||
|
||||
install_headers(spalib_headers, subdir : 'spa/lib')
|
||||
|
||||
spalib_sources = ['debug.c',
|
||||
'mapper.c',
|
||||
'props.c',
|
||||
'format.c']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue