fine tune sync by notching playback speed
This commit is contained in:
parent
8194783064
commit
37a2674f23
5 changed files with 31 additions and 3 deletions
1
player/check-overview
Executable file
1
player/check-overview
Executable 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
3
player/disable-overview
Executable 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
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=player
|
Description=player
|
||||||
|
After=gnome-session.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
Restart=always
|
Restart=on-failure
|
||||||
KillSignal=SIGINT
|
KillSignal=SIGINT
|
||||||
ExecStart=/srv/pandora/t_for_time/player/player.py --mode peer --playlist /srv/t_for_time/render/back.m3u
|
ExecStart=/srv/pandora/t_for_time/player/player.py --mode peer --playlist /srv/t_for_time/render/back.m3u
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=player
|
Description=player
|
||||||
|
After=gnome-session.target network-online.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
Restart=always
|
Restart=on-failure
|
||||||
KillSignal=SIGINT
|
KillSignal=SIGINT
|
||||||
ExecStart=/srv/pandora/t_for_time/player/player.py --mode main --playlist /srv/t_for_time/render/front.m3u
|
ExecStart=/srv/pandora/t_for_time/player/player.py --mode main --playlist /srv/t_for_time/render/front.m3u
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@ class Sync(Thread):
|
||||||
else:
|
else:
|
||||||
if self.need_to_sync:
|
if self.need_to_sync:
|
||||||
self.sync_to_main()
|
self.sync_to_main()
|
||||||
|
self.deviations = collections.deque(maxlen=10)
|
||||||
self.need_to_sync = False
|
self.need_to_sync = False
|
||||||
else:
|
else:
|
||||||
self.read_position_main()
|
self.read_position_main()
|
||||||
|
@ -167,6 +168,8 @@ class Sync(Thread):
|
||||||
data = self.sock.recvfrom(1024)[0].decode().split(" ", 1)
|
data = self.sock.recvfrom(1024)[0].decode().split(" ", 1)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
logger.error("failed to receive data from main")
|
logger.error("failed to receive data from main")
|
||||||
|
except OSError:
|
||||||
|
logger.error("socket closed")
|
||||||
else:
|
else:
|
||||||
self.main.time_pos = float(data[0])
|
self.main.time_pos = float(data[0])
|
||||||
self.main.playlist_current_pos = int(data[1])
|
self.main.playlist_current_pos = int(data[1])
|
||||||
|
@ -181,8 +184,25 @@ class Sync(Thread):
|
||||||
median_deviation = self.median(list(self.deviations))
|
median_deviation = self.median(list(self.deviations))
|
||||||
frames = deviation / 0.04
|
frames = deviation / 0.04
|
||||||
median_frames = median_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 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(
|
logger.error(
|
||||||
'%0.05f need to sync %0.05f (%d) median %0.05f (%d)' % (self.mpv.time_pos, deviation, frames, median_deviation, median_frames)
|
'%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:
|
except:
|
||||||
pass
|
pass
|
||||||
self.mpv.pause = True
|
self.mpv.pause = True
|
||||||
|
self.mpv.speed = 1
|
||||||
pos = self.main.time_pos + SYNC_JUMP_AHEAD
|
pos = self.main.time_pos + SYNC_JUMP_AHEAD
|
||||||
#print(pos, self.mpv.playlist_current_pos, self.mpv.time_pos)
|
#print(pos, self.mpv.playlist_current_pos, self.mpv.time_pos)
|
||||||
self.mpv.seek(pos, 'absolute', 'exact')
|
self.mpv.seek(pos, 'absolute', 'exact')
|
||||||
|
|
Loading…
Reference in a new issue