sync on main thread

This commit is contained in:
j 2023-11-14 12:26:33 +01:00
parent 8e9236a176
commit a604bdfab9

View file

@ -36,6 +36,7 @@ class Sync(Thread):
reload_check = None reload_check = None
_pos = None _pos = None
_tick = 0 _tick = 0
need_to_sync = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.is_main = kwargs.get('mode', 'main') == 'main' self.is_main = kwargs.get('mode', 'main') == 'main'
@ -76,6 +77,9 @@ class Sync(Thread):
else: else:
self.read_position_main() self.read_position_main()
#self.adjust_position() #self.adjust_position()
if self.need_to_sync:
self.sync_to_main()
self.need_to_sync = False
self.reload_playlist() self.reload_playlist()
if self._tick and abs(time.time() - self._tick) > 60: if self._tick and abs(time.time() - self._tick) > 60:
logger.error("player is stuck") logger.error("player is stuck")
@ -171,8 +175,9 @@ class Sync(Thread):
frames = deviation / 0.04 frames = deviation / 0.04
median_frames = median_deviation / 0.04 median_frames = median_deviation / 0.04
if time.time() - self.last_sync > SYNC_GRACE_TIME and abs(median_deviation) > SYNC_TOLERANCE: if time.time() - self.last_sync > SYNC_GRACE_TIME and abs(median_deviation) > SYNC_TOLERANCE:
print('need to sync %0.05f (%d) median %0.05f (%d)' % (deviation, frames, median_deviation, median_frames)) if not self.need_to_sync:
self.sync_to_main() logger.error('need to sync %0.05f (%d) median %0.05f (%d)' % (deviation, frames, median_deviation, median_frames))
self.need_to_sync = True
def median(self, lst): def median(self, lst):
quotient, remainder = divmod(len(lst), 2) quotient, remainder = divmod(len(lst), 2)