From 82a2ba5f555f69f5a6f14fd4a7f7eef8fd1f1fd9 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 1 Aug 2018 18:29:05 +0200 Subject: [PATCH] oss: Bail out on unsupported audio formats. This is better than assuming signed 16 bit little endian. The patch also improves the error message in oss.c that gets printed when the audio format could not be set. --- oss_write.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/oss_write.c b/oss_write.c index d4b76585..311a514d 100644 --- a/oss_write.c +++ b/oss_write.c @@ -57,7 +57,7 @@ static int get_oss_format(enum sample_format sf) case SF_S16_BE: return AFMT_S16_BE; case SF_U16_LE: return AFMT_U16_LE; case SF_U16_BE: return AFMT_U16_BE; - default: return AFMT_S16_LE; + default: return -E_BAD_SAMPLE_FORMAT; } } @@ -113,10 +113,14 @@ static int oss_init(struct writer_node *wn, unsigned sample_rate, if (ret < 0) goto err; /* set PCM format */ - sample_format = format = get_oss_format(sample_format); + ret = get_oss_format(sample_format); + if (ret < 0) + return ret; + sample_format = format = ret; ret = ioctl(powd->fd, SNDCTL_DSP_SETFMT, &format); if (ret < 0) { ret = -ERRNO_TO_PARA_ERROR(errno); + PARA_ERROR_LOG("could not set sample format\n"); goto err; } ret = -E_BAD_SAMPLE_FORMAT; -- 2.39.5