mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
Add some more format checks
The format parse functions don't really check if the parsed values make any sense so we need to to this ourselves.
This commit is contained in:
parent
c30d743198
commit
74447acedb
24 changed files with 182 additions and 59 deletions
|
|
@ -603,6 +603,10 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
return -EINVAL;
|
||||
if (spa_format_audio_raw_parse(param, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
if (info.info.raw.format == 0 ||
|
||||
info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0)
|
||||
return -EINVAL;
|
||||
|
||||
this->follower_current_format = info;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1072,7 +1072,10 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
if (info.info.raw.format == 0 ||
|
||||
info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
return -EINVAL;
|
||||
|
||||
infop = &info;
|
||||
|
|
@ -1951,9 +1954,13 @@ static int port_set_format(void *object,
|
|||
spa_log_error(this->log, "can't parse format %s", spa_strerror(res));
|
||||
return res;
|
||||
}
|
||||
if (info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS) {
|
||||
spa_log_error(this->log, "too many channels %d > %d",
|
||||
info.info.raw.channels, SPA_AUDIO_MAX_CHANNELS);
|
||||
if (info.info.raw.format == 0 ||
|
||||
info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS) {
|
||||
spa_log_error(this->log, "invalid format:%d rate:%d channels:%d",
|
||||
info.info.raw.format, info.info.raw.rate,
|
||||
info.info.raw.channels);
|
||||
return -EINVAL;
|
||||
}
|
||||
port->stride = calc_width(&info);
|
||||
|
|
|
|||
|
|
@ -535,8 +535,12 @@ static int calc_width(struct spa_audio_info *info)
|
|||
case SPA_AUDIO_FORMAT_S24:
|
||||
case SPA_AUDIO_FORMAT_S24_OE:
|
||||
return 3;
|
||||
default:
|
||||
case SPA_AUDIO_FORMAT_S32P:
|
||||
case SPA_AUDIO_FORMAT_S32:
|
||||
case SPA_AUDIO_FORMAT_S32_OE:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -571,6 +575,12 @@ static int port_set_format(void *object,
|
|||
return res;
|
||||
|
||||
port->stride = calc_width(&info);
|
||||
if (port->stride == 0)
|
||||
return -EINVAL;
|
||||
if (info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (SPA_AUDIO_FORMAT_IS_PLANAR(info.info.raw.format)) {
|
||||
port->blocks = info.info.raw.channels;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -566,6 +566,10 @@ static int port_set_format(void *object,
|
|||
if (memcmp(&info, &this->format, sizeof(struct spa_audio_info)))
|
||||
return -EINVAL;
|
||||
} else {
|
||||
if (info.info.raw.format == 0 ||
|
||||
info.info.raw.channels == 0)
|
||||
return -EINVAL;
|
||||
|
||||
this->ops.fmt = info.info.raw.format;
|
||||
this->ops.n_channels = info.info.raw.channels;
|
||||
this->ops.cpu_flags = this->cpu_flags;
|
||||
|
|
|
|||
|
|
@ -743,6 +743,10 @@ port_set_format(struct impl *this,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0)
|
||||
return -EINVAL;
|
||||
|
||||
switch (info.info.raw.format) {
|
||||
case SPA_AUDIO_FORMAT_S16:
|
||||
idx = 0;
|
||||
|
|
|
|||
|
|
@ -439,7 +439,7 @@ static int spa_format_to_aaf(uint32_t format)
|
|||
}
|
||||
}
|
||||
|
||||
static int frame_size(uint32_t format)
|
||||
static int calc_frame_size(uint32_t format)
|
||||
{
|
||||
switch(format) {
|
||||
case SPA_AUDIO_FORMAT_F32_BE:
|
||||
|
|
@ -647,7 +647,7 @@ static int setup_packet(struct state *state, struct spa_audio_info *fmt)
|
|||
SPA_AVBTP_PACKET_AAF_SET_FORMAT(pdu, spa_format_to_aaf(state->format));
|
||||
SPA_AVBTP_PACKET_AAF_SET_NSR(pdu, spa_rate_to_aaf(state->rate));
|
||||
SPA_AVBTP_PACKET_AAF_SET_CHAN_PER_FRAME(pdu, state->channels);
|
||||
SPA_AVBTP_PACKET_AAF_SET_BIT_DEPTH(pdu, frame_size(state->format)*8);
|
||||
SPA_AVBTP_PACKET_AAF_SET_BIT_DEPTH(pdu, calc_frame_size(state->format)*8);
|
||||
SPA_AVBTP_PACKET_AAF_SET_DATA_LEN(pdu, payload_size);
|
||||
SPA_AVBTP_PACKET_AAF_SET_SP(pdu, SPA_AVBTP_AAF_PCM_SP_NORMAL);
|
||||
}
|
||||
|
|
@ -690,14 +690,22 @@ int spa_avb_clear_format(struct state *state)
|
|||
|
||||
int spa_avb_set_format(struct state *state, struct spa_audio_info *fmt, uint32_t flags)
|
||||
{
|
||||
int res;
|
||||
int res, frame_size;
|
||||
struct props *p = &state->props;
|
||||
|
||||
frame_size = calc_frame_size(fmt->info.raw.format);
|
||||
if (frame_size == 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (fmt->info.raw.rate == 0 ||
|
||||
fmt->info.raw.channels == 0)
|
||||
return -EINVAL;
|
||||
|
||||
state->format = fmt->info.raw.format;
|
||||
state->rate = fmt->info.raw.rate;
|
||||
state->channels = fmt->info.raw.channels;
|
||||
state->blocks = 1;
|
||||
state->stride = state->channels * frame_size(state->format);
|
||||
state->stride = state->channels * frame_size;
|
||||
|
||||
if ((res = setup_socket(state)) < 0)
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -1344,6 +1344,11 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
return -EINVAL;
|
||||
|
||||
port->frame_size = info.info.raw.channels;
|
||||
switch (info.info.raw.format) {
|
||||
case SPA_AUDIO_FORMAT_S16:
|
||||
|
|
|
|||
|
|
@ -1101,6 +1101,11 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
return -EINVAL;
|
||||
|
||||
port->frame_size = info.info.raw.channels;
|
||||
|
||||
switch (info.info.raw.format) {
|
||||
|
|
|
|||
|
|
@ -1106,6 +1106,11 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_S16_LE ||
|
||||
info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels != 1)
|
||||
return -EINVAL;
|
||||
|
||||
port->frame_size = info.info.raw.channels * 2;
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
|
|
|
|||
|
|
@ -1073,6 +1073,11 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_S16_LE ||
|
||||
info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels != 1)
|
||||
return -EINVAL;
|
||||
|
||||
port->frame_size = info.info.raw.channels * 2;
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
|
|
|
|||
|
|
@ -610,6 +610,11 @@ port_set_format(struct impl *this,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.rate == 0 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format == SPA_AUDIO_FORMAT_F32) {
|
||||
port->bpf = 4 * info.info.raw.channels;
|
||||
port->blocks = 1;
|
||||
|
|
|
|||
|
|
@ -925,7 +925,6 @@ static int spa_v4l2_set_format(struct impl *this, struct spa_video_info *format,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
fmt.fmt.pix.pixelformat = info->fourcc;
|
||||
fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
||||
fmt.fmt.pix.width = size->width;
|
||||
|
|
|
|||
|
|
@ -599,8 +599,9 @@ static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
|||
if ((res = spa_format_parse(param, &info.media_type, &info.media_subtype)) < 0)
|
||||
return res;
|
||||
if (info.media_type != SPA_MEDIA_TYPE_video ||
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
return -EINVAL;
|
||||
info.media_subtype != SPA_MEDIA_SUBTYPE_raw)
|
||||
return -EINVAL;
|
||||
|
||||
if (spa_format_video_raw_parse(param, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
|
|||
|
|
@ -643,6 +643,12 @@ static int port_set_format(struct impl *this, struct port *port,
|
|||
else
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.size.width == 0 ||
|
||||
info.info.raw.size.height == 0 ||
|
||||
info.info.raw.framerate.num == 0 ||
|
||||
info.info.raw.framerate.denom == 0)
|
||||
return -EINVAL;
|
||||
|
||||
port->current_format = info;
|
||||
port->have_format = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,10 +321,9 @@ static int port_enum_formats(void *object,
|
|||
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_CHOICE_ENUM_Id(3,
|
||||
SPA_FORMAT_AUDIO_format, SPA_POD_CHOICE_ENUM_Id(2,
|
||||
SPA_AUDIO_FORMAT_S16,
|
||||
SPA_AUDIO_FORMAT_S16,
|
||||
SPA_AUDIO_FORMAT_S32),
|
||||
SPA_AUDIO_FORMAT_S16),
|
||||
SPA_FORMAT_AUDIO_rate, SPA_POD_CHOICE_RANGE_Int(
|
||||
DEFAULT_RATE, 1, INT32_MAX),
|
||||
SPA_FORMAT_AUDIO_channels, SPA_POD_CHOICE_RANGE_Int(
|
||||
|
|
@ -472,6 +471,11 @@ static int port_set_format(void *object,
|
|||
if (spa_format_audio_raw_parse(format, &info.info.raw) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
if (info.info.raw.format != SPA_AUDIO_FORMAT_S16 ||
|
||||
info.info.raw.channels == 0 ||
|
||||
info.info.raw.channels > SPA_AUDIO_MAX_CHANNELS)
|
||||
return -EINVAL;
|
||||
|
||||
this->bpf = 2 * info.info.raw.channels;
|
||||
this->current_format = info;
|
||||
port->have_format = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue