Skip to content

Commit 68939a9

Browse files
authored
Remove preAllocatedTensor from getFrameAtIndex (#322)
1 parent dc16154 commit 68939a9

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,8 @@ void VideoDecoder::validateFrameIndex(
10081008

10091009
VideoDecoder::DecodedOutput VideoDecoder::getFrameAtIndex(
10101010
int streamIndex,
1011-
int64_t frameIndex,
1012-
std::optional<torch::Tensor> preAllocatedOutputTensor) {
1013-
auto output = getFrameAtIndexInternal(
1014-
streamIndex, frameIndex, preAllocatedOutputTensor);
1011+
int64_t frameIndex) {
1012+
auto output = getFrameAtIndexInternal(streamIndex, frameIndex);
10151013
output.frame = MaybePermuteHWC2CHW(streamIndex, output.frame);
10161014
return output;
10171015
}

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ class VideoDecoder {
225225
// seconds=5.999, etc.
226226
DecodedOutput getFramePlayedAtTimestampNoDemux(double seconds);
227227

228-
DecodedOutput getFrameAtIndex(
228+
DecodedOutput getFrameAtIndex(int streamIndex, int64_t frameIndex);
229+
// This is morally private but needs to be exposed for C++ tests. Once
230+
// getFrameAtIndex supports the preAllocatedOutputTensor parameter, we can
231+
// move it back to private.
232+
DecodedOutput getFrameAtIndexInternal(
229233
int streamIndex,
230234
int64_t frameIndex,
231235
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
@@ -387,10 +391,6 @@ class VideoDecoder {
387391
DecodedOutput& output,
388392
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
389393

390-
DecodedOutput getFrameAtIndexInternal(
391-
int streamIndex,
392-
int64_t frameIndex,
393-
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
394394
DecodedOutput getNextFrameOutputNoDemuxInternal(
395395
std::optional<torch::Tensor> preAllocatedOutputTensor = std::nullopt);
396396

test/decoders/VideoDecoderTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorFilterGraph) {
400400
bestVideoStreamIndex,
401401
VideoDecoder::VideoStreamDecoderOptions(
402402
"color_conversion_library=filtergraph"));
403-
auto output = ourDecoder->getFrameAtIndex(
403+
auto output = ourDecoder->getFrameAtIndexInternal(
404404
bestVideoStreamIndex, 0, preAllocatedOutputTensor);
405405
EXPECT_EQ(output.frame.data_ptr(), preAllocatedOutputTensor.data_ptr());
406406
}
@@ -418,7 +418,7 @@ TEST_P(VideoDecoderTest, PreAllocatedTensorSwscale) {
418418
bestVideoStreamIndex,
419419
VideoDecoder::VideoStreamDecoderOptions(
420420
"color_conversion_library=swscale"));
421-
auto output = ourDecoder->getFrameAtIndex(
421+
auto output = ourDecoder->getFrameAtIndexInternal(
422422
bestVideoStreamIndex, 0, preAllocatedOutputTensor);
423423
EXPECT_EQ(output.frame.data_ptr(), preAllocatedOutputTensor.data_ptr());
424424
}

0 commit comments

Comments
 (0)