Repository navigation
[GStreamer] Use Content-Range to get the resource size when Content-L… - #1737
petartijanic01 wants to merge 1 commit into
Conversation
…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):
|
Looks good. Submitted it for review upstream as https://bugs.webkit.org/show_bug.cgi?id=329277 / WebKit/WebKit#78668 |
|
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 Still, I noticed that no matter how I tried, upstream WebKit was always computing a duration instead of setting it to 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:
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:
There are 3 media transfers in that network activity log:
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:
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. |
|
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: 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. |
…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.



…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