mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Use the DSP format for dsp formats
Use the DSP media subtype to describe DSP formats. DSP formats don't include the rate, channels and channel position in the format and must use the rate and duration from the position io. This makes it possible to later change the samplerate dynamically without having to renegotiate the graph. The same goes for the video DSP format, which uses the io_video_size from the io_position to get the size/stride. Set this up in the node based on the defaults from the context. Make it possible to define defaults in the daemon config file, such as samplerate, quantum, video size and framerate. This is stored in the context and used for the DSP formats.
This commit is contained in:
parent
5a6da7d5e1
commit
852ac043d3
20 changed files with 402 additions and 270 deletions
|
|
@ -54,6 +54,16 @@ spa_format_audio_raw_parse(const struct spa_pod *format, struct spa_audio_info_r
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_format_audio_dsp_parse(const struct spa_pod *format, struct spa_audio_info_dsp *info)
|
||||
{
|
||||
int res;
|
||||
res = spa_pod_parse_object(format,
|
||||
SPA_TYPE_OBJECT_Format, NULL,
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(&info->format));
|
||||
return res;
|
||||
}
|
||||
|
||||
static inline struct spa_pod *
|
||||
spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_raw *info)
|
||||
{
|
||||
|
|
@ -75,6 +85,18 @@ spa_format_audio_raw_build(struct spa_pod_builder *builder, uint32_t id, struct
|
|||
return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
|
||||
}
|
||||
|
||||
static inline struct spa_pod *
|
||||
spa_format_audio_dsp_build(struct spa_pod_builder *builder, uint32_t id, struct spa_audio_info_dsp *info)
|
||||
{
|
||||
struct spa_pod_frame f;
|
||||
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, id);
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(info->format),
|
||||
0);
|
||||
return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ struct spa_audio_info {
|
|||
uint32_t media_subtype;
|
||||
union {
|
||||
struct spa_audio_info_raw raw;
|
||||
struct spa_audio_info_dsp dsp;
|
||||
} info;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -82,8 +82,17 @@ enum spa_audio_format {
|
|||
SPA_AUDIO_FORMAT_F32P,
|
||||
SPA_AUDIO_FORMAT_F64P,
|
||||
|
||||
SPA_AUDIO_FORMAT_START_Other = 0x300,
|
||||
/* other formats start here */
|
||||
SPA_AUDIO_FORMAT_START_Other = 0x400,
|
||||
|
||||
/* Aliases */
|
||||
|
||||
/* DSP formats */
|
||||
SPA_AUDIO_FORMAT_DSP_S32 = SPA_AUDIO_FORMAT_S24_32P,
|
||||
SPA_AUDIO_FORMAT_DSP_F32 = SPA_AUDIO_FORMAT_F32P,
|
||||
SPA_AUDIO_FORMAT_DSP_F64 = SPA_AUDIO_FORMAT_F64P,
|
||||
|
||||
/* native endian */
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
SPA_AUDIO_FORMAT_S16 = SPA_AUDIO_FORMAT_S16_BE,
|
||||
SPA_AUDIO_FORMAT_U16 = SPA_AUDIO_FORMAT_U16_BE,
|
||||
|
|
@ -210,6 +219,11 @@ struct spa_audio_info_raw {
|
|||
|
||||
#define SPA_KEY_AUDIO_CHANNEL "audio.channel" /**< an audio channel as string,
|
||||
* Ex. "FL" */
|
||||
struct spa_audio_info_dsp {
|
||||
enum spa_audio_format format; /*< format, one of the DSP formats in enum spa_audio_format_dsp */
|
||||
};
|
||||
|
||||
#define SPA_AUDIO_INFO_DSP_INIT(...) (struct spa_audio_info_dsp) { __VA_ARGS__ }
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
|
|
|||
|
|
@ -57,6 +57,16 @@ spa_format_video_raw_parse(const struct spa_pod *format,
|
|||
SPA_FORMAT_VIDEO_colorPrimaries, SPA_POD_OPT_Id(&info->color_primaries));
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_format_video_dsp_parse(const struct spa_pod *format,
|
||||
struct spa_video_info_dsp *info)
|
||||
{
|
||||
return spa_pod_parse_object(format,
|
||||
SPA_TYPE_OBJECT_Format, NULL,
|
||||
SPA_FORMAT_VIDEO_format, SPA_POD_Id(&info->format),
|
||||
SPA_FORMAT_VIDEO_modifier, SPA_POD_OPT_Long(&info->modifier));
|
||||
}
|
||||
|
||||
static inline struct spa_pod *
|
||||
spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id,
|
||||
struct spa_video_info_raw *info)
|
||||
|
|
@ -109,6 +119,23 @@ spa_format_video_raw_build(struct spa_pod_builder *builder, uint32_t id,
|
|||
return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
|
||||
}
|
||||
|
||||
static inline struct spa_pod *
|
||||
spa_format_video_dsp_build(struct spa_pod_builder *builder, uint32_t id,
|
||||
struct spa_video_info_dsp *info)
|
||||
{
|
||||
struct spa_pod_frame f;
|
||||
spa_pod_builder_push_object(builder, &f, SPA_TYPE_OBJECT_Format, id);
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp),
|
||||
SPA_FORMAT_VIDEO_format, SPA_POD_Id(info->format),
|
||||
0);
|
||||
if (info->modifier)
|
||||
spa_pod_builder_add(builder,
|
||||
SPA_FORMAT_VIDEO_modifier, SPA_POD_Long(info->modifier), 0);
|
||||
return (struct spa_pod*)spa_pod_builder_pop(builder, &f);
|
||||
}
|
||||
|
||||
static inline int
|
||||
spa_format_video_h264_parse(const struct spa_pod *format,
|
||||
struct spa_video_info_h264 *info)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ struct spa_video_info {
|
|||
uint32_t media_subtype;
|
||||
union {
|
||||
struct spa_video_info_raw raw;
|
||||
struct spa_video_info_dsp dsp;
|
||||
struct spa_video_info_h264 h264;
|
||||
struct spa_video_info_mjpg mjpg;
|
||||
} info;
|
||||
|
|
|
|||
|
|
@ -120,6 +120,9 @@ enum spa_video_format {
|
|||
|
||||
SPA_VIDEO_FORMAT_RGBA_F16,
|
||||
SPA_VIDEO_FORMAT_RGBA_F32,
|
||||
|
||||
/* Aliases */
|
||||
SPA_VIDEO_FORMAT_DSP_F32 = SPA_VIDEO_FORMAT_RGBA_F32,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -204,6 +207,13 @@ struct spa_video_info_raw {
|
|||
|
||||
#define SPA_VIDEO_INFO_RAW_INIT(...) (struct spa_video_info_raw) { __VA_ARGS__ }
|
||||
|
||||
struct spa_video_info_dsp {
|
||||
enum spa_video_format format;
|
||||
int64_t modifier;
|
||||
};
|
||||
|
||||
#define SPA_VIDEO_INFO_DSP_INIT(...) (struct spa_video_info_dsp) { __VA_ARGS__ }
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ static void emit_port_info(struct impl *this, struct port *port, bool full)
|
|||
}
|
||||
|
||||
static int init_port(struct impl *this, enum spa_direction direction, uint32_t port_id,
|
||||
uint32_t rate, uint32_t position)
|
||||
uint32_t position)
|
||||
{
|
||||
struct port *port = GET_PORT(this, direction, port_id);
|
||||
|
||||
|
|
@ -184,15 +184,12 @@ static int init_port(struct impl *this, enum spa_direction direction, uint32_t p
|
|||
port->n_buffers = 0;
|
||||
port->have_format = false;
|
||||
port->format.media_type = SPA_MEDIA_TYPE_audio;
|
||||
port->format.media_subtype = SPA_MEDIA_SUBTYPE_raw;
|
||||
port->format.info.raw.format = SPA_AUDIO_FORMAT_F32P;
|
||||
port->format.info.raw.rate = rate;
|
||||
port->format.info.raw.channels = 1;
|
||||
port->format.info.raw.position[0] = position;
|
||||
port->format.media_subtype = SPA_MEDIA_SUBTYPE_dsp;
|
||||
port->format.info.dsp.format = SPA_AUDIO_FORMAT_DSP_F32;
|
||||
spa_list_init(&port->queue);
|
||||
|
||||
spa_log_debug(this->log, NAME " %p: add port %d:%d rate:%d position:%s",
|
||||
this, direction, port_id, rate, port->position);
|
||||
spa_log_debug(this->log, NAME " %p: add port %d:%d position:%s",
|
||||
this, direction, port_id, port->position);
|
||||
emit_port_info(this, port, true);
|
||||
|
||||
return 0;
|
||||
|
|
@ -310,10 +307,9 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
this->port_count = info.info.raw.channels;
|
||||
this->monitor_count = this->monitor ? this->port_count : 0;
|
||||
for (i = 0; i < this->port_count; i++) {
|
||||
init_port(this, SPA_DIRECTION_INPUT, i, info.info.raw.rate,
|
||||
info.info.raw.position[i]);
|
||||
init_port(this, SPA_DIRECTION_INPUT, i, info.info.raw.position[i]);
|
||||
if (this->monitor)
|
||||
init_port(this, SPA_DIRECTION_OUTPUT, i+1, info.info.raw.rate,
|
||||
init_port(this, SPA_DIRECTION_OUTPUT, i+1,
|
||||
info.info.raw.position[i]);
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -403,7 +399,10 @@ static int port_enum_formats(void *object,
|
|||
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (PORT_IS_DSP(direction, port_id) || port->have_format) {
|
||||
if (PORT_IS_DSP(direction, port_id)) {
|
||||
*param = spa_format_audio_dsp_build(builder,
|
||||
SPA_PARAM_EnumFormat, &port->format.info.dsp);
|
||||
} else if (port->have_format) {
|
||||
*param = spa_format_audio_raw_build(builder,
|
||||
SPA_PARAM_EnumFormat, &port->format.info.raw);
|
||||
}
|
||||
|
|
@ -481,7 +480,10 @@ impl_node_port_enum_params(void *object, int seq,
|
|||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
|
||||
if (PORT_IS_DSP(direction, port_id))
|
||||
param = spa_format_audio_dsp_build(&b, id, &port->format.info.dsp);
|
||||
else
|
||||
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
|
||||
break;
|
||||
case SPA_PARAM_Buffers:
|
||||
if (!port->have_format)
|
||||
|
|
@ -557,7 +559,7 @@ static int setup_convert(struct impl *this)
|
|||
|
||||
outport = GET_OUT_PORT(this, 0);
|
||||
|
||||
src_fmt = SPA_AUDIO_FORMAT_F32P;
|
||||
src_fmt = SPA_AUDIO_FORMAT_DSP_F32;
|
||||
dst_fmt = outport->format.info.raw.format;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: %s/%d@%dx%d->%s/%d@%d", this,
|
||||
|
|
@ -630,53 +632,52 @@ static int port_set_format(void *object,
|
|||
spa_log_error(this->log, "can't parse format %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw) {
|
||||
spa_log_error(this->log, "unexpected types %d/%d",
|
||||
info.media_type, info.media_subtype);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((res = spa_format_audio_raw_parse(format, &info.info.raw)) < 0) {
|
||||
spa_log_error(this->log, "can't parse format %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
if (PORT_IS_DSP(direction, port_id)) {
|
||||
if (info.info.raw.rate != port->format.info.raw.rate) {
|
||||
spa_log_error(this->log, "unexpected rate %d<->%d",
|
||||
info.info.raw.rate, port->format.info.raw.rate);
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_dsp) {
|
||||
spa_log_error(this->log, "unexpected types %d/%d",
|
||||
info.media_type, info.media_subtype);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32P) {
|
||||
if ((res = spa_format_audio_dsp_parse(format, &info.info.dsp)) < 0) {
|
||||
spa_log_error(this->log, "can't parse format %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
if (info.info.dsp.format != SPA_AUDIO_FORMAT_DSP_F32) {
|
||||
spa_log_error(this->log, "unexpected format %d<->%d",
|
||||
info.info.raw.format, SPA_AUDIO_FORMAT_F32P);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (info.info.raw.channels != 1) {
|
||||
spa_log_error(this->log, "unexpected channels %d<->1",
|
||||
info.info.raw.channels);
|
||||
info.info.dsp.format, SPA_AUDIO_FORMAT_DSP_F32);
|
||||
return -EINVAL;
|
||||
}
|
||||
port->blocks = 1;
|
||||
port->stride = 4;
|
||||
}
|
||||
else {
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw) {
|
||||
spa_log_error(this->log, "unexpected types %d/%d",
|
||||
info.media_type, info.media_subtype);
|
||||
return -EINVAL;
|
||||
}
|
||||
if ((res = spa_format_audio_raw_parse(format, &info.info.raw)) < 0) {
|
||||
spa_log_error(this->log, "can't parse format %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
if (info.info.raw.channels != this->port_count) {
|
||||
spa_log_error(this->log, "unexpected channels %d<->%d",
|
||||
info.info.raw.channels, this->port_count);
|
||||
return -EINVAL;
|
||||
}
|
||||
port->stride = calc_width(&info);
|
||||
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {
|
||||
port->blocks = info.info.raw.channels;
|
||||
}
|
||||
else {
|
||||
port->stride *= info.info.raw.channels;
|
||||
port->blocks = 1;
|
||||
}
|
||||
}
|
||||
|
||||
port->format = info;
|
||||
port->stride = calc_width(&info);
|
||||
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {
|
||||
port->blocks = info.info.raw.channels;
|
||||
}
|
||||
else {
|
||||
port->stride *= info.info.raw.channels;
|
||||
port->blocks = 1;
|
||||
}
|
||||
|
||||
spa_log_debug(this->log, NAME " %p: %d %d %d", this,
|
||||
port_id, port->stride, port->blocks);
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ static void emit_port_info(struct impl *this, struct port *port, bool full)
|
|||
}
|
||||
|
||||
static int init_port(struct impl *this, enum spa_direction direction,
|
||||
uint32_t port_id, uint32_t rate, uint32_t position)
|
||||
uint32_t port_id, uint32_t position)
|
||||
{
|
||||
struct port *port = GET_OUT_PORT(this, port_id);
|
||||
|
||||
|
|
@ -178,14 +178,11 @@ static int init_port(struct impl *this, enum spa_direction direction,
|
|||
port->n_buffers = 0;
|
||||
port->have_format = false;
|
||||
port->format.media_type = SPA_MEDIA_TYPE_audio;
|
||||
port->format.media_subtype = SPA_MEDIA_SUBTYPE_raw;
|
||||
port->format.info.raw.format = SPA_AUDIO_FORMAT_F32P;
|
||||
port->format.info.raw.rate = rate;
|
||||
port->format.info.raw.channels = 1;
|
||||
port->format.info.raw.position[0] = position;
|
||||
port->format.media_subtype = SPA_MEDIA_SUBTYPE_dsp;
|
||||
port->format.info.dsp.format = SPA_AUDIO_FORMAT_DSP_F32;
|
||||
|
||||
spa_log_debug(this->log, NAME " %p: init port %d:%d rate:%d position:%s",
|
||||
this, direction, port_id, rate, port->position);
|
||||
spa_log_debug(this->log, NAME " %p: init port %d:%d position:%s",
|
||||
this, direction, port_id, port->position);
|
||||
emit_port_info(this, port, true);
|
||||
|
||||
return 0;
|
||||
|
|
@ -280,7 +277,8 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
if (port->have_format && memcmp(&port->format, &info, sizeof(info)) == 0)
|
||||
return 0;
|
||||
|
||||
spa_log_debug(this->log, NAME " %p: profile %d", this, info.info.raw.channels);
|
||||
spa_log_debug(this->log, NAME " %p: port config %d/%d", this,
|
||||
info.info.raw.rate, info.info.raw.channels);
|
||||
|
||||
for (i = 0; i < this->port_count; i++)
|
||||
spa_node_emit_port_info(&this->hooks,
|
||||
|
|
@ -293,7 +291,7 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
|
||||
this->port_count = info.info.raw.channels;
|
||||
for (i = 0; i < this->port_count; i++) {
|
||||
init_port(this, SPA_DIRECTION_OUTPUT, i, info.info.raw.rate,
|
||||
init_port(this, SPA_DIRECTION_OUTPUT, i,
|
||||
info.info.raw.position[i]);
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -379,7 +377,10 @@ static int port_enum_formats(void *object,
|
|||
|
||||
switch (index) {
|
||||
case 0:
|
||||
if (direction == SPA_DIRECTION_OUTPUT || port->have_format) {
|
||||
if (direction == SPA_DIRECTION_OUTPUT) {
|
||||
*param = spa_format_audio_dsp_build(builder,
|
||||
SPA_PARAM_EnumFormat, &port->format.info.dsp);
|
||||
} else if (port->have_format) {
|
||||
*param = spa_format_audio_raw_build(builder,
|
||||
SPA_PARAM_EnumFormat, &port->format.info.raw);
|
||||
}
|
||||
|
|
@ -462,7 +463,10 @@ impl_node_port_enum_params(void *object, int seq,
|
|||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
|
||||
if (direction == SPA_DIRECTION_OUTPUT)
|
||||
param = spa_format_audio_dsp_build(&b, id, &port->format.info.dsp);
|
||||
else
|
||||
param = spa_format_audio_raw_build(&b, id, &port->format.info.raw);
|
||||
break;
|
||||
case SPA_PARAM_Buffers:
|
||||
if (!port->have_format)
|
||||
|
|
@ -540,7 +544,7 @@ static int setup_convert(struct impl *this)
|
|||
inport = GET_IN_PORT(this, 0);
|
||||
|
||||
src_fmt = inport->format.info.raw.format;
|
||||
dst_fmt = SPA_AUDIO_FORMAT_F32P;
|
||||
dst_fmt = SPA_AUDIO_FORMAT_DSP_F32;
|
||||
|
||||
spa_log_info(this->log, NAME " %p: %s/%d@%d->%s/%d@%dx%d", this,
|
||||
spa_debug_type_find_name(spa_type_audio_format, src_fmt),
|
||||
|
|
@ -615,35 +619,38 @@ static int port_set_format(void *object,
|
|||
if ((res = spa_format_parse(format, &info.media_type, &info.media_subtype)) < 0)
|
||||
return res;
|
||||
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (direction == SPA_DIRECTION_OUTPUT) {
|
||||
if (info.info.raw.rate != port->format.info.raw.rate)
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_dsp)
|
||||
return -EINVAL;
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32P)
|
||||
if (spa_format_audio_dsp_parse(format, &info.info.dsp) < 0)
|
||||
return -EINVAL;
|
||||
if (info.info.raw.channels != 1)
|
||||
if (info.info.dsp.format != SPA_AUDIO_FORMAT_DSP_F32)
|
||||
return -EINVAL;
|
||||
|
||||
port->stride = 4;
|
||||
port->blocks = 1;
|
||||
}
|
||||
else {
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
return -EINVAL;
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
if (info.info.raw.channels != this->port_count)
|
||||
return -EINVAL;
|
||||
|
||||
port->stride = calc_width(&info);
|
||||
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {
|
||||
port->blocks = info.info.raw.channels;
|
||||
} else {
|
||||
port->stride *= info.info.raw.channels;
|
||||
port->blocks = 1;
|
||||
}
|
||||
}
|
||||
|
||||
port->format = info;
|
||||
port->stride = calc_width(&info);
|
||||
|
||||
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {
|
||||
port->blocks = info.info.raw.channels;
|
||||
} else {
|
||||
port->stride *= info.info.raw.channels;
|
||||
port->blocks = 1;
|
||||
}
|
||||
spa_log_debug(this->log, NAME " %p: %d %d %d", this, port_id, port->stride, port->blocks);
|
||||
|
||||
if (direction == SPA_DIRECTION_INPUT)
|
||||
|
|
|
|||
|
|
@ -315,16 +315,14 @@ static int port_enum_formats(void *object,
|
|||
switch (index) {
|
||||
case 0:
|
||||
if (this->have_format) {
|
||||
*param = spa_format_audio_raw_build(builder, SPA_PARAM_EnumFormat,
|
||||
&this->format.info.raw);
|
||||
*param = spa_format_audio_dsp_build(builder, SPA_PARAM_EnumFormat,
|
||||
&this->format.info.dsp);
|
||||
} else {
|
||||
*param = spa_pod_builder_add_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(SPA_AUDIO_FORMAT_F32P),
|
||||
SPA_FORMAT_AUDIO_rate, SPA_POD_CHOICE_RANGE_Int(44100, 1, INT32_MAX),
|
||||
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(1));
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(SPA_AUDIO_FORMAT_DSP_F32));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
@ -373,7 +371,7 @@ next:
|
|||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &this->format.info.raw);
|
||||
param = spa_format_audio_dsp_build(&b, id, &this->format.info.dsp);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
|
|
@ -495,23 +493,18 @@ static int port_set_format(void *object,
|
|||
return res;
|
||||
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_dsp)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
if (spa_format_audio_dsp_parse(format, &info.info.dsp) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_F32P)
|
||||
return -EINVAL;
|
||||
if (info.info.raw.channels != 1)
|
||||
if (info.info.dsp.format != SPA_AUDIO_FORMAT_DSP_F32)
|
||||
return -EINVAL;
|
||||
|
||||
if (this->have_format) {
|
||||
if (info.info.raw.rate != this->format.info.raw.rate)
|
||||
return -EINVAL;
|
||||
} else {
|
||||
this->ops.fmt = info.info.raw.format;
|
||||
this->ops.n_channels = info.info.raw.channels;
|
||||
if (!this->have_format) {
|
||||
this->ops.fmt = info.info.dsp.format;
|
||||
this->ops.n_channels = 1;
|
||||
this->ops.cpu_flags = this->cpu_flags;
|
||||
|
||||
if ((res = mix_ops_init(&this->ops)) < 0)
|
||||
|
|
|
|||
|
|
@ -146,8 +146,8 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
case SPA_PARAM_Format:
|
||||
switch (result.index) {
|
||||
case 0:
|
||||
param = spa_format_audio_raw_build(&b,
|
||||
id, &this->current_format.info.raw);
|
||||
param = spa_format_audio_dsp_build(&b,
|
||||
id, &this->current_format.info.dsp);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -447,11 +447,8 @@ static int init_ports(struct impl *this)
|
|||
}
|
||||
this->n_in_ports = i;
|
||||
|
||||
this->current_format.info.raw = SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32P,
|
||||
.flags = SPA_AUDIO_FLAG_UNPOSITIONED,
|
||||
.rate = jack_get_sample_rate(client),
|
||||
.channels = this->n_in_ports);
|
||||
this->current_format.info.dsp = SPA_AUDIO_INFO_DSP_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_DSP_F32);
|
||||
|
||||
spa_jack_client_add_listener(this->client,
|
||||
&this->client_listener,
|
||||
|
|
@ -499,10 +496,8 @@ static int port_enum_formats(struct impl *this,
|
|||
*param = spa_pod_builder_add_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(SPA_AUDIO_FORMAT_F32P),
|
||||
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(this->client->frame_rate),
|
||||
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(1));
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(SPA_AUDIO_FORMAT_DSP_F32));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -552,7 +547,7 @@ impl_node_port_enum_params(void *object, int seq,
|
|||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &port->current_format.info.raw);
|
||||
param = spa_format_audio_dsp_build(&b, id, &port->current_format.info.dsp);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
|
|
@ -627,17 +622,16 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
return res;
|
||||
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio &&
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_dsp)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
if (spa_format_audio_dsp_parse(format, &info.info.dsp) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format == SPA_AUDIO_FORMAT_F32P)
|
||||
port->stride = 4;
|
||||
else
|
||||
if (info.info.dsp.format != SPA_AUDIO_FORMAT_DSP_F32)
|
||||
return -EINVAL;
|
||||
|
||||
port->stride = 4;
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,8 +148,8 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
case SPA_PARAM_Format:
|
||||
switch (result.index) {
|
||||
case 0:
|
||||
param = spa_format_audio_raw_build(&b,
|
||||
id, &this->current_format.info.raw);
|
||||
param = spa_format_audio_dsp_build(&b,
|
||||
id, &this->current_format.info.dsp);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -446,11 +446,8 @@ static int init_ports(struct impl *this)
|
|||
}
|
||||
this->n_out_ports = i;
|
||||
|
||||
this->current_format.info.raw = SPA_AUDIO_INFO_RAW_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_F32P,
|
||||
.flags = SPA_AUDIO_FLAG_UNPOSITIONED,
|
||||
.rate = jack_get_sample_rate(client),
|
||||
.channels = this->n_out_ports);
|
||||
this->current_format.info.dsp = SPA_AUDIO_INFO_DSP_INIT(
|
||||
.format = SPA_AUDIO_FORMAT_DSP_F32);
|
||||
|
||||
spa_jack_client_add_listener(this->client,
|
||||
&this->client_listener,
|
||||
|
|
@ -498,10 +495,8 @@ static int port_enum_formats(struct impl *this,
|
|||
*param = spa_pod_builder_add_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_audio),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(SPA_AUDIO_FORMAT_F32P),
|
||||
SPA_FORMAT_AUDIO_rate, SPA_POD_Int(this->client->frame_rate),
|
||||
SPA_FORMAT_AUDIO_channels, SPA_POD_Int(1));
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp),
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_Id(SPA_AUDIO_FORMAT_DSP_F32));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -551,7 +546,7 @@ impl_node_port_enum_params(void *object, int seq,
|
|||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_audio_raw_build(&b, id, &port->current_format.info.raw);
|
||||
param = spa_format_audio_dsp_build(&b, id, &port->current_format.info.dsp);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
|
|
@ -627,17 +622,16 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
return res;
|
||||
|
||||
if (info.media_type != SPA_MEDIA_TYPE_audio &&
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_dsp)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
if (spa_format_audio_dsp_parse(format, &info.info.dsp) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format == SPA_AUDIO_FORMAT_F32P)
|
||||
port->stride = 4;
|
||||
else
|
||||
if (info.info.dsp.format != SPA_AUDIO_FORMAT_DSP_F32)
|
||||
return -EINVAL;
|
||||
|
||||
port->stride = 4;
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,11 +46,13 @@
|
|||
|
||||
#define NAME "vulkan-compute-source"
|
||||
|
||||
#define FRAMES_TO_TIME(port,f) ((port->current_format.info.raw.framerate.denom * (f) * SPA_NSEC_PER_SEC) / \
|
||||
(port->current_format.info.raw.framerate.num))
|
||||
#define FRAMES_TO_TIME(this,f) ((this->position->video.framerate.denom * (f) * SPA_NSEC_PER_SEC) / \
|
||||
(this->position->video.framerate.num))
|
||||
|
||||
#define DEFAULT_LIVE true
|
||||
|
||||
#define MAX_HEIGHT 1024
|
||||
|
||||
struct props {
|
||||
bool live;
|
||||
};
|
||||
|
|
@ -80,8 +82,6 @@ struct port {
|
|||
|
||||
bool have_format;
|
||||
struct spa_video_info current_format;
|
||||
size_t bpp;
|
||||
int stride;
|
||||
|
||||
struct buffer buffers[MAX_BUFFERS];
|
||||
uint32_t n_buffers;
|
||||
|
|
@ -98,6 +98,9 @@ struct impl {
|
|||
struct spa_loop *data_loop;
|
||||
struct spa_system *data_system;
|
||||
|
||||
struct spa_io_clock *clock;
|
||||
struct spa_io_position *position;
|
||||
|
||||
uint64_t info_all;
|
||||
struct spa_node_info info;
|
||||
struct spa_param_info params[2];
|
||||
|
|
@ -193,7 +196,23 @@ static int impl_node_enum_params(void *object, int seq,
|
|||
|
||||
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
struct impl *this = object;
|
||||
|
||||
spa_return_val_if_fail(this != NULL, -EINVAL);
|
||||
|
||||
switch (id) {
|
||||
case SPA_IO_Clock:
|
||||
if (size > 0 && size < sizeof(struct spa_io_clock))
|
||||
return -EINVAL;
|
||||
this->clock = data;
|
||||
break;
|
||||
case SPA_IO_Position:
|
||||
this->position = data;
|
||||
break;
|
||||
default:
|
||||
return -ENOENT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
||||
|
|
@ -300,7 +319,7 @@ static int make_buffer(struct impl *this)
|
|||
|
||||
b->outbuf->datas[0].chunk->offset = 0;
|
||||
b->outbuf->datas[0].chunk->size = n_bytes;
|
||||
b->outbuf->datas[0].chunk->stride = port->stride;
|
||||
b->outbuf->datas[0].chunk->stride = this->position->video.stride;
|
||||
|
||||
if (b->h) {
|
||||
b->h->seq = this->frame_count;
|
||||
|
|
@ -315,7 +334,7 @@ static int make_buffer(struct impl *this)
|
|||
}
|
||||
next:
|
||||
this->frame_count++;
|
||||
this->elapsed_time = FRAMES_TO_TIME(port, this->frame_count);
|
||||
this->elapsed_time = FRAMES_TO_TIME(this, this->frame_count);
|
||||
set_timer(this, true);
|
||||
|
||||
return res;
|
||||
|
|
@ -507,16 +526,8 @@ static int port_enum_formats(void *object,
|
|||
*param = spa_pod_builder_add_object(builder,
|
||||
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
|
||||
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
|
||||
SPA_FORMAT_VIDEO_format, SPA_POD_Id(SPA_VIDEO_FORMAT_RGBA_F32),
|
||||
SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(
|
||||
&SPA_RECTANGLE(320, 240),
|
||||
&SPA_RECTANGLE(1, 1),
|
||||
&SPA_RECTANGLE(INT32_MAX, INT32_MAX)),
|
||||
SPA_FORMAT_VIDEO_framerate, SPA_POD_CHOICE_RANGE_Fraction(
|
||||
&SPA_FRACTION(25,1),
|
||||
&SPA_FRACTION(0, 1),
|
||||
&SPA_FRACTION(INT32_MAX, 1)));
|
||||
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_dsp),
|
||||
SPA_FORMAT_VIDEO_format, SPA_POD_Id(SPA_VIDEO_FORMAT_DSP_F32));
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
|
|
@ -565,15 +576,15 @@ impl_node_port_enum_params(void *object, int seq,
|
|||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
param = spa_format_video_raw_build(&b, id, &port->current_format.info.raw);
|
||||
param = spa_format_video_dsp_build(&b, id, &port->current_format.info.dsp);
|
||||
break;
|
||||
|
||||
case SPA_PARAM_Buffers:
|
||||
{
|
||||
struct spa_video_info_raw *raw_info = &port->current_format.info.raw;
|
||||
|
||||
if (!port->have_format)
|
||||
return -EIO;
|
||||
if (this->position == NULL)
|
||||
return -EIO;
|
||||
if (result.index > 0)
|
||||
return 0;
|
||||
|
||||
|
|
@ -581,8 +592,8 @@ impl_node_port_enum_params(void *object, int seq,
|
|||
SPA_TYPE_OBJECT_ParamBuffers, id,
|
||||
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(2, 1, MAX_BUFFERS),
|
||||
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
|
||||
SPA_PARAM_BUFFERS_size, SPA_POD_Int(port->stride * raw_info->size.height),
|
||||
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(port->stride),
|
||||
SPA_PARAM_BUFFERS_size, SPA_POD_Int(this->position->video.stride * MAX_HEIGHT),
|
||||
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(this->position->video.stride),
|
||||
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
|
||||
break;
|
||||
}
|
||||
|
|
@ -645,19 +656,17 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
return res;
|
||||
|
||||
if (info.media_type != SPA_MEDIA_TYPE_video &&
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_dsp)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_video_raw_parse(format, &info.info.raw) < 0)
|
||||
if (spa_format_video_dsp_parse(format, &info.info.dsp) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format == SPA_VIDEO_FORMAT_RGBA_F32)
|
||||
port->bpp = 16;
|
||||
else
|
||||
if (info.info.dsp.format != SPA_VIDEO_FORMAT_DSP_F32)
|
||||
return -EINVAL;
|
||||
|
||||
this->state.constants.width = info.info.raw.size.width;
|
||||
this->state.constants.height = info.info.raw.size.height;
|
||||
this->state.constants.width = this->position->video.size.width;
|
||||
this->state.constants.height = this->position->video.size.height;
|
||||
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
|
|
@ -666,8 +675,6 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
|
||||
port->info.change_mask |= SPA_PORT_CHANGE_MASK_PARAMS;
|
||||
if (port->have_format) {
|
||||
struct spa_video_info_raw *raw_info = &port->current_format.info.raw;
|
||||
port->stride = SPA_ROUND_UP_N(port->bpp * raw_info->size.width, 4);
|
||||
port->params[3] = SPA_PARAM_INFO(SPA_PARAM_Format, SPA_PARAM_INFO_READWRITE);
|
||||
port->params[4] = SPA_PARAM_INFO(SPA_PARAM_Buffers, SPA_PARAM_INFO_READ);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue