Skip to content

Commit 1cb4890

Browse files
committed
Merge branch 'aeaenjfjanef' into nvdec-rework-frame-ordering
2 parents f55dcc0 + 186eaa4 commit 1cb4890

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

src/torchcodec/_core/BetaCudaDeviceInterface.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ static UniqueCUvideodecoder createDecoder(CUVIDEOFORMAT* videoFormat) {
9797
"x",
9898
caps.nMaxHeight);
9999

100+
// See nMaxMBCount in cuviddec.h
101+
constexpr unsigned int macroblockConstant = 256;
100102
TORCH_CHECK(
101-
videoFormat->coded_width * videoFormat->coded_height / 256 <=
103+
videoFormat->coded_width * videoFormat->coded_height /
104+
macroblockConstant <=
102105
caps.nMaxMBCount,
103106
"Video is too large (too many macroblocks). "
104-
"Provided (width * height / 256): ",
105-
videoFormat->coded_width * videoFormat->coded_height / 256,
107+
"Provided (width * height / ",
108+
macroblockConstant,
109+
"): ",
110+
videoFormat->coded_width * videoFormat->coded_height / macroblockConstant,
106111
" vs supported:",
107112
caps.nMaxMBCount);
108113

@@ -310,8 +315,10 @@ void BetaCudaDeviceInterface::applyBSF(ReferenceAVPacket& packet) {
310315
// fields of the filtered packet into the original packet. The filtered packet
311316
// fields are re-set by av_packet_move_ref, so when it goes out of scope and
312317
// gets destructed, it's not going to affect the original packet.
313-
av_packet_unref(packet.get());
314-
av_packet_move_ref(packet.get(), filteredPacket.get());
318+
packet.reset(filteredPacket);
319+
// TODONVDEC P0: consider cleaner ways to do this. Maybe we should let
320+
// applyBSF return a new packet, and maybe that new packet needs to be a field
321+
// on the interface to avoid complex lifetime issues.
315322
}
316323

317324
// Parser triggers this callback within cuvidParseVideoData when a frame is
@@ -411,6 +418,9 @@ UniqueAVFrame BetaCudaDeviceInterface::convertCudaFrameToAVFrame(
411418
avFrame->format = AV_PIX_FMT_CUDA;
412419
avFrame->pts = dispInfo.timestamp;
413420

421+
// TODONVDEC P0: Zero division error!!!
422+
// TODONVDEC P0: Move AVRational arithmetic to FFMPEGCommon, and put the
423+
// similar SingleStreamDecoder stuff there too.
414424
unsigned int frameRateNum = videoFormat_.frame_rate.numerator;
415425
unsigned int frameRateDen = videoFormat_.frame_rate.denominator;
416426
int64_t duration = static_cast<int64_t>((frameRateDen * timeBase_.den)) /

src/torchcodec/_core/FFMPEGCommon.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ AVPacket* ReferenceAVPacket::operator->() {
3333
return avPacket_;
3434
}
3535

36+
void ReferenceAVPacket::reset(ReferenceAVPacket& other) {
37+
if (this != &other) {
38+
av_packet_unref(avPacket_);
39+
av_packet_move_ref(avPacket_, other.avPacket_);
40+
}
41+
}
42+
3643
AVCodecOnlyUseForCallingAVFindBestStream
3744
makeAVCodecOnlyUseForCallingAVFindBestStream(const AVCodec* codec) {
3845
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 18, 100)

src/torchcodec/_core/FFMPEGCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class ReferenceAVPacket {
135135
~ReferenceAVPacket();
136136
AVPacket* get();
137137
AVPacket* operator->();
138+
void reset(ReferenceAVPacket& other);
138139
};
139140

140141
// av_find_best_stream is not const-correct before commit:

src/torchcodec/_core/NVDECCache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class NVDECCache {
4949
// all these parameters match.
5050
struct CacheKey {
5151
cudaVideoCodec codecType;
52-
unsigned int width;
53-
unsigned int height;
52+
uint32_t width;
53+
uint32_t height;
5454
cudaVideoChromaFormat chromaFormat;
55-
unsigned int bitDepthLumaMinus8;
56-
unsigned char numDecodeSurfaces;
55+
uint32_t bitDepthLumaMinus8;
56+
uint8_t numDecodeSurfaces;
5757

5858
CacheKey() = delete;
5959

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ UniqueAVFrame SingleStreamDecoder::decodeAVFrame(
12021202
if (status == AVERROR_EOF) {
12031203
// End of file reached. We must drain the decoder
12041204
if (useCustomInterface) {
1205+
// TODONVDEC P0: Re-think this. This should be simpler.
12051206
AutoAVPacket eofAutoPacket;
12061207
ReferenceAVPacket eofPacket(eofAutoPacket);
12071208
eofPacket->data = nullptr;

0 commit comments

Comments
 (0)