Skip to content

Commit cf5b718

Browse files
author
Molly Xu
committed
modify comments
1 parent b32e6f3 commit cf5b718

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/torchcodec/decoders/_video_decoder.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
class FallbackInfo:
2828
"""Information about decoder fallback status.
2929
30-
This class tracks whether hardware-accelerated decoding failed and the decoder
31-
fell back to software decoding.
30+
This class tracks whether the decoder fell back to CPU decoding.
3231
3332
Usage:
34-
- Use ``str(fallback_info)`` or ``print(fallback_info)`` to see the fallback status
33+
- Use ``str(fallback_info)`` or ``print(fallback_info)`` to see the cpu fallback status
3534
- Use ``bool(fallback_info)`` to check if any fallback occurred
3635
3736
Attributes:
@@ -44,13 +43,13 @@ def __init__(self):
4443
self.__video_not_supported = False
4544

4645
def __bool__(self):
47-
"""Returns True if fallback occurred (and status is known)."""
46+
"""Returns True if fallback occurred."""
4847
return self.status_known and (
4948
self.__nvcuvid_unavailable or self.__video_not_supported
5049
)
5150

5251
def __str__(self):
53-
"""Returns a human-readable string representation of the fallback status."""
52+
"""Returns a human-readable string representation of the cpu fallback status."""
5453
if not self.status_known:
5554
return "Fallback status: Unknown"
5655

@@ -223,24 +222,15 @@ def __init__(
223222
custom_frame_mappings=custom_frame_mappings_data,
224223
)
225224

226-
# Initialize fallback info
227225
self._fallback_info = FallbackInfo()
228226

229227
def __len__(self) -> int:
230228
return self._num_frames
231229

232230
@property
233231
def cpu_fallback(self) -> FallbackInfo:
234-
"""Get information about decoder fallback status.
235-
236-
Returns:
237-
FallbackInfo: Information about whether hardware-accelerated decoding
238-
failed and the decoder fell back to software decoding.
239-
240-
Note:
241-
The fallback status is only determined after the first frame access.
242-
Before that, the status will be "Unknown".
243-
"""
232+
# We can only determine whether fallback to CPU is happening after
233+
# the first frame access. Before that, the status will be "Unknown".
244234
return self._fallback_info
245235

246236
def _update_cpu_fallback(self):

test/test_decoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,10 +1790,10 @@ def test_cpu_fallback_no_fallback_on_supported_video(self):
17901790
"""Test that supported videos don't trigger fallback on CUDA."""
17911791
decoder = VideoDecoder(NASA_VIDEO.path, device="cuda")
17921792

1793-
# Access a frame to determine status
17941793
_ = decoder[0]
17951794

17961795
assert not bool(decoder.cpu_fallback)
1796+
assert "No fallback required" in str(decoder.cpu_fallback)
17971797

17981798
def test_cpu_fallback_status_cached(self):
17991799
"""Test that cpu_fallback status is determined once and then cached."""

0 commit comments

Comments
 (0)