Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
process, server: omxplayer-wrapper bringup
Browse files Browse the repository at this point in the history
  • Loading branch information
rudcode committed Apr 21, 2020
1 parent 96e2484 commit 35a5819
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
40 changes: 26 additions & 14 deletions process.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@
import threading
import logging
import json
import time

from omxplayer.player import OMXPlayer

logger = logging.getLogger("RaspberryCast")
volume = 0
player = None

def playeraction(action):
global player
try:
player.action(action)
except:
pass


def launchvideo(url, config, sub=False):
setState("2")

os.system("echo -n q > /tmp/cmd &") # Kill previous instance of OMX
try:
player.quit() #Kill previous instance of OMX
except:
pass

if config["new_log"]:
os.system("sudo fbi -T 1 -a --noverbose images/processing.jpg")
Expand All @@ -25,8 +40,6 @@ def launchvideo(url, config, sub=False):
new_log=config["new_log"]))
thread.start()

os.system("echo . > /tmp/cmd &") # Start signal for OMXplayer


def queuevideo(url, config, onlyqueue=False):
logger.info('Extracting source video URL, before adding to queue...')
Expand All @@ -42,7 +55,6 @@ def queuevideo(url, config, onlyqueue=False):
kwargs=dict(width=config["width"], height=config["height"],
new_log=config["new_log"]))
thread.start()
os.system("echo . > /tmp/cmd &") # Start signal for OMXplayer
else:
if out is not None:
with open('video.queue', 'a') as f:
Expand Down Expand Up @@ -140,6 +152,7 @@ def playlistToQueue(url, config):


def playWithOMX(url, sub, width="", height="", new_log=False):
global player
logger.info("Starting OMXPlayer now.")

logger.info("Attempting to read resolution from configuration file.")
Expand All @@ -150,19 +163,19 @@ def playWithOMX(url, sub, width="", height="", new_log=False):
resolution = " --win '0 0 {0} {1}'".format(width, height)

setState("1")
args = "-b" + resolution + " --vol " + str(volume)
if sub:
os.system(
"omxplayer -b -r -o both '" + url + "'" + resolution +
" --vol " + str(volume) +
" --subtitles subtitle.srt < /tmp/cmd"
)
player = OMXPlayer(url, args + " --subtitles subtitle.srt")
elif url is None:
pass
else:
os.system(
"omxplayer -b -r -o both '" + url + "' " + resolution + " --vol " +
str(volume) + " < /tmp/cmd"
)
player = OMXPlayer(url, args)

try:
while not player.playback_status() == "Stopped": # Wait until video finished or stopped
time.sleep(0.5)
except:
pass

if getState() != "2": # In case we are again in the launchvideo function
setState("0")
Expand All @@ -181,7 +194,6 @@ def playWithOMX(url, sub, width="", height="", new_log=False):
new_log=new_log),
)
thread.start()
os.system("echo . > /tmp/cmd &") # Start signal for OMXplayer
else:
logger.info("Playlist empty, skipping.")
if new_log:
Expand Down
28 changes: 12 additions & 16 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
from urllib import urlretrieve
from bottle import Bottle, SimpleTemplate, request, response, \
template, run, static_file

from process import launchvideo, queuevideo, playlist, \
setState, getState, setVolume
setState, getState, setVolume, playeraction

from omxplayer.keys import *

if len(sys.argv) > 1:
config_file = sys.argv[1]
Expand Down Expand Up @@ -41,13 +44,6 @@
ch.setFormatter(formatter)
root.addHandler(ch)

try:
os.mkfifo("/tmp/cmd")
except OSError as e:
# 17 means the file already exists.
if e.errno != 17:
raise

if config["new_log"]:
os.system("sudo fbi -T 1 --noverbose -a images/ready.jpg")

Expand Down Expand Up @@ -171,27 +167,27 @@ def video():
control = request.query['control']
if control == "pause":
logger.info('Command : pause')
os.system("echo -n p > /tmp/cmd &")
playeraction(PAUSE)
return "1"
elif control in ["stop", "next"]:
logger.info('Command : stop video')
os.system("echo -n q > /tmp/cmd &")
playeraction(EXIT)
return "1"
elif control == "right":
logger.info('Command : forward')
os.system("echo -n $'\x1b\x5b\x43' > /tmp/cmd &")
playeraction(SEEK_FORWARD_SMALL)
return "1"
elif control == "left":
logger.info('Command : backward')
os.system("echo -n $'\x1b\x5b\x44' > /tmp/cmd &")
playeraction(SEEK_BACK_SMALL)
return "1"
elif control == "longright":
logger.info('Command : long forward')
os.system("echo -n $'\x1b\x5b\x41' > /tmp/cmd &")
playeraction(SEEK_FORWARD_LARGE)
return "1"
elif control == "longleft":
logger.info('Command : long backward')
os.system("echo -n $'\x1b\x5b\x42' > /tmp/cmd &")
playeraction(SEEK_BACK_LARGE)
return "1"


Expand All @@ -200,10 +196,10 @@ def sound():
vol = request.query['vol']
if vol == "more":
logger.info('REMOTE: Command : Sound ++')
os.system("echo -n + > /tmp/cmd &")
playeraction(INCREASE_VOLUME)
elif vol == "less":
logger.info('REMOTE: Command : Sound --')
os.system("echo -n - > /tmp/cmd &")
playeraction(DECREASE_VOLUME)
setVolume(vol)
return "1"

Expand Down

0 comments on commit 35a5819

Please sign in to comment.