Skip to content

Commit 10a5ddc

Browse files
committed
Actually fix C++ test
1 parent 2635230 commit 10a5ddc

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

test/VideoDecoderTest.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,19 @@ class SingleStreamDecoderTest : public testing::TestWithParam<bool> {
5050
outputStringStream << input.rdbuf();
5151
content_ = outputStringStream.str();
5252

53-
void* buffer = content_.data();
54-
size_t length = content_.length();
55-
auto contextHolder =
56-
std::make_unique<AVIOFromTensorContext>(buffer, length);
53+
// Note that we copy the data from the string into a new buffer. The
54+
// tensor has ownership of that buffer. This is not strictly necessary,
55+
// as the lifetime of the content_ string will outlast the decoder. But,
56+
// we do it to test the common usage where the decoder should own the
57+
// memory through the tensor.
58+
int64_t length = content_.length();
59+
char* data = new char[length];
60+
std::memcpy(data, content_.data(), length);
61+
auto deleter = [data](void*) { delete[] data; };
62+
at::Tensor tensor = at::from_blob(
63+
static_cast<void*>(data), {length}, deleter, {torch::kUInt8});
64+
65+
auto contextHolder = std::make_unique<AVIOFromTensorContext>(tensor);
5766
return std::make_unique<SingleStreamDecoder>(
5867
std::move(contextHolder), SingleStreamDecoder::SeekMode::approximate);
5968
} else {

0 commit comments

Comments
 (0)