Skip to content

gst1-plugins-bad, gst1-plugins-base: fix DASH bitrate and GL uploads - #31543

Draft
dangowrt wants to merge 2 commits into
openwrt:masterfrom
dangowrt:gst1-plugins-bad-adaptivedemux-latency
Draft

dangowrt wants to merge 2 commits into
openwrt:masterfrom
dangowrt:gst1-plugins-bad-adaptivedemux-latency

Conversation

@dangowrt

@dangowrt dangowrt commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

📦 Package Details

Maintainer: @flyn-org @thess

Description:
Two GStreamer fixes, one commit per package.

gst1-plugins-bad, patch 102: the legacy adaptive demuxer library (libgstadaptivedemux, used by dashdemux, hlsdemux and mssdemux) estimates the link bandwidth per fragment as its size divided by the time from starting the download to its end. That time includes the request round trip and the wait for the first byte. With live DASH in 2 s segments and a few hundred milliseconds to the first byte, which is common at the live edge of a CDN, the estimate follows the fragment size instead of the link: the small fragments of calm scenes read as a slow link, and since the demuxer takes the minimum of the last fragment and the average of the last three, times 0.8, a single small fragment is enough to switch down. tagesschau24 (dashdemux in WPE WebKit) dropped from 720p (3.2 Mbit/s) to 540p or 360p every few seconds to minutes on a Wi-Fi link delivering 55 to 80 Mbit/s.

Patch 102 times the transfer from the first buffer to the end of the fragment and uses that bitrate, or the whole-request bitrate where it is higher. A fragment that arrives in a single buffer has no measurable transfer; for it, the previous estimate is kept and only raised to the whole-request bitrate, since that is a lower bound of the link bandwidth. The patch adds one field to GstAdaptiveDemuxStream, which the demuxers built from the same source pick up.

gst1-plugins-base, patch 101: GStreamer GL uploads a texture plane with GL_UNPACK_ROW_LENGTH set to the plane stride but leaves GL_UNPACK_ALIGNMENT at its default of 4 on desktop GL and GLES 3 (gst_gl_memory_texsubimage()). GL starts every source row at a multiple of the unpack alignment, so a plane whose stride is not a multiple of 4 is read with a rounded-up stride and past its end. Decoders usually pad their strides, but the Widevine CDM puts out tightly packed I420: WPE WebKit drew YouTube's 240p (426x240, 213 byte chroma rows) and 480p (854x480, 427 byte chroma rows) as green garbage, while 144p and 360p were fine. Patch 101 sets the unpack alignment to the largest power of two up to 8 that divides the stride, as the GLES 2 path already does with its alignment, and resets it afterwards. Patch 202 is refreshed for the new context.

Each package's PKG_RELEASE is bumped once. Neither patch is submitted upstream yet.

LLM use: the cause analyses, both patches, their tests, the packaging, the commit messages and this description were written with LLM coding agents working under my direction, which also ran the tests below on my device.


🔬 Run Testing Details

  • OpenWrt Version: SNAPSHOT (main, with a port for the device below)
  • OpenWrt Target/Subtarget: sunxi/cortexa53
  • OpenWrt Device: AmediaTech X98H (Allwinner H618, Mali-G31 with Mesa panfrost), WPE WebKit 2.54.3, Wi-Fi
  • Patch 102, tagesschau24 live DASH in WPE WebKit (<video> with playbin and dashdemux), video resolution sampled once a second from the DRM plane state:
    • unpatched: 56 resolution switches in 900 s, and 78 in 1000 s in a second run;
    • patched: 360p for the first 2 s, then 1280x720 without a switch for the remaining 11.5 min.
  • With curl on the device, 720p segments download at 55 to 80 Mbit/s. A trace of WebKit's network process showed 128 to 717 kB per 2 s 720p segment and 80 to 440 ms to the first byte.
  • A deterministic dashdemux test with a test clock (400 ms to the first byte, 50 Mbit/s, 1.6 and 3.2 Mbit/s representations) passes 1 of 3 cases unpatched and 3 of 3 patched. The hls_demux (13) and mssdemux (12) check programs pass with and without the patch.
  • Patch 101, on the device without a display (GST_GL_PLATFORM=egl GST_GL_WINDOW=surfaceless), a tightly packed 854x480 I420 frame repeated 20 times through rawvideoparse ! glupload ! glcolorconvert ! video/x-raw(memory:GLMemory),format=RGBA ! gldownload:
    • unpatched: strides 854/427 give an all-green picture and two different outputs for identical input frames; the same picture repacked to strides 856/428 renders correctly;
    • patched: strides 854/427 render the same as 856/428, all 20 frames identical; a 640x360 frame renders the same as before.
  • Patch 101 in YouTube's TV web app with Widevine in WPE WebKit: 480p (854x480) plays with a correct picture and 0 dropped frames, where it was green garbage unpatched.

✅ Formalities

  • I have reviewed the contributing guidelines.
  • I have reviewed the AI policy.
    • I have used AI or LLM in my pull request, description, or commit
      messages, and the description says what it was used for.

If your PR contains a patch:

  • It can be applied using git am
  • It has been refreshed to avoid offsets, fuzzes, etc.
  • It is structured in a way that it is potentially upstreamable

The legacy adaptive demuxer library divides a fragment's size by the
time from starting its download to its end, so the request round trip
and the wait for the first byte count as transfer time. With 2 s live
DASH segments and a few hundred milliseconds to the first byte, the
small fragments of calm scenes read as a slow link, and dashdemux
switches tagesschau24 from 720p down to 540p or 360p on a link with
more than ten times the bandwidth 720p needs.

Add a patch timing the transfer from the first buffer to the end of
the fragment, so that the estimate follows the link. It adds a field
to the library's stream struct; the demuxers using it are built from
the same source.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@flyn-org

flyn-org commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Is the patch upstream?

GStreamer GL uploads a plane with GL_UNPACK_ROW_LENGTH set to its
stride but leaves GL_UNPACK_ALIGNMENT at 4, so GL reads a plane whose
stride is not a multiple of 4 with a rounded-up stride and past its
end. The Widevine CDM puts out tightly packed I420, and WebKit draws
YouTube's 240p and 480p, with 213 and 427 byte chroma rows, as green
garbage. Add a patch setting the unpack alignment from the stride.
Patch 202 is refreshed for the new context.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@dangowrt dangowrt changed the title gst1-plugins-bad: time adaptive bitrate over the transfer gst1-plugins-bad, gst1-plugins-base: fix DASH bitrate and GL uploads Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants