Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[GStreamer] Use Content-Range to get the resource size when Content-L… - #1737

Open
petartijanic01 wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.46from
petartijanic01:gstreamer-content-range-size
Open

petartijanic01 wants to merge 1 commit into
WebPlatformForEmbedded:wpe-2.46from
petartijanic01:gstreamer-content-range-size

Conversation

@petartijanic01

@petartijanic01 petartijanic01 commented Oct 22, 2026 •

Copy link
Copy Markdown

…ength is missing

A server can answer a progressive media request with 206 Partial Content and
Content-Range but without Content-Length (e.g. chunked transfer encoding). The
total size is then only available in Content-Range ("bytes 0-25059330/25059331").

WebKitWebSource took the size only from Content-Length, so the resource was
reported as unseekable with no size, and MediaPlayerPrivateGStreamer set
m_isLiveStream. seekable() was empty and every seek was ignored
("ignored seek to ...").

This change takes the total size from a valid Content-Range when Content-Length
is missing, in both places. Responses with Content-Length and live streams
without Content-Range are not affected.

Fixes HbbTV test org.hbbtv_HTML52090 (seek to an unbuffered position in a
progressive MP4 must issue a Range request).

Testing: a server answering 206 + Content-Range, chunked, without
Content-Length. Before: the seek is ignored and no new request is made.
After: the seek issues "Range: bytes=14404095-" and playback continues from
the seek position.

a02cf70

Build-Tests Layout-Tests
✅ 🛠 wpe-246-amd64-build ✅ 🧪 wpe-246-amd64-layout
✅ 🛠 wpe-246-arm32-build ✅ 🧪 wpe-246-arm32-layout

…ength is missing

A server can answer a progressive media request with 206 Partial Content
and a Content-Range header but without Content-Length, for example when
the body is sent with chunked transfer encoding. The total size is then
only available as the instance length in Content-Range, for example
"bytes 0-25059330/25059331".

WebKitWebSource took the size only from Content-Length, so such a
resource was reported as having no size and not being seekable.
MediaPlayerPrivateGStreamer found no Content-Length in the response
headers either and set m_isLiveStream. maxTimeSeekable() then returned
zero, seekable() was empty and HTMLMediaElement ignored every seek.

When Content-Length is missing, take the total size from a valid
Content-Range in both places.

This fixes the HbbTV test org.hbbtv_HTML52090, where a seek to an
unbuffered position in a progressive MP4 must issue a Range request.

* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::handleMessage):
* Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(CachedResourceStreamingClient::responseReceived):
@eocanha

eocanha commented Oct 28, 2026

Copy link
Copy Markdown
Member

Looks good. Submitted it for review upstream as https://bugs.webkit.org/show_bug.cgi?id=329277 / WebKit/WebKit#78668

@eocanha eocanha added the upstream Related to an upstream bug (or should be at some point) label Oct 28, 2026
@eocanha

eocanha commented Nov 11, 2026

Copy link
Copy Markdown
Member

While trying to write a test to get the patch accepted upstream, it was difficult to me to reproduce the exact conditions you describe in the PR description. I wrote my own CGI script that forces 206 Partial Content responses without Content-Length, with Transfer-Encoding: chunked and with Content-Range: bytes <start>-<stop>/<total-media-length> headers.

