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

@ -112,14 +112,12 @@ int main(int argc, char *argv[])
data.remote = pw_stream_get_remote(data.stream);
params[0] = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_F32,
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
":", SPA_FORMAT_AUDIO_channels, "i", DEFAULT_CHANNELS,
":", SPA_FORMAT_AUDIO_rate, "i", DEFAULT_RATE);
params[0] = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat,
&SPA_AUDIO_INFO_RAW_INIT(
.format = SPA_AUDIO_FORMAT_F32,
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
.channels = DEFAULT_CHANNELS,
.rate = DEFAULT_RATE ));
pw_stream_connect(data.stream,
PW_DIRECTION_OUTPUT,

View file

@ -205,31 +205,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,
const struct spa_pod *filter,
struct spa_pod **result,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
if (*index != 0 || d->format.format == 0)
return 0;
*result = spa_pod_builder_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_Format,
"I", SPA_MEDIA_TYPE_video,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_VIDEO_format, "I", d->format.format,
":", SPA_FORMAT_VIDEO_size, "R", &d->format.size,
":", SPA_FORMAT_VIDEO_framerate, "F", &d->format.framerate);
(*index)++;
return 1;
}
static int impl_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
@ -261,7 +236,10 @@ static int impl_port_enum_params(struct spa_node *node,
return port_enum_formats(node, direction, port_id, index, filter, result, builder);
case SPA_PARAM_Format:
return port_get_format(node, direction, port_id, index, filter, result, builder);
if (*index != 0 || d->format.format == 0)
return 0;
param = spa_format_video_raw_build(builder, id, &d->format);
break;
case SPA_PARAM_Buffers:
if (*index != 0)

View file

@ -200,35 +200,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,
const struct spa_pod *filter,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
if (*index != 0)
return 0;
if (d->format.format == 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", d->format.format,
":", SPA_FORMAT_AUDIO_layout, "I", d->format.layout,
":", SPA_FORMAT_AUDIO_channels, "i", d->format.channels,
":", SPA_FORMAT_AUDIO_rate, "i", d->format.rate);
(*index)++;
return 1;
}
static int impl_port_enum_params(struct spa_node *node,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t *index,
@ -236,6 +207,7 @@ static int impl_port_enum_params(struct spa_node *node,
struct spa_pod **result,
struct spa_pod_builder *builder)
{
struct data *d = SPA_CONTAINER_OF(node, struct data, impl_node);
struct spa_pod *param;
switch (id) {
@ -259,7 +231,12 @@ static int impl_port_enum_params(struct spa_node *node,
return port_enum_formats(node, direction, port_id, index, filter, result, builder);
case SPA_PARAM_Format:
return port_get_format(node, direction, port_id, index, filter, result, builder);
if (*index != 0)
return 0;
if (d->format.format == 0)
return 0;
param = spa_format_audio_raw_build(builder, id, &d->format);
break;
case SPA_PARAM_Buffers:
if (*index > 0)
@ -275,6 +252,7 @@ static int impl_port_enum_params(struct spa_node *node,
":", SPA_PARAM_BUFFERS_stride, "i", 0,
":", SPA_PARAM_BUFFERS_align, "i", 16);
break;
case SPA_PARAM_Meta:
switch (*index) {
case 0:

View file

@ -324,14 +324,8 @@ static int port_enum_formats(struct spa_node *node,
switch (*index) {
case 0:
if (this->have_format) {
*param = spa_pod_builder_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
"I", SPA_MEDIA_TYPE_audio,
"I", SPA_MEDIA_SUBTYPE_raw,
":", SPA_FORMAT_AUDIO_format, "I", this->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "I", this->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", this->format.info.raw.channels);
*param = spa_format_audio_raw_build(builder, SPA_PARAM_EnumFormat,
&this->format.info.raw);
} else {
*param = spa_pod_builder_object(builder,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
@ -350,32 +344,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", this->format.info.raw.format,
":", SPA_FORMAT_AUDIO_layout, "I", this->format.info.raw.layout,
":", SPA_FORMAT_AUDIO_rate, "i", this->format.info.raw.rate,
":", SPA_FORMAT_AUDIO_channels, "i", this->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,
@ -426,9 +394,14 @@ 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(builder, id, &this->format.info.raw);
break;
case SPA_PARAM_Buffers:
if (!port->have_format)
return -EIO;