audiotestsrc: Make audiotestsrc work

This small patch makes audiotestsrc work.

You will need to uncomment the following lines in pipewire.conf

	add-spa-lib audiotestsrc audiotestsrc/libspa-audiotestsrc
	create-object adapter node.name=my-test factory.name=audiotestsrc

If you use pw-record, use --list-targets to find the target id and
record using --target=<n>

Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
This commit is contained in:
Pantelis Antoniou 2020-03-04 11:28:25 +02:00 committed by Wim Taymans
parent d4fcbaa5d1
commit 4db9a1e96d

View file

@ -37,6 +37,7 @@
#include <spa/node/node.h> #include <spa/node/node.h>
#include <spa/node/utils.h> #include <spa/node/utils.h>
#include <spa/node/io.h> #include <spa/node/io.h>
#include <spa/node/keys.h>
#include <spa/param/audio/format-utils.h> #include <spa/param/audio/format-utils.h>
#include <spa/param/param.h> #include <spa/param/param.h>
#include <spa/pod/filter.h> #include <spa/pod/filter.h>
@ -53,7 +54,7 @@ enum wave_type {
WAVE_SQUARE, WAVE_SQUARE,
}; };
#define DEFAULT_LIVE false #define DEFAULT_LIVE true
#define DEFAULT_WAVE WAVE_SINE #define DEFAULT_WAVE WAVE_SINE
#define DEFAULT_FREQ 440.0 #define DEFAULT_FREQ 440.0
#define DEFAULT_VOLUME 1.0 #define DEFAULT_VOLUME 1.0
@ -121,6 +122,8 @@ struct impl {
struct spa_node_info info; struct spa_node_info info;
struct spa_param_info params[2]; struct spa_param_info params[2];
struct props props; struct props props;
struct spa_io_clock *clock;
struct spa_io_position *position;
struct spa_hook_list hooks; struct spa_hook_list hooks;
struct spa_callbacks callbacks; struct spa_callbacks callbacks;
@ -228,6 +231,26 @@ static int impl_node_enum_params(void *object, int seq,
} }
break; break;
} }
case SPA_PARAM_IO:
{
switch (result.index) {
case 0:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Clock),
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_clock)));
break;
case 1:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, SPA_POD_Id(SPA_IO_Position),
SPA_PARAM_IO_size, SPA_POD_Int(sizeof(struct spa_io_position)));
break;
default:
return 0;
}
break;
}
default: default:
return -ENOENT; return -ENOENT;
} }
@ -277,7 +300,23 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size) static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
{ {
return -ENOTSUP; struct impl *this = object;
spa_return_val_if_fail(this != NULL, -EINVAL);
switch (id) {
case SPA_IO_Clock:
if (size > 0 && size < sizeof(struct spa_io_clock))
return -EINVAL;
this->clock = data;
break;
case SPA_IO_Position:
this->position = data;
break;
default:
return -ENOENT;
}
return 0;
} }
#include "render.c" #include "render.c"
@ -347,12 +386,18 @@ static int make_buffer(struct impl *this)
filled = 0; filled = 0;
index = 0; index = 0;
avail = maxsize - filled; avail = maxsize - filled;
n_bytes = SPA_MIN(avail, n_bytes);
offset = index % maxsize; offset = index % maxsize;
n_samples = n_bytes / port->bpf; if (this->position && this->position->clock.duration) {
n_bytes = SPA_MIN(avail, n_bytes);
n_samples = this->position->clock.duration;
if (n_samples * port->bpf < n_bytes)
n_bytes = n_samples * port->bpf;
} else {
n_bytes = SPA_MIN(avail, n_bytes);
n_samples = n_bytes / port->bpf;
}
l0 = SPA_MIN(n_bytes, maxsize - offset) / port->bpf; l0 = SPA_MIN(n_bytes, maxsize - offset) / port->bpf;
l1 = n_samples - l0; l1 = n_samples - l0;
@ -442,6 +487,7 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
static const struct spa_dict_item node_info_items[] = { static const struct spa_dict_item node_info_items[] = {
{ SPA_KEY_MEDIA_CLASS, "Audio/Source" }, { SPA_KEY_MEDIA_CLASS, "Audio/Source" },
{ SPA_KEY_NODE_DRIVER, "true" },
}; };
static void emit_node_info(struct impl *this, bool full) static void emit_node_info(struct impl *this, bool full)