diff --git a/src/torchcodec/_core/FFMPEGCommon.cpp b/src/torchcodec/_core/FFMPEGCommon.cpp index 262b67dfd..a8740b1f6 100644 --- a/src/torchcodec/_core/FFMPEGCommon.cpp +++ b/src/torchcodec/_core/FFMPEGCommon.cpp @@ -161,9 +161,9 @@ void setChannelLayout( } SwrContext* createSwrContext( - AVSampleFormat sourceSampleFormat, + AVSampleFormat srcSampleFormat, AVSampleFormat desiredSampleFormat, - int sourceSampleRate, + int srcSampleRate, int desiredSampleRate, const UniqueAVFrame& srcAVFrame, int desiredNumChannels) { @@ -178,8 +178,8 @@ SwrContext* createSwrContext( desiredSampleFormat, desiredSampleRate, &srcAVFrame->ch_layout, - sourceSampleFormat, - sourceSampleRate, + srcSampleFormat, + srcSampleRate, 0, nullptr); @@ -196,8 +196,8 @@ SwrContext* createSwrContext( desiredSampleFormat, desiredSampleRate, srcAVFrame->channel_layout, - sourceSampleFormat, - sourceSampleRate, + srcSampleFormat, + srcSampleRate, 0, nullptr); #endif @@ -228,8 +228,8 @@ UniqueAVFrame convertAudioAVFrameSamples( convertedAVFrame->format = static_cast(desiredSampleFormat); convertedAVFrame->sample_rate = desiredSampleRate; - int sourceSampleRate = srcAVFrame->sample_rate; - if (sourceSampleRate != desiredSampleRate) { + int srcSampleRate = srcAVFrame->sample_rate; + if (srcSampleRate != desiredSampleRate) { // Note that this is an upper bound on the number of output samples. // `swr_convert()` will likely not fill convertedAVFrame with that many // samples if sample rate conversion is needed. It will buffer the last few @@ -239,10 +239,9 @@ UniqueAVFrame convertAudioAVFrameSamples( // output samples, but empirically `av_rescale_rnd()` seems to provide a // tighter bound. convertedAVFrame->nb_samples = av_rescale_rnd( - swr_get_delay(swrContext.get(), sourceSampleRate) + - srcAVFrame->nb_samples, + swr_get_delay(swrContext.get(), srcSampleRate) + srcAVFrame->nb_samples, desiredSampleRate, - sourceSampleRate, + srcSampleRate, AV_ROUND_UP); } else { convertedAVFrame->nb_samples = srcAVFrame->nb_samples; diff --git a/src/torchcodec/_core/FFMPEGCommon.h b/src/torchcodec/_core/FFMPEGCommon.h index 4281689e2..d0d3a6823 100644 --- a/src/torchcodec/_core/FFMPEGCommon.h +++ b/src/torchcodec/_core/FFMPEGCommon.h @@ -161,9 +161,9 @@ void setChannelLayout( int desiredNumChannels); SwrContext* createSwrContext( - AVSampleFormat sourceSampleFormat, + AVSampleFormat srcSampleFormat, AVSampleFormat desiredSampleFormat, - int sourceSampleRate, + int srcSampleRate, int desiredSampleRate, const UniqueAVFrame& srcAVFrame, int desiredNumChannels); diff --git a/src/torchcodec/_core/SingleStreamDecoder.cpp b/src/torchcodec/_core/SingleStreamDecoder.cpp index 770f78bd4..b73f7038d 100644 --- a/src/torchcodec/_core/SingleStreamDecoder.cpp +++ b/src/torchcodec/_core/SingleStreamDecoder.cpp @@ -1184,40 +1184,40 @@ FrameOutput SingleStreamDecoder::convertAVFrameToFrameOutput( void SingleStreamDecoder::convertAudioAVFrameToFrameOutputOnCPU( UniqueAVFrame& srcAVFrame, FrameOutput& frameOutput) { - AVSampleFormat sourceSampleFormat = + AVSampleFormat srcSampleFormat = static_cast(srcAVFrame->format); AVSampleFormat desiredSampleFormat = AV_SAMPLE_FMT_FLTP; StreamInfo& streamInfo = streamInfos_[activeStreamIndex_]; - int sourceSampleRate = srcAVFrame->sample_rate; + int srcSampleRate = srcAVFrame->sample_rate; int desiredSampleRate = - streamInfo.audioStreamOptions.sampleRate.value_or(sourceSampleRate); + streamInfo.audioStreamOptions.sampleRate.value_or(srcSampleRate); - int sourceNumChannels = getNumChannels(streamInfo.codecContext); + int srcNumChannels = getNumChannels(streamInfo.codecContext); TORCH_CHECK( - sourceNumChannels == getNumChannels(srcAVFrame), + srcNumChannels == getNumChannels(srcAVFrame), "The frame has ", getNumChannels(srcAVFrame), " channels, expected ", - sourceNumChannels, + srcNumChannels, ". If you are hitting this, it may be because you are using " "a buggy FFmpeg version. FFmpeg4 is known to fail here in some " "valid scenarios. Try to upgrade FFmpeg?"); int desiredNumChannels = - streamInfo.audioStreamOptions.numChannels.value_or(sourceNumChannels); + streamInfo.audioStreamOptions.numChannels.value_or(srcNumChannels); bool mustConvert = - (sourceSampleFormat != desiredSampleFormat || - sourceSampleRate != desiredSampleRate || - sourceNumChannels != desiredNumChannels); + (srcSampleFormat != desiredSampleFormat || + srcSampleRate != desiredSampleRate || + srcNumChannels != desiredNumChannels); UniqueAVFrame convertedAVFrame; if (mustConvert) { if (!streamInfo.swrContext) { streamInfo.swrContext.reset(createSwrContext( - sourceSampleFormat, + srcSampleFormat, desiredSampleFormat, - sourceSampleRate, + srcSampleRate, desiredSampleRate, srcAVFrame, desiredNumChannels));