mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
bluez5: lc3: clean up some sanity checks
Fix some sanity checks and add mtu check. Don't use spa_return_val_if_fail here as it can spam stderr. The buffer size check in codec_encode can't be hit.
This commit is contained in:
parent
61c585c8e6
commit
ddf3be0a39
1 changed files with 19 additions and 15 deletions
|
|
@ -915,6 +915,7 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!parse_conf(&conf, config, config_len)) {
|
if (!parse_conf(&conf, config, config_len)) {
|
||||||
|
spa_log_error(log, "invalid LC3 config");
|
||||||
res = -ENOTSUP;
|
res = -ENOTSUP;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
@ -936,15 +937,24 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
spa_log_info(log, "LC3 rate:%d frame_duration:%d channels:%d framelen:%d",
|
spa_log_info(log, "LC3 rate:%d frame_duration:%d channels:%d framelen:%d nblks:%d",
|
||||||
this->samplerate, this->frame_dus, this->channels, this->framelen);
|
this->samplerate, this->frame_dus, this->channels, this->framelen, conf.n_blks);
|
||||||
|
|
||||||
this->samples = lc3_frame_samples(this->frame_dus, this->samplerate);
|
if (this->framelen * this->channels * conf.n_blks > this->mtu) {
|
||||||
if (this->samples < 0) {
|
spa_log_error(log, "too big LC3 frame length %u*%u*%u > %u",
|
||||||
|
this->framelen, this->channels, conf.n_blks, this->mtu);
|
||||||
res = -EINVAL;
|
res = -EINVAL;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
this->codesize = this->samples * this->channels * conf.n_blks * sizeof(int32_t);
|
|
||||||
|
res = lc3_frame_samples(this->frame_dus, this->samplerate);
|
||||||
|
if (res < 0) {
|
||||||
|
spa_log_error(log, "invalid LC3 frame samples");
|
||||||
|
res = -EINVAL;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
this->samples = res;
|
||||||
|
this->codesize = (size_t)this->samples * this->channels * conf.n_blks * sizeof(int32_t);
|
||||||
|
|
||||||
if (!(flags & MEDIA_CODEC_FLAG_SINK)) {
|
if (!(flags & MEDIA_CODEC_FLAG_SINK)) {
|
||||||
for (ich = 0; ich < this->channels; ich++) {
|
for (ich = 0; ich < this->channels; ich++) {
|
||||||
|
|
@ -1021,18 +1031,16 @@ static int codec_encode(void *data,
|
||||||
size_t *dst_out, int *need_flush)
|
size_t *dst_out, int *need_flush)
|
||||||
{
|
{
|
||||||
struct impl *this = data;
|
struct impl *this = data;
|
||||||
int frame_bytes;
|
|
||||||
int ich, res;
|
int ich, res;
|
||||||
int size, processed;
|
int size, processed;
|
||||||
|
|
||||||
frame_bytes = lc3_frame_bytes(this->frame_dus, this->samplerate);
|
|
||||||
processed = 0;
|
processed = 0;
|
||||||
size = 0;
|
size = 0;
|
||||||
|
|
||||||
if (src_size < (size_t)this->codesize)
|
if (src_size < (size_t)this->codesize)
|
||||||
goto done;
|
return -EINVAL;
|
||||||
if (dst_size < (size_t)frame_bytes)
|
if (dst_size < (size_t)this->framelen * this->channels)
|
||||||
goto done;
|
return -EINVAL;
|
||||||
|
|
||||||
for (ich = 0; ich < this->channels; ich++) {
|
for (ich = 0; ich < this->channels; ich++) {
|
||||||
uint8_t *in = (uint8_t *)src + (ich * 4);
|
uint8_t *in = (uint8_t *)src + (ich * 4);
|
||||||
|
|
@ -1046,7 +1054,6 @@ static int codec_encode(void *data,
|
||||||
|
|
||||||
processed += this->codesize;
|
processed += this->codesize;
|
||||||
|
|
||||||
done:
|
|
||||||
spa_assert(size <= this->mtu);
|
spa_assert(size <= this->mtu);
|
||||||
*need_flush = NEED_FLUSH_ALL;
|
*need_flush = NEED_FLUSH_ALL;
|
||||||
|
|
||||||
|
|
@ -1067,13 +1074,10 @@ static SPA_UNUSED int codec_decode(void *data,
|
||||||
struct impl *this = data;
|
struct impl *this = data;
|
||||||
int ich, res;
|
int ich, res;
|
||||||
int consumed;
|
int consumed;
|
||||||
int samples;
|
|
||||||
|
|
||||||
spa_return_val_if_fail((size_t)(this->framelen * this->channels) == src_size, -EINVAL);
|
|
||||||
consumed = 0;
|
consumed = 0;
|
||||||
|
|
||||||
samples = lc3_frame_samples(this->frame_dus, this->samplerate);
|
if (src_size < (size_t)this->framelen * this->channels)
|
||||||
if (samples == -1)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (dst_size < this->codesize)
|
if (dst_size < this->codesize)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue