@@ -159,74 +159,74 @@ namespace {
159159#if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
160160
161161// Returns:
162- // - the srcAVFrame's channel layout if srcAVFrame has desiredNumChannels
163- // - the default channel layout with desiredNumChannels otherwise.
164- AVChannelLayout getDesiredChannelLayout (
165- int desiredNumChannels ,
162+ // - the srcAVFrame's channel layout if srcAVFrame has outNumChannels
163+ // - the default channel layout with outNumChannels otherwise.
164+ AVChannelLayout getOutputChannelLayout (
165+ int outNumChannels ,
166166 const UniqueAVFrame& srcAVFrame) {
167- AVChannelLayout desiredLayout ;
168- if (desiredNumChannels == getNumChannels (srcAVFrame)) {
169- desiredLayout = srcAVFrame->ch_layout ;
167+ AVChannelLayout outLayout ;
168+ if (outNumChannels == getNumChannels (srcAVFrame)) {
169+ outLayout = srcAVFrame->ch_layout ;
170170 } else {
171- av_channel_layout_default (&desiredLayout, desiredNumChannels );
171+ av_channel_layout_default (&outLayout, outNumChannels );
172172 }
173- return desiredLayout ;
173+ return outLayout ;
174174}
175175
176176#else
177177
178178// Same as above
179- int64_t getDesiredChannelLayout (
180- int desiredNumChannels ,
179+ int64_t getOutputChannelLayout (
180+ int outNumChannels ,
181181 const UniqueAVFrame& srcAVFrame) {
182- int64_t desiredLayout ;
183- if (desiredNumChannels == getNumChannels (srcAVFrame)) {
184- desiredLayout = srcAVFrame->channel_layout ;
182+ int64_t outLayout ;
183+ if (outNumChannels == getNumChannels (srcAVFrame)) {
184+ outLayout = srcAVFrame->channel_layout ;
185185 } else {
186- desiredLayout = av_get_default_channel_layout (desiredNumChannels );
186+ outLayout = av_get_default_channel_layout (outNumChannels );
187187 }
188- return desiredLayout ;
188+ return outLayout ;
189189}
190190#endif
191191} // namespace
192192
193- // Sets dstAVFrame' channel layout to getDesiredChannelLayout (): see doc above
193+ // Sets dstAVFrame' channel layout to getOutputChannelLayout (): see doc above
194194void setChannelLayout (
195195 UniqueAVFrame& dstAVFrame,
196196 const UniqueAVFrame& srcAVFrame,
197- int desiredNumChannels ) {
197+ int outNumChannels ) {
198198#if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
199- AVChannelLayout desiredLayout =
200- getDesiredChannelLayout (desiredNumChannels , srcAVFrame);
201- auto status = av_channel_layout_copy (&dstAVFrame->ch_layout , &desiredLayout );
199+ AVChannelLayout outLayout =
200+ getOutputChannelLayout (outNumChannels , srcAVFrame);
201+ auto status = av_channel_layout_copy (&dstAVFrame->ch_layout , &outLayout );
202202 TORCH_CHECK (
203203 status == AVSUCCESS,
204204 " Couldn't copy channel layout to avFrame: " ,
205205 getFFMPEGErrorStringFromErrorCode (status));
206206#else
207207 dstAVFrame->channel_layout =
208- getDesiredChannelLayout (desiredNumChannels , srcAVFrame);
209- dstAVFrame->channels = desiredNumChannels ;
208+ getOutputChannelLayout (outNumChannels , srcAVFrame);
209+ dstAVFrame->channels = outNumChannels ;
210210#endif
211211}
212212
213213SwrContext* createSwrContext (
214214 AVSampleFormat srcSampleFormat,
215- AVSampleFormat desiredSampleFormat ,
215+ AVSampleFormat outSampleFormat ,
216216 int srcSampleRate,
217- int desiredSampleRate ,
217+ int outSampleRate ,
218218 const UniqueAVFrame& srcAVFrame,
219- int desiredNumChannels ) {
219+ int outNumChannels ) {
220220 SwrContext* swrContext = nullptr ;
221221 int status = AVSUCCESS;
222222#if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
223- AVChannelLayout desiredLayout =
224- getDesiredChannelLayout (desiredNumChannels , srcAVFrame);
223+ AVChannelLayout outLayout =
224+ getOutputChannelLayout (outNumChannels , srcAVFrame);
225225 status = swr_alloc_set_opts2 (
226226 &swrContext,
227- &desiredLayout ,
228- desiredSampleFormat ,
229- desiredSampleRate ,
227+ &outLayout ,
228+ outSampleFormat ,
229+ outSampleRate ,
230230 &srcAVFrame->ch_layout ,
231231 srcSampleFormat,
232232 srcSampleRate,
@@ -238,13 +238,12 @@ SwrContext* createSwrContext(
238238 " Couldn't create SwrContext: " ,
239239 getFFMPEGErrorStringFromErrorCode (status));
240240#else
241- int64_t desiredLayout =
242- getDesiredChannelLayout (desiredNumChannels, srcAVFrame);
241+ int64_t outLayout = getOutputChannelLayout (outNumChannels, srcAVFrame);
243242 swrContext = swr_alloc_set_opts (
244243 nullptr ,
245- desiredLayout ,
246- desiredSampleFormat ,
247- desiredSampleRate ,
244+ outLayout ,
245+ outSampleFormat ,
246+ outSampleRate ,
248247 srcAVFrame->channel_layout ,
249248 srcSampleFormat,
250249 srcSampleRate,
@@ -267,19 +266,19 @@ SwrContext* createSwrContext(
267266UniqueAVFrame convertAudioAVFrameSamples (
268267 const UniqueSwrContext& swrContext,
269268 const UniqueAVFrame& srcAVFrame,
270- AVSampleFormat desiredSampleFormat ,
271- int desiredSampleRate ,
272- int desiredNumChannels ) {
269+ AVSampleFormat outSampleFormat ,
270+ int outSampleRate ,
271+ int outNumChannels ) {
273272 UniqueAVFrame convertedAVFrame (av_frame_alloc ());
274273 TORCH_CHECK (
275274 convertedAVFrame,
276275 " Could not allocate frame for sample format conversion." );
277276
278- convertedAVFrame->format = static_cast <int >(desiredSampleFormat );
277+ convertedAVFrame->format = static_cast <int >(outSampleFormat );
279278
280- convertedAVFrame->sample_rate = desiredSampleRate ;
279+ convertedAVFrame->sample_rate = outSampleRate ;
281280 int srcSampleRate = srcAVFrame->sample_rate ;
282- if (srcSampleRate != desiredSampleRate ) {
281+ if (srcSampleRate != outSampleRate ) {
283282 // Note that this is an upper bound on the number of output samples.
284283 // `swr_convert()` will likely not fill convertedAVFrame with that many
285284 // samples if sample rate conversion is needed. It will buffer the last few
@@ -290,14 +289,14 @@ UniqueAVFrame convertAudioAVFrameSamples(
290289 // tighter bound.
291290 convertedAVFrame->nb_samples = av_rescale_rnd (
292291 swr_get_delay (swrContext.get (), srcSampleRate) + srcAVFrame->nb_samples ,
293- desiredSampleRate ,
292+ outSampleRate ,
294293 srcSampleRate,
295294 AV_ROUND_UP);
296295 } else {
297296 convertedAVFrame->nb_samples = srcAVFrame->nb_samples ;
298297 }
299298
300- setChannelLayout (convertedAVFrame, srcAVFrame, desiredNumChannels );
299+ setChannelLayout (convertedAVFrame, srcAVFrame, outNumChannels );
301300
302301 auto status = av_frame_get_buffer (convertedAVFrame.get (), 0 );
303302 TORCH_CHECK (
0 commit comments