@@ -1351,22 +1351,20 @@ void VideoDecoder::convertAudioAVFrameToFrameOutputOnCPU(
13511351 !preAllocatedOutputTensor.has_value (),
13521352 " pre-allocated audio tensor not supported yet." );
13531353
1354- const UniqueAVFrame& avFrame = avFrameStream.avFrame ;
1355-
13561354 AVSampleFormat sourceSampleFormat =
1357- static_cast <AVSampleFormat>(avFrame->format );
1355+ static_cast <AVSampleFormat>(avFrameStream. avFrame ->format );
13581356 AVSampleFormat desiredSampleFormat = AV_SAMPLE_FMT_FLTP;
1359- AVFrame* rawAVFrame = nullptr ;
1357+
13601358 UniqueAVFrame convertedAVFrame;
1361- if (sourceSampleFormat == desiredSampleFormat) {
1362- rawAVFrame = avFrame.get ();
1363- } else {
1359+ if (sourceSampleFormat != desiredSampleFormat) {
13641360 convertedAVFrame = convertAudioAVFrameSampleFormat (
1365- avFrame, sourceSampleFormat, desiredSampleFormat);
1366- rawAVFrame = convertedAVFrame.get ();
1361+ avFrameStream.avFrame , sourceSampleFormat, desiredSampleFormat);
13671362 }
1363+ const UniqueAVFrame& avFrame = (sourceSampleFormat != desiredSampleFormat)
1364+ ? convertedAVFrame
1365+ : avFrameStream.avFrame ;
13681366
1369- AVSampleFormat format = static_cast <AVSampleFormat>(rawAVFrame ->format );
1367+ AVSampleFormat format = static_cast <AVSampleFormat>(avFrame ->format );
13701368 TORCH_CHECK (
13711369 format == desiredSampleFormat,
13721370 " Something went wrong, the frame didn't get converted to the desired format. " ,
@@ -1375,8 +1373,8 @@ void VideoDecoder::convertAudioAVFrameToFrameOutputOnCPU(
13751373 " source format = " ,
13761374 av_get_sample_fmt_name (format));
13771375
1378- auto numSamples = rawAVFrame ->nb_samples ; // per channel
1379- auto numChannels = getNumChannels (rawAVFrame );
1376+ auto numSamples = avFrame ->nb_samples ; // per channel
1377+ auto numChannels = getNumChannels (avFrame );
13801378 torch::Tensor outputData =
13811379 torch::empty ({numChannels, numSamples}, torch::kFloat32 );
13821380
@@ -1385,9 +1383,7 @@ void VideoDecoder::convertAudioAVFrameToFrameOutputOnCPU(
13851383 for (auto channel = 0 ; channel < numChannels;
13861384 ++channel, outputChannelData += numBytesPerChannel) {
13871385 memcpy (
1388- outputChannelData,
1389- rawAVFrame->extended_data [channel],
1390- numBytesPerChannel);
1386+ outputChannelData, avFrame->extended_data [channel], numBytesPerChannel);
13911387 }
13921388 frameOutput.data = outputData;
13931389}
0 commit comments