streaming-docker/tools/pulse2feed

84 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
#
# IMPORTANT >>>>>You need to get port, ip and feed_id right<<<<<
if [ "X$SNOWMIX" = X ] ; then
echo "You need to set the SNOWMIX environment variable to the base of the Snowmix installed directory"
exit 1
fi
if [ "X$SNOWMIX_PORT" = X ] ; then export SNOWMIX_PORT=9999 ;fi
if [ "X$SNOWMIX_IP" = X ] ; then export SNOWMIX_IP=127.0.0.1 ;fi
# Check for the snowmix and gstreamer settings
if [ ! -f $SNOWMIX/scripts/gstreamer-settings -o ! -f $SNOWMIX/scripts/snowmix-settings ] ; then
echo "Can not find the scripts/gstreamer-settings or the scripts/snowmix-settings in the directory set by the SNOWMIX environment variable"
exit 1
fi
if [ $# -lt 2 ] ; then
echo parameter error. Usage $0 feed hwid
exit 1
fi
# Set video feed and audio feed id
feed_id=$1
hw_id=$2
# Load the Snowmix and GStreamer settings
. $SNOWMIX/scripts/gstreamer-settings
. $SNOWMIX/scripts/snowmix-settings
# This will set
# a) feed_rate
# b) feed_channels
# c) feed_control_pipe
# d) feed_width
# e) feed_height
# f) ctrsocket
# g) system_width
# h) system_height
# i) ratefraction
# j) snowmix
# k) channels
# l) rate
feed_channels=2
feed_rate=44100
if [ X$feed_control_pipe = X -o X$system_width = X -o X$system_height = X ] ; then
echo Failed to get control pipe or width or height from running snowmix
# exit 1
fi
if [ X$feed_rate = X -o X$feed_channels = X ] ; then
echo Failed to get rate or channels from running snowmix
echo Disabling audio
else
echo "Audio rate and channels : $feed_rate $feed_channels"
fi
SHMSIZE='shm-size=40000000'
SHMOPTION="wait-for-connection=0"
SHMSINK1="shmsink socket-path=$feed_control_pipe $SHMSIZE $SHMOPTION"
#SCALE="$VIDEOCONVERT ! videoscale ! $VIDEOCONVERT"
SCALE="videoscale ! $VIDEOCONVERT"
AUDIOFORMAT="$AUDIOS16LE"', rate=(int)'$feed_rate', channels=(int)'$feed_channels
VIDEOFORMAT=$VIDEOBGRA', width=(int)'$feed_width', height=(int)'$feed_height', framerate=(fraction)'$ratefraction
SRC='pulsesrc device='$hw_id
while true ; do
# Remove the named pipe if it exist
rm -f $feed_control_pipe
snowmix=`ps c |cut -c28-34 | grep snowmix | head -1`
snowmix=snowmix
if [ X$snowmix != X ] ; then
(
echo 'audio feed ctr isaudio '$feed_id
$gstlaunch -q $SRC ! queue ! audioconvert ! audioresample ! audiorate ! $AUDIOFORMAT ! queue ! fdsink fd=1 sync=false
) | nc $SNOWMIX_IP $SNOWMIX_PORT
else
echo Snowmix is not running. Quitting $0
exit 1
fi
sleep 2
done
exit