alloc-params: use dynamic types for alloc-params

This commit is contained in:
Wim Taymans 2017-03-23 10:12:20 +01:00
parent 7270986c3a
commit 048a4b81a8
21 changed files with 166 additions and 271 deletions

View file

@ -27,7 +27,7 @@ extern "C" {
#include <spa/defs.h>
#include <spa/props.h>
#include <spa/format.h>
#include <spa/port.h>
#include <spa/alloc-param.h>
#include <spa/node.h>
typedef struct _PinosClientNodeBuffer PinosClientNodeBuffer;

View file

@ -30,7 +30,6 @@ typedef struct _PinosTransportArea PinosTransportArea;
#include <string.h>
#include <spa/defs.h>
#include <spa/port.h>
#include <spa/node.h>
#include <pinos/client/mem.h>

View file

@ -52,4 +52,7 @@ pinos_uri_init (PinosURI *uri)
spa_node_events_map (uri->map, &uri->node_events);
spa_node_commands_map (uri->map, &uri->node_commands);
spa_monitor_types_map (uri->map, &uri->monitor_types);
spa_alloc_param_buffers_map (uri->map, &uri->alloc_param_buffers);
spa_alloc_param_meta_enable_map (uri->map, &uri->alloc_param_meta_enable);
spa_alloc_param_video_padding_map (uri->map, &uri->alloc_param_video_padding);
}

View file

@ -58,6 +58,9 @@ struct _PinosURI {
SpaNodeEvents node_events;
SpaNodeCommands node_commands;
SpaMonitorTypes monitor_types;
SpaAllocParamBuffers alloc_param_buffers;
SpaAllocParamMetaEnable alloc_param_meta_enable;
SpaAllocParamVideoPadding alloc_param_video_padding;
};
void pinos_uri_init (PinosURI *uri);

View file

@ -128,29 +128,31 @@ do_start (GstBufferPool * pool)
SpaPODBuilder b = { NULL };
uint8_t buffer[1024];
SpaPODFrame f[2];
PinosContext *ctx = p->stream->context;
config = gst_buffer_pool_get_config (pool);
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, &max_buffers);
spa_pod_builder_init (&b, buffer, sizeof (buffer));
spa_pod_builder_object (&b, &f[0], 0, SPA_ALLOC_PARAM_TYPE_BUFFERS,
PROP (&f[1], SPA_ALLOC_PARAM_BUFFERS_SIZE, SPA_POD_TYPE_INT, size),
PROP (&f[1], SPA_ALLOC_PARAM_BUFFERS_STRIDE, SPA_POD_TYPE_INT, 0),
PROP_MM (&f[1], SPA_ALLOC_PARAM_BUFFERS_BUFFERS, SPA_POD_TYPE_INT, min_buffers, min_buffers, max_buffers),
PROP (&f[1], SPA_ALLOC_PARAM_BUFFERS_ALIGN, SPA_POD_TYPE_INT, 16));
spa_pod_builder_object (&b, &f[0], 0, ctx->uri.alloc_param_buffers.Buffers,
PROP (&f[1], ctx->uri.alloc_param_buffers.size, SPA_POD_TYPE_INT, size),
PROP (&f[1], ctx->uri.alloc_param_buffers.stride, SPA_POD_TYPE_INT, 0),
PROP_MM (&f[1], ctx->uri.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, min_buffers, min_buffers, max_buffers),
PROP (&f[1], ctx->uri.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
port_params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
spa_pod_builder_object (&b, &f[0], 0, SPA_ALLOC_PARAM_TYPE_META_ENABLE,
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
spa_pod_builder_object (&b, &f[0], 0, ctx->uri.alloc_param_meta_enable.MetaEnable,
PROP (&f[1], ctx->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
port_params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
spa_pod_builder_object (&b, &f[0], 0, SPA_ALLOC_PARAM_TYPE_META_ENABLE,
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, SPA_META_TYPE_RINGBUFFER),
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_RB_SIZE, SPA_POD_TYPE_INT,
size * SPA_MAX (4, SPA_MAX (min_buffers, max_buffers))),
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_RB_STRIDE, SPA_POD_TYPE_INT, 0),
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_RB_BLOCKS, SPA_POD_TYPE_INT, 1),
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_RB_ALIGN, SPA_POD_TYPE_INT, 16));
spa_pod_builder_object (&b, &f[0], 0, ctx->uri.alloc_param_meta_enable.MetaEnable,
PROP (&f[1], ctx->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_RINGBUFFER),
PROP (&f[1], ctx->uri.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT,
size * SPA_MAX (4,
SPA_MAX (min_buffers, max_buffers))),
PROP (&f[1], ctx->uri.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, 0),
PROP (&f[1], ctx->uri.alloc_param_meta_enable.ringbufferBlocks, SPA_POD_TYPE_INT, 1),
PROP (&f[1], ctx->uri.alloc_param_meta_enable.ringbufferAlign, SPA_POD_TYPE_INT, 16));
port_params[2] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
pinos_stream_finish_format (p->stream, SPA_RESULT_OK, port_params, 2);

