diff options
author | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2017-09-20 18:01:56 +0200 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2017-09-26 15:13:25 +0000 |
commit | 37e58f8cfacde4163735cf1be8b89f6ec06144c2 (patch) | |
tree | a3926a24a962d7cb94cdbd5b60d8aa169c1de4fa | |
parent | 020e8018bb1e5d787937e043ff9d5670ee7b004e (diff) |
PulseAudio: Reject unsupported audio formats
Based on https://freedesktop.org/software/pulseaudio/doxygen/sample.html
Applied a fix to allow only supported combinations sample type/sample size/byte order.
If the combination has not been found PA_SAMPLE_INVALID is returned.
Task-number: QTBUG-62621
Change-Id: I14c3d3828a0527aef0a5afa753fb640ead0cc18d
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r-- | src/plugins/pulseaudio/qpulsehelpers.cpp | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/src/plugins/pulseaudio/qpulsehelpers.cpp b/src/plugins/pulseaudio/qpulsehelpers.cpp index 17579bdd9..0604c97f5 100644 --- a/src/plugins/pulseaudio/qpulsehelpers.cpp +++ b/src/plugins/pulseaudio/qpulsehelpers.cpp @@ -49,30 +49,23 @@ pa_sample_spec audioFormatToSampleSpec(const QAudioFormat &format) spec.rate = format.sampleRate(); spec.channels = format.channelCount(); - - if (format.sampleSize() == 8) { - spec.format = PA_SAMPLE_U8; - } else if (format.sampleSize() == 16) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S16BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S16LE; break; - } - } else if (format.sampleSize() == 24) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: spec.format = PA_SAMPLE_S24BE; break; - case QAudioFormat::LittleEndian: spec.format = PA_SAMPLE_S24LE; break; - } - } else if (format.sampleSize() == 32) { - switch (format.byteOrder()) { - case QAudioFormat::BigEndian: - format.sampleType() == QAudioFormat::Float ? spec.format = PA_SAMPLE_FLOAT32BE : spec.format = PA_SAMPLE_S32BE; - break; - case QAudioFormat::LittleEndian: - format.sampleType() == QAudioFormat::Float ? spec.format = PA_SAMPLE_FLOAT32LE : spec.format = PA_SAMPLE_S32LE; - break; + spec.format = PA_SAMPLE_INVALID; + const bool isBigEndian = (format.byteOrder() == QAudioFormat::BigEndian); + + if (format.sampleType() == QAudioFormat::UnSignedInt) { + if (format.sampleSize() == 8) + spec.format = PA_SAMPLE_U8; + } else if (format.sampleType() == QAudioFormat::SignedInt) { + if (format.sampleSize() == 16) { + spec.format = isBigEndian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE; + } else if (format.sampleSize() == 24) { + spec.format = isBigEndian ? PA_SAMPLE_S24BE : PA_SAMPLE_S24LE; + } else if (format.sampleSize() == 32) { + spec.format = isBigEndian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE; } - } else { - spec.format = PA_SAMPLE_INVALID; + } else if (format.sampleType() == QAudioFormat::Float) { + if (format.sampleSize() == 32) + spec.format = isBigEndian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE; } return spec; |