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:
Wim Taymans 2017-06-06 13:30:34 +02:00
parent 4433203d5f
commit b4fdcbd322
40 changed files with 508 additions and 494 deletions

View file

@ -0,0 +1,81 @@
/* 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_LOG_IMPL_H__
#define __SPA_LOG_IMPL_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/log.h>
static inline void spa_log_impl_logv(struct spa_log *log,
enum spa_log_level level,
const char *file,
int line,
const char *func,
const char *fmt,
va_list args)
{
char text[512], location[1024];
static const char *levels[] = { "-", "E", "W", "I", "D", "T" };
vsnprintf(text, sizeof(text), fmt, args);
snprintf(location, sizeof(location), "[%s][%s:%i %s()] %s\n",
levels[level], strrchr(file, '/') + 1, line, func, text);
fputs(location, stderr);
}
static inline void spa_log_impl_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);
spa_log_impl_logv(log, level, file, line, func, fmt, args);
va_end(args);
}
static inline void spa_log_impl_set_loop(struct spa_log *log, struct spa_loop *loop)
{
}
#define SPA_LOG_IMPL_DEFINE(name) \
struct { \
struct spa_log log; \
} name
#define SPA_LOG_IMPL_INIT \
{ { sizeof(struct spa_log), \
NULL, \
SPA_LOG_LEVEL_INFO, \
spa_log_impl_log, \
spa_log_impl_logv, \
spa_log_impl_set_loop,} }
#define SPA_LOG_IMPL(name) \
SPA_LOG_IMPL_DEFINE(name) = SPA_LOG_IMPL_INIT
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_LOG_IMPL_H__ */

View file

@ -31,6 +31,7 @@ extern "C" {
#include <spa/defs.h>
#include <spa/plugin.h>
#include <spa/loop.h>
enum spa_log_level {
SPA_LOG_LEVEL_NONE = 0,
@ -102,8 +103,21 @@ struct spa_log {
const char *func,
const char *fmt,
va_list args) SPA_PRINTF_FUNC(6, 0);
/**
* Set the loop for trace logging
* \param log the logger
* \param loop the loop for trace logging
*
* Trace logging will be done to a ringbuffer and written to
* the console/device from \a loop to ensure no blocking operations
* are done from the realtime thread.
*/
void (*set_loop) (struct spa_log *log,
struct spa_loop *loop);
};
#define spa_log_set_loop(l,...) (l)->set_loop((l),__VA_ARGS__)
#define spa_log_level_enabled(l,lev) ((l) && (l)->level >= (lev))
#if __STDC_VERSION__ >= 199901L

View file

@ -82,7 +82,7 @@ struct spa_port_info {
struct spa_node_callbacks {
/**
/**
* struct spa_node_callbacks::event:
* @node: a #struct spa_node
* @event: the event that was emited
@ -132,6 +132,8 @@ struct spa_node_callbacks {
void (*reuse_buffer) (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id, void *user_data);
void (*done) (struct spa_node *node, int seq, int res, void *user_data);
};
/**

View file

@ -0,0 +1,81 @@
/* 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_TYPE_MAP_IMPL_H__
#define __SPA_TYPE_MAP_IMPL_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <spa/type-map.h>
static inline uint32_t
spa_type_map_impl_get_id (struct spa_type_map *map, const char *type)
{
struct { struct spa_type_map map; uint32_t n_types; char *types[1]; } *impl = (void*) map;
uint32_t i = 0;
for (i = 1; i <= impl->n_types; i++) {
if (strcmp(impl->types[i], type) == 0)
return i;
}
impl->types[i] = (char *) type;
impl->n_types++;
return i;
}
static inline const char *
spa_type_map_impl_get_type (const struct spa_type_map *map, uint32_t id)
{
struct { struct spa_type_map map; uint32_t n_types; char *types[1]; } *impl = (void*) map;
if (id <= impl->n_types)
return impl->types[id];
return NULL;
}
static inline size_t spa_type_map_impl_get_size (const struct spa_type_map *map)
{
struct { struct spa_type_map map; uint32_t n_types; char *types[1]; } *impl = (void*) map;
return impl->n_types;
}
#define SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) \
struct { \
struct spa_type_map map; \
unsigned int n_types; \
char *types[maxtypes]; \
} name
#define SPA_TYPE_MAP_IMPL_INIT \
{ { sizeof(struct spa_type_map), \
NULL, \
spa_type_map_impl_get_id, \
spa_type_map_impl_get_type, \
spa_type_map_impl_get_size,}, \
0, { NULL, } }
#define SPA_TYPE_MAP_IMPL(name,maxtypes) \
SPA_TYPE_MAP_IMPL_DEFINE(name,maxtypes) = SPA_TYPE_MAP_IMPL_INIT
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __SPA_TYPE_MAP_IMPL_H__ */

View file

@ -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(&param->object.pod, map);
spa_debug_pod(&param->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;
}

View file

@ -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

View file

@ -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,

View file

@ -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;
}

View file

@ -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__ */

View file

@ -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']

View file

@ -31,7 +31,7 @@
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) == 0)
static const char default_device[] = "default";
static const char default_device[] = "hw:0";
static const uint32_t default_min_latency = 1024;
static void reset_props(struct props *props)

