[osx] - fix issues with turning off/on tv when playback is paused #4441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes issues which users pointed out when turning off the amp or tv over night and try to continue where left of on the next day.
This change does the following
The last one looks a bit ugly in the diff but it is really easy what it does:
a. Adds a timer which is started whenever osx tells us "lost device"
aa. that timer is canceled when we get a proper "device reset" callback from osx
ab. if this is not the case the timeout of this timer will fire that callback (after 3secs with lost device) - and so wakes up AE again.
b. The callbacks we fire are refactored into 2 methods which are dumb (not checking flags or anything)
c. The logic of when those callbacks are called is completely in the "DisplayReconfigured" method
d. In addition to the kCGDisplayBeginConfigurationFlag and kCGDisplaySetModeFlag flags we also fire the onresetdevice callback when flags == 0. This is something which is not documented in Apples API but it is definitly happening (verified with a user)
e. Before this we only fired onresetdevice when there was a valid screen given in the callback from the os. But this assumption is not true. Because when the tv is turned off osx calls us without valid screen. In that case we still need to fire the onresetdevice for AE - else the engine never wakes up again.
Lot of text - hopefully it helps in understanding what this does - and that it is really needed for gotham :)
The bug hunting can be followed here:
http://forum.xbmc.org/showthread.php?tid=185395
Thx to repstein and gigantur who really did a great job in providing logs with a dozens of testbuilds over the last weeks for tracking the issue down (and having a response time which was only a couple of hours each time!).
Also thx to @FernetMenta who did a great job in interpreting that log files and finding the race and its fix.