-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send requested byte range from SW, with correct headers #868
Conversation
@Jaifroid : this is still a draft but it seems to solve the issue on my Chromium. |
That's good news! Great sleuthing. I'll do a test of this on Electron as soon as I can. |
It seems to me that it started working when I fixed the response HTTP status code. |
No, it was not only a matter of http status code. |
OK, interesting. At a very low level, our FileReaders (at least for compressed BLOBs in the archive) decompress data as a stream. When I implemented ZSTD decoding, a lot of the challenge was in understanding how the decoder extracts just enough of the data stream to decompress a few bytes, then loops back and asks for more bytes only if needed, stopping at the end of the requested BLOB. This means that we only decompress just enough of the data stream to get the BLOB we are looking for, even though a compressed cluster may contain several BLOBs. But I expect video BLOBs are stored without ZSTD compression, like images. |
Apart from the debug logs, that I will have to remove, this PR is ready for test/review (but no rush) |
I've tested this in Electron, by incorporating this code into the Service Worker for KJSW (on a branch). I've only tested on Windows so far. It's a great improvement on the original behaviour. 😀 Skipping forward particularly works very well. Occasionally, skipping backwards, the video will stop, and I have to press play again, but it mostly will resume from where I had skipped back to. Occasionally, it will show a reload icon and ask me to reload the video, after which it works fine again (but from the beginning). Is this your experience? By clicking backwards and forwards too many times without waiting much between clicks, eventually the video crashes. I assume this is just me overwhelming the back-end. In any case, I would definitely consider the issue to be fixed, and I wouldn't expect absolute ability to jump around in the stream, given that it is not cached in memory. @mossroy Would you like me to test other frameworks and other OS? If so, I would do a nightly build based on the branch and test the packages. |
Just a thought: if we want truly random access to the video stream, would it be worth adding a simple video cache to the Service Worker (like the memory-based assetsCache we have?). Just a Map. There would have to be logic to clear it (to free up memory) once the SW receives a request for a new video OR a new article. The downside is increased memory use by the app, but it would be no more than we already use in jQuery mode (since making a BLOB URL must be the same kind of memory requirement). |
Thanks for the test! Which ZIM file are you using to test? |
It would probably speed up seeking in videos. |
I tested with: There could be a different issue with Electron apps, to do with the non-standard use of the file:// protocol. It would be a better test for me to try with NWJS, because this uses a standard extension and standard extension URLs. I may also be causing the "stop" by the issue you point out (of clicking too far above the line). I'll test on NWJS. |
Good news: it works very well in NWJS, and it's also working well in Electron 👍. The issue with the video stopping was indeed what you identified: because I hadn't changed the video to full screen, it was quite hard to hit the video timeline perfectly. When testing in full screen, I can be sure to click exactly on the line, and then the video doesn't stop, and I can jump around, forwards and backwards, in both frameworks. There's one possible improvement. If you try "dragging" the video pip in the timeline backwards and forwards, seeking that way is very slow. On phones and tablets this is the main way people move video forward with their finger. Now these ZIMs are not well optimized for this use-case, because it's an old video.js that doesn't seem optimized for touch (video timeline is too narrow to touch properly). But you can sort of simulate it by dragging the pip with the mouse. It seems clear that when we do this, the SW is (I imagine) processing multiple requests for closely adjacent bits of the file, and it has to cancel those requests and re-request potentially multiple times a second. Would some kind of rate-limiting be possible? If not, or if it's too complicated, don't worry. Dragging does work, it's just much slower than simply clicking. To see how it "should" work, try dragging in jQuery mode. Because the video is in memory, it drags forwards and backwards at an acceptable pace, even showing some frames along the way. Improving dragging could be separate issue. You've already made a very big improvement here! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice PR!
I've commited the changes you requested, and also removed the debug logs. I also think that the dragging slowness can be considered a separate improvement. I just created #869 for that |
Port of kiwix/kiwix-js#868 Former-commit-id: 37036c9
Fixes #531