Make StreamReader return PTS (#2975)
Summary:
This commit makes `StreamReader` report PTS (presentation time stamp) of the returned chunk as well.
Example
```python
from torchaudio.io import StreamReader
s = StreamReader(...)
s.add_video_stream(...)
for (video_chunk, ) in s.stream():
# video_chunk is Torch tensor type but has extra attribute of PTS
print(video_chunk.pts) # reports the PTS of the first frame of the video chunk.
```
For the backward compatibility, we introduce a `_ChunkTensor`, that is a composition
of Tensor and metadata, but works like a normal tensor in PyTorch operations.
The implementation of `_ChunkTensor` is based on [TrivialTensorViaComposition](https://github.com/albanD/subclass_zoo/blob/0eeb1d68fb59879029c610bc407f2997ae43ba0a/trivial_tensors.py#L83).
It was also suggested to attach metadata directly to Tensor object,
but the possibility to have the collision on torchaudio's metadata and new attributes introduced in
PyTorch cannot be ignored, so we use Tensor subclass implementation.
If any unexpected issue arise from metadata attribute name collision, client code can
fetch the bare Tensor and continue.
Pull Request resolved: https://github.com/pytorch/audio/pull/2975
Reviewed By: hwangjeff
Differential Revision: D42526945
Pulled By: mthrok
fbshipit-source-id: b4e9422e914ff328421b975120460f3001268f35
Showing
Please register or sign in to comment