Skip to content

Commit

Permalink
tools: add jbuf plot tools
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Sep 27, 2023
1 parent 09c9642 commit c6abcbf
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/jbuf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.env
contacts
current_contact
*.dat
*.eps
plots
uuid
*.json
24 changes: 24 additions & 0 deletions tools/jbuf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
How to use
----------
- Increase the `DEBUG_LEVEL` to `6` and re-build `re`

- At the call target automatic answer mode should be configured.
E.g. if baresip then the account parameter `;answermode=auto`

- Generate the plots
```
cd tools/jbuf
cp env-template .env
# edit .env
./generate_plot.sh
```

- The plots are collected in sub-directory plots.

Units in the Plots
------------------

The variables `rdiff`, `wish` and `n` are given in number of packets.
The events "underflow", "overrun", "too late", "duplicate", "out of sequence"
and "lost" are printed only as dimensionless dots with a `y` value somewhere
in the middle of the diagram.
1 change: 1 addition & 0 deletions tools/jbuf/audio/accounts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<sip:alice@office>;regint=0;ptime=20
35 changes: 35 additions & 0 deletions tools/jbuf/audio/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#audio_path /usr/local/share/baresip
audio_player pulse,
audio_source pulse,
audio_alert pulse,
audio_level no
audio_buffer 10-50
audio_buffer_mode adaptive
audio_silence 0.0

audio_jitter_buffer_type adaptive
audio_jitter_buffer_delay 0-500

statmode_default off
rtp_stats no

module_path /usr/local/lib/baresip/modules

# UI Modules
module stdio.so
module cons.so

module opus.so

module auconv.so
module auresamp.so

module pulse.so


module_app account.so
module_app menu.so
module_app netroam.so


cons_listen 0.0.0.0:5555 # cons 0-500
4 changes: 4 additions & 0 deletions tools/jbuf/env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target=1.2.3.4
netif=eno1
once=true

85 changes: 85 additions & 0 deletions tools/jbuf/generate_plot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

if [ ! -f .env ]; then
echo ".env is missing. Copy and edit env-template!"
exit 1
fi

export `cat .env`

echo "target: $target"
echo "netif: $netif"
echo "once: $once"

if ! which jq; then
echo "Install jq"
exit 1
fi

trap "./jitter-off.sh; killall -q baresip" EXIT

function gen_datfile() {
ph=$1
filename=$2

jqc='.traceEvents[] | select (.ph == "'"${ph}"'") | .args.line'
cat jbuf.json | jq -r "${jqc}" > $filename
}

source ./jitter.sh
init_jitter $netif

strm="audio"
for jmin in 0 10 20; do
for i in 0 1; do
if [ "$i" == "0" ]; then
strm="audio"
else
strm="video"
fi

echo "########### jitter buffer $strm $jmin ###############"

sed -e "s/${strm}_jitter_buffer_delay\s*[0-9]*\-.*/${strm}_jitter_buffer_delay ${jmin}-500/" -i ${strm}/config
baresip -v -f ${strm} > /tmp/${strm}.log 2>&1 &
sleep 1
echo "/dial $target" | nc -N localhost 5555

sleep 3

enable_jitter

sleep 5

disable_jitter

sleep 25

echo "/quit" | nc -N localhost 5555

sleep 1

gen_datfile "P" jbuf.dat
gen_datfile "O" overrun.dat
gen_datfile "U" underflow.dat
gen_datfile "L" toolate.dat
gen_datfile "D" duplicate.dat
gen_datfile "S" oosequence.dat
gen_datfile "T" lost.dat

./jbuf.plot
if [ ! -d plots ]; then
mkdir plots
fi
if [ -f jbuf.eps ]; then
mv jbuf.eps plots/jbuf_${strm}_${jmin}.eps
fi
if [ -f jbuf.png ]; then
mv jbuf.png plots/jbuf_${strm}_${jmin}.png
fi
done

if [ $once == "true" ]; then
exit 0
fi
done
53 changes: 53 additions & 0 deletions tools/jbuf/jbuf.plot
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/gnuplot
#
# How to generate a plot
# ======================
# This gnuplot script plots DEBUG_LEVEL 6 output of jbuf.c. You have to
# increment the DEBUG_LEVEL in ajb.c if you want to get the table for
# jbuf.dat. Then call baresip like this:
#
# ./baresip 2>&1 | grep -Eo "jbuf.*" > jbuf.dat
#
# Call this script. Then compare the plot legend with the variables in jbuf.c!
#
#
# Description of the plot
# =======================
# The plot is a time based diagram.
#
# Events:
# - overflow
# - underflow
# - packet too late
# - out of sequence
# - lost packet
# Copyright (C) 2023 commend.com - Christian Spielberger


