Merge pull request #2934 from fewtarius/dev
Add input service for mpv media player.
This commit is contained in:
commit
e32b17e492
5 changed files with 173 additions and 38 deletions
|
@ -1,38 +0,0 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
||||
|
||||
function sendkey() {
|
||||
echo '{"command":["keypress", "'${1}'"]}' | socat - "/tmp/mpvsocket"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"pause")
|
||||
sendkey "p"
|
||||
;;
|
||||
"changeaudio")
|
||||
sendkey "#"
|
||||
;;
|
||||
"changesub")
|
||||
sendkey "j"
|
||||
;;
|
||||
"showosd")
|
||||
sendkey "O"
|
||||
;;
|
||||
"back5s")
|
||||
sendkey "LEFT"
|
||||
;;
|
||||
"skip5s")
|
||||
sendkey "RIGHT"
|
||||
;;
|
||||
"back60s")
|
||||
sendkey "DOWN"
|
||||
;;
|
||||
"skip60s")
|
||||
sendkey "UP"
|
||||
;;
|
||||
"quit")
|
||||
sendkey "Q"
|
||||
;;
|
||||
esac
|
||||
|
|
@ -27,3 +27,8 @@ else
|
|||
fi
|
||||
|
||||
PKG_MESON_OPTS_TARGET+=" -Dsdl2=enabled"
|
||||
|
||||
post_makeinstall_target() {
|
||||
cp ${PKG_DIR}/scripts/* ${INSTALL}/usr/bin
|
||||
chmod 0755 ${INSTALL}/usr/bin/* 2>/dev/null ||:
|
||||
}
|
||||
|
|
152
packages/multimedia/mpv/scripts/mpv_sense
Executable file
152
packages/multimedia/mpv/scripts/mpv_sense
Executable file
|
@ -0,0 +1,152 @@
|
|||
#!/bin/bash
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
# Copyright (C) 2023 JELOS (https://github.com/JustEnoughLinuxOS)
|
||||
# 2021-present pkegg
|
||||
|
||||
. /etc/profile
|
||||
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
### Summary
|
||||
# This script listens to input events and takes actions. mpv edition.
|
||||
###
|
||||
|
||||
### Enable logging
|
||||
case $(get_setting system.loglevel) in
|
||||
verbose)
|
||||
DEBUG=true
|
||||
;;
|
||||
*)
|
||||
DEBUG=false
|
||||
;;
|
||||
esac
|
||||
|
||||
### Set up match variables
|
||||
PAUSE_EVENT='*(BTN_SOUTH), value 1'
|
||||
CHANGE_AUDIO_EVENT='*(BTN_EAST), value 1'
|
||||
CHANGE_SUB_EVENT='*(BTN_WEST), value 1'
|
||||
SHOW_OSD_EVENT='*(BTN_NORTH), value 1'
|
||||
BACK_5S_DPAD_EVENT='*(DPAD_LEFT), value 1'
|
||||
BACK_5S_HAT_EVENT='*(ABS_HAT0X), value -1*'
|
||||
SKIP_5S_DPAD_EVENT='*(DPAD_RIGHT), value 1'
|
||||
SKIP_5S_HAT_EVENT='*(ABS_HAT0X), value 1*'
|
||||
BACK_60S_DPAD_EVENT='*(DPAD_DOWN), value 1'
|
||||
BACK_60S_HAT_EVENT='*(ABS_HAT0Y), value 1*'
|
||||
SKIP_60S_DPAD_EVENT='*(DPAD_UP), value 1'
|
||||
SKIP_60S_HAT_EVENT='*(ABS_HAT0X), value -1*'
|
||||
QUIT_HOTKEY_EVENT='*(BTN_SELECT), value 1'
|
||||
QUIT_SELECT_EVENT='*(BTN_START), value 1'
|
||||
|
||||
### Search the system for useful devices to monitor for inputs.
|
||||
get_devices() {
|
||||
KJDEVS=false
|
||||
FOUNDKEYS=false
|
||||
FOUNDJOY=false
|
||||
RETRY=5
|
||||
while [ ${KJDEVS} = false ]
|
||||
do
|
||||
# Detect input devices automatically
|
||||
for DEV in /dev/input/ev*
|
||||
do
|
||||
unset SUPPORTS
|
||||
SUPPORTS=$(udevadm info ${DEV} | awk '/ID_INPUT_KEY=|ID_INPUT_JOYSTICK=/ {print $2}')
|
||||
if [ -n "${SUPPORTS}" ]
|
||||
then
|
||||
DEVICE=$(udevadm info ${DEV} | awk 'BEGIN {FS="="} /DEVNAME=/ {print $2}')
|
||||
INPUT_DEVICES+=("${DEVICE}")
|
||||
if [[ "${SUPPORTS}" =~ ID_INPUT_KEY ]]
|
||||
then
|
||||
${DEBUG} log $0 "Found Keyboard: ${DEVICE}"
|
||||
FOUNDKEYS=true
|
||||
elif [[ "${SUPPORTS}" =~ ID_INPUT_JOYSTICK ]]
|
||||
then
|
||||
${DEBUG} log $0 "Found Joystick: ${DEVICE}"
|
||||
FOUNDJOY=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
if [ "${FOUNDKEYS}" = "true" ] &&
|
||||
[ "${FOUNDJOY}" = "true" ]
|
||||
then
|
||||
${DEBUG} log $0 "Found all of the needed devices."
|
||||
KJDEVS=true
|
||||
break
|
||||
fi
|
||||
if [ "${RETRY}" -ge 5 ]
|
||||
then
|
||||
${DEBUG} log $0 "Did not find all of the needed devices, but that may be OK. Breaking."
|
||||
break
|
||||
else
|
||||
RETRY=$(( ${RETRY} + 1 ))
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
function send_key() {
|
||||
${DEBUG} && log $0 "Send key ${1}."
|
||||
echo '{"command":["keypress", "'${1}'"]}' | socat - "/tmp/mpvsocket"
|
||||
}
|
||||
|
||||
get_devices
|
||||
|
||||
(
|
||||
for INPUT_DEVICE in ${INPUT_DEVICES[@]}
|
||||
do
|
||||
evtest "${INPUT_DEVICE}" 2>&1 &
|
||||
done
|
||||
wait
|
||||
) | while read line; do
|
||||
case ${line} in
|
||||
(${CONTROLLER_DISCONNECTED})
|
||||
${DEBUG} log $0 "Reloading due to ${CONTROLLER_DEVICE} reattach..."
|
||||
get_devices
|
||||
;;
|
||||
(${DEVICE_DISCONNECTED})
|
||||
${DEBUG} log $0 "Reloading due to ${DEVICE} reattach..."
|
||||
get_devices
|
||||
;;
|
||||
(${PAUSE_EVENT})
|
||||
send_key "p"
|
||||
;;
|
||||
(${CHANGE_AUDIO_EVENT})
|
||||
send_key "#"
|
||||
;;
|
||||
(${CHANGE_SUB_EVENT})
|
||||
send_key "j"
|
||||
;;
|
||||
(${SHOW_OSD_EVENT})
|
||||
send_key "O"
|
||||
;;
|
||||
(${BACK_5S_DPAD_EVENT}|${BACK_5S_HAT_EVENT})
|
||||
send_key "LEFT"
|
||||
;;
|
||||
(${SKIP_5S_DPAD_EVENT}|${SKIP_5S_HAT_EVENT})
|
||||
send_key "RIGHT"
|
||||
;;
|
||||
(${BACK_60S_DPAD_EVENT}|${BACK_60S_HAT_EVENT})
|
||||
send_key "DOWN"
|
||||
;;
|
||||
(${SKIP_60S_DPAD_EVENT}|${SKIP_60S_HAT_EVENT})
|
||||
send_key "UP"
|
||||
;;
|
||||
(${QUIT_HOTKEY_EVENT})
|
||||
if [[ "${line}" =~ ${PRESS} ]]
|
||||
then
|
||||
${DEBUG} && log $0 "HOTKEY: Pressed"
|
||||
HOTKEY_PRESSED=true
|
||||
elif [[ "${line}" =~ ${RELEASE} ]]
|
||||
then
|
||||
${DEBUG} && log $0 "HOTKEY: Released"
|
||||
HOTKEY_PRESSED=false
|
||||
fi
|
||||
;;
|
||||
(${QUIT_SELECT_EVENT})
|
||||
if [ "${HOTKEY_PRESSED}" = true ]
|
||||
then
|
||||
send_key "Q"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
. /etc/profile
|
||||
set_kill set "mpv"
|
||||
systemctl start mpv
|
||||
|
||||
FBWIDTH="$(fbwidth)"
|
||||
FBHEIGHT="$(fbheight)"
|
||||
|
@ -21,4 +22,5 @@ case ${ASPECT} in
|
|||
esac
|
||||
|
||||
/usr/bin/mpv --fullscreen --geometry=${RES} --hwdec=auto-safe --input-ipc-server=/tmp/mpvsocket "${1}"
|
||||
systemctl stop mpv
|
||||
exit 0
|
14
packages/multimedia/mpv/system.d/mpv.service
Normal file
14
packages/multimedia/mpv/system.d/mpv.service
Normal file
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=MPV controller input service
|
||||
After=jelos.target
|
||||
StartLimitIntervalSec=0
|
||||
|
||||
[Service]
|
||||
Environment=HOME=/storage
|
||||
EnvironmentFile=/etc/profile
|
||||
ExecStart=/usr/bin/mpv_sense
|
||||
Restart=always
|
||||
RestartSec=1
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Loading…
Reference in a new issue