@@ -741,19 +741,18 @@ def test_decode_start_equal_stop(self, asset):
741
741
742
742
@pytest .mark .parametrize ("asset" , (NASA_AUDIO , NASA_AUDIO_MP3 ))
743
743
def test_multiple_calls (self , asset ):
744
- # Ensure that multiple calls are OK as long as we're decoding
745
- # "sequentially", i.e. we don't require a backwards seek.
746
- # And ensure a proper error is raised in such case.
747
- # TODO-AUDIO We shouldn't error, we should just implement the seeking
748
- # back to the beginning of the stream.
744
+ # Ensure that multiple calls to get_frames_by_pts_in_range_audio on the
745
+ # same decoder are supported and correct, whether it involves forward
746
+ # seeks or backwards seeks.
749
747
750
748
def get_reference_frames (start_seconds , stop_seconds ):
751
- # This stateless helper exists for convenience, to avoid
752
- # complicating this test with pts-to-index conversions. Eventually
753
- # we should remove it and just rely on the asset's methods.
754
- # Using this helper is OK for now: we're comparing a decoder which
755
- # seeks multiple times with a decoder which seeks only once (the one
756
- # here, treated as the reference)
749
+ # Usually we get the reference frames from the asset's methods, but
750
+ # for this specific test, this helper is more convenient, because
751
+ # relying on the asset would force us to convert all timestamps into
752
+ # indices.
753
+ # Ultimately, this test compares a "stateful decoder" which calls
754
+ # `get_frames_by_pts_in_range_audio()`` multiple times with a
755
+ # "stateless decoder" (the one here, treated as the reference)
757
756
decoder = create_from_file (str (asset .path ), seek_mode = "approximate" )
758
757
add_audio_stream (decoder )
759
758
@@ -794,23 +793,30 @@ def get_reference_frames(start_seconds, stop_seconds):
794
793
frames , get_reference_frames (start_seconds , stop_seconds )
795
794
)
796
795
797
- # but starting immediately on the same frame raises
798
- expected_match = "Audio decoder cannot seek backwards"
799
- with pytest .raises (RuntimeError , match = expected_match ):
800
- get_frames_by_pts_in_range_audio (
801
- decoder , start_seconds = stop_seconds , stop_seconds = 6
802
- )
796
+ # starting immediately on the same frame is OK
797
+ start_seconds , stop_seconds = stop_seconds , 6
798
+ frames = get_frames_by_pts_in_range_audio (
799
+ decoder , start_seconds = start_seconds , stop_seconds = stop_seconds
800
+ )
801
+ torch .testing .assert_close (
802
+ frames , get_reference_frames (start_seconds , stop_seconds )
803
+ )
803
804
804
- with pytest .raises (RuntimeError , match = expected_match ):
805
- get_frames_by_pts_in_range_audio (
806
- decoder , start_seconds = stop_seconds + 1e-4 , stop_seconds = 6
807
- )
805
+ get_frames_by_pts_in_range_audio (
806
+ decoder , start_seconds = start_seconds + 1e-4 , stop_seconds = stop_seconds
807
+ )
808
+ torch .testing .assert_close (
809
+ frames , get_reference_frames (start_seconds , stop_seconds )
810
+ )
808
811
809
- # and seeking backwards doesn't work either
810
- with pytest .raises (RuntimeError , match = expected_match ):
811
- frames = get_frames_by_pts_in_range_audio (
812
- decoder , start_seconds = 0 , stop_seconds = 2
813
- )
812
+ # seeking backwards
813
+ start_seconds , stop_seconds = 0 , 2
814
+ frames = get_frames_by_pts_in_range_audio (
815
+ decoder , start_seconds = start_seconds , stop_seconds = stop_seconds
816
+ )
817
+ torch .testing .assert_close (
818
+ frames , get_reference_frames (start_seconds , stop_seconds )
819
+ )
814
820
815
821
816
822
if __name__ == "__main__" :
0 commit comments