summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio/qaudiodecoder.cpp
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2021-08-20 15:20:54 +0200
committerDoris Verria <doris.verria@qt.io>2021-08-25 10:31:42 +0200
commit185ff0902181f29990c371d0b19b47915b172143 (patch)
tree733a45af5892e6c551c2ec261328d0855cbc1e8a /src/multimedia/audio/qaudiodecoder.cpp
parentcbe038d8fbea6d9328a6e05bfca0ee68b7040a61 (diff)
QAudioDecoder: Re-add API for setting desired audio format
Re-add API for setting/getting desired format for the decoded audio samples. Readd support on all backends with the exception of Android. - Add a warning in the docs for lack of support on Android. - Make the behavior of audioFormat() consistent on all platforms. It will return an invalid format if no format is set. Change Windows implementation to do so. - Fix the documentation for audioFormat(). The format returned is the one set to the decoder, and the decoded buffers may not have this format, in the case when it was set to an invalid one. - Some small fixes on darwin and Windows. Partly reverts af1182b5e29afa0cd69f929d54da224019707214. Fixes: QTBUG-95766 Pick-to: 6.2 Change-Id: Id1d6b33a6b9d916e272d3b9d9cee78b6f63609f3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/audio/qaudiodecoder.cpp')
-rw-r--r--src/multimedia/audio/qaudiodecoder.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp
index 610c6b332..e0587d31a 100644
--- a/src/multimedia/audio/qaudiodecoder.cpp
+++ b/src/multimedia/audio/qaudiodecoder.cpp
@@ -217,6 +217,49 @@ void QAudioDecoder::setSourceDevice(QIODevice *device)
}
/*!
+ Returns the audio format the decoder is set to.
+
+ \note This may be different than the format of the decoded
+ samples, if the audio format was set to an invalid one.
+
+ \sa setAudioFormat(), formatChanged()
+*/
+QAudioFormat QAudioDecoder::audioFormat() const
+{
+ if (decoder)
+ return decoder->audioFormat();
+ return QAudioFormat();
+}
+
+/*!
+ Set the desired audio format for decoded samples to \a format.
+
+ This property can only be set while the decoder is stopped.
+ Setting this property at other times will be ignored.
+
+ If the decoder does not support this format, \l error() will
+ be set to \c FormatError.
+
+ If you do not specify a format, the format of the decoded
+ audio itself will be used. Otherwise, some format conversion
+ will be applied.
+
+ If you wish to reset the decoded format to that of the original
+ audio file, you can specify an invalid \a format.
+
+ \warning Setting a desired audio format is not yet supported
+ on Android.
+*/
+void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
+{
+ if (isDecoding())
+ return;
+
+ if (decoder != nullptr)
+ decoder->setAudioFormat(format);
+}
+
+/*!
Returns true if a buffer is available to be read,
and false otherwise. If there is no buffer available, calling
the \l read() function will return an invalid buffer.
@@ -301,6 +344,14 @@ QAudioBuffer QAudioDecoder::read() const
*/
/*!
+ \fn void QAudioDecoder::formatChanged(const QAudioFormat &format)
+
+ Signals that the current audio format of the decoder has changed to \a format.
+
+ \sa audioFormat(), setAudioFormat()
+*/
+
+/*!
\fn void QAudioDecoder::bufferReady()
Signals that a new decoded audio buffer is available to be read.