Skip to content

Commit d07f7d8

Browse files
committed
Update C++ tests
1 parent 890e2b4 commit d07f7d8

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

test/VideoDecoderTest.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,15 @@ double computeAverageCosineSimilarity(
146146
return averageCosineSimilarity;
147147
}
148148

149-
// TEST(DecoderOptionsTest, ConvertsFromStringToOptions) {
150-
// std::string optionsString =
151-
// "ffmpeg_thread_count=3,dimension_order=NCHW,width=100,height=120";
152-
// SingleStreamDecoder::DecoderOptions options =
153-
// SingleStreamDecoder::DecoderOptions(optionsString);
154-
// EXPECT_EQ(options.ffmpegThreadCount, 3);
155-
// }
156-
157149
TEST(SingleStreamDecoderTest, RespectsWidthAndHeightFromOptions) {
158150
std::string path = getResourcePath("nasa_13013.mp4");
159151
std::unique_ptr<SingleStreamDecoder> decoder =
160152
std::make_unique<SingleStreamDecoder>(path);
161153
VideoStreamOptions videoStreamOptions;
162154
videoStreamOptions.width = 100;
163155
videoStreamOptions.height = 120;
164-
decoder->addVideoStream(-1, videoStreamOptions);
156+
std::vector<Transform*> transforms;
157+
decoder->addVideoStream(-1, transforms, videoStreamOptions);
165158
torch::Tensor tensor = decoder->getNextFrame().data;
166159
EXPECT_EQ(tensor.sizes(), std::vector<long>({3, 120, 100}));
167160
}
@@ -172,7 +165,8 @@ TEST(SingleStreamDecoderTest, RespectsOutputTensorDimensionOrderFromOptions) {
172165
std::make_unique<SingleStreamDecoder>(path);
173166
VideoStreamOptions videoStreamOptions;
174167
videoStreamOptions.dimensionOrder = "NHWC";
175-
decoder->addVideoStream(-1, videoStreamOptions);
168+
std::vector<Transform*> transforms;
169+
decoder->addVideoStream(-1, transforms, videoStreamOptions);
176170
torch::Tensor tensor = decoder->getNextFrame().data;
177171
EXPECT_EQ(tensor.sizes(), std::vector<long>({270, 480, 3}));
178172
}
@@ -181,7 +175,8 @@ TEST_P(SingleStreamDecoderTest, ReturnsFirstTwoFramesOfVideo) {
181175
std::string path = getResourcePath("nasa_13013.mp4");
182176
std::unique_ptr<SingleStreamDecoder> ourDecoder =
183177
createDecoderFromPath(path, GetParam());
184-
ourDecoder->addVideoStream(-1);
178+
std::vector<Transform*> transforms;
179+
ourDecoder->addVideoStream(-1, transforms);
185180
auto output = ourDecoder->getNextFrame();
186181
torch::Tensor tensor0FromOurDecoder = output.data;
187182
EXPECT_EQ(tensor0FromOurDecoder.sizes(), std::vector<long>({3, 270, 480}));
@@ -220,7 +215,8 @@ TEST_P(SingleStreamDecoderTest, DecodesFramesInABatchInNCHW) {
220215
ourDecoder->scanFileAndUpdateMetadataAndIndex();
221216
int bestVideoStreamIndex =
222217
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
223-
ourDecoder->addVideoStream(bestVideoStreamIndex);
218+
std::vector<Transform*> transforms;
219+
ourDecoder->addVideoStream(bestVideoStreamIndex, transforms);
224220
// Frame with index 180 corresponds to timestamp 6.006.
225221
auto output = ourDecoder->getFramesAtIndices({0, 180});
226222
auto tensor = output.data;
@@ -244,7 +240,9 @@ TEST_P(SingleStreamDecoderTest, DecodesFramesInABatchInNHWC) {
244240
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
245241
VideoStreamOptions videoStreamOptions;
246242
videoStreamOptions.dimensionOrder = "NHWC";
247-
ourDecoder->addVideoStream(bestVideoStreamIndex, videoStreamOptions);
243+
std::vector<Transform*> transforms;
244+
ourDecoder->addVideoStream(
245+
bestVideoStreamIndex, transforms, videoStreamOptions);
248246
// Frame with index 180 corresponds to timestamp 6.006.
249247
auto output = ourDecoder->getFramesAtIndices({0, 180});
250248
auto tensor = output.data;
@@ -264,7 +262,8 @@ TEST_P(SingleStreamDecoderTest, SeeksCloseToEof) {
264262
std::string path = getResourcePath("nasa_13013.mp4");
265263
std::unique_ptr<SingleStreamDecoder> ourDecoder =
266264
createDecoderFromPath(path, GetParam());
267-
ourDecoder->addVideoStream(-1);
265+
std::vector<Transform*> transforms;
266+
ourDecoder->addVideoStream(-1, transforms);
268267
ourDecoder->setCursorPtsInSeconds(388388. / 30'000);
269268
auto output = ourDecoder->getNextFrame();
270269
EXPECT_EQ(output.ptsSeconds, 388'388. / 30'000);
@@ -277,7 +276,8 @@ TEST_P(SingleStreamDecoderTest, GetsFramePlayedAtTimestamp) {
277276
std::string path = getResourcePath("nasa_13013.mp4");
278277
std::unique_ptr<SingleStreamDecoder> ourDecoder =
279278
createDecoderFromPath(path, GetParam());
280-
ourDecoder->addVideoStream(-1);
279+
std::vector<Transform*> transforms;
280+
ourDecoder->addVideoStream(-1, transforms);
281281
auto output = ourDecoder->getFramePlayedAt(6.006);
282282
EXPECT_EQ(output.ptsSeconds, 6.006);
283283
// The frame's duration is 0.033367 according to ffprobe,
@@ -307,7 +307,8 @@ TEST_P(SingleStreamDecoderTest, SeeksToFrameWithSpecificPts) {
307307
std::string path = getResourcePath("nasa_13013.mp4");
308308
std::unique_ptr<SingleStreamDecoder> ourDecoder =
309309
createDecoderFromPath(path, GetParam());
310-
ourDecoder->addVideoStream(-1);
310+
std::vector<Transform*> transforms;
311+
ourDecoder->addVideoStream(-1, transforms);
311312
ourDecoder->setCursorPtsInSeconds(6.0);
312313
auto output = ourDecoder->getNextFrame();
313314
torch::Tensor tensor6FromOurDecoder = output.data;
@@ -410,7 +411,9 @@ TEST_P(SingleStreamDecoderTest, PreAllocatedTensorFilterGraph) {
410411
VideoStreamOptions videoStreamOptions;
411412
videoStreamOptions.colorConversionLibrary =
412413
ColorConversionLibrary::FILTERGRAPH;
413-
ourDecoder->addVideoStream(bestVideoStreamIndex, videoStreamOptions);
414+
std::vector<Transform*> transforms;
415+
ourDecoder->addVideoStream(
416+
bestVideoStreamIndex, transforms, videoStreamOptions);
414417
auto output =
415418
ourDecoder->getFrameAtIndexInternal(0, preAllocatedOutputTensor);
416419
EXPECT_EQ(output.data.data_ptr(), preAllocatedOutputTensor.data_ptr());
@@ -427,7 +430,9 @@ TEST_P(SingleStreamDecoderTest, PreAllocatedTensorSwscale) {
427430
*ourDecoder->getContainerMetadata().bestVideoStreamIndex;
428431
VideoStreamOptions videoStreamOptions;
429432
videoStreamOptions.colorConversionLibrary = ColorConversionLibrary::SWSCALE;
430-
ourDecoder->addVideoStream(bestVideoStreamIndex, videoStreamOptions);
433+
std::vector<Transform*> transforms;
434+
ourDecoder->addVideoStream(
435+
bestVideoStreamIndex, transforms, videoStreamOptions);
431436
auto output =
432437
ourDecoder->getFrameAtIndexInternal(0, preAllocatedOutputTensor);
433438
EXPECT_EQ(output.data.data_ptr(), preAllocatedOutputTensor.data_ptr());

0 commit comments

Comments
 (0)