client-node: use dynamic pod builder

This commit is contained in:
Wim Taymans 2022-03-01 21:07:56 +01:00
parent 07a410e715
commit cdf1b15d38
2 changed files with 43 additions and 31 deletions

View file

@ -33,6 +33,7 @@
#include <spa/node/node.h> #include <spa/node/node.h>
#include <spa/node/utils.h> #include <spa/node/utils.h>
#include <spa/pod/filter.h> #include <spa/pod/filter.h>
#include <spa/pod/dynamic.h>
#include <spa/pod/parser.h> #include <spa/pod/parser.h>
#include <spa/debug/types.h> #include <spa/debug/types.h>
@ -293,7 +294,7 @@ static int impl_node_enum_params(void *object, int seq,
{ {
struct node *this = object; struct node *this = object;
uint8_t buffer[1024]; uint8_t buffer[1024];
struct spa_pod_builder b = { 0 }; struct spa_pod_dynamic_builder b;
struct spa_result_node_params result; struct spa_result_node_params result;
uint32_t count = 0; uint32_t count = 0;
bool found = false; bool found = false;
@ -321,14 +322,15 @@ static int impl_node_enum_params(void *object, int seq,
if (result.index < start) if (result.index < start)
continue; continue;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096);
if (spa_pod_filter(&b, &result.param, param, filter) != 0) if (spa_pod_filter(&b.b, &result.param, param, filter) == 0) {
continue; pw_log_debug("%p: %d param %u", this, seq, result.index);
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
count++;
}
spa_pod_dynamic_builder_clean(&b);
pw_log_debug("%p: %d param %u", this, seq, result.index); if (count == num)
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
if (++count == num)
break; break;
} }
return found ? 0 : -ENOENT; return found ? 0 : -ENOENT;
@ -563,7 +565,7 @@ impl_node_port_enum_params(void *object, int seq,
struct node *this = object; struct node *this = object;
struct port *port; struct port *port;
uint8_t buffer[1024]; uint8_t buffer[1024];
struct spa_pod_builder b = { 0 }; struct spa_pod_dynamic_builder b;
struct spa_result_node_params result; struct spa_result_node_params result;
uint32_t count = 0; uint32_t count = 0;
bool found = false; bool found = false;
@ -597,14 +599,15 @@ impl_node_port_enum_params(void *object, int seq,
if (result.index < start) if (result.index < start)
continue; continue;
spa_pod_builder_init(&b, buffer, sizeof(buffer)); spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096);
if (spa_pod_filter(&b, &result.param, param, filter) < 0) if (spa_pod_filter(&b.b, &result.param, param, filter) == 0) {
continue; pw_log_debug("%p: %d param %u", this, seq, result.index);
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
count++;
}
spa_pod_dynamic_builder_clean(&b);
pw_log_debug("%p: %d param %u", this, seq, result.index); if (count == num)
spa_node_emit_result(&this->hooks, seq, 0, SPA_RESULT_TYPE_NODE_PARAMS, &result);
if (++count == num)
break; break;
} }
return found ? 0 : -ENOENT; return found ? 0 : -ENOENT;

View file

@ -31,6 +31,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include <spa/pod/parser.h> #include <spa/pod/parser.h>
#include <spa/pod/dynamic.h>
#include <spa/node/utils.h> #include <spa/node/utils.h>
#include <spa/utils/result.h> #include <spa/utils/result.h>
#include <spa/debug/types.h> #include <spa/debug/types.h>
@ -301,7 +302,7 @@ static int add_node_update(struct node_data *data, uint32_t change_mask, uint32_
if (change_mask & PW_CLIENT_NODE_UPDATE_PARAMS) { if (change_mask & PW_CLIENT_NODE_UPDATE_PARAMS) {
uint32_t i, idx, id; uint32_t i, idx, id;
uint8_t buf[4096]; uint8_t buf[4096];
struct spa_pod_builder b = { 0 }; struct spa_pod_dynamic_builder b;
for (i = 0; i < node->info.n_params; i++) { for (i = 0; i < node->info.n_params; i++) {
struct spa_pod *param; struct spa_pod *param;
@ -311,14 +312,17 @@ static int add_node_update(struct node_data *data, uint32_t change_mask, uint32_
continue; continue;
for (idx = 0;;) { for (idx = 0;;) {
spa_pod_builder_init(&b, buf, sizeof(buf)); spa_pod_dynamic_builder_init(&b, buf, sizeof(buf), 4096);
if (spa_node_enum_params_sync(node->node,
id, &idx,
NULL, &param, &b) != 1)
break;
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1)); res = spa_node_enum_params_sync(node->node,
params[n_params++] = spa_pod_copy(param); id, &idx, NULL, &param, &b.b);
if (res == 1) {
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
params[n_params++] = spa_pod_copy(param);
}
spa_pod_dynamic_builder_clean(&b);
if (res != 1)
break;
} }
} }
} }
@ -356,7 +360,7 @@ static int add_port_update(struct node_data *data, struct pw_impl_port *port, ui
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) { if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
uint32_t i, idx, id; uint32_t i, idx, id;
uint8_t buf[4096]; uint8_t buf[4096];
struct spa_pod_builder b = { 0 }; struct spa_pod_dynamic_builder b;
for (i = 0; i < port->info.n_params; i++) { for (i = 0; i < port->info.n_params; i++) {
struct spa_pod *param; struct spa_pod *param;
@ -366,15 +370,20 @@ static int add_port_update(struct node_data *data, struct pw_impl_port *port, ui
continue; continue;
for (idx = 0;;) { for (idx = 0;;) {
spa_pod_builder_init(&b, buf, sizeof(buf)); spa_pod_dynamic_builder_init(&b, buf, sizeof(buf), 4096);
if (spa_node_port_enum_params_sync(port->node->node,
res = spa_node_port_enum_params_sync(port->node->node,
port->direction, port->port_id, port->direction, port->port_id,
id, &idx, id, &idx, NULL, &param, &b.b);
NULL, &param, &b) != 1) if (res == 1) {
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
params[n_params++] = spa_pod_copy(param);
}
spa_pod_dynamic_builder_clean(&b);
if (res != 1)
break; break;
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
params[n_params++] = spa_pod_copy(param);
} }
} }
} }