improve format filters

This commit is contained in:
Wim Taymans 2017-04-04 20:25:02 +02:00
parent 4bdbb58276
commit 22070ecbf8
4 changed files with 34 additions and 8 deletions

View file

@ -28,6 +28,7 @@
#include <sys/mman.h>
#include <sys/eventfd.h>
#include "pinos/client/pinos.h"
#include "pinos/client/interfaces.h"
#include "pinos/client/transport.h"
@ -36,6 +37,7 @@
#include "pinos/server/client-node.h"
#include "spa/include/spa/node.h"
#include "spa/include/spa/format-builder.h"
#define MAX_INPUTS 64
#define MAX_OUTPUTS 64
@ -107,6 +109,7 @@ struct _SpaProxy
SpaProxyPort in_ports[MAX_INPUTS];
SpaProxyPort out_ports[MAX_OUTPUTS];
uint8_t format_buffer[1024];
uint32_t seq;
};
@ -446,6 +449,10 @@ spa_proxy_node_port_enum_formats (SpaNode *node,
{
SpaProxy *this;
SpaProxyPort *port;
SpaFormat *fmt;
SpaPODBuilder b = { NULL, };
SpaResult res;
uint32_t count, match = 0;
if (node == NULL || format == NULL)
return SPA_RESULT_INVALID_ARGUMENTS;
@ -457,10 +464,20 @@ spa_proxy_node_port_enum_formats (SpaNode *node,
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
if (index >= port->n_formats)
count = match = filter ? 0 : index;
next:
if (count >= port->n_formats)
return SPA_RESULT_ENUM_END;
*format = port->formats[index];
fmt = port->formats[count++];
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, SpaFormat);
return SPA_RESULT_OK;
}

View file

@ -480,6 +480,7 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
uint8_t buffer[256];
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
uint32_t count, match;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
@ -488,10 +489,12 @@ spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
count = match = filter ? 0 : index;
next:
spa_pod_builder_init (&b, buffer, sizeof (buffer));
switch (index++) {
switch (count++) {
case 0:
spa_pod_builder_format (&b, &f[0], this->type.format,
this->type.media_type.audio, this->type.media_subtype.raw,
@ -510,7 +513,7 @@ next:
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK)
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, SpaFormat);

View file

@ -465,6 +465,7 @@ spa_videotestsrc_node_port_enum_formats (SpaNode *node,
uint8_t buffer[1024];
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
uint32_t count, match;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
@ -473,10 +474,12 @@ spa_videotestsrc_node_port_enum_formats (SpaNode *node,
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
count = match = filter ? 0 : index;
next:
spa_pod_builder_init (&b, buffer, sizeof (buffer));
switch (index++) {
switch (count++) {
case 0:
spa_pod_builder_format (&b, &f[0], this->type.format,
this->type.media_type.video, this->type.media_subtype.raw,
@ -500,7 +503,7 @@ next:
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK)
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, SpaFormat);

View file

@ -300,6 +300,7 @@ spa_volume_node_port_enum_formats (SpaNode *node,
uint8_t buffer[1024];
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
uint32_t count, match;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
@ -308,10 +309,12 @@ spa_volume_node_port_enum_formats (SpaNode *node,
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
count = match = filter ? 0 : index;
next:
spa_pod_builder_init (&b, buffer, sizeof (buffer));
switch (index++) {
switch (count++) {
case 0:
spa_pod_builder_format (&b, &f[0], this->type.format,
this->type.media_type.audio, this->type.media_subtype.raw,
@ -329,7 +332,7 @@ next:
fmt = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat);
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK)
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, SpaFormat);