View file

@ -775,6 +775,7 @@ on_format_changed (PinosListener *listener,
GstPinosSrc *pinossrc = SPA_CONTAINER_OF (listener, GstPinosSrc, stream_format_changed);
GstCaps *caps;
gboolean res;
PinosContext *ctx = stream->context;
caps = gst_caps_from_format (format);
GST_DEBUG_OBJECT (pinossrc, "we got format %" GST_PTR_FORMAT, caps);
@ -788,8 +789,8 @@ on_format_changed (PinosListener *listener,
SpaPODFrame f[2];
spa_pod_builder_init (&b, buffer, sizeof (buffer));
spa_pod_builder_object (&b, &f[0], 0, SPA_ALLOC_PARAM_TYPE_META_ENABLE,
PROP (&f[1], SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
spa_pod_builder_object (&b, &f[0], 0, ctx->uri.alloc_param_meta_enable.MetaEnable,
PROP (&f[1], ctx->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, SPA_META_TYPE_HEADER));
params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
GST_DEBUG_OBJECT (pinossrc, "doing finish format");

View file

@ -141,7 +141,7 @@ error:
}
static void *
find_param (const SpaPortInfo *info, SpaAllocParamType type)
find_param (const SpaPortInfo *info, uint32_t type)
{
uint32_t i;
@ -153,16 +153,16 @@ find_param (const SpaPortInfo *info, SpaAllocParamType type)
}
static void *
find_meta_enable (const SpaPortInfo *info, SpaMetaType type)
find_meta_enable (PinosCore *core, const SpaPortInfo *info, SpaMetaType type)
{
uint32_t i;
for (i = 0; i < info->n_params; i++) {
if (spa_pod_is_object_type (&info->params[i]->pod, SPA_ALLOC_PARAM_TYPE_META_ENABLE)) {
if (spa_pod_is_object_type (&info->params[i]->pod, core->uri.alloc_param_meta_enable.MetaEnable)) {
uint32_t qtype;
if (spa_alloc_param_query (info->params[i],
SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, &qtype, 0) != 1)
core->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, &qtype, 0) != 1)
continue;
if (qtype == type)
@ -208,11 +208,11 @@ alloc_buffers (PinosLink *this,
for (i = 0; i < n_params; i++) {
SpaAllocParam *ap = params[i];
if (ap->pod.type == SPA_ALLOC_PARAM_TYPE_META_ENABLE) {
if (ap->pod.type == this->core->uri.alloc_param_meta_enable.MetaEnable) {
uint32_t type;
if (spa_alloc_param_query (ap,
SPA_ALLOC_PARAM_META_ENABLE_TYPE, SPA_POD_TYPE_INT, &type,
this->core->uri.alloc_param_meta_enable.type, SPA_POD_TYPE_INT, &type,
0) != 1)
continue;
@ -397,50 +397,50 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
uint32_t max_buffers;
size_t minsize = 1024, stride = 0;
in_me = find_meta_enable (iinfo, SPA_META_TYPE_RINGBUFFER);
out_me = find_meta_enable (oinfo, SPA_META_TYPE_RINGBUFFER);
in_me = find_meta_enable (this->core, iinfo, SPA_META_TYPE_RINGBUFFER);
out_me = find_meta_enable (this->core, oinfo, SPA_META_TYPE_RINGBUFFER);
if (in_me && out_me) {
uint32_t ms1, ms2, s1, s2;
max_buffers = 1;
if (spa_alloc_param_query (in_me,
SPA_ALLOC_PARAM_META_ENABLE_RB_SIZE, SPA_POD_TYPE_INT, &ms1,
SPA_ALLOC_PARAM_META_ENABLE_RB_STRIDE, SPA_POD_TYPE_INT, &s1, 0) == 2 &&
this->core->uri.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT, &ms1,
this->core->uri.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, &s1, 0) == 2 &&
spa_alloc_param_query (in_me,
SPA_ALLOC_PARAM_META_ENABLE_RB_SIZE, SPA_POD_TYPE_INT, &ms2,
SPA_ALLOC_PARAM_META_ENABLE_RB_STRIDE, SPA_POD_TYPE_INT, &s2, 0) == 2) {
this->core->uri.alloc_param_meta_enable.ringbufferSize, SPA_POD_TYPE_INT, &ms2,
this->core->uri.alloc_param_meta_enable.ringbufferStride, SPA_POD_TYPE_INT, &s2, 0) == 2) {
minsize = SPA_MAX (ms1, ms2);
stride = SPA_MAX (s1, s2);
}
} else {
max_buffers = MAX_BUFFERS;
minsize = stride = 0;
in_alloc = find_param (iinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
in_alloc = find_param (iinfo, this->core->uri.alloc_param_buffers.Buffers);
if (in_alloc) {
uint32_t qmax_buffers = max_buffers,
qminsize = minsize,
qstride = stride;
spa_alloc_param_query (in_alloc,
SPA_ALLOC_PARAM_BUFFERS_SIZE, SPA_POD_TYPE_INT, &qminsize,
SPA_ALLOC_PARAM_BUFFERS_STRIDE, SPA_POD_TYPE_INT, &qstride,
SPA_ALLOC_PARAM_BUFFERS_BUFFERS, SPA_POD_TYPE_INT, &qmax_buffers,
this->core->uri.alloc_param_buffers.size, SPA_POD_TYPE_INT, &qminsize,
this->core->uri.alloc_param_buffers.stride, SPA_POD_TYPE_INT, &qstride,
this->core->uri.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, &qmax_buffers,
0);
max_buffers = qmax_buffers == 0 ? max_buffers : SPA_MIN (qmax_buffers, max_buffers);
minsize = SPA_MAX (minsize, qminsize);
stride = SPA_MAX (stride, qstride);
}
out_alloc = find_param (oinfo, SPA_ALLOC_PARAM_TYPE_BUFFERS);
out_alloc = find_param (oinfo, this->core->uri.alloc_param_buffers.Buffers);
if (out_alloc) {
uint32_t qmax_buffers = max_buffers,
qminsize = minsize,
qstride = stride;
spa_alloc_param_query (out_alloc,
SPA_ALLOC_PARAM_BUFFERS_SIZE, SPA_POD_TYPE_INT, &qminsize,
SPA_ALLOC_PARAM_BUFFERS_STRIDE, SPA_POD_TYPE_INT, &qstride,
SPA_ALLOC_PARAM_BUFFERS_BUFFERS, SPA_POD_TYPE_INT, &qmax_buffers,
this->core->uri.alloc_param_buffers.size, SPA_POD_TYPE_INT, &qminsize,
this->core->uri.alloc_param_buffers.stride, SPA_POD_TYPE_INT, &qstride,
this->core->uri.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, &qmax_buffers,
0);
max_buffers = qmax_buffers == 0 ? max_buffers : SPA_MIN (qmax_buffers, max_buffers);