Repository navigation
Description
Description
GL video memory is only usable in the exact GL context that created it. GStreamer shares a context inside one pipeline: the bin caches HAVE_CONTEXT and answers NEED_CONTEXT. Between pipelines it shares nothing unless the application hands the context over. Strom does not hand it over anywhere.
Two Strom boundaries carry decoded video from one pipeline into another:
- Media Player: an internal decode pipeline → appsink → appsrc in the flow.
- Inter Output → Inter Input:
intersinkin flow A →intersrcin flow B.
When GL memory crosses either boundary, the first GL element on the far side that converts it fails:
glcolorconvert0 input memory OpenGL context is different. we have <glcontext…1> memory has <glcontext…0>
The video branch then dies until the flow restarts. The Media Player case on macOS (VideoToolbox decodes to GL memory) is the bug that #1091 reports. The Inter case is reachable today: a GPU Vision Mixer with gl_download=false sends GL memory into Inter Output.
Thesis
- Only GL needs a shared context. CUDA, D3D12 and D3D11 memory crossed both boundaries without any context sharing on every host measured.
- Forwarding the context fixes GL at a boundary we own. The internal pipeline's bus gets a sync handler that re-posts
NEED_CONTEXTandHAVE_CONTEXTfrom an element in the flow pipeline. The flow's bin then answers from its cache, or caches what the internal pipeline created. Both sides end up in the sameGLContext, whichever pipeline starts first. webrtcsink already does this for its own session and discovery pipelines (CustomBusStreaminwebrtcsink/imp.rs). - Two flows cannot share one context without a process-wide GL context. Flows start and stop independently. A process-wide display would put all GL work of all flows on one GL thread, and a flow that hangs would take every other flow with it. At the Inter boundary the consumer downloads instead:
gldownloadin flow B reads GL memory from flow A's context without sharing. - WHEP Output's "always download" rule stays. webrtcsink uses one encoder per codec: the highest-ranked one at rank MARGINAL or above. It builds its converter for the input memory in front of that encoder whether or not the encoder takes that memory. Whether the memory works is therefore decided by that one encoder, and on every host measured the download was the right call:
- macOS: no encoder takes GL memory.
- Windows: the top encoders (
nvh26xenc,nvav1enc) do not take D3D11 memory.whepserversinkrefuses D3D12 memory at link time. GL memory into nvenc works, but nvenc falls back to a CPU copy (Couldn't get GL context). - Linux with NVIDIA: GL memory works for H.264 and H.265, but not for VP9, and Strom offers VP9 to viewers when the input is raw.
Evidence
A standalone probe, tools/gpu-context-probe on branch explore/gpu-context-probe, runs every case in its own process (gpu-context-probe all, gpu-context-probe webrtc). Hosts measured:
- macOS arm64, GStreamer 1.28.6
- Linux x86_64 with NVIDIA L4, in the
strom-full:0.7.1image (GStreamer 1.26.6). Host GStreamer 1.24.2 was also measured. - Windows 11, GStreamer 1.26.8, NVIDIA RTX 2000 Ada and Intel Arc
| Crossing (appsink→appsrc and intersink→intersrc) | No sharing | Context forwarded |
|---|---|---|
GL, glcolorconvert on the far side (macOS, Linux, Windows) |
FAIL, context is different | OK, same GLContext |
| GL from a real VideoToolbox decode (macOS) | FAIL | OK |
GL, gldownload on the far side (macOS) |
OK | — |
| CUDA (Linux, Windows) | OK | OK |
| D3D12, D3D11 (Windows) | OK | OK |
Through a real whepserversink, the probe predicted every outcome from the registry alone: "the top encoder for the codec lists the memory". The two exceptions are not about the memory rule. webrtcsink downloads CUDA itself (cudadownload ! videoconvert when cudaconvert is missing). QSV VP9 on Windows is unreliable with any memory type.
Proposed Fix
- Media Player: forward
NEED_CONTEXT/HAVE_CONTEXTfrom the internal pipeline's bus to the block's appsrc in the flow.- All context types are forwarded, not only GL.
- The handler holds only a
WeakRef. - The internal bus has no other sync handler today.
- This lets the decoder emit the memory it naturally produces, so fix(media player): keep a clip's decoded video out of GL memory #1091's restriction of the appsink to CUDA/system memory is not needed.
- Inter Input: splice
gldownloadwhen the incoming caps carrymemory:GLMemory, as a consumer-side rule invideo_adapt::decide(). The decision is on caps alone: a buffer arriving at Inter Input always comes from another pipeline's context, so no per-buffer check is needed. - WHEP Output: no change. fix(video adapt): download D3D12 and D3D11 memory for inputs that cannot take it #1093 stands, with its description corrected: the sink refuses D3D12 memory, it does not accept it and then fail.
Rejected:
- A process-wide GL display or context, for the reasons in thesis 3.
- Pinning the Media Player appsink to CUDA/system memory (fix(media player): keep a clip's decoded video out of GL memory #1091). That is a producer-side choice, and forwarding the context makes it unnecessary.
Test Case
- Media Player:
- A test through the real
create_decode_pipelineshows that aNEED_CONTEXTfrom the internal pipeline is answered by the flow's bin. - On the CI GL runner, GL memory from the internal pipeline reaches a
glcolorconvertin the flow. - Both must fail with forwarding removed. The probe reproduces "context is different" with surfaceless EGL on Linux, the environment CI uses.
- A test through the real
- Inter: GL memory into Inter Input reaches a
glcolorconvertin flow B. The test must fail without the adaptation.
Out of scope
- Keeping GL memory into WHEP Output on NVIDIA Linux, for H.264/H.265 only. That would need WHEP Output to offer only codecs whose top encoder takes the memory. It is an optimisation, not a fix.
- AV1 through
whepserversinkreported "No codec available" for every memory type on Linux. Not investigated. - QSV VP9 instability on Windows (
MFX_WRN_INCOMPATIBLE_VIDEO_PARAM, one heap-corruption crash).
Related: #1091 (Media Player GL context on macOS; thanks for the clear report and repro), #1093 (D3D downloads in video_adapt::decide()).
Activity
docs(video adapt): say why WHEP Output downloads D3D12 and D3D11 memory
fix(video adapt): download D3D12 and D3D11 memory for inputs that can…
srperens commentedon Oct 21, 2026
Area: GPU memory across pipeline boundaries (Media Player bridge, Inter Input)
About: GL frames only work in the GL context that made them, and Strom never passes a context between pipelines. GL memory crossing the Media Player bridge or Inter Output→Inter Input fails at the first GL converter on the far side.
Relates to: #1091 (same bug, producer-side fix this proposes to make unnecessary), merged #1093 (same
video_adapt::decide()rules, D3D side), #1021 and #969 (other consumer-side GL downloads), #1097 (process-wide GL display, seen from CI).References: GstContext design
Thoughts: The code matches: the internal bus has only a signal watch, and Inter Input is a bare
intersrc. Stinger clips already pin system memory, for alpha. GL buffers held in an inter channel keep flow A's context alive after A stops; worth a lifecycle test.srperens commentedon Oct 27, 2026
Open question: WHIP Input's decoders
WHIP Input runs each publisher in a session pipeline of its own. Only encoded RTP crosses into the flow, and the decoders sit in the flow pipeline: per slot, appsrc →
decodebin→videoconvert→ tee (slots.rs). So no GPU memory crosses that boundary today, and this issue does not touch WHIP Input.It is not settled that the decoders belong there. A slot is not tied to one publisher. The next session in the same slot can be a different publisher with a different codec, resolution or profile. The flow-side
decodebinthen has to follow a stream change it did not start, which is the kind of change the Media Player keeps inside its own pipeline. The alternative is a decoder inside each session pipeline, with the session forwarding its contexts to the flow as proposed here for the Media Player. A new publisher would then get a new decoder, and the flow would see one continuous raw stream.Not decided. It needs its own look: how the flow-side decodebin handles a new publisher in a reused slot today, and what moving it would cost (decoder startup per session, GPU memory crossing per frame). Until then, WHIP Input keeps its decoders where they are.
fix(media player): forward only GL contexts, and guard through the re…
fix(media player): share the flow's GL context with the internal pipe…
srperens commentedon Oct 27, 2026
The Media Player half is released in v0.7.2: #1108 (fix(media player): share the flow's GL context with the internal pipeline). It forwards GL context messages from the decode pipeline to the flow, so VideoToolbox frames reach the flow in GL memory without a copy.
Still open here: Inter Input, which needs to download GL memory that arrives from another flow's context.
🤖 Generated with Claude Code
fix(inter input): download GL memory that arrives from another flow (E…