@@ -890,16 +890,15 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
890
890
std::optional<double > stopSecondsOptional) {
891
891
validateActiveStream (AVMEDIA_TYPE_AUDIO);
892
892
893
- double stopSeconds =
894
- stopSecondsOptional.value_or (std::numeric_limits<double >::max ());
895
-
896
- TORCH_CHECK (
897
- startSeconds <= stopSeconds,
898
- " Start seconds (" + std::to_string (startSeconds) +
899
- " ) must be less than or equal to stop seconds (" +
900
- std::to_string (stopSeconds) + " )." );
893
+ if (stopSecondsOptional.has_value ()) {
894
+ TORCH_CHECK (
895
+ startSeconds <= *stopSecondsOptional,
896
+ " Start seconds (" + std::to_string (startSeconds) +
897
+ " ) must be less than or equal to stop seconds (" +
898
+ std::to_string (*stopSecondsOptional) + " )." );
899
+ }
901
900
902
- if (startSeconds == stopSeconds ) {
901
+ if (stopSecondsOptional. has_value () && startSeconds == *stopSecondsOptional ) {
903
902
// For consistency with video
904
903
return AudioFramesOutput{torch::empty ({0 , 0 }), 0.0 };
905
904
}
@@ -912,7 +911,7 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
912
911
// If we need to seek backwards, then we have to seek back to the beginning
913
912
// of the stream.
914
913
// See [Audio Decoding Design].
915
- setCursorPtsInSecondsInternal (INT64_MIN);
914
+ setCursor (INT64_MIN);
916
915
}
917
916
918
917
// TODO-AUDIO Pre-allocate a long-enough tensor instead of creating a vec +
@@ -921,7 +920,9 @@ VideoDecoder::AudioFramesOutput VideoDecoder::getFramesPlayedInRangeAudio(
921
920
std::vector<torch::Tensor> frames;
922
921
923
922
std::optional<double > firstFramePtsSeconds = std::nullopt;
924
- auto stopPts = secondsToClosestPts (stopSeconds, streamInfo.timeBase );
923
+ auto stopPts = stopSecondsOptional.has_value ()
924
+ ? secondsToClosestPts (*stopSecondsOptional, streamInfo.timeBase )
925
+ : INT64_MAX;
925
926
auto finished = false ;
926
927
while (!finished) {
927
928
try {
@@ -971,13 +972,13 @@ void VideoDecoder::setCursorPtsInSeconds(double seconds) {
971
972
// We don't allow public audio decoding APIs to seek, see [Audio Decoding
972
973
// Design]
973
974
validateActiveStream (AVMEDIA_TYPE_VIDEO);
974
- setCursorPtsInSecondsInternal (seconds);
975
+ setCursor (
976
+ secondsToClosestPts (seconds, streamInfos_[activeStreamIndex_].timeBase ));
975
977
}
976
978
977
- void VideoDecoder::setCursorPtsInSecondsInternal ( double seconds ) {
979
+ void VideoDecoder::setCursor ( int64_t pts ) {
978
980
cursorWasJustSet_ = true ;
979
- cursor_ =
980
- secondsToClosestPts (seconds, streamInfos_[activeStreamIndex_].timeBase );
981
+ cursor_ = pts;
981
982
}
982
983
983
984
/*
0 commit comments