Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to allow persistent audio streaming over network #159

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
38 changes: 38 additions & 0 deletions package/ingenic-audiodaemon/files/S96iad
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,51 @@

DAEMON_ARGS="-r -c /etc/iad.json"

# read web config, create if missing
AUDIO_WEBUI_CONF=/etc/webui/audio.conf
[ ! -d $(dirname $AUDIO_WEBUI_CONF) ] && mkdir -p $(dirname $AUDIO_WEBUI_CONF)
[ ! -f $AUDIO_WEBUI_CONF ] && touch $AUDIO_WEBUI_CONF
. $AUDIO_WEBUI_CONF

# default debugging
if [ -z "$audio_debug" ]; then
audio_debug="false"
echo "audio_debug=$audio_debug" >> $AUDIO_WEBUI_CONF
fi

# default to "disabled" and update config
if [ -z "$audio_net_enabled" ]; then
audio_net_enabled="false"
echo "audio_net_enabled=$audio_net_enabled" >> $AUDIO_WEBUI_CONF
fi

# set default port and update config
if [ -z "$audio_net_port" ]; then
audio_net_port=8081
echo "audio_net_port=$audio_net_port" >> $AUDIO_WEBUI_CONF
fi

start() {
starting
[ "$audio_debug" = "true" ] && logger "Starting IAD Daemon"
start_daemon

# Run listener in background for playing audio over the network
if [ "$audio_net_enabled" = "true" ]; then
[ "$audio_debug" = "true" ] && logger "Starting network listener on port $audio_net_port"
nc -ll -p $audio_net_port -e iac -s &
echo $! > /run/network_audio.pid
check_result
fi
}

stop() {
stopping
is_streamer_disabled && quit "Streamer disabled"

[ "$audio_debug" = "true" ] && logger "Killing network listener - PID $(cat /run/network_audio.pid)"
kill "$(cat /run/network_audio.pid)"

stop_daemon
}

Expand Down
81 changes: 81 additions & 0 deletions package/thingino-webui/files/var/www/x/config-audio.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/haserl

jayfan0 marked this conversation as resolved.
Show resolved Hide resolved
<%in _common.cgi %>

<%
plugin="audio"
jayfan0 marked this conversation as resolved.
Show resolved Hide resolved
plugin_name="Audio"
page_title="Audio"
params="debug net_enabled net_port"

tmp_file=/tmp/$plugin

config_file="${ui_config_dir}/${plugin}.conf"
[ ! -f "$config_file" ] && touch $config_file

audio_control=/etc/init.d/S96iad

if [ "POST" = "$REQUEST_METHOD" ]; then
# parse values from parameters
for p in $params; do
eval ${plugin}_${p}=\$POST_${plugin}_${p}
sanitize "${plugin}_${p}"
done; unset p

# validation

if [ -z "$error" ]; then
:>$tmp_file
for p in $params; do
echo "${plugin}_${p}=\"$(eval echo \$${plugin}_${p})\"" >>$tmp_file
done; unset p
mv $tmp_file $config_file

if [ -f "$audio_control" ]; then
$audio_control restart >> /tmp/webui.log
else
echo "$audio_control not found" >> /tmp/webui.log
fi

update_caminfo
redirect_to "$SCRIPT_NAME"
fi
else
include $config_file

# default values
[ -z "$audio_debug" ] && audio_debug=false
[ -z "$audio_net_enabled" ] && audio_net_enabled=false
[ -z "$audio_net_port" ] && audio_net_port=8081
fi
%>

<%in _header.cgi %>

<form action="<%= $SCRIPT_NAME %>" method="post">
<div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4 mb-4">
<div class="col">
<h3>Network Audio</h3>
<% field_switch "audio_net_enabled" "Enable Incoming Audio" "Live stream audio to the camera speaker over the network" %>
<% field_number "audio_net_port" "Incoming Audio Port" "" "Which port to listen on" %>

<a href="https://github.com/gtxaspec/ingenic-audiodaemon?tab=readme-ov-file#on-pc">See this repo for usage instructions</a>

<br><br>
jayfan0 marked this conversation as resolved.
Show resolved Hide resolved
<% button_submit %>
</div>

<div class="col">
</div>

<div class="col">
<% field_switch "audio_debug" "Enable Debugging" %>
<h3>Configuration</h3>
<% [ -f $config_file ] && ex "cat $config_file" %>
jayfan0 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>

</form>

<% fi %>
<%in _footer.cgi %>