Skip to content

Commit

Permalink
develop #comment Fix dbus connection deadlock problem.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luc Sinet committed May 10, 2019
1 parent c78ab2c commit 0fcd22c
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions OpenCast/player_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from enum import Enum
from pathlib import Path

import psutil
from dbus import DBusException

from omxplayer import keys
Expand Down Expand Up @@ -213,14 +214,23 @@ def _make_player(self, video):
if config.hide_background is True:
command += ['--blank']

logger.debug("[player] opening {} with opt: {}".format(video, command))
try:
self._player = self._player_factory(video.path,
command,
'org.mpris.MediaPlayer2.omxplayer1',
self._on_exit)
except SystemError:
logger.error("[player] couldn't connect to dbus")
for tries in range(5):
logger.debug("[player] opening {} with opt: {}".format(video, command))
try:
self._player = self._player_factory(video.path,
command,
'org.mpris.MediaPlayer2.omxplayer1',
self._on_exit)
return True
except SystemError:
logger.error("[player] couldn't connect to dbus")
# Kill instance if it is a dbus problem
for proc in psutil.process_iter():
if "omxplayer" in proc.name():
logger.debug("[player] killing process {}".format(proc.name()))
proc.kill()

return False

def _play(self):
with self._player_cv:
Expand All @@ -240,14 +250,17 @@ def _play(self):
if not Path(video.path).is_file():
logger.error("[player] file not found: {}".format(video))
if self._history.browsing():
logger.error("[player] removing video")
self._history.remove(video)
self._history.stop_browsing()
return

self._make_player(video)
self._state = PlayerState.STARTED

logger.info("[player] started")
if self._make_player(video):
self._state = PlayerState.STARTED
logger.info("[player] started")
else:
logger.error("[player] couldn't start")
self._history.remove(video)

def _play_videos(self):
def should_play():
Expand Down

0 comments on commit 0fcd22c

Please sign in to comment.