format: make helper functions to create formats

Use helper functions to create a fully specified format.
This commit is contained in:
Wim Taymans 2018-08-29 15:53:26 +02:00
parent 80de83f38a
commit 514528f2c7
24 changed files with 158 additions and 430 deletions

View file

@ -335,32 +335,6 @@ static int port_enum_formats(struct spa_node *node,
return 1;
}
static int port_get_format(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t *index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
struct port *port = GET_PORT(this, direction, port_id);
if (!port->have_format)
return -EIO;
if (*index > 0)
return 0;
*param = spa_pod_builder_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_Format,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", port->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "I", port->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", port->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", port->format.info.raw.channels);
return 1;
}
static int
impl_node_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
@ -412,8 +386,12 @@ impl_node_port_enum_params(struct spa_node *node,
break;
case SPA_PARAM_Format:
if ((res = port_get_format(node, direction, port_id, index, &param, &b)) <= 0)
return res;
if (!port->have_format)
return -EIO;
if (*index > 0)
return 0;
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
break;
case SPA_PARAM_Buffers: