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.

❌ 1 New Failure, 3 Unrelated Failures

As of commit fe3317e with merge base 6f705bb (image):

NEW FAILURE - The following job has failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 2 times, most recently from 1c94f1e to 6e589f9 Compare September 4, 2026 10:18
@NicolasHug
NicolasHug removed this pull request from stack #1700 September 10, 2026 08:52
@NicolasHug
NicolasHug added this pull request to stack #1702 September 10, 2026 08:55
@NicolasHug
NicolasHug force-pushed the packet-seam-const-avpacket branch from 6e589f9 to ff5352b Compare September 10, 2026 08:55
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 ff5352b to fe3317e Compare September 11, 2026 10:53
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