Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[torchcodec] fix simple decoder iteration (#59)
Summary: Pull Request resolved: #59 The previous iterable and iterator implementation had a bug, demonstrated by the test modified in this diff. The problem: 1. We were using the `SimpleVideoDecoder` as its own iterator object by directly implementing `__iter__()` and `__next__()`. 2. In `__next__()`, we were calling a core library function, `get_next_frame()`, that returned the next frame to be decoded, and advanced the internal state of the C++ decoder. 3. But we were not *initializing* the iterator. Because of the points above, for-based iteration only worked as expected on a freshly-created `SimpleVideoDecoder` object. The simplest fix is to just remove the implementations of `__iter__()` and `__next__()`. Because it implements `__len__()` and `__getitem__()`, a `SimpleVideoDecoder` is a Python sequence. Python sequences are automatically iterable through `__len__()` and `__getitem__()`. See: https://docs.python.org/3/glossary.html#term-iterable Differential Revision: D59309882
- Loading branch information