-
Notifications
You must be signed in to change notification settings - Fork 39
Turn BytesContext into FromTensorContext #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!!
test/test_decoders.py
Outdated
def test_create_bytes_ownership(self): | ||
# Note that the bytes object we use to instantiate the decoder does not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_create_bytes_ownership(self): | |
# Note that the bytes object we use to instantiate the decoder does not | |
def test_create_bytes_ownership(self): | |
# Non-regression test for https://github.com/pytorch/torchcodec/issues/720 | |
# Note that the bytes object we use to instantiate the decoder does not |
|
||
SingleStreamDecoder::SeekMode realSeek = SingleStreamDecoder::SeekMode::exact; | ||
if (seek_mode.has_value()) { | ||
realSeek = seekModeFromString(seek_mode.value()); | ||
} | ||
|
||
auto contextHolder = std::make_unique<AVIOBytesContext>(data, length); | ||
auto contextHolder = std::make_unique<AVIOFromTensorContext>(video_tensor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm my understanding that the crux of the fix is this line, where we now pass-in the tensor which is ref-counted, instead of passing the raw underlying data which wasn't ref-counted and thus freed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!!
Fixes #720.
Reading from a raw
void*
is problematic because we have no way of claiming ownership of it. This PR makes sure reading from bytes only happens through a tensor. The tensor is effectively a smart pointer, so it ensures that we actually keep the data around. We now have both a tensor-reading context and a tensor-writing context. This PR also refactors both to share code - which we thought we may eventually need to do.The test added by this PR fails without these changes in the C++ level.