Skip to content

Commit 2954c9b

Browse files
committed
Move type aliases, fix avioAllocContext name
1 parent 0f415c1 commit 2954c9b

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

src/torchcodec/_core/AVIOContextHolder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void AVIOContextHolder::createAVIOContext(
2727
(seek != nullptr) && ((write != nullptr) ^ (read != nullptr)),
2828
"seek method must be defined, and either write or read must be defined. "
2929
"But not both!")
30-
avioContext_.reset(AVIOAllocContext(
30+
avioContext_.reset(avioAllocContext(
3131
buffer,
3232
bufferSize,
3333
/*write_flag=*/write != nullptr,

src/torchcodec/_core/AVIOContextHolder.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ class AVIOContextHolder {
4444
// enforced by having a pure virtual methods, but we don't have any.)
4545
AVIOContextHolder() = default;
4646

47-
// These signatures are defined by FFmpeg.
48-
using AVIOReadFunction = int (*)(void*, uint8_t*, int);
49-
using AVIOWriteFunction = int (*)(void*, const uint8_t*, int);
50-
using AVIOSeekFunction = int64_t (*)(void*, int64_t, int);
51-
5247
// Deriving classes should call this function in their constructor.
5348
void createAVIOContext(
5449
AVIOReadFunction read,

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ void setFFmpegLogLevel() {
261261
av_log_set_level(logLevel);
262262
}
263263

264-
AVIOContext* AVIOAllocContext(
264+
AVIOContext* avioAllocContext(
265265
uint8_t* buffer,
266266
int buffer_size,
267267
int write_flag,
268268
void* opaque,
269-
int (*read_packet)(void* opaque, uint8_t* buf, int buf_size),
270-
int (*write_packet)(void* opaque, const uint8_t* buf, int buf_size),
271-
int64_t (*seek)(void* opaque, int64_t offset, int whence)) {
269+
AVIOReadFunction read_packet,
270+
AVIOWriteFunction write_packet,
271+
AVIOSeekFunction seek) {
272272
return avio_alloc_context(
273273
buffer,
274274
buffer_size,
@@ -279,7 +279,7 @@ AVIOContext* AVIOAllocContext(
279279
#if LIBAVFILTER_VERSION_MAJOR >= 10 // FFmpeg >= 7
280280
write_packet,
281281
#else
282-
reinterpret_cast<int (*)(void*, uint8_t*, int)>(write_packet),
282+
reinterpret_cast<AVIOWriteFunctionOld>(write_packet),
283283
#endif
284284
seek);
285285
}

src/torchcodec/_core/FFMPEGCommon.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,19 @@ bool canSwsScaleHandleUnalignedData();
177177

178178
void setFFmpegLogLevel();
179179

180-
AVIOContext* AVIOAllocContext(
180+
// These signatures are defined by FFmpeg.
181+
using AVIOReadFunction = int (*)(void*, uint8_t*, int);
182+
using AVIOWriteFunction = int (*)(void*, const uint8_t*, int); // FFmpeg >= 7
183+
using AVIOWriteFunctionOld = int (*)(void*, uint8_t*, int); // FFmpeg < 7
184+
using AVIOSeekFunction = int64_t (*)(void*, int64_t, int);
185+
186+
AVIOContext* avioAllocContext(
181187
uint8_t* buffer,
182188
int buffer_size,
183189
int write_flag,
184190
void* opaque,
185-
int (*read_packet)(void* opaque, uint8_t* buf, int buf_size),
186-
int (*write_packet)(void* opaque, const uint8_t* buf, int buf_size),
187-
int64_t (*seek)(void* opaque, int64_t offset, int whence));
191+
AVIOReadFunction read_packet,
192+
AVIOWriteFunction write_packet,
193+
AVIOSeekFunction seek);
188194

189195
} // namespace facebook::torchcodec

0 commit comments

Comments
 (0)