Improve channel positions

Sort the channel positions as the suggested format
Use the session node channel positions as the target profile
This commit is contained in:
Wim Taymans 2018-10-09 20:11:01 +02:00
parent 1edf2dd210
commit 805240258b
2 changed files with 14 additions and 10 deletions

View file

@ -305,6 +305,11 @@ impl_node_port_get_info(struct spa_node *node,
return 0; return 0;
} }
static int int32_cmp(const void *v1, const void *v2)
{
return *(int32_t*)v1 - *(int32_t*)v2;
}
static int port_enum_formats(struct spa_node *node, static int port_enum_formats(struct spa_node *node,
enum spa_direction direction, uint32_t port_id, enum spa_direction direction, uint32_t port_id,
uint32_t *index, uint32_t *index,
@ -320,6 +325,12 @@ static int port_enum_formats(struct spa_node *node,
switch (*index) { switch (*index) {
case 0: case 0:
if (other->info.raw.channels > 0) { if (other->info.raw.channels > 0) {
struct spa_audio_info info;
info = *other;
qsort(info.info.raw.position, info.info.raw.channels, sizeof(uint32_t), int32_cmp);
spa_pod_builder_push_object(builder, spa_pod_builder_push_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat); SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat);
spa_pod_builder_props(builder, spa_pod_builder_props(builder,
@ -335,7 +346,7 @@ static int port_enum_formats(struct spa_node *node,
0); 0);
spa_pod_builder_prop(builder, SPA_FORMAT_AUDIO_position, 0); spa_pod_builder_prop(builder, SPA_FORMAT_AUDIO_position, 0);
spa_pod_builder_array(builder, sizeof(uint32_t), SPA_TYPE_Id, spa_pod_builder_array(builder, sizeof(uint32_t), SPA_TYPE_Id,
other->info.raw.channels, other->info.raw.position); info.info.raw.channels, info.info.raw.position);
*param = spa_pod_builder_pop(builder); *param = spa_pod_builder_pop(builder);
} else { } else {
*param = spa_pod_builder_object(builder, *param = spa_pod_builder_object(builder,
@ -536,11 +547,6 @@ static int clear_buffers(struct impl *this, struct port *port)
} }
return 0; return 0;
} }
static int int32_cmp(const void *v1, const void *v2)
{
return *(int32_t*)v1 - *(int32_t*)v2;
}
static int port_set_format(struct spa_node *node, static int port_set_format(struct spa_node *node,
enum spa_direction direction, enum spa_direction direction,
uint32_t port_id, uint32_t port_id,
@ -581,8 +587,6 @@ static int port_set_format(struct spa_node *node,
return -ENOTSUP; return -ENOTSUP;
} }
qsort(info.info.raw.position, info.info.raw.channels, sizeof(uint32_t), int32_cmp);
port->stride = calc_width(&info); port->stride = calc_width(&info);
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) { if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {

View file

@ -913,10 +913,10 @@ static int rescan_node(struct impl *impl, struct node *node)
spa_list_append(&session->node_list, &node->session_link); spa_list_append(&session->node_list, &node->session_link);
if (!exclusive) { if (!exclusive) {
audio_info = node->format; audio_info = session->node->format;
audio_info.format = SPA_AUDIO_FORMAT_F32P; audio_info.format = SPA_AUDIO_FORMAT_F32P;
audio_info.rate = session->node->format.rate; audio_info.rate = session->node->format.rate;
audio_info.channels = SPA_MIN(session->node->format.channels, audio_info.channels); audio_info.channels = SPA_MIN(session->node->format.channels, node->format.channels);
spa_pod_builder_init(&b, buf, sizeof(buf)); spa_pod_builder_init(&b, buf, sizeof(buf));
param = spa_pod_builder_object(&b, param = spa_pod_builder_object(&b,