Skip to content

Commit aa6e253

Browse files
committed
Create packet.reset() and add P0 TODO
1 parent f614846 commit aa6e253

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/torchcodec/_core/BetaCudaDeviceInterface.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,10 @@ void BetaCudaDeviceInterface::applyBSF(ReferenceAVPacket& packet) {
312312
// fields of the filtered packet into the original packet. The filtered packet
313313
// fields are re-set by av_packet_move_ref, so when it goes out of scope and
314314
// gets destructed, it's not going to affect the original packet.
315-
av_packet_unref(packet.get());
316-
av_packet_move_ref(packet.get(), filteredPacket.get());
315+
packet.reset(filteredPacket);
316+
// TODONVDEC P0: consider cleaner ways to do this. Maybe we should let
317+
// applyBSF return a new packet, and maybe that new packet needs to be a field
318+
// on the interface to avoid complex lifetime issues.
317319
}
318320

319321
// Parser triggers this callback within cuvidParseVideoData when a frame is

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:

0 commit comments

Comments
 (0)