Skip to content

Commit bbf2af2

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into encoding_yolo
2 parents 52c4d54 + 9ebac73 commit bbf2af2

File tree

12 files changed

+80
-18
lines changed

12 files changed

+80
-18
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ add_subdirectory(src/torchcodec/_core)
77
option(BUILD_TESTS "Build tests" OFF)
88
if(BUILD_TESTS)
99
enable_testing()
10-
add_subdirectory(test/decoders)
10+
add_subdirectory(test)
1111
endif()

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717
#include "torch/types.h"
1818

1919
extern "C" {
20-
#include <libavcodec/avcodec.h>
2120
#include <libavfilter/buffersink.h>
2221
#include <libavfilter/buffersrc.h>
23-
#include <libavformat/avformat.h>
2422
#include <libavutil/imgutils.h>
2523
#include <libavutil/log.h>
26-
#include <libavutil/pixdesc.h>
27-
#include <libswresample/swresample.h>
28-
#include <libswscale/swscale.h>
2924
}
3025

3126
namespace facebook::torchcodec {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_executable(
2323

2424
target_include_directories(VideoDecoderTest SYSTEM PRIVATE ${TORCH_INCLUDE_DIRS})
2525
target_include_directories(VideoDecoderTest SYSTEM PRIVATE ${libav_include_dirs})
26-
target_include_directories(VideoDecoderTest PRIVATE ../../)
26+
target_include_directories(VideoDecoderTest PRIVATE ../)
2727

2828
target_link_libraries(
2929
VideoDecoderTest
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ std::string getResourcePath(const std::string& filename) {
3434
#else
3535
std::filesystem::path dirPath = std::filesystem::path(__FILE__);
3636
std::string filepath =
37-
dirPath.parent_path().string() + "/../resources/" + filename;
37+
dirPath.parent_path().string() + "/resources/" + filename;
3838
#endif
3939
return filepath;
4040
}

test/decoders/__init__.py

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

test/samplers/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
VideoStreamMetadata,
1919
)
2020

21-
from ..utils import (
21+
from .utils import (
2222
assert_frames_equal,
2323
AV1_VIDEO,
2424
cpu_and_cuda,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919
from torchcodec.decoders import AudioDecoder, VideoDecoder
2020

21-
from ..utils import NASA_AUDIO_MP3, NASA_VIDEO
21+
from .utils import NASA_AUDIO_MP3, NASA_VIDEO
2222

2323

2424
# TODO: Expected values in these tests should be based on the assets's
Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
seek_to_pts,
4242
)
4343

44-
from ..utils import (
44+
from .utils import (
4545
assert_frames_equal,
4646
cpu_and_cuda,
4747
NASA_AUDIO,
@@ -996,6 +996,78 @@ def seek(self, offset: int, whence: int) -> bytes:
996996

997997
assert file_counter.num_seeks > last_frame_seeks
998998

999+
def test_file_like_method_check_fails(self):
1000+
class ReadMethodMissing:
1001+
def seek(self, offset: int, whence: int) -> bytes:
1002+
return bytes()
1003+
1004+
with pytest.raises(RuntimeError, match="must implement a read method"):
1005+
create_from_file_like(ReadMethodMissing(), "approximate")
1006+
1007+
class SeekMethodMissing:
1008+
def read(self, size: int) -> bytes:
1009+
return bytes()
1010+
1011+
with pytest.raises(RuntimeError, match="must implement a seek method"):
1012+
create_from_file_like(SeekMethodMissing(), "approximate")
1013+
1014+
class ReadMethodWrongSignature:
1015+
def __init__(self, file: io.RawIOBase):
1016+
self._file = file
1017+
1018+
# io.RawIOBase says we should accept a single int; wrong signature on purpose
1019+
def read(self) -> bytes:
1020+
return bytes()
1021+
1022+
def seek(self, offset: int, whence: int) -> bytes:
1023+
return self._file.seeK(offset, whence)
1024+
1025+
with pytest.raises(
1026+
TypeError, match="takes 1 positional argument but 2 were given"
1027+
):
1028+
create_from_file_like(
1029+
ReadMethodWrongSignature(open(NASA_VIDEO.path, mode="rb", buffering=0)),
1030+
"approximate",
1031+
)
1032+
1033+
class SeekMethodWrongSignature:
1034+
def __init__(self, file: io.RawIOBase):
1035+
self._file = file
1036+
1037+
def read(self, size: int) -> bytes:
1038+
return self._file.read(size)
1039+
1040+
# io.RawIOBase says we should accept two ints; wrong signature on purpose
1041+
def seek(self, offset: int) -> bytes:
1042+
return bytes()
1043+
1044+
with pytest.raises(
1045+
TypeError, match="takes 2 positional arguments but 3 were given"
1046+
):
1047+
create_from_file_like(
1048+
SeekMethodWrongSignature(open(NASA_VIDEO.path, mode="rb", buffering=0)),
1049+
"approximate",
1050+
)
1051+
1052+
def test_file_like_read_fails(self):
1053+
class BadReader(io.RawIOBase):
1054+
1055+
def __init__(self, file: io.RawIOBase):
1056+
self._file = file
1057+
1058+
def read(self, size: int) -> bytes:
1059+
# We intentionally read more than requested.
1060+
return self._file.read(size + 10)
1061+
1062+
def seek(self, offset: int, whence: int) -> bytes:
1063+
return self._file.seek(offset, whence)
1064+
1065+
with pytest.raises(RuntimeError, match="does not conform to read protocol"):
1066+
create_from_file_like(
1067+
BadReader(open(NASA_VIDEO.path, mode="rb", buffering=0)),
1068+
"approximate",
1069+
)
1070+
9991071

10001072
class TestAudioEncoderOps:
10011073

0 commit comments

Comments
 (0)