From dede545a7fa5447d88fe2f4a59d5031a4e1feda7 Mon Sep 17 00:00:00 2001 From: nazar-gavrylyk Date: Fri, 20 Nov 2026 20:33:00 +0100 Subject: [PATCH] #805: Docs: keep a job's regions until every helper process has exited --- docs/video-helper-protocol.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/video-helper-protocol.md b/docs/video-helper-protocol.md index c91659afc..ab5e7d279 100644 --- a/docs/video-helper-protocol.md +++ b/docs/video-helper-protocol.md @@ -71,7 +71,7 @@ encode.open → encode.opened → (encode.frame → encode.packets)… → encod | `{"op":"encode.open","job":1,"device":"nvenc:0","codec":"h264","width":1920,"height":1080,"rate":[30,1],"bitrate_kbps":15000,"profile":"high","keyint":60,"colour":{"primaries":1,"transfer":1,"matrix":1,"range":"limited"},"slots":[{"in":{"offset":0,"len":3110400},"out":{"offset":3110400,"len":1048576}},…]}` | `{"op":"encode.opened","job":1,"codec_config":"","delay":2}` | `job` is chosen by EffectCraft and is never reused. `slots` is the memory the helper may use, decided by EffectCraft. `codec_config` is the `avcC` (H.264) or `hvcC` (HEVC) record for the MP4 sample entry. `delay` is the number of frames the encoder holds back (B-frames). | | `{"op":"encode.frame","job":1,"frame":0,"slot":0}` | `{"op":"encode.packets","job":1,"frame":0,"packets":[{"offset":0,"len":41230,"pts":0,"dts":-2,"key":true}]}` | The picture is in `slots[0].in`. The reply means the slot may be reused and says where the packets are, inside `slots[0].out`. It may hold no packets (the encoder is still holding frames) or several. | | `{"op":"encode.flush","job":1,"out":{"offset":…,"len":…}}` | `{"op":"encode.packets","job":1,"frame":null,"packets":[…]}` then `{"op":"encode.flushed","job":1}` | The rest of the stream, inside `out`. EffectCraft sizes `out` for the frames the encoder still holds: at least `(delay + 1)` times the length of a slot's `out` region. A packet that still does not fit is `packet_too_large`. | -| `{"op":"encode.close","job":1}` | none | Free everything for the job. EffectCraft sends it after `encode.flushed` or `cancelled`, and frees or reuses the job's regions only then. If the helper was stopped first, there is no reply to wait for: the regions are freed once the helper process has exited, and a process that has exited cannot write to them. | +| `{"op":"encode.close","job":1}` | none | Free everything for the job. EffectCraft sends it after `encode.flushed` or `cancelled`, and frees or reuses the job's regions only then. If the helper was stopped first, there is no reply to wait for: the regions are freed only once every process that can reach them has exited (see [stopping](#timeouts-and-errors)). | | `{"op":"cancel","job":1}` | `{"op":"cancelled","job":1}` | Stop now. After it sends `cancel`, EffectCraft ignores every reply for the job except `cancelled`, so replies for frames still in flight are not protocol breaks. The helper stops using the job's regions before it replies `cancelled`, and `cancelled` ends every frame of the job that is still outstanding. | - **Packets are MP4 samples.** Each is a sequence of length-prefixed NAL units, every length a @@ -115,6 +115,12 @@ encode.open → encode.opened → (encode.frame → encode.packets)… → encod - **EffectCraft stops the helper** when it exits, closes stdout, sends a line that does not parse or does not fit, breaks the rules above, or misses a timeout. After 3 stops it is turned off and listed in `helper_blocklist.txt` until the user retries in Settings, as for effect helpers. +- **Stopping ends every process the helper started.** A child of the helper can map the exchange + file too, so the regions stay reserved until all of them have exited. EffectCraft starts the + helper in its own process group (Unix) or job object that kills its members when it closes + (Windows), kills the whole group or job, and waits until it is empty. If it cannot confirm that + (a descendant left the group), it does not reuse the regions: it drops the exchange file and + gives the next helper a new one, so a stray process can only write into a file nobody reads. What EffectCraft does with a failure: