param: add more generic port params

Remove port properties and replace them with port params. Move the
params from the PortInfo to enum_params.
Use the Param ranges to specify possible sizes etc.
This commit is contained in:
Wim Taymans 2017-05-22 13:06:18 +02:00
parent 12effccb06
commit d1a6d6e03f
37 changed files with 1044 additions and 755 deletions

View file

@ -28,6 +28,7 @@
#include <spa/log.h>
#include <spa/loop.h>
#include <spa/node.h>
#include <spa/param-alloc.h>
#include <spa/list.h>
#include <spa/format-builder.h>
#include <lib/props.h>
@ -42,8 +43,8 @@ typedef struct {
SpaTypeData data;
SpaTypeEventNode event_node;
SpaTypeCommandNode command_node;
SpaTypeAllocParamBuffers alloc_param_buffers;
SpaTypeAllocParamMetaEnable alloc_param_meta_enable;
SpaTypeParamAllocBuffers param_alloc_buffers;
SpaTypeParamAllocMetaEnable param_alloc_meta_enable;
} Type;
static inline void
@ -58,8 +59,8 @@ init_type (Type *type, SpaTypeMap *map)
spa_type_data_map (map, &type->data);
spa_type_event_node_map (map, &type->event_node);
spa_type_command_node_map (map, &type->command_node);
spa_type_alloc_param_buffers_map (map, &type->alloc_param_buffers);
spa_type_alloc_param_meta_enable_map (map, &type->alloc_param_meta_enable);
spa_type_param_alloc_buffers_map (map, &type->param_alloc_buffers);
spa_type_param_alloc_meta_enable_map (map, &type->param_alloc_meta_enable);
}
typedef struct _SpaFakeSink SpaFakeSink;
@ -100,7 +101,6 @@ struct _SpaFakeSink {
struct itimerspec timerspec;
SpaPortInfo info;
SpaAllocParam *params[2];
uint8_t params_buffer[1024];
SpaPortIO *io;
@ -467,33 +467,6 @@ spa_fakesink_node_port_set_format (SpaNode *node,
memcpy (this->format_buffer, format, SPA_POD_SIZE (format));
this->have_format = true;
}
if (this->have_format) {
SpaPODBuilder b = { NULL };
SpaPODFrame f[2];
this->info.latency = 0;
this->info.maxbuffering = -1;
this->info.n_params = 2;
this->info.params = this->params;
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, 128),
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 1),
PROP_U_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32),
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header),
PROP (&f[1], this->type.alloc_param_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader)));
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
this->info.extra = NULL;
}
return SPA_RESULT_OK;
}
@ -541,29 +514,63 @@ spa_fakesink_node_port_get_info (SpaNode *node,
}
static SpaResult
spa_fakesink_node_port_get_props (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaProps **props)
spa_fakesink_node_port_enum_params (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
uint32_t index,
SpaParam **param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
SpaFakeSink *this;
SpaPODBuilder b = { NULL };
SpaPODFrame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaFakeSink, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
switch (index) {
case 0:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_buffers.Buffers,
PROP (&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT, 128),
PROP (&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT, 1),
PROP_U_MM (&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32),
PROP (&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT, 16));
break;
case 1:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable,
PROP (&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header),
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader)));
break;
default:
return SPA_RESULT_NOT_IMPLEMENTED;
}
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam);
return SPA_RESULT_OK;
}
static SpaResult
spa_fakesink_node_port_set_props (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaProps *props)
spa_fakesink_node_port_set_param (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaParam *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_fakesink_node_port_use_buffers (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
SpaDirection direction,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
{
SpaFakeSink *this;
uint32_t i;
@ -604,7 +611,7 @@ static SpaResult
spa_fakesink_node_port_alloc_buffers (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaAllocParam **params,
SpaParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
@ -716,8 +723,8 @@ static const SpaNode fakesink_node = {
spa_fakesink_node_port_set_format,
spa_fakesink_node_port_get_format,
spa_fakesink_node_port_get_info,
spa_fakesink_node_port_get_props,
spa_fakesink_node_port_set_props,
spa_fakesink_node_port_enum_params,
spa_fakesink_node_port_set_param,
spa_fakesink_node_port_use_buffers,
spa_fakesink_node_port_alloc_buffers,
spa_fakesink_node_port_set_io,

View file

@ -28,6 +28,7 @@
#include <spa/log.h>
#include <spa/loop.h>
#include <spa/node.h>
#include <spa/param-alloc.h>
#include <spa/list.h>
#include <spa/format-builder.h>
#include <lib/props.h>
@ -43,8 +44,8 @@ typedef struct {
SpaTypeData data;
SpaTypeEventNode event_node;
SpaTypeCommandNode command_node;
SpaTypeAllocParamBuffers alloc_param_buffers;
SpaTypeAllocParamMetaEnable alloc_param_meta_enable;
SpaTypeParamAllocBuffers param_alloc_buffers;
SpaTypeParamAllocMetaEnable param_alloc_meta_enable;
} Type;
static inline void
@ -60,8 +61,8 @@ init_type (Type *type, SpaTypeMap *map)
spa_type_data_map (map, &type->data);
spa_type_event_node_map (map, &type->event_node);
spa_type_command_node_map (map, &type->command_node);
spa_type_alloc_param_buffers_map (map, &type->alloc_param_buffers);
spa_type_alloc_param_meta_enable_map (map, &type->alloc_param_meta_enable);
spa_type_param_alloc_buffers_map (map, &type->param_alloc_buffers);
spa_type_param_alloc_meta_enable_map (map, &type->param_alloc_meta_enable);
}
typedef struct _SpaFakeSrc SpaFakeSrc;
@ -103,7 +104,6 @@ struct _SpaFakeSrc {
struct itimerspec timerspec;
SpaPortInfo info;
SpaAllocParam *params[2];
uint8_t params_buffer[1024];
SpaPortIO *io;
@ -481,29 +481,6 @@ spa_fakesrc_node_port_set_format (SpaNode *node,
}
if (this->have_format) {
SpaPODBuilder b = { NULL };
SpaPODFrame f[2];
this->info.latency = 0;
this->info.maxbuffering = -1;
this->info.n_params = 2;
this->info.params = this->params;
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, 128),
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 1),
PROP_U_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32),
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header),
PROP (&f[1], this->type.alloc_param_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader)));
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
this->info.extra = NULL;
}
return SPA_RESULT_OK;
@ -553,19 +530,53 @@ spa_fakesrc_node_port_get_info (SpaNode *node,
}
static SpaResult
spa_fakesrc_node_port_get_props (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaProps **props)
spa_fakesrc_node_port_enum_params (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
uint32_t index,
SpaParam **param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
SpaFakeSrc *this;
SpaPODBuilder b = { NULL };
SpaPODFrame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaFakeSrc, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
switch (index) {
case 0:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_buffers.Buffers,
PROP (&f[1], this->type.param_alloc_buffers.size, SPA_POD_TYPE_INT, 128),
PROP (&f[1], this->type.param_alloc_buffers.stride, SPA_POD_TYPE_INT, 1),
PROP_U_MM (&f[1], this->type.param_alloc_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32),
PROP (&f[1], this->type.param_alloc_buffers.align, SPA_POD_TYPE_INT, 16));
break;
case 1:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable,
PROP (&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header),
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader)));
break;
default:
return SPA_RESULT_NOT_IMPLEMENTED;
}
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam);
return SPA_RESULT_OK;
}
static SpaResult
spa_fakesrc_node_port_set_props (SpaNode *node,
spa_fakesrc_node_port_set_param (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
const SpaProps *props)
const SpaParam *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
@ -618,7 +629,7 @@ static SpaResult
spa_fakesrc_node_port_alloc_buffers (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaAllocParam **params,
SpaParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
@ -749,8 +760,8 @@ static const SpaNode fakesrc_node = {
spa_fakesrc_node_port_set_format,
spa_fakesrc_node_port_get_format,
spa_fakesrc_node_port_get_info,
spa_fakesrc_node_port_get_props,
spa_fakesrc_node_port_set_props,
spa_fakesrc_node_port_enum_params,
spa_fakesrc_node_port_set_param,
spa_fakesrc_node_port_use_buffers,
spa_fakesrc_node_port_alloc_buffers,
spa_fakesrc_node_port_set_io,