Skip to content

Commit 08c348e

Browse files
author
Molly Xu
committed
fix tests and move seekmode to metadata.h
1 parent 8bee8d7 commit 08c348e

File tree

6 files changed

+11
-37
lines changed

6 files changed

+11
-37
lines changed

src/torchcodec/_core/Metadata.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ std::optional<double> StreamMetadata::getDurationSeconds(
1414
case SeekMode::custom_frame_mappings:
1515
case SeekMode::exact:
1616
// In exact mode, use the scanned content value
17-
if (endStreamPtsSecondsFromContent.has_value() &&
18-
beginStreamPtsSecondsFromContent.has_value()) {
19-
return endStreamPtsSecondsFromContent.value() -
20-
beginStreamPtsSecondsFromContent.value();
21-
}
22-
return std::nullopt;
17+
return endStreamPtsSecondsFromContent.value() -
18+
beginStreamPtsSecondsFromContent.value();
2319
case SeekMode::approximate:
2420
if (durationSecondsFromHeader.has_value()) {
2521
return durationSecondsFromHeader.value();
@@ -38,10 +34,7 @@ double StreamMetadata::getBeginStreamSeconds(SeekMode seekMode) const {
3834
switch (seekMode) {
3935
case SeekMode::custom_frame_mappings:
4036
case SeekMode::exact:
41-
if (beginStreamPtsSecondsFromContent.has_value()) {
42-
return beginStreamPtsSecondsFromContent.value();
43-
}
44-
return 0.0;
37+
return beginStreamPtsSecondsFromContent.value();
4538
case SeekMode::approximate:
4639
return 0.0;
4740
}
@@ -53,10 +46,7 @@ std::optional<double> StreamMetadata::getEndStreamSeconds(
5346
switch (seekMode) {
5447
case SeekMode::custom_frame_mappings:
5548
case SeekMode::exact:
56-
if (endStreamPtsSecondsFromContent.has_value()) {
57-
return endStreamPtsSecondsFromContent.value();
58-
}
59-
return getDurationSeconds(seekMode);
49+
return endStreamPtsSecondsFromContent.value();
6050
case SeekMode::approximate:
6151
return getDurationSeconds(seekMode);
6252
}
@@ -67,10 +57,7 @@ std::optional<int64_t> StreamMetadata::getNumFrames(SeekMode seekMode) const {
6757
switch (seekMode) {
6858
case SeekMode::custom_frame_mappings:
6959
case SeekMode::exact:
70-
if (numFramesFromContent.has_value()) {
71-
return numFramesFromContent.value();
72-
}
73-
return std::nullopt;
60+
return numFramesFromContent.value();
7461
case SeekMode::approximate: {
7562
if (numFramesFromHeader.has_value()) {
7663
return numFramesFromHeader.value();

src/torchcodec/_core/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#include <string>
1111
#include <vector>
1212

13-
#include "SeekMode.h"
14-
1513
extern "C" {
1614
#include <libavcodec/avcodec.h>
1715
#include <libavutil/avutil.h>
@@ -20,6 +18,8 @@ extern "C" {
2018

2119
namespace facebook::torchcodec {
2220

21+
enum class SeekMode { exact, approximate, custom_frame_mappings };
22+
2323
struct StreamMetadata {
2424
// Common (video and audio) fields derived from the AVStream.
2525
int streamIndex;

src/torchcodec/_core/SeekMode.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/torchcodec/_core/SingleStreamDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "DeviceInterface.h"
1717
#include "FFMPEGCommon.h"
1818
#include "Frame.h"
19-
#include "SeekMode.h"
19+
#include "Metadata.h"
2020
#include "StreamOptions.h"
2121
#include "Transform.h"
2222

test/VideoDecoderTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class SingleStreamDecoderTest : public testing::TestWithParam<bool> {
6464

6565
auto contextHolder = std::make_unique<AVIOFromTensorContext>(tensor);
6666
return std::make_unique<SingleStreamDecoder>(
67-
std::move(contextHolder), SingleStreamDecoder::SeekMode::approximate);
67+
std::move(contextHolder), SeekMode::approximate);
6868
} else {
6969
return std::make_unique<SingleStreamDecoder>(
70-
filepath, SingleStreamDecoder::SeekMode::approximate);
70+
filepath, SeekMode::approximate);
7171
}
7272
}
7373

test/test_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_repr():
186186
bit_rate: 64000.0
187187
codec: mp3
188188
stream_index: 0
189-
duration_seconds: 13.013
189+
duration_seconds: {expected_duration_seconds_from_header}
190190
begin_stream_seconds: 0.0
191191
sample_rate: 8000
192192
num_channels: 2

0 commit comments

Comments
 (0)