View file

@ -59,9 +59,8 @@ struct impl {
struct spa_ringbuffer trace_rb;
uint8_t trace_data[TRACE_BUFFER];
struct spa_loop *main_loop;
bool have_source;
struct spa_source trace_source;
struct spa_source source;
};
static void
@ -95,7 +94,7 @@ impl_log_logv(struct spa_log *log,
index & impl->trace_rb.mask, location, size);
spa_ringbuffer_write_update(&impl->trace_rb, index + size);
write(impl->trace_source.fd, &count, sizeof(uint64_t));
write(impl->source.fd, &count, sizeof(uint64_t));
} else
fputs(location, stderr);
}
@ -115,14 +114,6 @@ impl_log_log(struct spa_log *log,
va_end(args);
}
static const struct spa_log impl_log = {
sizeof(struct spa_log),
NULL,
DEFAULT_LOG_LEVEL,
impl_log_log,
impl_log_logv,
};
static void on_trace_event(struct spa_source *source)
{
struct impl *impl = source->data;
@ -151,6 +142,35 @@ static void on_trace_event(struct spa_source *source)
}
}
static void
impl_log_set_loop(struct spa_log *log, struct spa_loop *loop)
{
struct impl *impl = SPA_CONTAINER_OF(log, struct impl, log);
if (impl->have_source) {
spa_loop_remove_source(impl->source.loop, &impl->source);
close(impl->source.fd);
impl->have_source = false;
}
if (loop) {
impl->source.func = on_trace_event;
impl->source.data = impl;
impl->source.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
impl->source.mask = SPA_IO_IN;
impl->source.rmask = 0;
spa_loop_add_source(loop, &impl->source);
impl->have_source = true;
}
}
static const struct spa_log impl_log = {
sizeof(struct spa_log),
NULL,
DEFAULT_LOG_LEVEL,
impl_log_log,
impl_log_logv,
impl_log_set_loop,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
@ -176,10 +196,7 @@ static int impl_clear(struct spa_handle *handle)
this = (struct impl *) handle;
if (this->have_source) {
spa_loop_remove_source(this->main_loop, &this->trace_source);
close(this->trace_source.fd);
}
impl_log_set_loop(&this->log, NULL);
return SPA_RESULT_OK;
}
@ -207,8 +224,6 @@ impl_init(const struct spa_handle_factory *factory,
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)
this->map = support[i].data;
else if (strcmp(support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
this->main_loop = support[i].data;
}
if (this->map == NULL) {
spa_log_error(&this->log, "a type-map is needed");
@ -218,16 +233,6 @@ impl_init(const struct spa_handle_factory *factory,
spa_ringbuffer_init(&this->trace_rb, TRACE_BUFFER);
if (this->main_loop) {
this->trace_source.func = on_trace_event;
this->trace_source.data = this;
this->trace_source.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
this->trace_source.mask = SPA_IO_IN;
this->trace_source.rmask = 0;
spa_loop_add_source(this->main_loop, &this->trace_source);
this->have_source = true;
}
spa_log_info(&this->log, NAME " %p: initialized", this);
return SPA_RESULT_OK;

View file

@ -1,27 +1,22 @@
executable('test-mixer', 'test-mixer.c',
include_directories : [spa_inc, spa_libinc ],
include_directories : [spa_inc ],
dependencies : [dl_lib, pthread_lib],
link_with : spalib,
install : false)
executable('test-ringbuffer', 'test-ringbuffer.c',
include_directories : [spa_inc, spa_libinc ],
dependencies : [dl_lib, pthread_lib],
link_with : spalib,
install : false)
executable('test-graph', 'test-graph.c',
include_directories : [spa_inc, spa_libinc ],
include_directories : [spa_inc ],
dependencies : [dl_lib, pthread_lib],
link_with : spalib,
install : false)
executable('test-perf', 'test-perf.c',
include_directories : [spa_inc, spa_libinc ],
dependencies : [dl_lib, pthread_lib],
link_with : spalib,
install : false)
executable('stress-ringbuffer', 'stress-ringbuffer.c',
include_directories : [spa_inc, spa_libinc ],
dependencies : [dl_lib, pthread_lib],
link_with : spalib,
install : false)
executable('test-v4l2', 'test-v4l2.c',
include_directories : [spa_inc, spa_libinc ],

View file

@ -28,16 +28,17 @@
#include <spa/node.h>
#include <spa/log.h>
#include <spa/log-impl.h>
#include <spa/loop.h>
#include <spa/type-map.h>
#include <spa/type-map-impl.h>
#include <spa/audio/format-utils.h>
#include <spa/format-utils.h>
#include <spa/format-builder.h>
#include <spa/graph.h>
#include <lib/mapper.h>
#include <lib/debug.h>
#include <lib/props.h>
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
uint32_t node;
@ -174,8 +175,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
int res;
void *hnd;
spa_handle_factory_enum_func_t enum_func;
unsigned int i;
uint32_t state = 0;
uint32_t i;
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
@ -190,7 +190,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, state++)) < 0) {
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
break;
@ -523,8 +523,8 @@ int main(int argc, char *argv[])
spa_graph_init(&data.graph);
data.map = spa_type_map_get_default();
data.log = spa_log_get_default();
data.map = &default_map.map;
data.log = &default_log.log;
data.data_loop.size = sizeof(struct spa_loop);
data.data_loop.add_source = do_add_source;
data.data_loop.update_source = do_update_source;

View file

@ -28,18 +28,20 @@
#include <spa/node.h>
#include <spa/log.h>
#include <spa/log-impl.h>
#include <spa/loop.h>
#include <spa/graph.h>
#include <spa/type-map.h>
#include <spa/type-map-impl.h>
#include <spa/audio/format-utils.h>
#include <spa/format-utils.h>
#include <spa/format-builder.h>
#include <lib/mapper.h>
#include <lib/debug.h>
#include <lib/props.h>
#undef USE_GRAPH
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
uint32_t node;
uint32_t props;
@ -184,8 +186,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
int res;
void *hnd;
spa_handle_factory_enum_func_t enum_func;
unsigned int i;
uint32_t state = 0;
uint32_t i;
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
@ -200,7 +201,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, state++)) < 0) {
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
break;
@ -627,8 +628,8 @@ int main(int argc, char *argv[])
int res;
const char *str;
data.map = spa_type_map_get_default();
data.log = spa_log_get_default();
data.map = &default_map.map;
data.log = &default_log.log;
data.data_loop.size = sizeof(struct spa_loop);
data.data_loop.add_source = do_add_source;
data.data_loop.update_source = do_update_source;

View file

@ -27,18 +27,14 @@
#include <poll.h>
#include <spa/node.h>
#include <spa/log.h>
#include <spa/log-impl.h>
#include <spa/loop.h>
#include <spa/type-map.h>
#include <spa/type-map-impl.h>
#include <spa/audio/format-utils.h>
#include <spa/format-utils.h>
#include <spa/format-builder.h>
#include <spa/graph.h>
#include <lib/mapper.h>
#include <lib/debug.h>
#include <lib/props.h>
#define MODE_SYNC_PUSH (1<<0)
#define MODE_SYNC_PULL (1<<1)
#define MODE_ASYNC_PUSH (1<<2)
@ -46,6 +42,9 @@
#define MODE_ASYNC_BOTH (MODE_ASYNC_PUSH|MODE_ASYNC_PULL)
#define MODE_DIRECT (1<<4)
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
uint32_t node;
uint32_t props;
@ -174,8 +173,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
struct spa_handle *handle;
int res;
spa_handle_factory_enum_func_t enum_func;
unsigned int i;
uint32_t state = 0;
uint32_t i;
if (data->hnd == NULL) {
if ((data->hnd = dlopen(lib, RTLD_NOW)) == NULL) {
@ -192,7 +190,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, state++)) < 0) {
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
break;
@ -514,8 +512,8 @@ int main(int argc, char *argv[])
spa_graph_init(&data.graph);
data.map = spa_type_map_get_default();
data.log = spa_log_get_default();
data.map = &default_map.map;
data.log = &default_log.log;
data.data_loop.size = sizeof(struct spa_loop);
data.data_loop.add_source = do_add_source;
data.data_loop.update_source = do_update_source;

View file

@ -24,13 +24,14 @@
#include <errno.h>
#include <spa/type-map.h>
#include <spa/type-map-impl.h>
#include <spa/log.h>
#include <spa/node.h>
#include <spa/loop.h>
#include <spa/video/format-utils.h>
#include <spa/format-builder.h>
#include <lib/debug.h>
#include <lib/mapper.h>
#if 0
/* { video/raw,
@ -64,6 +65,8 @@ spa_build(SPA_MEDIA_TYPE_VIDEO, SPA_MEDIA_SUBTYPE_RAW,
SPA_POD_PROP_FLAG_UNSET | SPA_PROP_RANGE_MIN_MAX, 0, 1, INT32_MAX, 1, 0);
#endif
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static struct {
uint32_t format;
struct spa_type_media_type media_type;
@ -142,8 +145,8 @@ static void do_static_struct(struct spa_type_map *map)
}
};
spa_debug_pod(&test_format.fmt.pod, map);
spa_debug_format(&test_format.fmt, map);
spa_debug_pod(&test_format.fmt.pod);
spa_debug_format(&test_format.fmt);
{
uint32_t format = 0, match;
@ -174,9 +177,10 @@ int main(int argc, char *argv[])
struct spa_pod_frame frame[4];
uint8_t buffer[1024];
struct spa_format *fmt;
struct spa_type_map *map = spa_type_map_get_default();
struct spa_type_map *map = &default_map.map;
type_init(map);
spa_debug_set_type_map(map);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -209,7 +213,7 @@ int main(int argc, char *argv[])
spa_pod_builder_pop(&b, &frame[0]);
spa_debug_pod(&fmt->pod, map);
spa_debug_pod(&fmt->pod);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -242,8 +246,8 @@ int main(int argc, char *argv[])
-SPA_POD_TYPE_PROP, &frame[1]);
fmt = SPA_MEMBER(buffer, frame[0].ref, struct spa_format);
spa_debug_pod(&fmt->pod, map);
spa_debug_format(fmt, map);
spa_debug_pod(&fmt->pod);
spa_debug_format(fmt);
spa_pod_builder_init(&b, buffer, sizeof(buffer));
@ -279,8 +283,8 @@ int main(int argc, char *argv[])
0);
fmt = SPA_MEMBER(buffer, frame[0].ref, struct spa_format);
spa_debug_pod(&fmt->pod, map);
spa_debug_format(fmt, map);
spa_debug_pod(&fmt->pod);
spa_debug_format(fmt);
do_static_struct(map);

View file

@ -28,11 +28,13 @@
#include <spa/pod-builder.h>
#include <spa/pod-iter.h>
#include <spa/type-map.h>
#include <spa/log.h>
#include <spa/type-map-impl.h>
#include <spa/log-impl.h>
#include <spa/video/format.h>
#include <lib/debug.h>
#include <lib/mapper.h>
static SPA_TYPE_MAP_IMPL(default_map, 4096);
int main(int argc, char *argv[])
{
@ -41,7 +43,9 @@ int main(int argc, char *argv[])
uint8_t buffer[1024];
struct spa_pod *obj;
struct spa_pod_iter i;
struct spa_type_map *map = spa_type_map_get_default();
struct spa_type_map *map = &default_map.map;
spa_debug_set_type_map(map);
b.data = buffer;
b.size = 1024;
@ -85,11 +89,11 @@ int main(int argc, char *argv[])
spa_pod_builder_pop(&b, &frame[0]);
obj = SPA_POD_BUILDER_DEREF(&b, frame[0].ref, struct spa_pod);
spa_debug_pod(obj, map);
spa_debug_pod(obj);
struct spa_pod_prop *p = spa_pod_object_find_prop((struct spa_pod_object *) obj, 4);
printf("%d %d\n", p->body.key, p->body.flags);
spa_debug_pod(&p->body.value, map);
spa_debug_pod(&p->body.value);
obj = SPA_POD_BUILDER_DEREF(&b, frame[2].ref, struct spa_pod);
@ -115,8 +119,5 @@ int main(int argc, char *argv[])
SPA_POD_ARRAY_BODY_FOREACH(&va->body, SPA_POD_BODY_SIZE(va), pi) {
printf("%d\n", *pi);
}
return 0;
}

View file

@ -27,16 +27,19 @@
#include <poll.h>
#include <spa/node.h>
#include <spa/log.h>
#include <spa/log-impl.h>
#include <spa/loop.h>
#include <spa/type-map.h>
#include <spa/type-map-impl.h>
#include <spa/audio/format-utils.h>
#include <spa/format-utils.h>
#include <spa/format-builder.h>
#include <lib/mapper.h>
#include <lib/debug.h>
#include <lib/props.h>
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
uint32_t node;
uint32_t props;
@ -162,8 +165,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
int res;
void *hnd;
spa_handle_factory_enum_func_t enum_func;
unsigned int i;
uint32_t state = 0;
uint32_t i;
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
@ -178,7 +180,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, state++)) < 0) {
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
break;
@ -455,8 +457,8 @@ int main(int argc, char *argv[])
int res;
const char *str;
data.map = spa_type_map_get_default();
data.log = spa_log_get_default();
data.map = &default_map.map;
data.log = &default_log.log;
data.data_loop.size = sizeof(struct spa_loop);
data.data_loop.add_source = do_add_source;
data.data_loop.update_source = do_update_source;

View file

@ -28,15 +28,17 @@
#include <SDL2/SDL.h>
#include <spa/type-map.h>
#include <spa/log.h>
#include <spa/type-map-impl.h>
#include <spa/log-impl.h>
#include <spa/node.h>
#include <spa/loop.h>
#include <spa/video/format-utils.h>
#include <spa/format-builder.h>
#include <lib/debug.h>
#include <lib/props.h>
#include <lib/mapper.h>
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
uint32_t node;
@ -122,8 +124,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
int res;
void *hnd;
spa_handle_factory_enum_func_t enum_func;
unsigned int i;
uint32_t state = 0;
uint32_t i;
if ((hnd = dlopen(lib, RTLD_NOW)) == NULL) {
printf("can't load %s: %s\n", lib, dlerror());
@ -138,7 +139,7 @@ static int make_node(struct data *data, struct spa_node **node, const char *lib,
const struct spa_handle_factory *factory;
void *iface;
if ((res = enum_func(&factory, state)) < 0) {
if ((res = enum_func(&factory, i)) < 0) {
if (res != SPA_RESULT_ENUM_END)
printf("can't enumerate factories: %d\n", res);
break;
@ -536,8 +537,8 @@ int main(int argc, char *argv[])
data.use_buffer = true;
data.map = spa_type_map_get_default();
data.log = spa_log_get_default();
data.map = &default_map.map;
data.log = &default_log.log;
if ((str = getenv("SPA_DEBUG")))
data.log->level = atoi(str);

View file

@ -23,13 +23,16 @@
#include <unistd.h>
#include <dlfcn.h>
#include <spa/type-map.h>
#include <spa/type-map-impl.h>
#include <spa/clock.h>
#include <spa/log.h>
#include <spa/log-impl.h>
#include <spa/node.h>
#include <spa/loop.h>
#include <lib/debug.h>
#include <lib/mapper.h>
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
uint32_t node;
@ -63,7 +66,7 @@ inspect_port(struct data *data, struct spa_node *node, enum spa_direction direct
break;
}
if (format)
spa_debug_format(format, data->map);
spa_debug_format(format);
}
@ -75,7 +78,7 @@ inspect_port(struct data *data, struct spa_node *node, enum spa_direction direct
printf("port_enum_params error: %d\n", res);
break;
}
spa_debug_param(param, data->map);
spa_debug_param(param);
}
}
@ -89,7 +92,7 @@ static void inspect_node(struct data *data, struct spa_node *node)
if ((res = spa_node_get_props(node, &props)) < 0)
printf("can't get properties: %d\n", res);
else
spa_debug_props(props, data->map);
spa_debug_props(props);
if ((res = spa_node_get_n_ports(node, &n_input, &max_input, &n_output, &max_output)) < 0) {
printf("can't get n_ports: %d\n", res);
@ -194,13 +197,15 @@ int main(int argc, char *argv[])
return -1;
}
data.map = spa_type_map_get_default();
data.log = NULL;
data.map = &default_map.map;
data.log = &default_log.log;
data.loop.size = sizeof(struct spa_loop);
data.loop.add_source = do_add_source;
data.loop.update_source = do_update_source;
data.loop.remove_source = do_remove_source;
spa_debug_set_type_map(data.map);
data.support[0].type = SPA_TYPE__TypeMap;
data.support[0].data = data.map;
data.support[1].type = SPA_TYPE__Log;

View file

@ -25,12 +25,15 @@
#include <errno.h>
#include <poll.h>
#include <spa/log.h>
#include <spa/type-map.h>
#include <spa/log-impl.h>
#include <spa/type-map-impl.h>
#include <spa/monitor.h>
#include <spa/loop.h>
#include <lib/debug.h>
#include <lib/mapper.h>
static SPA_TYPE_MAP_IMPL(default_map, 4096);
static SPA_LOG_IMPL(default_log);
struct type {
struct spa_type_monitor monitor;
@ -57,7 +60,7 @@ struct data {
static void inspect_item(struct data *data, struct spa_monitor_item *item)
{
spa_debug_pod(&item->object.pod, data->map);
spa_debug_pod(&item->object.pod);
}
static void on_monitor_event(struct spa_monitor *monitor, struct spa_event *event, void *user_data)
@ -162,13 +165,15 @@ int main(int argc, char *argv[])
spa_handle_factory_enum_func_t enum_func;
uint32_t fidx;
data.map = spa_type_map_get_default();
data.log = NULL;
data.map = &default_map.map;
data.log = &default_log.log;
data.main_loop.size = sizeof(struct spa_loop);
data.main_loop.add_source = do_add_source;
data.main_loop.update_source = do_update_source;
data.main_loop.remove_source = do_remove_source;
spa_debug_set_type_map(data.map);
data.support[0].type = SPA_TYPE__TypeMap;
data.support[0].data = data.map;
data.support[1].type = SPA_TYPE__Log;