mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04:00
audioconvert: fix s24 samples
Various cleanups
This commit is contained in:
parent
35e0399d97
commit
75a18d5c7f
5 changed files with 139 additions and 184 deletions
|
|
@ -108,7 +108,6 @@ struct link {
|
|||
uint32_t in_port;
|
||||
const struct spa_port_info *in_info;
|
||||
struct spa_io_buffers io;
|
||||
struct spa_audio_info *info;
|
||||
bool negotiated;
|
||||
uint32_t n_buffers;
|
||||
struct spa_buffer **buffers;
|
||||
|
|
@ -159,26 +158,21 @@ static int make_link(struct impl *this,
|
|||
l->io.status = SPA_STATUS_NEED_BUFFER;
|
||||
l->io.buffer_id = SPA_ID_INVALID;
|
||||
l->n_buffers = 0;
|
||||
l->info = info;
|
||||
|
||||
if (out_node != NULL) {
|
||||
spa_node_port_get_info(out_node,
|
||||
SPA_DIRECTION_OUTPUT, out_port,
|
||||
&l->out_info);
|
||||
spa_node_port_set_io(out_node,
|
||||
SPA_DIRECTION_OUTPUT, out_port,
|
||||
t->io.Buffers,
|
||||
&l->io, sizeof(l->io));
|
||||
}
|
||||
if (in_node != NULL) {
|
||||
spa_node_port_get_info(in_node,
|
||||
SPA_DIRECTION_INPUT, in_port,
|
||||
&l->in_info);
|
||||
spa_node_port_set_io(in_node,
|
||||
SPA_DIRECTION_INPUT, in_port,
|
||||
t->io.Buffers,
|
||||
&l->io, sizeof(l->io));
|
||||
}
|
||||
spa_node_port_get_info(out_node,
|
||||
SPA_DIRECTION_OUTPUT, out_port,
|
||||
&l->out_info);
|
||||
spa_node_port_set_io(out_node,
|
||||
SPA_DIRECTION_OUTPUT, out_port,
|
||||
t->io.Buffers,
|
||||
&l->io, sizeof(l->io));
|
||||
spa_node_port_get_info(in_node,
|
||||
SPA_DIRECTION_INPUT, in_port,
|
||||
&l->in_info);
|
||||
spa_node_port_set_io(in_node,
|
||||
SPA_DIRECTION_INPUT, in_port,
|
||||
t->io.Buffers,
|
||||
&l->io, sizeof(l->io));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -186,16 +180,12 @@ static void clean_link(struct impl *this, struct link *link)
|
|||
{
|
||||
struct type *t = &this->type;
|
||||
|
||||
if (link->in_node) {
|
||||
spa_node_port_set_param(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idFormat, 0, NULL);
|
||||
}
|
||||
if (link->out_node) {
|
||||
spa_node_port_set_param(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idFormat, 0, NULL);
|
||||
}
|
||||
spa_node_port_set_param(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idFormat, 0, NULL);
|
||||
spa_node_port_set_param(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idFormat, 0, NULL);
|
||||
if (link->buffers)
|
||||
free(link->buffers);
|
||||
link->buffers = NULL;
|
||||
|
|
@ -250,62 +240,44 @@ static int negotiate_link_format(struct impl *this, struct link *link)
|
|||
return 0;
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
if (link->info) {
|
||||
filter = spa_pod_builder_object(&b,
|
||||
0, t->format,
|
||||
"I", link->info->media_type,
|
||||
"I", link->info->media_subtype,
|
||||
":", t->format_audio.format, "I", link->info->info.raw.format,
|
||||
":", t->format_audio.layout, "i", link->info->info.raw.layout,
|
||||
":", t->format_audio.rate, "i", link->info->info.raw.rate,
|
||||
":", t->format_audio.channels, "i", link->info->info.raw.channels);
|
||||
}
|
||||
else
|
||||
filter = NULL;
|
||||
|
||||
if (link->out_node != NULL) {
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idEnumFormat, &state,
|
||||
filter, &format, &b)) <= 0) {
|
||||
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idEnumFormat, filter);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
filter = format;
|
||||
state = 0;
|
||||
filter = NULL;
|
||||
if ((res = spa_node_port_enum_params(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idEnumFormat, &state,
|
||||
filter, &format, &b)) <= 0) {
|
||||
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idEnumFormat, filter);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
if (link->in_node != NULL) {
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idEnumFormat, &state,
|
||||
filter, &format, &b)) <= 0) {
|
||||
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idEnumFormat, filter);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
filter = format;
|
||||
filter = format;
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idEnumFormat, &state,
|
||||
filter, &format, &b)) <= 0) {
|
||||
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idEnumFormat, filter);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
filter = format;
|
||||
|
||||
spa_pod_fixate(filter);
|
||||
spa_debug_pod(filter, SPA_DEBUG_FLAG_FORMAT);
|
||||
|
||||
if (link->out_node != NULL) {
|
||||
if ((res = spa_node_port_set_param(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idFormat, 0,
|
||||
filter)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (link->in_node != NULL) {
|
||||
if ((res = spa_node_port_set_param(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idFormat, 0,
|
||||
filter)) < 0)
|
||||
return res;
|
||||
}
|
||||
if ((res = spa_node_port_set_param(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idFormat, 0,
|
||||
filter)) < 0)
|
||||
return res;
|
||||
|
||||
if ((res = spa_node_port_set_param(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idFormat, 0,
|
||||
filter)) < 0)
|
||||
return res;
|
||||
|
||||
link->negotiated = true;
|
||||
|
||||
return 0;
|
||||
|
|
@ -314,17 +286,6 @@ static int negotiate_link_format(struct impl *this, struct link *link)
|
|||
static int setup_convert(struct impl *this)
|
||||
{
|
||||
int i, j, res;
|
||||
struct spa_audio_info informat, outformat;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: %d/%d@%d.%d->%d/%d@%d.%d", this,
|
||||
informat.info.raw.format,
|
||||
informat.info.raw.channels,
|
||||
informat.info.raw.rate,
|
||||
informat.info.raw.layout,
|
||||
outformat.info.raw.format,
|
||||
outformat.info.raw.channels,
|
||||
outformat.info.raw.rate,
|
||||
outformat.info.raw.layout);
|
||||
|
||||
if (this->n_links > 0)
|
||||
return 0;
|
||||
|
|
@ -367,27 +328,23 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
|
|||
if (link->n_buffers > 0)
|
||||
return 0;
|
||||
|
||||
if (link->out_node != NULL) {
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idBuffers, &state,
|
||||
param, ¶m, &b)) <= 0) {
|
||||
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idBuffers, param);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idBuffers, &state,
|
||||
param, ¶m, &b)) <= 0) {
|
||||
debug_params(this, link->out_node, SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idBuffers, param);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
if (link->in_node != NULL) {
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idBuffers, &state,
|
||||
param, ¶m, &b)) <= 0) {
|
||||
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idBuffers, param);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
state = 0;
|
||||
if ((res = spa_node_port_enum_params(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
t->param.idBuffers, &state,
|
||||
param, ¶m, &b)) <= 0) {
|
||||
debug_params(this, link->in_node, SPA_DIRECTION_INPUT, link->in_port,
|
||||
t->param.idBuffers, param);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
spa_pod_fixate(param);
|
||||
|
|
@ -439,35 +396,31 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
|
|||
|
||||
link->n_buffers = buffers;
|
||||
|
||||
if (link->out_node != NULL) {
|
||||
if (out_alloc) {
|
||||
if ((res = spa_node_port_alloc_buffers(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
NULL, 0,
|
||||
link->buffers, &link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
if ((res = spa_node_port_use_buffers(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
link->buffers, link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (out_alloc) {
|
||||
if ((res = spa_node_port_alloc_buffers(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
NULL, 0,
|
||||
link->buffers, &link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (link->in_node != NULL) {
|
||||
if (in_alloc) {
|
||||
if ((res = spa_node_port_alloc_buffers(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
NULL, 0,
|
||||
link->buffers, &link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
if ((res = spa_node_port_use_buffers(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
link->buffers, link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
if ((res = spa_node_port_use_buffers(link->out_node,
|
||||
SPA_DIRECTION_OUTPUT, link->out_port,
|
||||
link->buffers, link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
if (in_alloc) {
|
||||
if ((res = spa_node_port_alloc_buffers(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
NULL, 0,
|
||||
link->buffers, &link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
else {
|
||||
if ((res = spa_node_port_use_buffers(link->in_node,
|
||||
SPA_DIRECTION_INPUT, link->in_port,
|
||||
link->buffers, link->n_buffers)) < 0)
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@
|
|||
|
||||
#define NAME "channelmix"
|
||||
|
||||
#define DEFAULT_RATE 44100
|
||||
#define DEFAULT_CHANNELS 2
|
||||
|
||||
#define MAX_BUFFERS 32
|
||||
|
||||
struct impl;
|
||||
|
|
@ -361,9 +364,9 @@ static int port_enum_formats(struct spa_node *node,
|
|||
"I", t->media_subtype.raw,
|
||||
":", t->format_audio.format, "I", t->audio_format.F32,
|
||||
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
|
||||
":", t->format_audio.rate, "iru", 44100,
|
||||
":", t->format_audio.rate, "iru", DEFAULT_RATE,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
|
||||
":", t->format_audio.channels, "iru", 2,
|
||||
":", t->format_audio.channels, "iru", DEFAULT_CHANNELS,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
|
||||
}
|
||||
break;
|
||||
|
|
@ -453,32 +456,30 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return res;
|
||||
}
|
||||
else if (id == t->param.idBuffers) {
|
||||
uint32_t buffers, size;
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
if (other->n_buffers > 0) {
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.buffers, "iru", other->n_buffers,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.blocks, "i", port->blocks,
|
||||
":", t->param_buffers.size, "i", (other->size / other->stride) *
|
||||
port->stride,
|
||||
":", t->param_buffers.stride, "i", port->stride,
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
buffers = other->n_buffers;
|
||||
size = other->size / other->stride;
|
||||
} else {
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.buffers, "iru", 1,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.blocks, "i", port->blocks,
|
||||
":", t->param_buffers.size, "iru", 2048 * port->stride,
|
||||
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
|
||||
":", t->param_buffers.stride, "i", port->stride,
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
buffers = 1;
|
||||
size = port->format.info.raw.rate * 1024 / DEFAULT_RATE;
|
||||
}
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.buffers, "iru", buffers,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.blocks, "i", port->blocks,
|
||||
":", t->param_buffers.size, "iru", size * port->stride,
|
||||
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
|
||||
":", t->param_buffers.stride, "i", port->stride,
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
}
|
||||
else if (id == t->param.idMeta) {
|
||||
if (!port->have_format)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ conv_s32d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
|
||||
#define READ24(s) (((uint32_t)s[0] << 16) | ((uint32_t)s[1] << 8) | ((uint32_t)s[2]))
|
||||
|
||||
#define S24_TO_F32(v) ((v) * (1.0f / S24_SCALE))
|
||||
#define S24_TO_F32(v) ((((int32_t)v)<<8) * (1.0f / S32_SCALE))
|
||||
|
||||
static void
|
||||
conv_s24_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_bytes)
|
||||
|
|
@ -205,7 +205,7 @@ conv_s24_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *
|
|||
static void
|
||||
conv_s24_to_f32d(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_bytes)
|
||||
{
|
||||
const int8_t *s = src[0];
|
||||
const uint8_t *s = src[0];
|
||||
float **d = (float **) dst;
|
||||
int i, j;
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ conv_s24_to_f32d(void *data, int n_dst, void *dst[n_dst], int n_src, const void
|
|||
static void
|
||||
conv_s24d_to_f32(void *data, int n_dst, void *dst[n_dst], int n_src, const void *src[n_src], int n_bytes)
|
||||
{
|
||||
const int8_t **s = (const int8_t **) src;
|
||||
const uint8_t **s = (const uint8_t **) src;
|
||||
float *d = dst[0];
|
||||
int i, n, n_samples;
|
||||
|
||||
|
|
|
|||
|
|
@ -599,7 +599,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
size = other->size / other->stride;
|
||||
} else {
|
||||
buffers = 1;
|
||||
size = 1024;
|
||||
size = port->format.info.raw.rate * 1024 / DEFAULT_RATE;
|
||||
}
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@
|
|||
|
||||
#define NAME "resample"
|
||||
|
||||
#define DEFAULT_RATE 44100
|
||||
#define DEFAULT_CHANNELS 2
|
||||
|
||||
#define MAX_BUFFERS 32
|
||||
|
||||
struct impl;
|
||||
|
|
@ -338,9 +341,9 @@ static int port_enum_formats(struct spa_node *node,
|
|||
"I", t->media_subtype.raw,
|
||||
":", t->format_audio.format, "I", t->audio_format.F32,
|
||||
":", t->format_audio.layout, "i", SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
|
||||
":", t->format_audio.rate, "iru", 44100,
|
||||
":", t->format_audio.rate, "iru", DEFAULT_RATE,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
|
||||
":", t->format_audio.channels, "iru", 2,
|
||||
":", t->format_audio.channels, "iru", DEFAULT_CHANNELS,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX));
|
||||
}
|
||||
break;
|
||||
|
|
@ -430,33 +433,31 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return res;
|
||||
}
|
||||
else if (id == t->param.idBuffers) {
|
||||
uint32_t buffers, size;
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
if (other->n_buffers > 0) {
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.buffers, "iru", other->n_buffers,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.blocks, "i", port->blocks,
|
||||
":", t->param_buffers.size, "iru", (other->size / other->stride) *
|
||||
port->stride,
|
||||
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
|
||||
":", t->param_buffers.stride, "i", port->stride,
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
} else {
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.buffers, "iru", 1,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.blocks, "i", port->blocks,
|
||||
":", t->param_buffers.size, "iru", 1024 * port->stride,
|
||||
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
|
||||
":", t->param_buffers.stride, "i", port->stride,
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
buffers = other->n_buffers;
|
||||
size = other->size / other->stride;
|
||||
}
|
||||
else {
|
||||
buffers = 1;
|
||||
size = port->format.info.raw.rate * 1024 / DEFAULT_RATE;
|
||||
}
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
id, t->param_buffers.Buffers,
|
||||
":", t->param_buffers.buffers, "iru", buffers,
|
||||
SPA_POD_PROP_MIN_MAX(1, MAX_BUFFERS),
|
||||
":", t->param_buffers.blocks, "i", port->blocks,
|
||||
":", t->param_buffers.size, "iru", size * port->stride,
|
||||
SPA_POD_PROP_MIN_MAX(16 * port->stride, INT32_MAX / port->stride),
|
||||
":", t->param_buffers.stride, "i", port->stride,
|
||||
":", t->param_buffers.align, "i", 16);
|
||||
}
|
||||
else if (id == t->param.idMeta) {
|
||||
if (!port->have_format)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue