mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
format: make helper functions to create formats
Use helper functions to create a fully specified format.
This commit is contained in:
parent
80de83f38a
commit
514528f2c7
24 changed files with 158 additions and 430 deletions
|
|
@ -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, ¶m, &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:
|
||||
|
|
|
|||
|
|
@ -465,32 +465,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,
|
||||
|
|
@ -543,8 +517,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, ¶m, &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:
|
||||
|
|
|
|||
|
|
@ -360,32 +360,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,
|
||||
|
|
@ -436,8 +410,12 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return res;
|
||||
break;
|
||||
case SPA_PARAM_Format:
|
||||
if ((res = port_get_format(node, direction, port_id, index, ¶m, &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:
|
||||
if (!port->have_format)
|
||||
|
|
|
|||
|
|
@ -309,32 +309,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,
|
||||
|
|
@ -385,8 +359,12 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return res;
|
||||
break;
|
||||
case SPA_PARAM_Format:
|
||||
if ((res = port_get_format(node, direction, port_id, index, ¶m, &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:
|
||||
{
|
||||
|
|
|
|||
|
|
@ -360,32 +360,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,
|
||||
|
|
@ -437,8 +411,12 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return res;
|
||||
break;
|
||||
case SPA_PARAM_Format:
|
||||
if ((res = port_get_format(node, direction, port_id, index, ¶m, &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:
|
||||
if (!port->have_format)
|
||||
|
|
|
|||
|
|
@ -353,31 +353,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_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,
|
||||
|
|
@ -427,8 +402,12 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
return res;
|
||||
break;
|
||||
case SPA_PARAM_Format:
|
||||
if ((res = port_get_format(node, direction, port_id, index, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &this->format.info.raw);
|
||||
break;
|
||||
case SPA_PARAM_Buffers:
|
||||
if (!port->have_format)
|
||||
|
|
|
|||
|
|
@ -534,6 +534,7 @@ port_enum_formats(struct impl *this,
|
|||
SPA_AUDIO_FORMAT_S32,
|
||||
SPA_AUDIO_FORMAT_F32,
|
||||
SPA_AUDIO_FORMAT_F64),
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "iru", 44100,
|
||||
SPA_POD_PROP_MIN_MAX(1, INT32_MAX),
|
||||
":", SPA_FORMAT_AUDIO_channels, "iru", 2,
|
||||
|
|
@ -545,30 +546,6 @@ port_enum_formats(struct impl *this,
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
port_get_format(struct impl *this,
|
||||
enum spa_direction direction,
|
||||
uint32_t port_id,
|
||||
uint32_t *index,
|
||||
struct spa_pod **param,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
if (!this->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->current_format.info.raw.format,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", this->current_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,
|
||||
|
|
@ -614,9 +591,14 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
if ((res = port_enum_formats(this, direction, port_id, index, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Format:
|
||||
if ((res = port_get_format(this, direction, port_id, index, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
|
|
|
|||
|
|
@ -984,14 +984,7 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, id,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", this->current_format.info.raw.format,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", this->current_format.info.raw.layout,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", this->current_format.info.raw.channels);
|
||||
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
|
|
|
|||
|
|
@ -482,31 +482,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 impl *this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
|
||||
if (!this->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_video,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_VIDEO_format, "I", this->current_format.info.raw.format,
|
||||
":", SPA_FORMAT_VIDEO_size, "R", &this->current_format.info.raw.size,
|
||||
":", SPA_FORMAT_VIDEO_framerate, "F", &this->current_format.info.raw.framerate);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_node_port_enum_params(struct spa_node *node,
|
||||
enum spa_direction direction, uint32_t port_id,
|
||||
|
|
@ -553,8 +528,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, filter, ¶m, &b)) <= 0)
|
||||
return res;
|
||||
if (!this->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_video_raw_build(builder, id, &this->current_format.info.raw);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
|
|
|
|||
|
|
@ -344,34 +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,
|
||||
const struct spa_pod *filter,
|
||||
struct spa_pod **param,
|
||||
struct spa_pod_builder *builder)
|
||||
{
|
||||
struct impl *this = SPA_CONTAINER_OF(node, struct impl, node);
|
||||
struct port *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->current_format.info.raw.format,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", this->current_format.info.raw.rate,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", this->current_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,
|
||||
|
|
@ -420,10 +392,16 @@ impl_node_port_enum_params(struct spa_node *node,
|
|||
if ((res = port_enum_formats(node, direction, port_id, index, 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)
|
||||
return res;
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (*index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &this->current_format.info.raw);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue