Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
78ab058
Let's just commit 3k loc in a single commit
NicolasHug Sep 25, 2025
b45decc
Fixes
NicolasHug Sep 26, 2025
316f218
Merge branch 'main' of github.com:pytorch/torchcodec into aeaenjfjanef
NicolasHug Sep 30, 2025
d0192ec
GetCache -> getCache
NicolasHug Sep 30, 2025
515deb5
Make UniqueCUvideodecoder a pointer on CUvideodecoder, not void
NicolasHug Sep 30, 2025
13fad10
Make device and device_variant have a default instead of being std::o…
NicolasHug Sep 30, 2025
eb8de72
Remove old registerDeviceInterface
NicolasHug Sep 30, 2025
4f7a4fb
Call std::memset
NicolasHug Sep 30, 2025
dcf3124
remove unnecessary cuda_runtime.h include, update cmake accordingly
NicolasHug Sep 30, 2025
0ad7370
abstract frameBuffer_ into a FrameBuffer class
NicolasHug Sep 30, 2025
aad142e
Cleanup BSF logic
NicolasHug Sep 30, 2025
2592888
Return int in callback instead of unsigned char
NicolasHug Sep 30, 2025
b5fe9bc
define width and height as unsigned int
NicolasHug Sep 30, 2025
5605c90
Rework frame ordering and pts matching
NicolasHug Oct 1, 2025
7494259
Merge branch 'main' of github.com:pytorch/torchcodec into aeaenjfjanef
NicolasHug Oct 1, 2025
560b376
Fix cuda context initialization
NicolasHug Oct 1, 2025
88196c5
Merge branch 'aeaenjfjanef' into nvdec-rework-frame-ordering
NicolasHug Oct 1, 2025
2a78b84
Renaming
NicolasHug Oct 1, 2025
5d194e5
Comment
NicolasHug Oct 1, 2025
d1e51b3
Merge branch 'main' of github.com:pytorch/torchcodec into aeaenjfjanef
NicolasHug Oct 2, 2025
f9c7297
Skip equality check on ffmepg 4
NicolasHug Oct 2, 2025
b7bbfb2
Merge branch 'aeaenjfjanef' into nvdec-rework-frame-ordering
NicolasHug Oct 2, 2025
390fd7c
Refac, simplify
NicolasHug Oct 2, 2025
f55dcc0
Update comment
NicolasHug Oct 2, 2025
7e4dd10
Define constant, add TODO for AVRational
NicolasHug Oct 2, 2025
f614846
Use uint32_t types
NicolasHug Oct 2, 2025
aa6e253
Create packet.reset() and add P0 TODO
NicolasHug Oct 2, 2025
186eaa4
Add TODO
NicolasHug Oct 2, 2025
1cb4890
Merge branch 'aeaenjfjanef' into nvdec-rework-frame-ordering
NicolasHug Oct 2, 2025
c5b32a4
Merge branch 'main' of github.com:pytorch/torchcodec into nvdec-rewor…
NicolasHug Oct 2, 2025
70873bf
lint
NicolasHug Oct 2, 2025
12c75e7
Add h265 support
NicolasHug Oct 2, 2025
7ea3ca9
Add h265 support
NicolasHug Oct 2, 2025
8ad66ce
Add AV1 support
NicolasHug Oct 3, 2025
f8f0402
Add BETA CUDA interface to built-in tests
NicolasHug Oct 3, 2025
bc55810
Refactor EOF packet logic
NicolasHug Oct 3, 2025
121a038
Merge branch 'main' of github.com:pytorch/torchcodec into nvdec-tests
NicolasHug Oct 4, 2025
204970e
Fix merge?
NicolasHug Oct 4, 2025
993d510
Merge branch 'nvdec-tests' into nvdec-send-eof
NicolasHug Oct 4, 2025
735e9e9
Merge branch 'main' of github.com:pytorch/torchcodec into nvdec-send-eof
NicolasHug Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions src/torchcodec/_core/BetaCudaDeviceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,28 +337,33 @@ int BetaCudaDeviceInterface::streamPropertyChange(CUVIDEOFORMAT* videoFormat) {
// Moral equivalent of avcodec_send_packet(). Here, we pass the AVPacket down to
// the NVCUVID parser.
int BetaCudaDeviceInterface::sendPacket(ReferenceAVPacket& packet) {
TORCH_CHECK(
packet.get() && packet->data && packet->size > 0,
"sendPacket received an empty packet, this is unexpected, please report.");

applyBSF(packet);

CUVIDSOURCEDATAPACKET cuvidPacket = {};
cuvidPacket.payload = packet->data;
cuvidPacket.payload_size = packet->size;
cuvidPacket.flags = CUVID_PKT_TIMESTAMP;
cuvidPacket.timestamp = packet->pts;

if (packet.get() && packet->data && packet->size > 0) {
applyBSF(packet);
return sendCuvidPacket(cuvidPacket);
}

// Regular packet with data
cuvidPacket.payload = packet->data;
cuvidPacket.payload_size = packet->size;
cuvidPacket.flags = CUVID_PKT_TIMESTAMP;
cuvidPacket.timestamp = packet->pts;
int BetaCudaDeviceInterface::sendEOFPacket() {
CUVIDSOURCEDATAPACKET cuvidPacket = {};
cuvidPacket.flags = CUVID_PKT_ENDOFSTREAM;
eofSent_ = true;

} else {
// End of stream packet
cuvidPacket.flags = CUVID_PKT_ENDOFSTREAM;
eofSent_ = true;
}
return sendCuvidPacket(cuvidPacket);
}

int BetaCudaDeviceInterface::sendCuvidPacket(
CUVIDSOURCEDATAPACKET& cuvidPacket) {
CUresult result = cuvidParseVideoData(videoParser_, &cuvidPacket);
if (result != CUDA_SUCCESS) {
return AVERROR_EXTERNAL;
}
return AVSUCCESS;
return result == CUDA_SUCCESS ? AVSUCCESS : AVERROR_EXTERNAL;
}

void BetaCudaDeviceInterface::applyBSF(ReferenceAVPacket& packet) {
Expand Down Expand Up @@ -551,17 +556,7 @@ UniqueAVFrame BetaCudaDeviceInterface::convertCudaFrameToAVFrame(
void BetaCudaDeviceInterface::flush() {
isFlushing_ = true;

// TODONVDEC P0: simplify flushing and "eofSent_" logic. We should just have a
// "sendEofPacket()" function that does the right thing, instead of setting
// CUVID_PKT_ENDOFSTREAM in different places.
if (!eofSent_) {
CUVIDSOURCEDATAPACKET cuvidPacket = {};
cuvidPacket.flags = CUVID_PKT_ENDOFSTREAM;
CUresult result = cuvidParseVideoData(videoParser_, &cuvidPacket);
if (result == CUDA_SUCCESS) {
eofSent_ = true;
}
}
sendEOFPacket();

isFlushing_ = false;

Expand Down
2 changes: 2 additions & 0 deletions src/torchcodec/_core/BetaCudaDeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BetaCudaDeviceInterface : public DeviceInterface {
}

int sendPacket(ReferenceAVPacket& packet) override;
int sendEOFPacket() override;
int receiveFrame(UniqueAVFrame& avFrame) override;
void flush() override;

Expand All @@ -61,6 +62,7 @@ class BetaCudaDeviceInterface : public DeviceInterface {
int frameReadyInDisplayOrder(CUVIDPARSERDISPINFO* dispInfo);

private:
int sendCuvidPacket(CUVIDSOURCEDATAPACKET& cuvidPacket);
// Apply bitstream filter, modifies packet in-place
void applyBSF(ReferenceAVPacket& packet);
void initializeBSF(
Expand Down
8 changes: 8 additions & 0 deletions src/torchcodec/_core/DeviceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ class DeviceInterface {
return AVERROR(ENOSYS);
}

// Send an EOF packet to flush the decoder
// Returns AVSUCCESS on success, or other AVERROR on failure
virtual int sendEOFPacket() {
TORCH_CHECK(
false, "Send EOF packet not implemented for this device interface");
return AVERROR(ENOSYS);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If SingleStreamDecoder doesn't need to call a member function, then maybe we don't need to make it a part of DeviceInterface? Since sendEOFPacket() is only called from within BetaCudaDeviceInterface, it feels more like an implementation detail for that device.

// Moral equivalent of avcodec_receive_frame()
// Returns AVSUCCESS on success, AVERROR(EAGAIN) if no frame ready,
// AVERROR_EOF if end of stream, or other AVERROR on failure
Expand Down
7 changes: 1 addition & 6 deletions src/torchcodec/_core/SingleStreamDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,12 +1220,7 @@ UniqueAVFrame SingleStreamDecoder::decodeAVFrame(
if (status == AVERROR_EOF) {
// End of file reached. We must drain the decoder
if (deviceInterface_->canDecodePacketDirectly()) {
// TODONVDEC P0: Re-think this. This should be simpler.
AutoAVPacket eofAutoPacket;
ReferenceAVPacket eofPacket(eofAutoPacket);
eofPacket->data = nullptr;
eofPacket->size = 0;
status = deviceInterface_->sendPacket(eofPacket);
status = deviceInterface_->sendEOFPacket();
} else {
status = avcodec_send_packet(
streamInfo.codecContext.get(),
Expand Down
Loading