Skip to content

Commit f36d050

Browse files
committed
Make exception args tuple; refactor visiblity of context stuff
1 parent 3608b50 commit f36d050

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/torchcodec/decoders/_core/AVIOContextHolder.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
namespace facebook::torchcodec {
1212

13-
// These signatures are defined by FFmpeg.
14-
using AVIOReadFunction = int (*)(void*, uint8_t*, int);
15-
using AVIOSeekFunction = int64_t (*)(void*, int64_t, int);
16-
1713
// The AVIOContextHolder serves several purposes:
1814
//
1915
// 1. It is a smart pointer for the AVIOContext. It has the logic to create
@@ -33,7 +29,7 @@ using AVIOSeekFunction = int64_t (*)(void*, int64_t, int);
3329
// write callback functions.
3430
// While it's not required, it is natural for the derived classes to make
3531
// all of the above members. Base classes need to call
36-
// createAVIOContext(), ideally in there constructor.
32+
// createAVIOContext(), ideally in their constructor.
3733
// 3. A generic handle for those that just need to manage having access to an
3834
// AVIOContext, but aren't necessarily concerned with how it was customized.
3935
class AVIOContextHolder {
@@ -47,6 +43,10 @@ class AVIOContextHolder {
4743
// enforced by having a pure virtual methods, but we don't have any.)
4844
AVIOContextHolder() = default;
4945

46+
// These signatures are defined by FFmpeg.
47+
using AVIOReadFunction = int (*)(void*, uint8_t*, int);
48+
using AVIOSeekFunction = int64_t (*)(void*, int64_t, int);
49+
5050
// Deriving classes should call this function in their constructor.
5151
void createAVIOContext(
5252
AVIOReadFunction read,

src/torchcodec/decoders/_core/AVIOFileLikeContext.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ namespace py = pybind11;
1515

1616
namespace facebook::torchcodec {
1717

18-
// Necessary to make sure that we hold the GIL when we delete a py::object.
19-
struct PyObjectDeleter {
20-
inline void operator()(py::object* obj) const {
21-
if (obj) {
22-
py::gil_scoped_acquire gil;
23-
delete obj;
24-
}
25-
}
26-
};
27-
28-
using UniquePyObject = std::unique_ptr<py::object, PyObjectDeleter>;
29-
3018
class AVIOFileLikeContext : public AVIOContextHolder {
3119
public:
3220
explicit AVIOFileLikeContext(py::object fileLike);
@@ -43,6 +31,16 @@ class AVIOFileLikeContext : public AVIOContextHolder {
4331
// and that's, at least, hard. For all of the common pitfalls, see:
4432
//
4533
// https://pybind11.readthedocs.io/en/stable/advanced/misc.html#common-sources-of-global-interpreter-lock-errors
34+
struct PyObjectDeleter {
35+
inline void operator()(py::object* obj) const {
36+
if (obj) {
37+
py::gil_scoped_acquire gil;
38+
delete obj;
39+
}
40+
}
41+
};
42+
43+
using UniquePyObject = std::unique_ptr<py::object, PyObjectDeleter>;
4644
UniquePyObject fileLike_;
4745
};
4846

src/torchcodec/decoders/_core/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def load_torchcodec_extension():
5454
except Exception as e:
5555
# TODO: recording and reporting exceptions this way is OK for now as it's just for debugging,
5656
# but we should probably handle that via a proper logging mechanism.
57-
exceptions.append(ffmpeg_major_version, e)
57+
exceptions.append((ffmpeg_major_version, e))
5858

5959
traceback = (
6060
"\n[start of libtorchcodec loading traceback]\n"

0 commit comments

Comments
 (0)