Skip to content

Commit

Permalink
ao: return invalid format if no backend. fix check from u8
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jul 28, 2016
1 parent 59fef5c commit 2db000f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/QtAV/AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Q_AV_EXPORT AudioOutput : public QObject, public AVOutput
* \brief setAudioFormat
* Set/Request to use the given \l format. If it's not supported, an preferred format will be used.
* \param format requested format
* \return actual format to use
* \return actual format to use. Invalid format if backend is not available
* NOTE: Check format support may fail for some backends (OpenAL) if it's closed.
*/
AudioFormat setAudioFormat(const AudioFormat& format);
Expand Down
63 changes: 34 additions & 29 deletions src/output/audio/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,37 +457,42 @@ AudioFormat AudioOutput::setAudioFormat(const AudioFormat& format)
if (d.format == format)
return format;
d.requested = format;
if (!d.backend) {
d.format = AudioFormat();
d.scale_samples = NULL;
return AudioFormat();
}
if (d.backend->isSupported(format)) {
d.format = format;
d.updateSampleScaleFunc();
return format;
}
AudioFormat af(format);
if (d.backend) {
if (!d.backend->isSupported(format)) {
// set channel layout first so that isSupported(AudioFormat) will not always false
if (!d.backend->isSupported(format.channelLayout())) {
af.setChannelLayout(AudioFormat::ChannelLayout_Stereo); // assume stereo is supported
}
int ss = af.bytesPerSample();
while (!d.backend->isSupported(af) && !d.backend->isSupported(af.sampleFormat())) {
if (af.bytesPerSample() < 1) {
if (ss > 1) {
qWarning("No sample format found");
break;
}
af.setSampleFormat(AudioFormat::SampleFormat_Float);
ss = af.bytesPerSample();
continue;
}
if (af.isPlanar()) {
af.setSampleFormat(AudioFormat::packedSampleFormat(af.sampleFormat()));
continue;
}
if (af.isFloat()) {
if (af.bytesPerSample() == 8)
af.setSampleFormat(AudioFormat::SampleFormat_Float);
else
af.setSampleFormat(AudioFormat::SampleFormat_Signed32);
} else {
af.setSampleFormat(AudioFormat::make(af.bytesPerSample()/2, false, af.bytesPerSample() == 2 | af.isUnsigned() /* U8, no S8 */, false));
}
// set channel layout first so that isSupported(AudioFormat) will not always false
if (!d.backend->isSupported(format.channelLayout()))
af.setChannelLayout(AudioFormat::ChannelLayout_Stereo); // assume stereo is supported
bool check_up = af.bytesPerSample() == 1;
while (!d.backend->isSupported(af) && !d.backend->isSupported(af.sampleFormat())) {
if (af.isPlanar()) {
af.setSampleFormat(AudioFormat::packedSampleFormat(af.sampleFormat()));
continue;
}
if (af.isFloat()) {
if (af.bytesPerSample() == 8)
af.setSampleFormat(AudioFormat::SampleFormat_Float);
else
af.setSampleFormat(AudioFormat::SampleFormat_Signed32);
} else {
af.setSampleFormat(AudioFormat::make(af.bytesPerSample()/2, false, af.bytesPerSample() == 2 | af.isUnsigned() /* U8, no S8 */, false));
}
if (af.bytesPerSample() < 1) {
if (!check_up) {
qWarning("No sample format found");
break;
}
af.setSampleFormat(AudioFormat::SampleFormat_Float);
check_up = false;
continue;
}
}
d.format = af;
Expand Down

0 comments on commit 2db000f

Please sign in to comment.