fine tune sync by notching playback speed

This commit is contained in:
j 2023-11-20 12:32:07 +00:00
parent 8194783064
commit 37a2674f23
5 changed files with 31 additions and 3 deletions

1
player/check-overview Executable file
View file

@ -0,0 +1 @@
dbus-send --session --dest=org.gnome.Shell --print-reply /org/gnome/Shell org.freedesktop.DBus.Properties.Get string:org.gnome.Shell string:OverviewActive

3
player/disable-overview Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
dbus-send --session --dest=org.gnome.Shell --type=method_call /org/gnome/Shell org.freedesktop.DBus.Properties.Set string:org.gnome.Shell string:OverviewActive variant:boolean:false

View file

@ -1,9 +1,11 @@
[Unit]
Description=player
After=gnome-session.target
Wants=network-online.target
[Service]
Type=simple
Restart=always
Restart=on-failure
KillSignal=SIGINT
ExecStart=/srv/pandora/t_for_time/player/player.py --mode peer --playlist /srv/t_for_time/render/back.m3u

View file

@ -1,9 +1,10 @@
[Unit]
Description=player
After=gnome-session.target network-online.target
[Service]
Type=simple
Restart=always
Restart=on-failure
KillSignal=SIGINT
ExecStart=/srv/pandora/t_for_time/player/player.py --mode main --playlist /srv/t_for_time/render/front.m3u

View file

@ -82,6 +82,7 @@ class Sync(Thread):
else:
if self.need_to_sync:
self.sync_to_main()
self.deviations = collections.deque(maxlen=10)
self.need_to_sync = False
else:
self.read_position_main()
@ -167,6 +168,8 @@ class Sync(Thread):
data = self.sock.recvfrom(1024)[0].decode().split(" ", 1)
except socket.timeout:
logger.error("failed to receive data from main")
except OSError:
logger.error("socket closed")
else:
self.main.time_pos = float(data[0])
self.main.playlist_current_pos = int(data[1])
@ -181,8 +184,25 @@ class Sync(Thread):
median_deviation = self.median(list(self.deviations))
frames = deviation / 0.04
median_frames = median_deviation / 0.04
if abs(deviation) <= 0.04 and self.mpv.speed != 1.0:
self.mpv.speed = 1.0
logger.error(
'%0.05f back to normal speed %0.05f (%d) median %0.05f (%d) -> %s' % (self.mpv.time_pos, deviation, frames, median_deviation, median_frames, self.mpv.speed)
)
if time.time() - self.last_sync > SYNC_GRACE_TIME and abs(median_deviation) > SYNC_TOLERANCE:
if self.mpv.time_pos > 2 and not self.need_to_sync:
if abs(median_deviation) < 1:
step = 0.02
if median_deviation > 0:
self.mpv.speed += step
else:
self.mpv.speed -= step
logger.error(
'%0.05f need to adjust speed %0.05f (%d) median %0.05f (%d) -> %s' % (self.mpv.time_pos, deviation, frames, median_deviation, median_frames, self.mpv.speed)
)
self.need_to_sync = False
self.deviations = collections.deque(maxlen=10)
self.last_sync = time.time()
elif self.mpv.time_pos > 2 and not self.need_to_sync:
logger.error(
'%0.05f need to sync %0.05f (%d) median %0.05f (%d)' % (self.mpv.time_pos, deviation, frames, median_deviation, median_frames)
)
@ -208,6 +228,7 @@ class Sync(Thread):
except:
pass
self.mpv.pause = True
self.mpv.speed = 1
pos = self.main.time_pos + SYNC_JUMP_AHEAD
#print(pos, self.mpv.playlist_current_pos, self.mpv.time_pos)
self.mpv.seek(pos, 'absolute', 'exact')