-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat(mv): enable caching for clapper #1010
Conversation
I cannot reproduce it reliably, but sometimes it will crash when dismissing, here's a backtrace:
edit: |
I will look into it when I can.
Linking for reference, where I mentioned different possibilities and why this is needed: #931 (comment). How it's done is entirely up to application to decide. But in the end cache dir or its content (except files you want to keep for next Tuba launch if any) should be deleted anyway since it might contain incomplete downloads, ideally we should detect them, but it would need work (creating PR) at GStreamer, since upstream doesn't expose that currently unfortunately. |
I'm split between setting a max limit (200mb) and checking every ~5 mins or when the media viewer closes vs just clearing on close or start, I'll make a choice later.
I think I can do it in app, by saving all completed destinations in an array and deleting every file that's in the folder but not the array when the media viewer closes |
Yeah, that could be done as workaround. Just shows that there is some logic/work here to decide and implement for you 😓. But hey, at least you do not have to care about streaming+downloading+seeking at the same time just managing files by paths in cache directory however you want. So I hope this is still useful for Tuba. |
You've done more than enough! In fact I'd suggest not overthinking cache further. Tuba is one of the first apps to use Clapper, but as other apps also start using it they'll have different needs than Tuba, so it's better if you have a generic approach so other apps decide on their own how they want to deal with cache. Libsoup's built in cache, for example, has an opinionated approach on loading, saving and flushing and when something doesn't work the way I want it to, I have to either disable it or attempt to bypass it by replicating what it does internally. |
Co-authored-by: Rafał Dzięgiel <[email protected]>
I compiled Tuba from source to test my stuff and download cache seems to be working nicely with Tuba. 👍
I pushed a commit to Clapper master that I hope will fix this. I haven't encountered any crashes anymore afterwards, but would be great if you could rebuild Clapper from latest source to confirm too. |
Awesome! Can confirm it got fixed! I added my initial cleanup implementation. It saves the locations in another array, and if there are more than 10 (I set it to 3 for testing, I will change it to 10 before merging), it will remove from the start of the array until there are 10 items max. Then will delete everything not in that array. That way there's at most 10 cached videos at a time. Also at boot, it will empty out the cache folder. I noticed a new bug: When opening this video https://mastodon.social/@anatudor/112432781314072465, the first attachment wont trigger the Notice how the 3rd video is missing from the cached items |
I did some debugging, and this is the culprit:
I'm mostly speculating again, but maybe it's because the video is short and finishes by the time it gets there? so the played_item is null? |
Thanks for help. I simply did not have time yet to look into it deeply. But if what you found is the case, then yes. It would be just that video playback cannot start playing until there is enough content downloaded and because video is very short its fully downloaded before there is enough data buffered for the playback to start. |
Should be fixed now. BTW, latest clapper-git can now also be compiled and runs on MS Windows. Just mentioning, cause you might care as I see you do windows builds of Tuba too. |
With current logic you did, it should be fairly easy to do a persistent cache across app launches. Do you think it would be plausible for Tuba? I think about adding something like Dunno if it is possible here that video at the exact same URI changes when post is updated (different video without URI change)... |
Thanks!
Awesome, I'll ask the msys2 maintainers or package it myself for msys2 when it makes it into a release!
I don't know if I want to keep the cache for Tuba between restarts to be honest (and might be better to just clear it on shutdown instead). I don't think people will like having huge files in cache that they are probably never going to play again. But I can probably see other apps needing it (?)
I believe that's close to what libsoup does for caching!
https://gitlab.gnome.org/GNOME/libsoup/-/blob/master/libsoup/cache/soup-cache.c libsoup keeps track of the media's etag, max cache/no cache headers etc to determine what to do. So if the same url has different etags, then it invalidates the previous one and caches the new one |
Thanks, but I do not want to give you additional thing to maintain. Hopefully once its in a stable release and there are some apps that can be built on Win that depend on it, then hopefully someone interested will step up and volunteer to maintain msys2 package.
👍
That would be more of a future thing to do (if needed). If Clapper were to do that checking internally, there would be few obstacles. First being that while app like Tuba uses only "https(s)" URIs that lead to video, it might not be the case for another app cause GStreamer can work with all different kind of sources. |
That's what I'm hoping for too, but I don't mind making the initial package for them!
Oh yeah, totally! I'm just pointing out how libsoup deals with urls with variable content |
I did that and made a PR (see: #1044) with changes to be added here. I think it simplifies your code a bit, since it removes custom structure and does not require you to store whole media item objects in memory (only location strings). |
Simplify code by storing only URIs and their cache file locations as strings, then use newly added "Clapper.MediaItem.cached" constructor to recreate an item.
Could you rebase this branch on top of main, pretty please? It will be easier to quickly checkout and test how this works together with recently merged GIFV looping. |
…able-clapper-caching
Done, thanks! well, didn't rebase, but merged main |
Feature freeze is finally done and I can merge this, I think it's pretty much done though I want to do some more testing. Let me know if there's any changes upstream :) |
Thanks for the rebase and update. I was a little busy this week, so haven't had much time to test this some more. I will try to do so, later today. |
No rush! It can wait if needed, next release is planned for months from now anyway |
I did some quick testing. Caching seems to work fine. For anything else I found out while testing this I did a fix PR: #1075 Mainly fixes problem with all GIFs being downloaded at once due to multiple players going "paused" and a problem created by using multiple MPRIS instances with the same name at once (seems we can simply disable MPRIS for GIFs as I think we should as all other posts have only 1 video max AFAIK - otherwise we would need to append instance number in MPRIS bus name). |
Looks like we are going to have to do that. While Mastodon only allows one video, other backends like Misskey don't have a limit I think I'll just use a uuid for the instance number 🤷 |
Oh, didn't know that. Thank you for clarifying. In this case instance numbers should be added if app might create more then 1 player with MPRIS feature at once. |
FWIW, I tried this after latest main update and seems to work fine here for me :-) |
Awesome, merging! Thanks for everything :) |
I'm not 100% sure about what cleaning up process to choose, so I'll leave it at that for now
Vapi is being to strict on clapper version matching so I sed it to 0.8.0 for now