Skip to content

Pass packets as const AVPacket& through the decode seam - #1691

Open
NicolasHug wants to merge 1 commit into
demuxer-owned-packetsfrom
packet-seam-const-avpacket
Open

Pass packets as const AVPacket& through the decode seam#1691
NicolasHug wants to merge 1 commit into
demuxer-owned-packetsfrom
packet-seam-const-avpacket

Conversation

@NicolasHug

@NicolasHug NicolasHug commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

DeviceInterface::send_packet() only ever reads the packet - the default
implementation hands it to avcodec_send_packet(), which takes a const one.
Except that BetaCuda's bitstream filter path did not: av_bsf_send_packet()
takes ownership of what it is given and resets it, so sending a packet
through the seam could empty it, silently, with nothing in the signature
saying so.

SingleStreamDecoder never noticed, because its packet is dead after the
send. PacketDecoder did: the packet it is handed is a user-visible Python
object that has to survive being decoded, so it referenced it into a
throwaway packet before every single send - a per-packet allocation, on
every device, to defend against a contract that was never stated.

State the contract instead. The seam takes a const AVPacket&, and the one
implementation that needs ownership references the packet itself, where the
reason for it is local.

@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1691

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 6e589f9 with merge base 2312413 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 3, 2026
@NicolasHug
NicolasHug force-pushed the packet-seam-const-avpacket branch from 22e7fec to d300cf7 Compare September 4, 2026 08:19
@NicolasHug
NicolasHug changed the base branch from main to demuxer-owned-packets September 4, 2026 08:25
@NicolasHug
NicolasHug force-pushed the packet-seam-const-avpacket branch from d300cf7 to 8be4e8a Compare September 4, 2026 08:55
@NicolasHug
NicolasHug force-pushed the packet-seam-const-avpacket branch from 8be4e8a to 05f579e Compare September 4, 2026 09:28
@NicolasHug
NicolasHug force-pushed the packet-seam-const-avpacket branch from 05f579e to 1c94f1e Compare September 4, 2026 10:02
DeviceInterface::send_packet() only ever reads the packet - the default
implementation hands it to avcodec_send_packet(), which takes a const one.
Except that BetaCuda's bitstream filter path did not: av_bsf_send_packet()
takes ownership of what it is given and resets it, so sending a packet
through the seam could empty it, silently, with nothing in the signature
saying so.

SingleStreamDecoder never noticed, because its packet is dead after the
send. PacketDecoder did: the packet it is handed is a user-visible Python
object that has to survive being decoded, so it referenced it into a
throwaway packet before every single send - a per-packet allocation, on
every device, to defend against a contract that was never stated.

State the contract instead. The seam takes a const AVPacket&, and the one
implementation that needs ownership references the packet itself, where the
reason for it is local.
@NicolasHug
NicolasHug force-pushed the packet-seam-const-avpacket branch from 1c94f1e to 6e589f9 Compare September 4, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant