@@ -159,74 +159,74 @@ namespace {
159
159
#if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
160
160
161
161
// 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 ,
166
166
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 ;
170
170
} else {
171
- av_channel_layout_default (&desiredLayout, desiredNumChannels );
171
+ av_channel_layout_default (&outLayout, outNumChannels );
172
172
}
173
- return desiredLayout ;
173
+ return outLayout ;
174
174
}
175
175
176
176
#else
177
177
178
178
// Same as above
179
- int64_t getDesiredChannelLayout (
180
- int desiredNumChannels ,
179
+ int64_t getOutputChannelLayout (
180
+ int outNumChannels ,
181
181
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 ;
185
185
} else {
186
- desiredLayout = av_get_default_channel_layout (desiredNumChannels );
186
+ outLayout = av_get_default_channel_layout (outNumChannels );
187
187
}
188
- return desiredLayout ;
188
+ return outLayout ;
189
189
}
190
190
#endif
191
191
} // namespace
192
192
193
- // Sets dstAVFrame' channel layout to getDesiredChannelLayout (): see doc above
193
+ // Sets dstAVFrame' channel layout to getOutputChannelLayout (): see doc above
194
194
void setChannelLayout (
195
195
UniqueAVFrame& dstAVFrame,
196
196
const UniqueAVFrame& srcAVFrame,
197
- int desiredNumChannels ) {
197
+ int outNumChannels ) {
198
198
#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 );
202
202
TORCH_CHECK (
203
203
status == AVSUCCESS,
204
204
" Couldn't copy channel layout to avFrame: " ,
205
205
getFFMPEGErrorStringFromErrorCode (status));
206
206
#else
207
207
dstAVFrame->channel_layout =
208
- getDesiredChannelLayout (desiredNumChannels , srcAVFrame);
209
- dstAVFrame->channels = desiredNumChannels ;
208
+ getOutputChannelLayout (outNumChannels , srcAVFrame);
209
+ dstAVFrame->channels = outNumChannels ;
210
210
#endif
211
211
}
212
212
213
213
SwrContext* createSwrContext (
214
214
AVSampleFormat srcSampleFormat,
215
- AVSampleFormat desiredSampleFormat ,
215
+ AVSampleFormat outSampleFormat ,
216
216
int srcSampleRate,
217
- int desiredSampleRate ,
217
+ int outSampleRate ,
218
218
const UniqueAVFrame& srcAVFrame,
219
- int desiredNumChannels ) {
219
+ int outNumChannels ) {
220
220
SwrContext* swrContext = nullptr ;
221
221
int status = AVSUCCESS;
222
222
#if LIBAVFILTER_VERSION_MAJOR > 7 // FFmpeg > 4
223
- AVChannelLayout desiredLayout =
224
- getDesiredChannelLayout (desiredNumChannels , srcAVFrame);
223
+ AVChannelLayout outLayout =
224
+ getOutputChannelLayout (outNumChannels , srcAVFrame);
225
225
status = swr_alloc_set_opts2 (
226
226
&swrContext,
227
- &desiredLayout ,
228
- desiredSampleFormat ,
229
- desiredSampleRate ,
227
+ &outLayout ,
228
+ outSampleFormat ,
229
+ outSampleRate ,
230
230
&srcAVFrame->ch_layout ,
231
231
srcSampleFormat,
232
232
srcSampleRate,
@@ -238,13 +238,12 @@ SwrContext* createSwrContext(
238
238
" Couldn't create SwrContext: " ,
239
239
getFFMPEGErrorStringFromErrorCode (status));
240
240
#else
241
- int64_t desiredLayout =
242
- getDesiredChannelLayout (desiredNumChannels, srcAVFrame);
241
+ int64_t outLayout = getOutputChannelLayout (outNumChannels, srcAVFrame);
243
242
swrContext = swr_alloc_set_opts (
244
243
nullptr ,
245
- desiredLayout ,
246
- desiredSampleFormat ,
247
- desiredSampleRate ,
244
+ outLayout ,
245
+ outSampleFormat ,
246
+ outSampleRate ,
248
247
srcAVFrame->channel_layout ,
249
248
srcSampleFormat,
250
249
srcSampleRate,
@@ -267,19 +266,19 @@ SwrContext* createSwrContext(
267
266
UniqueAVFrame convertAudioAVFrameSamples (
268
267
const UniqueSwrContext& swrContext,
269
268
const UniqueAVFrame& srcAVFrame,
270
- AVSampleFormat desiredSampleFormat ,
271
- int desiredSampleRate ,
272
- int desiredNumChannels ) {
269
+ AVSampleFormat outSampleFormat ,
270
+ int outSampleRate ,
271
+ int outNumChannels ) {
273
272
UniqueAVFrame convertedAVFrame (av_frame_alloc ());
274
273
TORCH_CHECK (
275
274
convertedAVFrame,
276
275
" Could not allocate frame for sample format conversion." );
277
276
278
- convertedAVFrame->format = static_cast <int >(desiredSampleFormat );
277
+ convertedAVFrame->format = static_cast <int >(outSampleFormat );
279
278
280
- convertedAVFrame->sample_rate = desiredSampleRate ;
279
+ convertedAVFrame->sample_rate = outSampleRate ;
281
280
int srcSampleRate = srcAVFrame->sample_rate ;
282
- if (srcSampleRate != desiredSampleRate ) {
281
+ if (srcSampleRate != outSampleRate ) {
283
282
// Note that this is an upper bound on the number of output samples.
284
283
// `swr_convert()` will likely not fill convertedAVFrame with that many
285
284
// samples if sample rate conversion is needed. It will buffer the last few
@@ -290,14 +289,14 @@ UniqueAVFrame convertAudioAVFrameSamples(
290
289
// tighter bound.
291
290
convertedAVFrame->nb_samples = av_rescale_rnd (
292
291
swr_get_delay (swrContext.get (), srcSampleRate) + srcAVFrame->nb_samples ,
293
- desiredSampleRate ,
292
+ outSampleRate ,
294
293
srcSampleRate,
295
294
AV_ROUND_UP);
296
295
} else {
297
296
convertedAVFrame->nb_samples = srcAVFrame->nb_samples ;
298
297
}
299
298
300
- setChannelLayout (convertedAVFrame, srcAVFrame, desiredNumChannels );
299
+ setChannelLayout (convertedAVFrame, srcAVFrame, outNumChannels );
301
300
302
301
auto status = av_frame_get_buffer (convertedAVFrame.get (), 0 );
303
302
TORCH_CHECK (
0 commit comments