mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -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
|
|
@ -144,6 +144,8 @@ struct spa_audio_info_raw {
|
|||
uint32_t channel_mask; /*< channel mask */
|
||||
};
|
||||
|
||||
#define SPA_AUDIO_INFO_RAW_INIT(...) (struct spa_audio_info_raw) { __VA_ARGS__ }
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include <spa/pod/parser.h>
|
||||
#include <spa/pod/builder.h>
|
||||
#include <spa/param/video/format.h>
|
||||
#include <spa/param/format-utils.h>
|
||||
|
||||
|
|
@ -49,6 +50,19 @@ spa_format_video_raw_parse(const struct spa_pod *format,
|
|||
":", SPA_FORMAT_VIDEO_colorPrimaries, "?i", &info->color_primaries, NULL);
|
||||
}
|
||||
|
||||
static inline struct spa_pod *
|
||||
spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id,
|
||||
struct spa_video_info_raw *info)
|
||||
{
|
||||
return spa_pod_builder_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, id,
|
||||
"I", SPA_MEDIA_TYPE_video,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_VIDEO_format, "I", &info->format,
|
||||
":", SPA_FORMAT_VIDEO_size, "R", &info->size,
|
||||
":", SPA_FORMAT_VIDEO_framerate, "F", &info->framerate);
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_format_video_h264_parse(const struct spa_pod *format,
|
||||
struct spa_video_info_h264 *info)
|
||||
|
|
|
|||
|
|
@ -191,6 +191,8 @@ struct spa_video_info_raw {
|
|||
enum spa_video_color_primaries color_primaries;
|
||||
};
|
||||
|
||||
#define SPA_VIDEO_INFO_RAW_INIT(...) (struct spa_video_info_raw) { __VA_ARGS__ }
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -379,14 +379,12 @@ static int negotiate_formats(struct data *data)
|
|||
uint8_t buffer[4096];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
filter = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
filter = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
spa_debug_pod(0, spa_debug_types, filter);
|
||||
|
||||
|
|
|
|||
|
|
@ -206,14 +206,13 @@ static int negotiate_formats(struct data *data)
|
|||
uint8_t buffer[4096];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
format = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
|
||||
format = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
if ((res = spa_node_port_set_param(data->conv,
|
||||
SPA_DIRECTION_INPUT, 0,
|
||||
|
|
@ -235,15 +234,12 @@ static int negotiate_formats(struct data *data)
|
|||
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
format = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"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_NON_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
|
||||
format = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32,
|
||||
.layout = SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
if ((res = spa_node_port_set_param(data->conv,
|
||||
SPA_DIRECTION_OUTPUT, 0,
|
||||
|
|
|
|||
|
|
@ -257,27 +257,23 @@ static int negotiate_formats(struct data *data)
|
|||
uint8_t buffer[4096];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
format = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
format = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
if ((res = negotiate_link_format(data, &data->links[0], format)) < 0)
|
||||
return res;
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
format = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"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_NON_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 48000,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 1);
|
||||
format = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_NON_INTERLEAVED,
|
||||
.rate = 48000,
|
||||
.channels = 1 ));
|
||||
|
||||
if ((res = negotiate_link_format(data, &data->links[4], format)) < 0)
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -346,14 +346,12 @@ static int negotiate_formats(struct data *data)
|
|||
uint8_t buffer[4096];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
filter = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
filter = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
spa_debug_pod(0, spa_debug_types, filter);
|
||||
|
||||
|
|
|
|||
|
|
@ -472,14 +472,12 @@ static int negotiate_formats(struct data *data)
|
|||
uint8_t buffer[2048];
|
||||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
filter = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
filter = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
if ((res =
|
||||
spa_node_port_enum_params(data->sink,
|
||||
|
|
|
|||
|
|
@ -270,14 +270,12 @@ static int negotiate_formats(struct data *data)
|
|||
|
||||
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
||||
|
||||
filter = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_audio,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_AUDIO_format, "I", SPA_AUDIO_FORMAT_S16,
|
||||
":", SPA_FORMAT_AUDIO_layout, "I", SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
":", SPA_FORMAT_AUDIO_rate, "i", 44100,
|
||||
":", SPA_FORMAT_AUDIO_channels, "i", 2);
|
||||
filter = spa_format_audio_raw_build(&b, 0,
|
||||
&SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_S16,
|
||||
.layout = SPA_AUDIO_LAYOUT_INTERLEAVED,
|
||||
.rate = 44100,
|
||||
.channels = 2 ));
|
||||
|
||||
if ((res = spa_node_port_enum_params(data->sink,
|
||||
SPA_DIRECTION_INPUT, 0,
|
||||
|
|
|
|||
|
|
@ -387,13 +387,11 @@ static int negotiate_formats(struct data *data)
|
|||
&data->source_output[0], sizeof(data->source_output[0]))) < 0)
|
||||
return res;
|
||||
|
||||
format = spa_pod_builder_object(&b,
|
||||
SPA_TYPE_OBJECT_Format, 0,
|
||||
"I", SPA_MEDIA_TYPE_video,
|
||||
"I", SPA_MEDIA_SUBTYPE_raw,
|
||||
":", SPA_FORMAT_VIDEO_format, "I", SPA_VIDEO_FORMAT_YUY2,
|
||||
":", SPA_FORMAT_VIDEO_size, "R", &SPA_RECTANGLE(320, 240),
|
||||
":", SPA_FORMAT_VIDEO_framerate, "F", &SPA_FRACTION(25,1));
|
||||
format = spa_format_video_raw_build(&b, 0,
|
||||
&SPA_VIDEO_INFO_RAW_INIT(
|
||||
.format = SPA_VIDEO_FORMAT_YUY2,
|
||||
.size = SPA_RECTANGLE(320, 240),
|
||||
.framerate = SPA_FRACTION(25,1)));
|
||||
|
||||
if ((res = spa_node_port_set_param(data->source,
|
||||
SPA_DIRECTION_OUTPUT, 0,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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, ¶m, &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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue