Skip to content

Commit

Permalink
omxplayer - checking status via dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
isra67 committed Nov 9, 2017
1 parent 63c3d46 commit 581cb5d
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 34 deletions.
4 changes: 3 additions & 1 deletion brightness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ then
VAL=$1
fi

echo $VAL > /sys/class/backlight/rpi_backlight/brightness
echo $VAL > /sys/class/backlight/rpi_backlight/brightness

sync
112 changes: 112 additions & 0 deletions dbuscntrl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash

#set -x

OMXPLAYER_DBUS_ADDR="/tmp/omxplayerdbus.${USER:-root}"
OMXPLAYER_DBUS_PID="/tmp/omxplayerdbus.${USER:-root}.pid"
export DBUS_SESSION_BUS_ADDRESS=`cat $OMXPLAYER_DBUS_ADDR`
export DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`

[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && { echo "Must have DBUS_SESSION_BUS_ADDRESS" >&2; exit 1; }

RTO="1500" # reply time-out

IDX="$1"

case $2 in
status)
duration=`dbus-send --print-reply=literal --session --reply-timeout=$RTO --dest=$IDX /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"Duration"`
[ $? -ne 0 ] && exit 1
duration="$(awk '{print $2}' <<< "$duration")"

position=`dbus-send --print-reply=literal --session --reply-timeout=$RTO --dest=$IDX /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"Position"`
[ $? -ne 0 ] && exit 1
position="$(awk '{print $2}' <<< "$position")"

playstatus=`dbus-send --print-reply=literal --session --reply-timeout=$RTO --dest=$IDX /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"PlaybackStatus"`
[ $? -ne 0 ] && exit 1
playstatus="$(sed 's/^ *//;s/ *$//;' <<< "$playstatus")"

paused="true"
[ "$playstatus" == "Playing" ] && paused="false"
echo "Duration: $duration"
echo "Position: $position"
echo "Paused: $paused"
;;

volume)
volume=`dbus-send --print-reply=double --session --reply-timeout=$RTO --dest=$IDX /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set string:"org.mpris.MediaPlayer2.Player" string:"Volume" ${2:+double:}$2`
[ $? -ne 0 ] && exit 1
volume="$(awk '{print $2}' <<< "$volume")"
echo "Volume: $volume"
;;

pause)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:16 >/dev/null
;;

stop)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:15 >/dev/null
;;

seek)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek int64:$3 >/dev/null
;;

setposition)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetPosition objpath:/not/used int64:$3 >/dev/null
;;

setalpha)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetAlpha objpath:/not/used int64:$3 >/dev/null
;;

setvideopos)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.VideoPos objpath:/not/used string:"$3 $4 $5 $6" >/dev/null
;;

setvideocroppos)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetVideoCropPos objpath:/not/used string:"$3 $4 $5 $6" >/dev/null
;;

setaspectmode)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetAspectMode objpath:/not/used string:"$3" >/dev/null
;;

hidevideo)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:28 >/dev/null
;;

unhidevideo)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:29 >/dev/null
;;

volumeup)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:18 >/dev/null
;;

volumedown)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:17 >/dev/null
;;

togglesubtitles)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:12 >/dev/null
;;

hidesubtitles)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:30 >/dev/null
;;

showsubtitles)
dbus-send --print-reply=literal --session --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Action int32:31 >/dev/null
;;
getsource)
source=$(dbus-send --print-reply=literal --session --reply-timeout=$RTO --dest=$IDX /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.GetSource)
[ $? -ne 0 ] && exit 1
echo "$source" | sed 's/^ *//'
;;
*)
echo "usage: $0 idx status|pause|stop|seek|volumeup|volumedown|setposition [position in microseconds]|hidevideo|unhidevideo|togglesubtitles|hidesubtitles|showsubtitles|setvideopos [x1 y1 x2 y2]|setvideocroppos [x1 y1 x2 y2]|setaspectmode [letterbox,fill,stretch,default]|setalpha [alpha (0..255)]|getsource" >&2
exit 1
;;
esac
10 changes: 5 additions & 5 deletions indoor.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[command]
screen_saver = 45
watches = none
brightness = 255
watches = digital
brightness = 120
dnd_mode = 0

[sip]
Expand Down Expand Up @@ -43,11 +43,11 @@ picture_1 = fill

[system]
network = 192.168.1.0
dns = 192.168.1.0
dns = 192.168.1.123
ipaddress = 192.168.1.60
gateway = 192.168.1.255
gateway = 192.168.1.123
inet = dhcp
netmask = 192.168.1.211
netmask = 255.255.255.0

[about]
serial = 0000000085a5ba7f
Expand Down
2 changes: 1 addition & 1 deletion my_lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
sipRegStatus = False

# ### time: ###
ICON_RELOAD = .2
ICON_RELOAD = .3
HIDINIT_TIME = 4.
PHONEINIT_TIME = 3.

Expand Down
Binary file modified my_lib/constants.pyc
Binary file not shown.
10 changes: 6 additions & 4 deletions my_lib/itools.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ def send_dbus_worker(dst,args):
omx = omxl[dst]

try:
if args[0] == 'status':
Logger.info('%s: dst=%s status=%r' % (whoami(), dst, omx.status()))
elif args[0] is 'setalpha':
if args[0] is 'setalpha':
# v = '1' if '0' is args[1] else '254'
# omx.setAlpha(v)
if '0' == args[1]: omx.action(OmxControl.ACTION_HIDE_VIDEO)
elif '255' == args[1]: omx.action(OmxControl.ACTION_UNHIDE_VIDEO)
else: omx.setAlpha(args[1])
elif args[0] == 'status':
Logger.info('%s: dst=%s status=%r' % (whoami(), dst, omx.status()))
else:
omx.videoPos(args[1:])

Expand All @@ -100,11 +100,13 @@ def send_dbus_worker(dst,args):

# try to repeat command
try:
time.sleep(1.5)
time.sleep(1.69)
if args[0] is 'setalpha':
if '0' == args[1]: omx.action(OmxControl.ACTION_HIDE_VIDEO)
elif '255' == args[1]: omx.action(OmxControl.ACTION_UNHIDE_VIDEO)
else: omx.setAlpha(args[1])
elif args[0] == 'status':
Logger.info('%s: dst=%s status=%r' % (whoami(), dst, omx.status()))
else:
omx.videoPos(args[1:])

Expand Down
Binary file modified my_lib/itools.pyc
Binary file not shown.
42 changes: 24 additions & 18 deletions pjindoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ def __init__(self,winpos,servaddr,sipcall,streamaddr,relaycmd,rotation=0,aspectr

prcs = self.initPlayer()
procs.append(prcs)
tt = Thread(target=self.play_worker)
tt.daemon = True
tt.start()
# tt = Thread(target=self.play_worker)
# tt.daemon = True
# tt.start()

self.startThread()

Expand All @@ -468,7 +468,7 @@ def __init__(self,winpos,servaddr,sipcall,streamaddr,relaycmd,rotation=0,aspectr


# ###############################################################
# """
"""
def play_worker(self):
"Player thread"
global procs
Expand All @@ -478,14 +478,14 @@ def play_worker(self):
Logger.debug('%s: (%d) %r' % (whoami(), self.screenIndex, _prcs))
while True:
"""
"" "
myLine = _prcs.stdout.readline()
if myLine:
Logger.info('%s: (%d) %s' % (whoami(), self.screenIndex, myLine))
# else:
# self.dbus_command(['status'])
# break
"""
"" "
try:
(res,err) = _prcs.communicate()
Logger.info('%s: (%d) %s (%s)' % (whoami(), self.screenIndex, str(res), str(err)))
Expand All @@ -494,7 +494,7 @@ def play_worker(self):
self.dbus_command(['status'])
break
# time.sleep(.1)
# """
"""

# ###############################################################
def startThread(self):
Expand Down Expand Up @@ -530,14 +530,14 @@ def initPlayer(self):

sendNodeInfo('[***]VIDEO: %d ERROR' % self.screenIndex)

interval = 19. + .2 * self.screenIndex
interval = 69.# + .2 * self.screenIndex
if self.checkEvent: Clock.unschedule(self.checkEvent)
self.checkEvent = Clock.schedule_interval(self.checkLoop, interval)
self.isPlaying = (mainLayout.scrmngr.current == CAMERA_SCR and not mainLayout.popupSettings and not current_call) or\
(current_call and active_display_index == self.screenIndex)

return subprocess.Popen(['omxplayer', '--live', '--no-osd', '--no-keys',\
'--alpha','0', '--layer','1', '--display','0', '-I',\
'--alpha','0', '--layer','1', '--display','0',\
'--dbus_name',dbn, '--orientation',str(self.rotation),\
'--aspect-mode',self.aspectratio, '--win',','.join(self.playerPosition), self.streamUrl],\
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
Expand All @@ -546,16 +546,22 @@ def initPlayer(self):
# ###############################################################
def checkLoop(self, dt):
"check video player state"
#global mainLayout, current_call, active_display_index
global mainLayout #, current_call, active_display_index

Logger.trace('%s: (%d)' % (whoami(), self.screenIndex))

sendNodeInfo('[***]VIDEO: %d OK' % self.screenIndex)
dbn = DBUS_PLAYERNAME + str(self.screenIndex)
status = get_info('%s %s status' % (DBUSCONTROL_SCRIPT, dbn)).split('\n')
try: p = int(status[1].split(' ')[1]) # check if position > 0
except: p = 0
if p < 0:
sendNodeInfo('[***]VIDEO: %d ERROR' % (self.screenIndex))
Logger.warning('%s: (%d): %r' % (whoami(), self.screenIndex, status))
mainLayout.restart_player_window(self.screenIndex)
else:
sendNodeInfo('[***]VIDEO: %d OK' % self.screenIndex)

val = 255 if self.isPlaying else 0

self.dbus_command(TRANSPARENCY_VIDEO_CMD + [str(val)])
# if self.isPlaying: self.dbus_command(['status'])

if self.bgrThread and not self.bgrThread.isAlive(): self.startThread()

Expand Down Expand Up @@ -1371,7 +1377,7 @@ def infinite_loop(self, dt):


# ###############################################################
@mainthread
# @mainthread
def image_update_loop(self,dt):
"image update"
Logger.debug('%s:' % whoami())
Expand Down Expand Up @@ -1539,7 +1545,7 @@ def setLockIcons(self, scrnIdx, locks):


# ###############################################################
@mainthread
# @mainthread
def refreshLockIcons(self):
"change lock icon activity"
global active_display_index
Expand Down Expand Up @@ -2051,7 +2057,7 @@ def showPlayers(self):


# ###############################################################
@mainthread
# @mainthread
def hideAndResizePlayers(self):
"d-bus command to hide and resize video"
Logger.debug('%s:' % whoami())
Expand All @@ -2077,7 +2083,7 @@ def hidePlayers(self, serial=False):


# ###############################################################
@mainthread
# @mainthread
def setButtons(self, visible):
"add/remove buttons"
global docall_button_global
Expand Down
2 changes: 2 additions & 0 deletions setipaddress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ fi

ifconfig $IFACE 0.0.0.0
systemctl restart $SERVICE.service

sync
2 changes: 2 additions & 0 deletions setmicvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ fi
amixer cset numid=$VOLUMEID $VOL%
amixer cset numid=$AGCID 0
alsactl store

sync
2 changes: 2 additions & 0 deletions settimezone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ rm /etc/localtime
ln -s /usr/share/zoneinfo/$TZ /etc/localtime
rm /etc/timezone
echo $TZ | tee /etc/timezone

sync
2 changes: 2 additions & 0 deletions setvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ fi
#amixer cset numid=$VOLUMEID $1%
amixer cset numid=$VOLUMEID $VOL%
alsactl store

sync
8 changes: 4 additions & 4 deletions share/indoor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ pustaj() {


## RPi 2 - set CPU performance:
#for cpucore in /sys/devices/system/cpu/cpu?;
#do
# [[ -f "$cpucore" ]] || echo "performance" | tee /sys/devices/system/cpu/cpu${cpucore:(-1)}/cpufreq/scaling_governor >/dev/null;
#done
for cpucore in /sys/devices/system/cpu/cpu?;
do
[[ -f "$cpucore" ]] || echo "performance" | tee /sys/devices/system/cpu/cpu${cpucore:(-1)}/cpufreq/scaling_governor >/dev/null;
done


## start WD:
Expand Down
2 changes: 1 addition & 1 deletion sysinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DNS=`cat /etc/resolv.conf | grep nameserver | awk 'NR==1 {print $2}'`
MACADDR=`ifconfig eth0 | grep "HWaddr" | awk '{print $5}' | sed -e 's/:/-/g'`

INET_TMP=`cat /etc/dhcpcd.conf | grep "interface eth0"`
if [ -z $INET_TMP ]; then
if [ -z "$INET_TMP" ]; then
INET='dhcp'
else
INET='static'
Expand Down

0 comments on commit 581cb5d

Please sign in to comment.