diff --git a/pinos/server/client-node.c b/pinos/server/client-node.c index 8e263bc09..ce780b419 100644 --- a/pinos/server/client-node.c +++ b/pinos/server/client-node.c @@ -28,6 +28,7 @@ #include #include + #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; } diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index 16f73cd15..60bcf1d4a 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -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); diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index 869fc8237..69613b33d 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -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); diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index a2c23b40c..4ca5427be 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -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);