Skip to content

Commit f46f64a

Browse files
authored
Remove createFrom functions in C++ (#485)
1 parent 3253c8f commit f46f64a

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

src/torchcodec/decoders/_core/VideoDecoder.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,6 @@ void VideoDecoder::initializeDecoder() {
318318
initialized_ = true;
319319
}
320320

321-
std::unique_ptr<VideoDecoder> VideoDecoder::createFromFilePath(
322-
const std::string& videoFilePath,
323-
SeekMode seekMode) {
324-
return std::unique_ptr<VideoDecoder>(
325-
new VideoDecoder(videoFilePath, seekMode));
326-
}
327-
328-
std::unique_ptr<VideoDecoder> VideoDecoder::createFromBuffer(
329-
const void* buffer,
330-
size_t length,
331-
SeekMode seekMode) {
332-
return std::unique_ptr<VideoDecoder>(
333-
new VideoDecoder(buffer, length, seekMode));
334-
}
335-
336321
void VideoDecoder::createFilterGraph(
337322
StreamInfo& streamInfo,
338323
int expectedOutputHeight,

src/torchcodec/decoders/_core/VideoDecoder.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ class VideoDecoder {
2929

3030
enum class SeekMode { exact, approximate };
3131

32-
explicit VideoDecoder(const std::string& videoFilePath, SeekMode seekMode);
33-
explicit VideoDecoder(const void* buffer, size_t length, SeekMode seekMode);
34-
3532
// Creates a VideoDecoder from the video at videoFilePath.
36-
static std::unique_ptr<VideoDecoder> createFromFilePath(
33+
explicit VideoDecoder(
3734
const std::string& videoFilePath,
3835
SeekMode seekMode = SeekMode::exact);
3936

4037
// Creates a VideoDecoder from a given buffer. Note that the buffer is not
4138
// owned by the VideoDecoder.
42-
static std::unique_ptr<VideoDecoder> createFromBuffer(
39+
explicit VideoDecoder(
4340
const void* buffer,
4441
size_t length,
4542
SeekMode seekMode = SeekMode::exact);

src/torchcodec/decoders/_core/VideoDecoderOps.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ at::Tensor create_from_file(
117117
}
118118

119119
std::unique_ptr<VideoDecoder> uniqueDecoder =
120-
VideoDecoder::createFromFilePath(filenameStr, realSeek);
120+
std::make_unique<VideoDecoder>(filenameStr, realSeek);
121121

122122
return wrapDecoderPointerToTensor(std::move(uniqueDecoder));
123123
}
@@ -134,9 +134,9 @@ at::Tensor create_from_tensor(
134134
realSeek = seekModeFromString(seek_mode.value());
135135
}
136136

137-
std::unique_ptr<VideoDecoder> videoDecoder =
138-
VideoDecoder::createFromBuffer(buffer, length, realSeek);
139-
return wrapDecoderPointerToTensor(std::move(videoDecoder));
137+
std::unique_ptr<VideoDecoder> uniqueDecoder =
138+
std::make_unique<VideoDecoder>(buffer, length, realSeek);
139+
return wrapDecoderPointerToTensor(std::move(uniqueDecoder));
140140
}
141141

142142
at::Tensor create_from_buffer(
@@ -149,7 +149,7 @@ at::Tensor create_from_buffer(
149149
}
150150

151151
std::unique_ptr<VideoDecoder> uniqueDecoder =
152-
VideoDecoder::createFromBuffer(buffer, length, realSeek);
152+
std::make_unique<VideoDecoder>(buffer, length, realSeek);
153153
return wrapDecoderPointerToTensor(std::move(uniqueDecoder));
154154
}
155155

test/decoders/VideoDecoderTest.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ class VideoDecoderTest : public testing::TestWithParam<bool> {
5050
content_ = outputStringStream.str();
5151
void* buffer = content_.data();
5252
size_t length = outputStringStream.str().length();
53-
return VideoDecoder::createFromBuffer(
53+
return std::make_unique<VideoDecoder>(
5454
buffer, length, VideoDecoder::SeekMode::approximate);
5555
} else {
56-
return VideoDecoder::createFromFilePath(
56+
return std::make_unique<VideoDecoder>(
5757
filepath, VideoDecoder::SeekMode::approximate);
5858
}
5959
}
@@ -94,8 +94,7 @@ TEST_P(VideoDecoderTest, ReturnsFpsAndDurationForVideoInMetadata) {
9494

9595
TEST(VideoDecoderTest, MissingVideoFileThrowsException) {
9696
EXPECT_THROW(
97-
VideoDecoder::createFromFilePath("/this/file/does/not/exist"),
98-
std::invalid_argument);
97+
VideoDecoder("/this/file/does/not/exist"), std::invalid_argument);
9998
}
10099

101100
void dumpTensorToDisk(
@@ -145,8 +144,7 @@ double computeAverageCosineSimilarity(
145144

146145
TEST(VideoDecoderTest, RespectsWidthAndHeightFromOptions) {
147146
std::string path = getResourcePath("nasa_13013.mp4");
148-
std::unique_ptr<VideoDecoder> decoder =
149-
VideoDecoder::createFromFilePath(path);
147+
std::unique_ptr<VideoDecoder> decoder = std::make_unique<VideoDecoder>(path);
150148
VideoDecoder::VideoStreamOptions videoStreamOptions;
151149
videoStreamOptions.width = 100;
152150
videoStreamOptions.height = 120;
@@ -157,8 +155,7 @@ TEST(VideoDecoderTest, RespectsWidthAndHeightFromOptions) {
157155

158156
TEST(VideoDecoderTest, RespectsOutputTensorDimensionOrderFromOptions) {
159157
std::string path = getResourcePath("nasa_13013.mp4");
160-
std::unique_ptr<VideoDecoder> decoder =
161-
VideoDecoder::createFromFilePath(path);
158+
std::unique_ptr<VideoDecoder> decoder = std::make_unique<VideoDecoder>(path);
162159
VideoDecoder::VideoStreamOptions videoStreamOptions;
163160
videoStreamOptions.dimensionOrder = "NHWC";
164161
decoder->addVideoStreamDecoder(-1, videoStreamOptions);

0 commit comments

Comments
 (0)