CPowerManager::OnSleep force stop/close player even in player state pause
#1
For example: I watch or listen something and want to resume later. I hit pause and turn my TV off (HTPC standby get triggered as expected). Some hours later I switch it back on and then:

Case A (paused Media File)
Expacted Behaivor
View should display my freezed pause view

Case B (running Stream)
Expacted Behaivor
View should play the livestream

Case C (running Media File)
Expacted Behaivor
View should resume the media

Current bevaivor:
the video player start to terminate as soon as standby entering is detected. Termination does finish on standby resume

Now I start to write a plugin to fix the resume state. Maybe I would call it "resume kodi as left" or "keep kodi state on resume" or something similar.

Is this plugin realy neccesary or did I miss a setting? Or is this a platform specific bug (does happen on windows)? If it is a bug I would prepair some clean environments to reproduce it and provide many details and debug logs.

If you tell me, yes falco. It's our target to reset kodi on stanby resume, we don't want to restore the last viewed screen. Then I would write a addon to restore the view state.
But if you tell me, no falco thats a bug or there is a setting or a addon to change that behaivor then I don't want to write a addon for this.

Yes I found some addons for Kodi Car users who do have a Kodi crash on each exit, but these plugins does constantly update the resume state. I don't like this approach, it feels silly.
And I found some other people who did request the same thing but no anweres there:

https://forum.kodi.tv/showthread.php?tid...ght=resume
https://forum.kodi.tv/showthread.php?tid...ght=resume

At least Case D (timeshift) is working, but only because the host can't enter standby/hibernate during stream recording. If I force standby it would just bringt me back to the kodi home screen after resume.

I hope you could clearify if this video player termination is expected or not because I did create this thread because I would not waste time by fixing this because the kodi team is maybe already working on this.

Based on latest discussions I do already have an idea to skip player termination workarround without breaking it.
IPlayer.h:
cpp:

/**
  if this return false, player will get terminated onSleep to force an player cold start onWake to fix any unknwon issues with closed connections or session timeouts
*/
virtual bool SupportsSleep() { return false; }

The following things are known todos for warm start:
- save and restore stack
- playlist sleep support
- optical disc sleep support
- keep last used player state
- keep video display state (foreground/background)
- (force terminated player) current behaivor, maybe it's not needed anymore and only existing because of the workarround
- (force startupaction) is maybe not needed, and if it is needed it would be not part of power management because this is an PVR feature.
- skip player termination
Reply
#2
Good questions. Would like also see a solution for that.
HTPC: Windows 10 Pro 22H2, Zalman HD135, Intel i3-7100, GTX 1070, UHD ASUS BW-16D1HT
NAS: Xpenology 7.2 Update 1, Intel i5-6600
Reply
#3
At least this wasn't a feature 4 Years ago.

people like matthuisman https://github.com/matthuisman did spend many hours. I found a copy of his deleted addon:
https://github.com/drax68/kodi-resume

I wonder why he did stop maintenance because this isn't just a script like the whole other addon solutions. He did handle alot more usecases and did spend much time into a nice addon integration.
https://forum.kodi.tv/showthread.php?tid=168824

I don't research for less sophisticated plugins because I guess, if somebody spend arround 50 hours or more into something, then they did already have an overview about the alternative solutions.
There are many of it. for example https://www.youtube.com/watch?v=EfikfSfICDU but they support much less usecases. But that would be an easy start. Just replace the deprecated api calls and tweak it for your own usecase.
But why why didn't I find anything in the kodi repos?

A smart idea was referenced by
(2017-09-01, 12:15)trogggy Wrote:
(2017-09-01, 10:08)extremeaudio Wrote: I suppose this won't work with Krypton. Any replacement? This is the only thing I miss in my car Kodi installation on my android head unit.
Not quite the same, but a script to resume the last-played item on startup. I tried it on windows and it worked perfectly.
www.reddit.com/r/kodi/ 

In this reddit post is a solution with the database. It does just force to run the last unfinished media file. This is a good thing because it does remind you to mark your files as watched Big Grin
Reply
#4
I did some more investigations and figured out that acually there isn't a reset to the home screen. Everything except for the videoplayer is kept as it was. Only the videoplayer does have this termination issue

On Standby resume you keep your open window (settings window, seasons selection, movie selection. Does not matter). the only wired thing is the stopped videoplayer.

Here are two examples of enter standby with a paused videoplayer, the first one is messed with my python player event logs: "wasPlayerOpen"
https://pastebin.com/crE3YS0F Standby entered at 21:20:30

xml:
21:20:26.814 T:1384   DEBUG: CAnnouncementManager - Announcement: OnSleep from xbmc
21:20:26.814 T:1536  NOTICE: CPowerManager::OnSleep: Running sleep jobs
21:20:26.814 T:1536  NOTICE: CPowerManager::OnSleep: Stopping lirc
21:20:26.814 T:1384   DEBUG: GOT ANNOUNCEMENT, type: 8, from xbmc, message OnSleep
21:20:26.840 T:7712   DEBUG: Skin Helper Service --> Kodi_Monitor: sender xbmc - method: System.OnSleep  - data: null
21:20:26.843 T:6764   DEBUG: Skin Helper Widgets --> Kodi_Monitor: sender xbmc - method: System.OnSleep  - data: null
21:20:27.150 T:7276 WARNING: CRenderManager::WaitForBuffer - timeout waiting for buffer
21:20:28.344 T:7156 WARNING: Previous line repeats 2 times.
21:20:28.344 T:7156   ERROR: ActiveAE::ActiveAE::CActiveAE::UnconfigureSink - failed to unconfigure
21:20:28.689 T:7276 WARNING: CRenderManager::WaitForBuffer - timeout waiting for buffer
21:20:28.764 T:528   DEBUG: Thread RemoteControl 528 terminating
21:20:28.764 T:1536   DEBUG: CSaveFileStateJob:Big GrinoWork - Saving file state for video item M:\FreeTV\The_Imitation_Game_Ein_streng_geheimes_Leben_17.07.03_20-15_orf1_105_TVOON_DE.mpg.HD.cut.avi
21:20:28.813 T:1536  NOTICE: CVideoPlayer::CloseFile()
21:20:28.813 T:1536  NOTICE: VideoPlayer: waiting for threads to exit
21:20:28.814 T:4324  NOTICE: CVideoPlayer::OnExit()
21:20:28.814 T:4324  NOTICE: Closing stream player 1
21:20:28.814 T:4324  NOTICE: Waiting for audio thread to exit
21:20:28.814 T:5252   ERROR: Got MSGQ_ABORT or MSGO_IS_ERROR return true
21:20:28.814 T:5252  NOTICE: thread end: CVideoPlayerAudio::OnExit()

this one is without my python execution:
https://pastebin.com/PgDJmHfz Standby entered at 21:37:58

xml:

21:37:55.970 T:1372   DEBUG: GOT ANNOUNCEMENT, type: 8, from xbmc, message OnSleep
21:37:55.970 T:2976  NOTICE: CPowerManager::OnSleep: Running sleep jobs
21:37:55.970 T:2976  NOTICE: CPowerManager::OnSleep: Stopping lirc
21:37:55.970 T:5392   DEBUG: Thread RemoteControl 5392 terminating
21:37:55.971 T:2976   DEBUG: CSaveFileStateJob:Big GrinoWork - Saving file state for video item M:\FreeTV\The_Expendables_2_17.07.02_22-05_orf1_90_TVOON_DE.mpg.HD.cut.avi
21:37:56.001 T:2976  NOTICE: CVideoPlayer::CloseFile()
21:37:56.001 T:2976  NOTICE: VideoPlayer: waiting for threads to exit
21:37:56.003 T:5636  NOTICE: CVideoPlayer::OnExit()
21:37:56.003 T:5636  NOTICE: Closing stream player 1
21:37:56.003 T:5636  NOTICE: Waiting for audio thread to exit
21:37:56.003 T:8640   ERROR: Got MSGQ_ABORT or MSGO_IS_ERROR return true
21:37:56.003 T:8640  NOTICE: thread end: CVideoPlayerAudio::OnExit()
21:37:56.003 T:8640   DEBUG: Thread VideoPlayerAudio 8640 terminating
21:37:56.003 T:5636  NOTICE: Closing audio device
21:37:56.032 T:8928   DEBUG: Skin Helper Widgets --> Kodi_Monitor: sender xbmc - method: System.OnSleep  - data: null
21:37:56.065 T:5184   DEBUG: Skin Helper Service --> Kodi_Monitor: sender xbmc - method: System.OnSleep  - data: null

