diff --git a/player/check-overview b/player/check-overview new file mode 100755 index 0000000..0cee69e --- /dev/null +++ b/player/check-overview @@ -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 diff --git a/player/disable-overview b/player/disable-overview new file mode 100755 index 0000000..3bf1e22 --- /dev/null +++ b/player/disable-overview @@ -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 + diff --git a/player/player-back.service b/player/player-back.service index 30cbe5f..4804318 100644 --- a/player/player-back.service +++ b/player/player-back.service @@ -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 diff --git a/player/player-front.service b/player/player-front.service index 856a32b..7470316 100644 --- a/player/player-front.service +++ b/player/player-front.service @@ -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 diff --git a/player/player.py b/player/player.py index 0dbe6cb..33c9a84 100755 --- a/player/player.py +++ b/player/player.py @@ -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')