@@ -951,9 +951,9 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
951951 (stopPts <= lastDecodedAvFrameEnd);
952952 }
953953
954- torch::Tensor lastSamples = maybeFlushSwrBuffers ();
955- if (lastSamples.numel () > 0 ) {
956- frames.push_back (lastSamples);
954+ auto lastSamples = maybeFlushSwrBuffers ();
955+ if (lastSamples.has_value () ) {
956+ frames.push_back (* lastSamples);
957957 }
958958
959959 return AudioFramesOutput{torch::cat (frames, 1 ), firstFramePtsSeconds};
@@ -1505,21 +1505,21 @@ UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormatAndSampleRate(
15051505 return convertedAVFrame;
15061506}
15071507
1508- torch::Tensor VideoDecoder::maybeFlushSwrBuffers () {
1508+ std::optional< torch::Tensor> VideoDecoder::maybeFlushSwrBuffers () {
15091509 // When sample rate conversion is involved, swresample buffers some of the
15101510 // samples in-between calls to swr_convert (see the libswresample docs).
15111511 // That's because the last few samples in a given frame require future samples
15121512 // from the next frame to be properly converted. This function flushes out the
15131513 // samples that are stored in swresample's buffers.
15141514 auto & streamInfo = streamInfos_[activeStreamIndex_];
15151515 if (!streamInfo.swrContext ) {
1516- return torch::empty ({ 0 , 0 }) ;
1516+ return std:: nullopt ;
15171517 }
15181518 auto numRemainingSamples = // this is an upper bound
15191519 swr_get_out_samples (streamInfo.swrContext .get (), 0 );
15201520
15211521 if (numRemainingSamples == 0 ) {
1522- return torch::empty ({ 0 , 0 }) ;
1522+ return std:: nullopt ;
15231523 }
15241524
15251525 torch::Tensor lastSamples = torch::empty (
0 commit comments