diff --git a/run_test.sh b/run_test.sh new file mode 100755 index 0000000..352b879 --- /dev/null +++ b/run_test.sh @@ -0,0 +1,98 @@ +#!/bin/bash +# +# Tested on Ubuntu 18.04 +# + +function cleanup { +#kill and wait for previous daemon instances to exit + sudo killall -q ptp4l + killall -q aes67-daemon + while killall -0 aes67-daemon 2>/dev/null ; do + sleep 1 + done +} + +if ! [ -x "$(command -v /usr/sbin/ptp4l)" ]; then + echo 'Error: ptp4l is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v arecord)" ]; then + echo 'Error: arecord is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v speaker-test)" ]; then + echo 'Error: speaker-test is not installed.' >&2 + exit 1 +fi + +if ! [ -x "$(command -v ./daemon/aes67-daemon)" ]; then + echo 'Error: aes67-daemon is not compiled.' >&2 + exit 1 +fi + +if ! [ -r "3rdparty/ravenna-alsa-lkm/driver/MergingRavennaALSA.ko" ]; then + echo 'Error: MergingRavennaALSA.ko module is not compiled.' >&2 + exit 1 +fi + +trap cleanup EXIT + +#configure system parms +sudo sysctl -w net/ipv4/igmp_max_memberships=66 + +if [ -x /usr/bin/pulseaudio ]; then + #stop pulseaudio, this seems to open/close ALSA continuosly + echo autospawn = no > $HOME/.config/pulse/client.conf + pulseaudio --kill >/dev/null 2>&1 + rm $HOME/.config/pulse/client.conf + #disable pulseaudio + systemctl --user stop pulseaudio.socket > /dev/null 2>&1 + systemctl --user stop pulseaudio.sservice > /dev/null 2>&1 +fi + +#install kernel module +sudo insmod 3rdparty/ravenna-alsa-lkm/driver/MergingRavennaALSA.ko + +cleanup +if [ -f ./test/sink_test.wav ] ; then + rm -f sink_test.wav +fi + +echo "Starting PTP master ..." +sudo /usr/sbin/ptp4l -i lo -l7 -E -S & + +#echo "Starting AES67 daemon ..." +./daemon/aes67-daemon -c ./test/daemon.conf & + +#open browser on configuration page +if [ -x "$(command -v xdg-open)" ]; then + xdg-open "http://127.0.0.1:8080/PTP" +fi + +echo "Waiting for PTP slave to sync ..." +sleep 30 + +#starting recording on sink +echo "Starting to record 240 secs from sink ..." +arecord -M -d 240 -D plughw:RAVENNA -f S24_3LE -r 48000 -c 2 -t wav /tmp/sink_test.wav > /dev/null 2>&1 & +sleep 10 + +#starting playback on source +echo "Starting to playback test on source ..." +aplay -M -D plughw:RAVENNA ./test/test.wav > /dev/null 2>&1 & + +while killall -0 arecord 2>/dev/null ; do + sleep 1 +done +killall aplay +if [ -f /tmp/sink_test.wav ] ; then + mv /tmp/sink_test.wav test/ + echo "Recording to file \"test/sink_test.wav\" successfull" +else + echo "Recording failed" +fi + +echo "Terminating processes ..." + diff --git a/test/check.cc b/test/check.cc new file mode 100644 index 0000000..cb99e8d --- /dev/null +++ b/test/check.cc @@ -0,0 +1,57 @@ +// basic file operations +#include +#include + +using namespace std; + +int main () +{ + fstream fl; + fl.open("./sink_test.wav", ios::in|ios::binary); + if (!fl.is_open()) { + cout << "cannot open file " << endl; + exit(1); + } + auto begin = fl.tellp(); + fl.seekp(0, ios::end); + auto end = fl.tellp(); + fl.seekp(68, ios::beg); + unsigned char ch = 0; + auto prev = fl.tellp(); + while(fl.tellp() < end && ch == 0) + { + prev = fl.tellp(); + ch = fl.get(); + } + unsigned char curr = 0; + bool first = true; + fl.seekp(prev); + while(fl.tellp() < end) + { + if (!first) { + ch = fl.get(); + if (ch != (uint8_t)curr) break; + } + ch = fl.get(); + if (ch != (uint8_t)(curr+1)) break; + ch = fl.get(); + if (ch != (uint8_t)(curr+2)) break; + ch = fl.get(); + if (ch != (uint8_t)curr) break; + ch = fl.get(); + if (ch != (uint8_t)(curr+1)) break; + ch = fl.get(); + if (ch != (uint8_t)(curr+2)) break; + curr += 3; + first = false; + } + int rc = 0; + if (fl.tellp() != end) + { + cout << "error at position: " << fl.tellp() << endl; + rc = 1; + } + else cout << "ok" << endl; + fl.close(); + return rc; +} diff --git a/test/daemon.conf b/test/daemon.conf new file mode 100644 index 0000000..e0756b3 --- /dev/null +++ b/test/daemon.conf @@ -0,0 +1,22 @@ +{ + "http_port": 8080, + "rtsp_port": 8854, + "http_base_dir": "./webui/build", + "log_severity": 3, + "playout_delay": 0, + "tic_frame_size_at_1fs": 192, + "max_tic_frame_size": 1024, + "sample_rate": 48000, + "rtp_mcast_base": "239.1.0.1", + "rtp_port": 5004, + "ptp_domain": 0, + "ptp_dscp": 48, + "sap_interval": 30, + "syslog_proto": "none", + "syslog_server": "255.255.255.254:1234", + "status_file": "./demo/status.json", + "mdns_enabled": false, + "interface_name": "lo", + "mac_addr": "01:00:5e:01:00:01", + "ip_addr": "127.0.0.1" +} diff --git a/test/status.json b/test/status.json new file mode 100644 index 0000000..84cfff2 --- /dev/null +++ b/test/status.json @@ -0,0 +1,28 @@ +{ + "sources": [ + { + "id": 0, + "enabled": true, + "name": "ALSA Source 0", + "io": "Audio Device", + "max_samples_per_packet": 48, + "codec": "L24", + "ttl": 15, + "payload_type": 98, + "dscp": 34, + "refclk_ptp_traceable": false, + "map": [ 0, 1 ] + } ], + "sinks": [ + { + "id": 0, + "name": "ALSA Sink 0", + "io": "Audio Device", + "use_sdp": true, + "source": "http://127.0.0.1:8080/api/source/sdp/0", + "sdp": "v=0\no=- 657664 657666 IN IP4 127.0.0.1\ns=AES67 daemon 000a0900 ALSA Source 0\nc=IN IP4 239.1.0.1/15\nt=0 0\na=clock-domain:PTPv2 0\nm=audio 5004 RTP/AVP 98\nc=IN IP4 239.1.0.1/15\na=rtpmap:98 L24/48000/2\na=sync-time:0\na=framecount:48\na=ptime:1\na=mediaclk:direct=0\na=ts-refclk:ptp=IEEE1588-2008:00-1D-C1-FF-FE-50-36-33:0\na=recvonly\n", + "delay": 576, + "ignore_refclk_gmid": true, + "map": [ 0, 1 ] + } ] +} diff --git a/test/test.wav b/test/test.wav new file mode 100644 index 0000000..8c1bbc9 Binary files /dev/null and b/test/test.wav differ