Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/torchcodec/decoders/_core/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,8 @@ void VideoDecoder::validateFrameIndex(

VideoDecoder::DecodedOutput VideoDecoder::getFrameAtIndex(
int streamIndex,
int64_t frameIndex,
std::optional<torch::Tensor> preAllocatedOutputTensor) {
auto output = getFrameAtIndexInternal(
streamIndex, frameIndex, preAllocatedOutputTensor);
int64_t frameIndex) {
auto output = getFrameAtIndexInternal(streamIndex, frameIndex);
output.frame = MaybePermuteHWC2CHW(streamIndex, output.frame);
return output;
}
Expand Down
10 changes: 5 additions & 5 deletions src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ class VideoDecoder {
// seconds=5.999, etc.
DecodedOutput getFramePlayedAtTimestampNoDemux(double seconds);

DecodedOutput getFrameAtIndex(
DecodedOutput getFrameAtIndex(int streamIndex, int64_t frameIndex);
// This is morally private but needs to be exposed for C++ tests. Once
// getFrameAtIndex supports the preAllocatedOutputTensor parameter, we can
// move it back to private.
DecodedOutput getFrameAtIndexInternal(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move this one back to public unfortunately, because we must now rely on this one for our C++ tests. Eventually once we accept pre-allocated tensors in all high-level entrypoints, we'll be able to move it back to private.

Copy link
Contributor

@scotts scotts Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also use the friend declaration, but I'd prefer not to even mention the testing class in the implementation. I think this is fine.

Can we put a comment here, saying that morally this is a private member function, and the conditions for making it so?

int streamIndex,
int64_t frameIndex,
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
Expand Down Expand Up @@ -387,10 +391,6 @@ class VideoDecoder {
DecodedOutput& output,
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);

DecodedOutput getFrameAtIndexInternal(
int streamIndex,
int64_t frameIndex,
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
DecodedOutput getNextFrameOutputNoDemuxInternal(
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);

Expand Down
4 changes: 2 additions & 2 deletions test/decoders/VideoDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorFilterGraph) {
bestVideoStreamIndex,
VideoDecoder::VideoStreamDecoderOptions(
"color_conversion_library=filtergraph"));
auto output = ourDecoder->getFrameAtIndex(
auto output = ourDecoder->getFrameAtIndexInternal(
bestVideoStreamIndex, 0, preAllocatedOutputTensor);
EXPECT_EQ(output.frame.data_ptr(), preAllocatedOutputTensor.data_ptr());
}
Expand All @@ -418,7 +418,7 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorSwscale) {
bestVideoStreamIndex,
VideoDecoder::VideoStreamDecoderOptions(
"color_conversion_library=swscale"));
auto output = ourDecoder->getFrameAtIndex(
auto output = ourDecoder->getFrameAtIndexInternal(
bestVideoStreamIndex, 0, preAllocatedOutputTensor);
EXPECT_EQ(output.frame.data_ptr(), preAllocatedOutputTensor.data_ptr());
}
Expand Down
Loading