diff options
author | 2019-04-24 14:28:01 +0200 | |
---|---|---|
committer | 2019-04-24 12:34:31 +0000 | |
commit | 224f667013ae930b3698eb896889edbf1c0cf2c5 (patch) | |
tree | efabd608de839e6493b4a8148b958d79184c9c53 /bin/4a-play | |
parent | 76c7d5f13902ee2a58a05c0de01394650bcb4613 (diff) | |
parent | 4d67fb6cfb56d0abd8ec1c9149b88efd4828935d (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/4a-play')
-rwxr-xr-x | bin/4a-play | 64 |
1 files changed, 64 insertions, 0 deletions
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 + |