mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
Improve async handling
Don't use special callback in node to receive the results. Instead, use a generic result callback to receive the result. This makes things a bit more symetric and generic again because then you can choose how to match the result to the request and you have a generic way to handle both the sync and async case. We can then also remove the wait method. This also makes the remote interface and spa interface to objects very similar. Make a helper object to receive and dispatch results. Use this in the helper for enum_params. Make device use the same result callbacks.
This commit is contained in:
parent
98463b689b
commit
d2c18c7b1a
64 changed files with 1298 additions and 1141 deletions
|
|
@ -110,28 +110,29 @@ struct impl {
|
|||
|
||||
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_PORTS)
|
||||
|
||||
static int impl_node_enum_params(struct spa_node *node,
|
||||
static int impl_node_enum_params(struct spa_node *node, int seq,
|
||||
uint32_t id, uint32_t start, uint32_t num,
|
||||
const struct spa_pod *filter,
|
||||
spa_result_func_t func, void *data)
|
||||
const struct spa_pod *filter)
|
||||
{
|
||||
struct impl *this;
|
||||
struct spa_pod *param;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
struct spa_result_node_enum_params result;
|
||||
struct spa_result_node_params result;
|
||||
uint32_t count = 0;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
spa_return_val_if_fail(func != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
|
||||
result.id = id;
|
||||
result.next = start;
|
||||
|
||||
next:
|
||||
result.index = result.next++;
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
switch (id) {
|
||||
|
|
@ -140,10 +141,10 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
uint32_t list[] = { SPA_PARAM_PropInfo,
|
||||
SPA_PARAM_Props };
|
||||
|
||||
if (result.next < SPA_N_ELEMENTS(list))
|
||||
if (result.index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_add_object(&b,
|
||||
SPA_TYPE_OBJECT_ParamList, id,
|
||||
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
|
||||
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.index]));
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
|
|
@ -153,7 +154,7 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
struct props *p = &this->props;
|
||||
struct spa_pod_frame f[2];
|
||||
|
||||
switch (result.next) {
|
||||
switch (result.index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_add_object(&b,
|
||||
SPA_TYPE_OBJECT_PropInfo, id,
|
||||
|
|
@ -186,7 +187,7 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
{
|
||||
struct props *p = &this->props;
|
||||
|
||||
switch (result.next) {
|
||||
switch (result.index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_add_object(&b,
|
||||
SPA_TYPE_OBJECT_Props, id,
|
||||
|
|
@ -202,12 +203,10 @@ static int impl_node_enum_params(struct spa_node *node,
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
result.next++;
|
||||
|
||||
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
if ((res = func(data, count, &result)) != 0)
|
||||
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
|
||||
return res;
|
||||
|
||||
if (++count != num)
|
||||
|
|
@ -490,31 +489,32 @@ static int port_enum_formats(struct spa_node *node,
|
|||
}
|
||||
|
||||
static int
|
||||
impl_node_port_enum_params(struct spa_node *node,
|
||||
impl_node_port_enum_params(struct spa_node *node, int seq,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t id, uint32_t start, uint32_t num,
|
||||
const struct spa_pod *filter,
|
||||
spa_result_func_t func, void *data)
|
||||
const struct spa_pod *filter)
|
||||
{
|
||||
struct impl *this;
|
||||
struct spa_pod_builder b = { 0 };
|
||||
uint8_t buffer[1024];
|
||||
struct spa_pod *param;
|
||||
struct spa_result_node_enum_params result;
|
||||
struct spa_result_node_params result;
|
||||
uint32_t count = 0;
|
||||
int res;
|
||||
|
||||
spa_return_val_if_fail(node != NULL, -EINVAL);
|
||||
spa_return_val_if_fail(num != 0, -EINVAL);
|
||||
spa_return_val_if_fail(func != NULL, -EINVAL);
|
||||
|
||||
this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
spa_return_val_if_fail(this->callbacks && this->callbacks->result, -EIO);
|
||||
|
||||
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
||||
|
||||
result.id = id;
|
||||
result.next = start;
|
||||
|
||||
next:
|
||||
result.index = result.next++;
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
switch (id) {
|
||||
|
|
@ -525,24 +525,24 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
SPA_PARAM_Buffers,
|
||||
SPA_PARAM_Meta };
|
||||
|
||||
if (result.next < SPA_N_ELEMENTS(list))
|
||||
if (result.index < SPA_N_ELEMENTS(list))
|
||||
param = spa_pod_builder_add_object(&b,
|
||||
SPA_TYPE_OBJECT_ParamList, id,
|
||||
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next]));
|
||||
SPA_PARAM_LIST_id, SPA_POD_Id(list[result.index]));
|
||||
else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
case SPA_PARAM_EnumFormat:
|
||||
if ((res = port_enum_formats(node, direction, port_id,
|
||||
result.next, filter, ¶m, &b)) <= 0)
|
||||
result.index, filter, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Format:
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (result.next > 0)
|
||||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_video_raw_build(&b, id, &this->current_format.info.raw);
|
||||
|
|
@ -554,7 +554,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (result.next > 0)
|
||||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_pod_builder_add_object(&b,
|
||||
|
|
@ -570,7 +570,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
if (!this->have_format)
|
||||
return -EIO;
|
||||
|
||||
switch (result.next) {
|
||||
switch (result.index) {
|
||||
case 0:
|
||||
param = spa_pod_builder_add_object(&b,
|
||||
SPA_TYPE_OBJECT_ParamMeta, id,
|
||||
|
|
@ -586,12 +586,10 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
result.next++;
|
||||
|
||||
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
||||
goto next;
|
||||
|
||||
if ((res = func(data, count, &result)) != 0)
|
||||
if ((res = this->callbacks->result(this->callbacks_data, seq, 0, &result)) != 0)
|
||||
return res;
|
||||
|
||||
if (++count != num)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue