diff options
Diffstat (limited to 'spa/plugins/test/fakesrc.c')
-rw-r--r-- | spa/plugins/test/fakesrc.c | 100 |
1 files changed, 62 insertions, 38 deletions
diff --git a/spa/plugins/test/fakesrc.c b/spa/plugins/test/fakesrc.c index 9f73e160..30783ed5 100644 --- a/spa/plugins/test/fakesrc.c +++ b/spa/plugins/test/fakesrc.c @@ -102,28 +102,32 @@ static void reset_props(struct impl *this, struct props *props) } static int impl_node_enum_params(struct spa_node *node, - uint32_t id, uint32_t *index, - const struct spa_pod *filter, - struct spa_pod **result, - struct spa_pod_builder *builder) + uint32_t id, uint32_t start, uint32_t num, + const struct spa_pod *filter, + spa_result_func_t func, void *data) { struct impl *this; struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; + struct spa_result_node_enum_params result; + uint32_t count = 0; + int res; spa_return_val_if_fail(node != NULL, -EINVAL); - spa_return_val_if_fail(index != NULL, -EINVAL); - spa_return_val_if_fail(builder != 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); + result.next = start; + next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); switch (id) { case SPA_PARAM_List: - if (*index > 0) + if (result.next > 0) return 0; param = spa_pod_builder_add_object(&b, @@ -135,7 +139,7 @@ static int impl_node_enum_params(struct spa_node *node, { struct props *p = &this->props; - if (*index > 0) + if (result.next > 0) return 0; param = spa_pod_builder_add_object(&b, @@ -148,12 +152,18 @@ static int impl_node_enum_params(struct spa_node *node, return -ENOENT; } - (*index)++; + result.next++; - if (spa_pod_filter(builder, result, param, filter) < 0) + if (spa_pod_filter(&b, &result.param, param, filter) < 0) goto next; - return 1; + if ((res = func(data, count, 1, &result)) != 0) + return res; + + if (++count != num) + goto next; + + return 0; } static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size) @@ -384,7 +394,7 @@ impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint3 static int port_enum_formats(struct spa_node *node, enum spa_direction direction, uint32_t port_id, - uint32_t *index, + uint32_t index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder) @@ -394,7 +404,7 @@ static int port_enum_formats(struct spa_node *node, static int port_get_format(struct spa_node *node, enum spa_direction direction, uint32_t port_id, - uint32_t *index, + uint32_t index, const struct spa_pod *filter, struct spa_pod **param, struct spa_pod_builder *builder) @@ -403,7 +413,7 @@ static int port_get_format(struct spa_node *node, if (!this->have_format) return -EIO; - if (*index > 0) + if (index > 0) return 0; *param = SPA_MEMBER(this->format_buffer, 0, struct spa_pod); @@ -413,23 +423,26 @@ static int port_get_format(struct spa_node *node, static int impl_node_port_enum_params(struct spa_node *node, - enum spa_direction direction, uint32_t port_id, - uint32_t id, uint32_t *index, - const struct spa_pod *filter, - struct spa_pod **result, - struct spa_pod_builder *builder) + 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) { struct spa_pod_builder b = { 0 }; uint8_t buffer[1024]; struct spa_pod *param; + struct spa_result_node_enum_params result; + uint32_t count = 0; int res; spa_return_val_if_fail(node != NULL, -EINVAL); - spa_return_val_if_fail(index != NULL, -EINVAL); - spa_return_val_if_fail(builder != NULL, -EINVAL); + spa_return_val_if_fail(num != 0, -EINVAL); + spa_return_val_if_fail(func != NULL, -EINVAL); spa_return_val_if_fail(CHECK_PORT(node, direction, port_id), -EINVAL); + result.next = start; + next: spa_pod_builder_init(&b, buffer, sizeof(buffer)); @@ -441,36 +454,41 @@ impl_node_port_enum_params(struct spa_node *node, SPA_PARAM_Buffers, SPA_PARAM_Meta }; - if (*index < SPA_N_ELEMENTS(list)) + if (result.next < SPA_N_ELEMENTS(list)) param = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamList, id, - SPA_PARAM_LIST_id, SPA_POD_Id(list[*index])); + SPA_PARAM_LIST_id, SPA_POD_Id(list[result.next])); else return 0; break; } case SPA_PARAM_EnumFormat: - if ((res = port_enum_formats(node, direction, port_id, index, filter, ¶m, &b)) <= 0) + if ((res = port_enum_formats(node, direction, port_id, + result.next, filter, ¶m, &b)) <= 0) return res; break; case SPA_PARAM_Format: - if ((res = port_get_format(node, direction, port_id, index, filter, ¶m, &b)) <= 0) + if ((res = port_get_format(node, direction, port_id, + result.next, filter, ¶m, &b)) <= 0) return res; break; case SPA_PARAM_Buffers: - if (*index > 0) + switch (result.next) { + case 0: + param = spa_pod_builder_add_object(&b, + SPA_TYPE_OBJECT_ParamBuffers, id, + SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(32, 2, 32), + SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), + SPA_PARAM_BUFFERS_size, SPA_POD_Int(128), + SPA_PARAM_BUFFERS_stride, SPA_POD_Int(1), + SPA_PARAM_BUFFERS_align, SPA_POD_Int(16)); + break; + default: return 0; - - param = spa_pod_builder_add_object(&b, - SPA_TYPE_OBJECT_ParamBuffers, id, - SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(32, 2, 32), - SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), - SPA_PARAM_BUFFERS_size, SPA_POD_Int(128), - SPA_PARAM_BUFFERS_stride, SPA_POD_Int(1), - SPA_PARAM_BUFFERS_align, SPA_POD_Int(16)); + } break; case SPA_PARAM_Meta: - switch (*index) { + switch (result.next) { case 0: param = spa_pod_builder_add_object(&b, SPA_TYPE_OBJECT_ParamMeta, id, @@ -485,12 +503,18 @@ impl_node_port_enum_params(struct spa_node *node, return -ENOENT; } - (*index)++; + result.next++; - if (spa_pod_filter(builder, result, param, filter) < 0) + if (spa_pod_filter(&b, &result.param, param, filter) < 0) goto next; - return 1; + if ((res = func(data, count, 1, &result)) != 0) + return res; + + if (++count != num) + goto next; + + return 0; } static int clear_buffers(struct impl *this) |