mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-06 13:30:01 -05:00
Pass channelmask around and use it to name ports
Use the channel name in the port names of the dsp
This commit is contained in:
parent
7aae01fe15
commit
fb3379e587
9 changed files with 217 additions and 15 deletions
|
|
@ -86,6 +86,7 @@ static void *create_object(void *_data,
|
|||
struct pw_client *client;
|
||||
struct pw_node *dsp;
|
||||
int res, channels, rate, maxbuffer;
|
||||
uint64_t channelmask;
|
||||
const char *str;
|
||||
enum pw_direction direction;
|
||||
struct node_data *nd;
|
||||
|
|
@ -106,6 +107,11 @@ static void *create_object(void *_data,
|
|||
|
||||
channels = pw_properties_parse_int(str);
|
||||
|
||||
if ((str = pw_properties_get(properties, "audio-dsp.channelmask")) == NULL)
|
||||
goto no_props;
|
||||
|
||||
channelmask = pw_properties_parse_uint64(str);
|
||||
|
||||
if ((str = pw_properties_get(properties, "audio-dsp.rate")) == NULL)
|
||||
goto no_props;
|
||||
|
||||
|
|
@ -119,7 +125,7 @@ static void *create_object(void *_data,
|
|||
dsp = pw_audio_dsp_new(pw_module_get_core(d->module),
|
||||
properties,
|
||||
direction,
|
||||
channels, rate, maxbuffer,
|
||||
channels, channelmask, rate, maxbuffer,
|
||||
sizeof(struct node_data));
|
||||
|
||||
if (dsp == NULL)
|
||||
|
|
|
|||
|
|
@ -620,6 +620,7 @@ static const struct pw_node_events dsp_events = {
|
|||
struct channel_data {
|
||||
struct impl *impl;
|
||||
uint32_t channels;
|
||||
uint64_t channelmask;
|
||||
uint32_t rate;
|
||||
};
|
||||
|
||||
|
|
@ -645,6 +646,7 @@ static int collect_audio_format(void *data, uint32_t id,
|
|||
|
||||
if (info.channels > d->channels) {
|
||||
d->channels = info.channels;
|
||||
d->channelmask = info.channel_mask;
|
||||
d->rate = info.rate;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -652,7 +654,7 @@ static int collect_audio_format(void *data, uint32_t id,
|
|||
|
||||
|
||||
static int find_port_format(struct impl *impl, struct pw_port *port,
|
||||
uint32_t *channels, uint32_t *rate)
|
||||
uint32_t *channels, uint64_t *channelmask, uint32_t *rate)
|
||||
{
|
||||
struct channel_data data = { impl, 0, 0 };
|
||||
|
||||
|
|
@ -661,9 +663,10 @@ static int find_port_format(struct impl *impl, struct pw_port *port,
|
|||
0, 0, NULL,
|
||||
collect_audio_format, &data);
|
||||
|
||||
pw_log_debug("port channels %d rate %d", data.channels, data.rate);
|
||||
pw_log_debug("port channels %d %"PRIu64" rate %d", data.channels, data.channelmask, data.rate);
|
||||
|
||||
*channels = data.channels;
|
||||
*channelmask = data.channelmask;
|
||||
*rate = data.rate;
|
||||
|
||||
return data.channels > 0 ? 0 : -1;
|
||||
|
|
@ -679,6 +682,7 @@ static int on_global(void *data, struct pw_global *global)
|
|||
enum pw_direction direction;
|
||||
struct pw_port *node_port, *dsp_port;
|
||||
uint32_t id, channels, rate;
|
||||
uint64_t channelmask;
|
||||
bool need_dsp;
|
||||
uint64_t plugged;
|
||||
|
||||
|
|
@ -739,13 +743,14 @@ static int on_global(void *data, struct pw_global *global)
|
|||
pw_node_add_listener(node, &sess->node_listener, &node_events, sess);
|
||||
|
||||
if (need_dsp) {
|
||||
if (find_port_format(impl, node_port, &channels, &rate) < 0)
|
||||
if (find_port_format(impl, node_port, &channels, &channelmask, &rate) < 0)
|
||||
return 0;
|
||||
|
||||
dsp = pw_audio_dsp_new(impl->core,
|
||||
properties,
|
||||
direction,
|
||||
channels,
|
||||
channelmask,
|
||||
rate,
|
||||
MAX_QUANTUM_SIZE * sizeof(float),
|
||||
0);
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ struct node {
|
|||
void *user_data;
|
||||
|
||||
int channels;
|
||||
uint64_t channelmask;
|
||||
int sample_rate;
|
||||
int max_buffer_size;
|
||||
};
|
||||
|
|
@ -141,10 +142,65 @@ static const struct pw_port_implementation port_implementation = {
|
|||
.use_buffers = port_use_buffers,
|
||||
};
|
||||
|
||||
static const char *chmap_names[] =
|
||||
{
|
||||
"FL",
|
||||
"FR", /**< front right */
|
||||
"RL", /**< rear left */
|
||||
"RR", /**< rear right */
|
||||
"FC", /**< front center */
|
||||
"LFE", /**< LFE */
|
||||
"SL", /**< side left */
|
||||
"SR", /**< side right */
|
||||
"RC", /**< rear center */
|
||||
"FLC", /**< front left center */
|
||||
"FRC", /**< front right center */
|
||||
"RLC", /**< rear left center */
|
||||
"RRC", /**< rear right center */
|
||||
"FLW", /**< front left wide */
|
||||
"FRW", /**< front right wide */
|
||||
"FLH", /**< front left high */
|
||||
"FCH", /**< front center high */
|
||||
"FRH", /**< front right high */
|
||||
"TC", /**< top center */
|
||||
"TFL", /**< top front left */
|
||||
"TFR", /**< top front right */
|
||||
"TFC", /**< top front center */
|
||||
"TRL", /**< top rear left */
|
||||
"TRR", /**< top rear right */
|
||||
"TRC", /**< top rear center */
|
||||
"TFLC", /**< top front left center */
|
||||
"TFRC", /**< top front right center */
|
||||
"TSL", /**< top side left */
|
||||
"TSR", /**< top side right */
|
||||
"LLFE", /**< left LFE */
|
||||
"RLFE", /**< right LFE */
|
||||
"BC", /**< bottom center */
|
||||
"BLC", /**< bottom left center */
|
||||
"BRC", /**< bottom right center */
|
||||
};
|
||||
|
||||
static int make_channel_name(struct node *n, char *channel_name, int i, uint64_t channelmask)
|
||||
{
|
||||
int j;
|
||||
|
||||
sprintf(channel_name, "%d", i + 1);
|
||||
for (j = 0; j < 64; j++) {
|
||||
if (channelmask & (1LL << j)) {
|
||||
if (i-- == 0) {
|
||||
sprintf(channel_name, "%s", chmap_names[j]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct pw_node *pw_audio_dsp_new(struct pw_core *core,
|
||||
const struct pw_properties *props,
|
||||
enum pw_direction direction,
|
||||
uint32_t channels,
|
||||
uint64_t channelmask,
|
||||
uint32_t sample_rate,
|
||||
uint32_t max_buffer_size,
|
||||
size_t user_data_size)
|
||||
|
|
@ -204,6 +260,7 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
|
|||
n->node = node;
|
||||
|
||||
n->channels = channels;
|
||||
n->channelmask = channelmask;
|
||||
n->sample_rate = sample_rate;
|
||||
n->max_buffer_size = max_buffer_size;
|
||||
|
||||
|
|
@ -219,20 +276,23 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
|
|||
for (i = 0; i < n->channels; i++) {
|
||||
struct port *p;
|
||||
struct pw_properties *props;
|
||||
char channel_name[16];
|
||||
|
||||
make_channel_name(n, channel_name, i, channelmask);
|
||||
|
||||
props = pw_properties_new(
|
||||
"port.dsp", "32 bit float mono audio",
|
||||
"port.physical", "1",
|
||||
"port.terminal", "1",
|
||||
NULL);
|
||||
pw_properties_setf(props, "port.name", "%s_%d",
|
||||
pw_properties_setf(props, "port.name", "%s_%s",
|
||||
direction == PW_DIRECTION_INPUT ? "playback" : "capture",
|
||||
i + 1);
|
||||
pw_properties_setf(props, "port.alias", "%s_pcm:%s:%s%d",
|
||||
channel_name);
|
||||
pw_properties_setf(props, "port.alias1", "%s_pcm:%s:%s%s",
|
||||
api,
|
||||
alias,
|
||||
direction == PW_DIRECTION_INPUT ? "in" : "out",
|
||||
i + 1);
|
||||
channel_name);
|
||||
|
||||
port = pw_port_new(direction,
|
||||
i,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ pw_audio_dsp_new(struct pw_core *core,
|
|||
const struct pw_properties *properties,
|
||||
enum pw_direction direction,
|
||||
uint32_t channels,
|
||||
uint64_t channelmask,
|
||||
uint32_t sample_rate,
|
||||
uint32_t max_buffer_size,
|
||||
size_t user_data_size);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue