summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2019-04-24 14:28:01 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2019-04-24 12:34:31 +0000
commit224f667013ae930b3698eb896889edbf1c0cf2c5 (patch)
treeefabd608de839e6493b4a8148b958d79184c9c53 /bin
parent76c7d5f13902ee2a58a05c0de01394650bcb4613 (diff)
parent4d67fb6cfb56d0abd8ec1c9149b88efd4828935d (diff)
Merge branch 'sandbox/tbultel/avirt'
This migrates all the commits that were on the now-deprecated iot.bzh github. Bug-AGL: SPEC-2259 Change-Id: I98820a409cd02ee977e0383c1be227dc22344099 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/4a-api78
-rwxr-xr-xbin/4a-play64
-rwxr-xr-xbin/4a-status50
-rw-r--r--bin/lib4a-tools.sh54
4 files changed, 246 insertions, 0 deletions
diff --git a/bin/4a-api b/bin/4a-api
new file mode 100755
index 0000000..694397f
--- /dev/null
+++ b/bin/4a-api
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+# load shell lib
+. $(dirname $BASH_SOURCE)/lib4a-tools.sh
+
+cmd=$1
+shift
+
+function usage() {
+ log "Usage: $0 <cmd> [opts]"
+ log "Commands:"
+ log " help: show this help"
+ log " api <verb> [args]: send direct request to API verb with args"
+ log " roles: get AHL roles"
+ log " hals [-a|--all] [-v|--verbose]: get HALs status"
+ log " mediascanner ... : interact with mediascanner service"
+ log " example: 4a-api mediascanner media_result \"\""
+ log " mediaplayer ... : interact with mediaplayer service"
+ log " example: 4a-api mediaplayer playlist \"\""
+ log " radio ... : interact with radio service"
+ exit 1
+}
+
+case $cmd in
+ roles)
+ 4a-client ahl-4a get_roles ""
+ ;;
+ api)
+ 4a-client "$@"
+ ;;
+ hals)
+ verbose=false
+ all=false
+ while [[ -n "$1" ]]; do
+ case $1 in
+ -a|--all) all=true;;
+ -v|--verbose) verbose=true;;
+ -av) all=true; verbose=true;;
+ esac
+ shift
+ done
+ 4a-client 4a-hal-manager loaded "{'verbose':$verbose,'all':$all}"
+ ;;
+ mediascanner)
+ mediascanner-client "$@"
+ ;;
+ mediaplayer)
+ mediaplayer-client "$@"
+ ;;
+ radio)
+ echo "TODO"
+ ;;
+ help|-h|--help)
+ usage
+ ;;
+ *)
+ error "Invalid command"
+ usage
+ ;;
+esac
+
+# commandes HAL manager:
+# 4a-hal-manager loaded
+# 4a-hal-manager loaded { "verbose": true } <= +metadata
+# 4a-hal-manager loaded { "all": true } <= hals avec un json
+# 4a-hal-manager loaded { "all": true, "verbose":true }
+
+# open/close multimedia
+#afb-client-demo -H -d $WS4A << EOF
+#multimedia { "action":"open" }
+#multimedia { "action":"close" }
+#EOF
+
+# volume multimedia
+#afb-client-demo -H -d $WS4A << EOF
+#multimedia { "action":"open" }
+#multimedia { "action":"close" }
+#EOF
diff --git a/bin/4a-play b/bin/4a-play
new file mode 100755
index 0000000..7650d4d
--- /dev/null
+++ b/bin/4a-play
@@ -0,0 +1,64 @@
+#!/bin/bash
+
+# load shell lib
+. $(dirname $BASH_SOURCE)/lib4a-tools.sh
+
+function usage() {
+ log "$0 <file> [device] [role]"
+ log " - 'device' can be hw:X where X is a number or the device name."
+ log " It can also be hw:X,Y,Z, it is used when playing on the loopback card"
+ log " which is the 4a default sink."
+ log " Default: hw:Loopback,0,2"
+ log " - 'role' is the 4a role to use. In future version it will be guessed"
+ log " based on the device. Use '4a-api roles' to get a list of known roles"
+ log " Default: multimedia"
+}
+
+if [ "$#" == "0" ]; then
+ error "No file to play!"
+ usage
+fi
+
+avirt=$(cat /proc/modules | grep avirt_ap_loopback | head -n1 | cut -d ' ' -f 1)
+if [ x$avirt == x ]; then
+hwdev=Loopback,0,2
+else
+hwdev=avirt,0
+fi
+
+FILEPATH="$( realpath "$1" )"
+DEVICE=${2:-"hw:$hwdev"}
+ROLE=${3:-'multimedia'}
+
+CARDID=$( echo "$DEVICE" | cut -d':' -f2 | cut -d',' -f1 )
+
+log "Play '$FILEPATH' on '$DEVICE'"
+
+LOOPBACK_CARDID=$( LANG="C" aplay -l | grep -oEe "^card\\s+[0-9]: Loopback" | uniq | grep -oEe "[0-9]+" )
+if [ "$CARDID" == "Loopback" ] || [ "$CARDID" == "$LOOPBACK_CARDID" ]; then
+ IS_4A_DEVICE=1
+else
+ IS_4A_DEVICE=0
+fi
+
+if [ "$IS_4A_DEVICE" == "1" ]; then
+ log "The selected card (hw:$CARDID) is handle by 4a, call open on '$ROLE'"
+ 4a-client ahl-4a "$ROLE" '{ "action": "open" }'
+
+ # BUG: afb-client-demo does not exit an exit code different from zero when api return an error
+ #if [ "$?" -ne "0" ]; then
+ # exit -1
+ #fi
+fi
+
+if [ "$DEBUG" == "1" ]; then
+ gst-launch-1.0 -v uridecodebin uri="file://$FILEPATH" ! audioconvert ! audioresample ! alsasink device="$DEVICE"
+else
+ gst-launch-1.0 -v uridecodebin uri="file://$FILEPATH" ! audioconvert ! audioresample ! alsasink device="$DEVICE" > /dev/null
+fi
+
+if [ "$IS_4A_DEVICE" == "1" ]; then
+ log "The selected card (hw;$CARDID) is handled by 4a, call close on '$ROLE'"
+ 4a-client ahl-4a "$ROLE" '{ "action": "close" }'
+fi
+
diff --git a/bin/4a-status b/bin/4a-status
new file mode 100755
index 0000000..c3e361e
--- /dev/null
+++ b/bin/4a-status
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+# load shell lib
+. $(dirname $BASH_SOURCE)/lib4a-tools.sh
+
+set -o pipefail
+
+ERR="${color_red}ERROR${color_none}"
+WRN="${color_yellow}WARNING${color_none}"
+SUC="${color_green}SUCCESS${color_none}"
+
+EXIT_CODE=0
+
+# ------------------- enumerate sound cards ------------------------
+
+log "---- Audio cards detected ----"
+LANG="C" aplay -l | grep -oEe "^card\\s+[^\\[]+" | sort -u
+
+# -------------------- snd-aloop ------------------------
+
+log ""
+log "---- snd-aloop driver availability ----"
+if zcat /proc/config.gz | grep "CONFIG_SND_ALOOP=y" > /dev/null; then
+ log "$SUC: Built into the kernel"
+else
+ log "$WRN: Not built into the kernel, devices order can randomly change!"
+ if zcat /proc/config.gz | grep "CONFIG_SND_ALOOP=m" > /dev/null; then
+ log "$SUC: snd-aloop is provided!"
+ if lsmod | grep "snd_aloop" > /dev/null; then
+ log "$SUC: snd-aloop is loaded!"
+ else
+ log "$ERR: snd-aloop is not loaded! 4a-softmixer can't work, please load it using: modprobe snd-aloop"
+ fi
+ else
+ log "$ERR: snd-aloop is not provided at all, 4a-softmixer can't work!"
+ EXIT_CODE=1
+ fi
+fi
+
+log ""
+log "---- 4a service status ----"
+if ps x | grep "service-audio-4a" | grep -v "grep" > /dev/null; then
+ log "$SUC: Service is currently running!"
+else
+ log "$WRN: Service is not currently running!"
+ log "It can be started using the following command:"
+ log "systemctl restart *agl-service-audio-4a*.service"
+fi
+
+exit $EXIT_CODE
diff --git a/bin/lib4a-tools.sh b/bin/lib4a-tools.sh
new file mode 100644
index 0000000..f799cc2
--- /dev/null
+++ b/bin/lib4a-tools.sh
@@ -0,0 +1,54 @@
+stdout_in_terminal=0
+[[ -t 1 ]] && stdout_in_terminal=1
+function color {
+ [[ $stdout_in_terminal == 0 ]] && return
+ for k in $*; do
+ case $k in
+ bold) tput bold 2>/dev/null;;
+ none) tput sgr0 2>/dev/null;;
+ *) tput setaf $k 2>/dev/null;;
+ esac
+ done
+}
+color_green=$(color bold 2)
+color_yellow=$(color bold 3)
+color_red=$(color bold 1)
+color_blue=$(color bold 4)
+color_none=$(color none)
+
+function error() { echo "${color_red}$@${color_none}" >&2; }
+function warning() { echo "${color_yellow}$@${color_none}" >&2; }
+function info() { echo "${color_green}$@${color_none}" >&2; }
+function log() { echo "$@" >&2; }
+function debug() { [[ "$DEBUG" == 1 ]] && echo "${color_blue}DEBUG:" "$@" "${color_none}" >&2; }
+
+function 4a-client() {
+ # get port for audio service
+ local port=""
+ local token="HELLO"
+ local unitfile=$( ls /var/local/lib/systemd/system/afm-service-agl-service-audio-4a*.service )
+
+ if [ -f "$unitfile" ]; then
+ log "Detected systemd unit file!"
+ port=$( grep -sr X-AFM-http /var/local/lib/systemd/system/afm-service-agl-service-audio-4a*.service | cut -f2 -d'=' )
+ log "Port detected: $port"
+ else
+ log "No systemd unit file detected, assuming running on host, please set 'API_4A_PORT' and 'API_4A_TOKEN' environment variables to correct values!"
+ port=${API_4A_PORT:-1234}
+ token=${API_4A_TOKEN:-"HELLO"}
+ log "Port: $port, token: $token"
+ fi
+
+ afb-client-demo -H "localhost:$port/api?token=$token&uuid=magic" "$@"
+}
+
+function 4a-roles() {
+ 4a-client ahl-4a get_roles "" | tail -n +2 | jq '.response|.[]'
+}
+
+function mediascanner-client() {
+ afb-client-demo -H -d unix:/run/user/0/apis/ws/mediascanner "$@"
+}
+function mediaplayer-client() {
+ afb-client-demo -H -d unix:/run/user/0/apis/ws/mediaplayer "$@"
+}