On the second run it is more clear that we close the paused video player direct after onSleep event.
It is maybe a bugfix to force sleep button press on a running video. But even if that is the case, a player stop it not needed for paused players, is it?

I found one stop trigger here:
https://github.com/xbmc/xbmc/blob/4b2259...r.cpp#L259
Normally this should by skipped by the following IsPlaying() check:
https://github.com/xbmc/xbmc/blob/4b2259....cpp#L3765

IsPlaying() check does only check for stop:
https://github.com/xbmc/xbmc/blob/3a9b82...r.cpp#L782

But a paused media is not stoped, it is playspeed 0:
https://github.com/xbmc/xbmc/blob/3a9b82....cpp#L3029
Which means the paused player got terminated as well on the current onsleep handling.

Would it be possible to use pause instead of stop during PowerManager::OnSleep()? It would be a little bit more complex because we have to prevent timeshift.

I could test the behaivor next week by removing the stop line. If resume works fine we could think about when we apply pause and when we do apply stop.

Does anybody have a point why we should not use pause instead of stop?
Reply
#5
I have great news.

Kodi does work very well without forced player termination. At least windows 10 standby does not breake the running player. Our player is even stable enoght to keep the freezed video frame during standby enter and resume.

I could create a pull request for a suspend handling without forced player termination.

My question is: do we need a setting for users who may have trouble to retain the old behaivor?

Setting: "Force player termination on entering suspend mode"
Default: false
Description: "If you have trouble with video during suspend mode resume you could force player stop to close the player during suspend. The player will get closed on suspend enter or resume.

And if we need a setting, would advancedsettings.xml be enoght? Because I may not able to integrate it into the settings ui without help.


Still, we can't replace all actions with pause. threre are 2 excludes:
!IsPausable() || IsLiveTV()
 need to be terminated with StopPlayer

All others could stay in state pause
My new function which is doing this would be called something like: application::prepairIdle() but instead of terminating everything with stopPlaying this would keep as many thing as possible in a paused state. Items which does not support an idle state like liveTV have to be terminated.
Reply
#6
This does work for me
https://github.com/xbmc/xbmc/pull/13133/...99d3da7d76

I would just write a plugin to force LiveTV if noting is played on resume.
Reply
#7
For everybod how do not follow open pull requests I have a summary.

I did close my first PR because we can't just turn the player termination off. The player termination is a highly needed workarround for all plugins which did not support resuming closed network connections or plugins which do not support session timeouts.
We did not discuss this in detail. But for my point of view we can't just tell all the developers to fix there addons, because the requirement of an very stable addon would reduce the flexibility of kodi. And in worse case our addon interface could maybe not good enoght to give them the ability to do this. We don't check this because maybe nobody did try to implement handling of closed connections or session timeouts.

I still like to push an solution without player termination, but this would not be possible as the first step.

I did create a new PR for the first step where we keep the workarround of player termination
https://github.com/xbmc/xbmc/pull/13138

After this is done I would like to push an PR where we don't terminate the player on very selected usecases like local files or smb shares.

And we did discuss alot about the whole kodi story where some of use would like to have a cold start resume. I'm not sure if I will try to push an coldstart topic in future because I don't like to waste cpu cycles with reconstructing everything.
And I don't like the need of special cold start resume crash handlings. if you try to resume to a broken state you will be in an endless crash loop of resuming to the broken state.
Reply
#8
If you need cold start resume soltions, then python is the way to do, everthing is possible with the python api, except for resume from pause onSleep to onWake pause.
 
Quote:da-anda:
Side note: I was playing with the idea to periodically store the playback progress to disc during playback (like every 10 sec). This would allow to do any kind of resume playback handling we could think of and also be a nice f.e. on app crashes or whatever to be able to resume where you left. Just as an idea.
This approach is already part of many resume plugins, I did found maybe 8 or 9 of them which are not maintained anymore.

Here is the list of todos orderd by (Bugs before features, and preconditions first):
- fix resume from memory (especially resume to pause)
- implement auto resume media on startup
- implement save state timer

It's not possible to fix the bug with python, but it's easy to implement the cold start and the save state timer.
@ksooo
For example the cold start autoresume is just dozen of python lines in autoexecute.py have a look at https://www.reddit.com/r/kodi/comments/6...nprogress/
Reply

Logout Mark Read Team Forum Stats Members Help
CPowerManager::OnSleep force stop/close player even in player state pause0