Skip to content

Commit

Permalink
Shuffle around some checks for resampling config
Browse files Browse the repository at this point in the history
BytesPerSample and NeedsResample were getting set when an unsupported
conversion was requests, which resulted in things breaking when the
caller later tried to request unresampled data.
  • Loading branch information
tgoyne committed Sep 1, 2013
1 parent cca92ad commit 52b06a6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/core/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,25 @@ void FFMS_AudioSource::SetOutputFormat(const FFMS_ResampleOptions *opt) {
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_USER,
"Cannot change the output format after audio decoding has begun");

BytesPerSample = av_get_bytes_per_sample(static_cast<AVSampleFormat>(opt->SampleFormat)) * av_get_channel_layout_nb_channels(opt->ChannelLayout);
if (opt->SampleRate != AP.SampleRate)
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_UNSUPPORTED,
"Sample rate changes are currently unsupported.");

#ifndef WITH_AVRESAMPLE
if (opt->SampleFormat != AP.SampleFormat || opt->SampleRate != AP.SampleRate || opt->ChannelLayout != AP.ChannelLayout)
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_UNSUPPORTED,
"FFMS was not built with resampling enabled. The only supported conversion is interleaving planar audio.");
#endif

BytesPerSample = av_get_bytes_per_sample(static_cast<AVSampleFormat>(opt->SampleFormat)) * av_get_channel_layout_nb_channels(opt->ChannelLayout);
NeedsResample =
opt->SampleFormat != (int)CodecContext->sample_fmt ||
opt->SampleRate != AP.SampleRate ||
opt->ChannelLayout != AP.ChannelLayout ||
opt->ForceResample;
if (!NeedsResample) return;

if (opt->SampleRate != AP.SampleRate)
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_UNSUPPORTED,
"Sample rate changes are currently unsupported.");

#ifdef WITH_AVRESAMPLE
if (opt->SampleRate != AP.SampleRate)
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_UNSUPPORTED,
"Changing the audio sample rate is currently not supported");
if (!NeedsResample) return;

std::auto_ptr<FFMS_ResampleOptions> oldOptions(ReadOptions(ResampleContext, resample_options));
SetOptions(opt, ResampleContext, resample_options);
Expand All @@ -222,10 +224,6 @@ void FFMS_AudioSource::SetOutputFormat(const FFMS_ResampleOptions *opt) {
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_UNKNOWN,
"Could not open avresample context");
}
#else
if (opt->SampleFormat != AP.SampleFormat || opt->SampleRate != AP.SampleRate || opt->ChannelLayout != AP.ChannelLayout)
throw FFMS_Exception(FFMS_ERROR_RESAMPLING, FFMS_ERROR_UNSUPPORTED,
"FFMS was not built with resampling enabled. The only supported conversion is interleaving planar audio.");
#endif
}

Expand Down

0 comments on commit 52b06a6

Please sign in to comment.