# Choose your preferred gnuplot terminal or use e.g. evince to view the
# jbuf.eps!

#set terminal qt persist
set terminal postscript eps size 15,10 enhanced color
set output 'jbuf.eps'
#set terminal png size 1280,480
#set output 'jbuf.png'
set datafile separator ","
set key outside
set xlabel "time/[ms]"
set ylabel "#packets"

stats "jbuf.dat" using ($6) name "N"
event_h(i) = (0.5*N_max) + 0.3*N_max*(i/6.0)

plot \
'jbuf.dat' using 3:4 title 'rdiff' with linespoints lc "orange", \
'jbuf.dat' using 3:5 title 'wish' with linespoints lc "sea-green", \
'jbuf.dat' using 3:6 title 'n' with linespoints lc "skyblue", \
'jbuf.dat' using 3:7 title 'nf' with linespoints lc "light-blue", \
'overrun.dat' using 3:(event_h(1)) title 'overrun' pt 7 ps 1.5 lc "#FF0000", \
'underflow.dat' using 3:(event_h(2)) title 'underflow' pt 7 ps 1.5 lc "#FF4444", \
'toolate.dat' using 3:(event_h(3)) title 'toolate' pt 7 ps 1.5 lc "#BB5454", \
'duplicate.dat' using 3:(event_h(4)) title 'duplicate' pt 7 ps 1.5 lc "#E919C6", \
'oosequence.dat' using 3:(event_h(5)) title 'out of seq' pt 7 ps 1.5 lc "#A5A5A5", \
'lost.dat' using 3:(event_h(6)) title 'lost' pt 7 ps 1.5 lc "#C08DBC"
18 changes: 18 additions & 0 deletions tools/jbuf/jitter-off.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ ! -f .env ]; then
echo ".env is missing. Copy and edit env-template!"
exit 1
fi

export `cat .env`

echo "netif: $netif"

source ./jitter.sh


disable_jitter

cleanup_jitter $netif

18 changes: 18 additions & 0 deletions tools/jbuf/jitter-on.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

if [ ! -f .env ]; then
echo ".env is missing. Copy and edit env-template!"
exit 1
fi

export `cat .env`

echo "netif: $netif"

source ./jitter.sh


init_jitter $netif

enable_jitter

31 changes: 31 additions & 0 deletions tools/jbuf/jitter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

function init_jitter () {
netif=$1
sudo ip link add ifb1 type ifb || :
sudo ip link set ifb1 up
sudo tc qdisc add dev $netif handle ffff: ingress
sudo tc filter add dev $netif parent ffff: u32 match u32 0 0 action mirred egress redirect dev ifb1
}


function enable_jitter() {
echo "ENABLE JITTER ..."
sudo tc qdisc add dev ifb1 root netem delay 0ms 50ms
}


function disable_jitter() {
echo "DISABLE JITTER ..."
sudo tc qdisc del dev ifb1 root
}


function cleanup_jitter() {
netif=$1
echo "CLEANUP jitter"
sudo tc filter delete dev $netif parent ffff:
sudo tc qdisc delete dev $netif ingress
sudo ip link set ifb1 down
sudo ip link delete ifb1
}
1 change: 1 addition & 0 deletions tools/jbuf/video/accounts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<sip:alice@office>;regint=0;ptime=20
49 changes: 49 additions & 0 deletions tools/jbuf/video/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#audio_path /usr/local/share/baresip
audio_player pulse,
audio_source pulse,
audio_alert pulse,
audio_level no
audio_buffer 10-50
audio_buffer_mode adaptive
audio_silence 0.0

audio_jitter_buffer_type off
video_jitter_buffer_type adaptive
video_jitter_buffer_delay 0-500

statmode_default off
rtp_stats no

module_path /usr/local/lib/baresip/modules

# Video
video_source v4l2,/dev/video0
video_display x11,nil
# video_source comvideo,
video_size 640x480
video_bitrate 500000
video_fps 15.0

# module comvideo.so
module x11.so
module avcodec.so
module v4l2.so

# UI Modules
module stdio.so
module cons.so

module opus.so

module auconv.so
module auresamp.so

module pulse.so


module_app account.so
module_app menu.so
module_app netroam.so


cons_listen 0.0.0.0:5555 # cons 0-500

0 comments on commit c6abcbf

Please sign in to comment.