Still, I noticed that no matter how I tried, upstream WebKit was always computing a duration instead of setting it to Infinity (as would happen in a live stream or in the non-live stream that you describe in the PR). This might be because the files I was serving were local ones instead of real live content (that I don't know how to simulate in a test).

Debugging the cause a bit more, I noticed that WebKit/WebKit@fee3035 (not present in wpe-2.46) brought recalculateDurationIfNeeded() and recalculateLengthAndSeekableIfNeeded() that correct the duration and make it nearly impossible to simulate a situation where a file-backed video is detected as "live", generates an Infinite duration and is regarded as non-seekable.

At this point I took a step back, tried then to create a new test case from scratch that reproduces the requirements of the HbbTV test (to which I don't have access) to see how it behaves downstream. The test description from the HbbTV documentation says:

org.hbbtv_HTML52090: "HTML5 media element seek using Content-range header"
When requested to seek to an unbuffered position in a HEAAC HTML5 media element referencing a large (much greater than 10 seconds) Unicast stream over HTTP 1.1, then the terminal shall make a Content-range header request that encompasses the seek position.

So I created test.html (read the instructions in the header about how to download the 264 MB media test file!; it must be served from a regular web server, I personally use lighttpd for that) and noticed that the duration was also set downstream through a different mechanism during an initial load:

image

There are 3 media transfers in that network activity log:

  • The first one is empty (?)
  • The second one requests the full video, is answered with HTTP 200, provides the Content-Length and is used by WebKit to get the total video size, populate the duration and declare the video as "not live" and "seekable". This one is interrupted early, and only 4.1 MB are actually downloaded.
image
  • The third one is caused by the seek to 3 min (180 s, I chose that value to be safer than with just a seek to 30 s as the HbbTV does). It's answered with an HTTP 206 Partial Content by the server, and it specifies Content-Range (including the whole size of the file) and Content-Length (of the chunk that is being downloaded, less than the whole file). However, that whole size in the content range is useless at this point, since the previous request had provided the total file length already.
image

So, at this point I would need some guidance about how to setup a test case that exercises what's happening in the original HbbTV test. This would help me to check two things:

  • That the original issue is actually reproducible in wpe-2.46 (and maybe not upstream with the introduction of the commit I mentioned at the begining, so upstreaming wouldn't be needed in this case)
  • That the PR actually fixes the problem.

Could you provide a more detailed description of what the HbbTV test is doing and where it's getting its media content from, so that we can create a neutral media content "compatible" with the test that can reproduce the same behaviour?

Thanks in advance.

@petartijanic01

Copy link
Copy Markdown
Author

Sorry for the late reply, I was on vacation until today. Thanks for looking into this, and sorry, my description was not clear enough.

The test server answers every request with 206 and Content-Range, including the first one, which has no Range header. There is no Content-Length, and the file (25 MB, 35 min AAC) is sent slowly, in 10 pieces 1 second apart. The test seeks to 1200 s about 5 s after canplay, so the download is still running. In your setup the first response was 200 with Content-Length, and a local file finishes downloading before the seek, so the bug doesn't show up.

I attached a small repro (range206-repro.zip) that does the same thing:

ffmpeg -f lavfi -i "sine=frequency=440:duration=2100" -c:a aac -b:a 96k -movflags +faststart long-audio.mp4
python3 range206_server.py long-audio.mp4 --port 8080

Then open http://localhost:8080/ (add ?cl=1 for the control case with Content-Length).

On our wpe-2.46 device the seek is ignored without the patch. With the patch, this repro passes and the seek sends "Range: bytes=13764514-".

Let me know if anything else would help.

range206-repro.zip

eocanha added a commit to eocanha/WebKit that referenced this pull request Nov 24, 2026
…ength is missing

https://bugs.webkit.org/show_bug.cgi?id=329277

Reviewed by NOBODY (OOPS!).

A server can answer a progressive media request with 206 Partial Content
and a Content-Range header but without Content-Length, for example when
the body is sent with chunked transfer encoding. The total size is then
only available as the instance length in Content-Range, for example
"bytes 0-25059330/25059331".

WebKitWebSource took the size only from Content-Length, so such a
resource was reported as having no size and not being seekable.
MediaPlayerPrivateGStreamer found no Content-Length in the response
headers either and set m_isLiveStream. Then:

- On the old wpe-2.46 version, maxTimeSeekable() then returned zero,
  seekable() was empty and HTMLMediaElement ignored every seek.
- On the current main branch, maxTimeSeekable() returns +Infinity [1],
  so seekable() is not empty and HTMLMediaElement doesn't ignore the
  seek. Instead, MediaPlayerPrivateGStreamer::seek() drops it with
  "[Seek] Live stream seek unhandled" [2]. The visible result is the
  same: no Range request is made and playback stays where it was.

When Content-Length is missing, take the total size from a valid
Content-Range in both places.

This fixes the HbbTV test org.hbbtv_HTML52090, where a seek to an
unbuffered position in a progressive MP4 must issue a Range request.

The media file has to be served in a very specific way that can't be
achieved with the regular Apache CGI infrastructure, as it controls
certain aspects of the HTTP response that this test needs to handle in a
very specific way. To tackle this, we've added a "regular" Python CGI
script that spawns a standalone ThreadingHTTPServer in a specific port
and controls all the needed aspects of the HTTP interaction for the test
to work reliably. Also, this is the reason why we need a relatively
heavy media file for this test. A smaller file wouldn't work as
intended.

[1] WebKit@081be27#diff-4376b854280205494dc9de0f08f985afd4d6584a7487c0a136adac2954c003cdR860
[2] https://github.com/WebKit/WebKit/blob/148206b06ccbac25ed70072c706335608fc0b96b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp#L715

See: WebPlatformForEmbedded/WPEWebKit#1737

Original author: Petar Tijanic <petartijanic01@gmail.com>

Test: platform/glib/http/tests/media/video-play-206-partial-content.html

* LayoutTests/http/tests/media/resources/long-audio.mp4: Added.
* LayoutTests/http/tests/resources/206-partial-content-no-content-length.py: Added.
(log): Helper log function.
(WebServerThread): Manage a standalone webserver in a background thread while the main program acts as dummy Apache CGI just to have the opportunity to spawn the standalone webserver.
(WebServerThread.__init__):
(WebServerThread.run): Code to be run in the background thread.
(WebServerThread.start_server): Starts the background task from the main thread.
(WebServerThread.stop_server): Stops the background task from the main thread.
(Handler): Controls the behaviour of the standalone webserver.
(Handler.log_message): Log helper function.
(Handler.do_GET): Process GET requests. "/media" serves the media using range requests, "/report" forces a wait until the current media chunk has been served (for seek control), "/result" lets the test webpage to provide messages to be logged to stdout (when running this server as a standalone tool from command line, for debugging), "/kill" (optionally) kills the standalone webserver before the standard lifetime has expired.
(Handler.send_body): Common response for text based responses (all except "/media").
(Handler.media): Serves the media file range requests done by the main html layout test using 206 Partial Content responses. It only provides Content-Length When "/media?cl=1" is used.
(main): Intented to work as a standalone app or as a CGI script. The CGI accepts the "port", "media_file" and "lifetime" parameters. It will spawn a standalone web server listening in "port" (8086 by default) during a maximum of "lifetime" seconds (unless manually killed by requesting "/kill"), and serving the file specified by "media_file" (path relative to the script).
* LayoutTests/platform/glib/http/tests/media/video-play-206-partial-content-expected.txt: Added.
* LayoutTests/platform/glib/http/tests/media/video-play-206-partial-content.html: Added.
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::handleMessage): Try to get the total length from the content range if the HTTP response doesn't specify one.
* Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(CachedResourceStreamingClient::responseReceived): Ditto.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream Related to an upstream bug (or should be at some point) wpe-2.46

Development

Successfully merging this pull request may close these issues.

2 participants