\doxysection{twjit.\+h}
\label{twjit_8h_source}\index{include/osmocom/netif/twjit.h@{include/osmocom/netif/twjit.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*}}
\DoxyCodeLine{00002\ \textcolor{comment}{\ *\ Themyscira\ Wireless\ RTP\ jitter\ buffer\ implementation:}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ public\ API\ definition\ for\ Osmocom-\/integrated\ version.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ This\ code\ was\ contributed\ to\ Osmocom\ Cellular\ Network\ Infrastructure}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ project\ by\ Mother\ Mychaela\ N.\ Falconia\ of\ Themyscira\ Wireless.}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ Mother\ Mychaela's\ contributions\ are\ NOT\ subject\ to\ copyright:}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ no\ rights\ reserved,\ all\ rights\ relinquished.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#include\ <stdint.h>}}
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#include\ <stdbool.h>}}
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00016\ \textcolor{preprocessor}{\#include\ <osmocom/core/msgb.h>}}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00035\ \textcolor{keyword}{struct\ }osmo\_twjit;}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00048\ \textcolor{keyword}{struct\ }osmo\_twjit\_config;}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00059\ \textcolor{keyword}{struct\ }osmo\_twjit\_stats\ \{}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ For\ ABI\ reasons,\ none\ of\ the\ following\ fields\ may\ be\ deleted}}
\DoxyCodeLine{00061\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ or\ reordered!\ */}}
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ normal\ operation\ */}}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ uint32\_t\ rx\_packets;}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ uint32\_t\ delivered\_pkt;}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ uint32\_t\ handovers\_in;}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ uint32\_t\ handovers\_out;}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ uint32\_t\ marker\_resets;}
\DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ undesirable,\ but\ not\ totally\ unexpected\ */}}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \ \ uint32\_t\ too\_old;}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ uint32\_t\ underruns;}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ uint32\_t\ ho\_underruns;}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ uint32\_t\ output\_gaps;}
\DoxyCodeLine{00074\ \ \ \ \ \ \ \ \ uint32\_t\ thinning\_drops;}
\DoxyCodeLine{00075\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ unusual\ error\ events\ */}}
\DoxyCodeLine{00076\ \ \ \ \ \ \ \ \ uint32\_t\ bad\_packets;}
\DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ uint32\_t\ duplicate\_ts;}
\DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ independent\ analysis\ of\ Rx\ packet\ stream\ */}}
\DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ uint32\_t\ ssrc\_changes;}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ uint32\_t\ seq\_skips;}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ uint32\_t\ seq\_backwards;}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ uint32\_t\ seq\_repeats;}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ uint32\_t\ intentional\_gaps;}
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ uint32\_t\ ts\_resets;}
\DoxyCodeLine{00085\ \ \ \ \ \ \ \ \ uint32\_t\ jitter\_max;}
\DoxyCodeLine{00086\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ New\ fields\ may\ be\ added\ here\ at\ the\ end;\ once\ added,\ they\ become}}
\DoxyCodeLine{00087\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ permanent\ like\ the\ initially\ defined\ ones.\ */}}
\DoxyCodeLine{00088\ \};}
\DoxyCodeLine{00089\ }
\DoxyCodeLine{00100\ \textcolor{keyword}{struct\ }osmo\_twjit\_rr\_info\ \{}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ For\ ABI\ reasons,\ none\ of\ the\ following\ fields\ may\ be\ deleted}}
\DoxyCodeLine{00102\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ or\ reordered!\ */}}
\DoxyCodeLine{00103\ }
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ uint32\_t\ ssrc;}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ uint32\_t\ rx\_packets;}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ uint32\_t\ base\_seq;}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ uint32\_t\ max\_seq\_ext;}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ uint32\_t\ expected\_pkt;}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ uint32\_t\ jitter\_accum;}
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ New\ fields\ may\ be\ added\ here\ at\ the\ end;\ once\ added,\ they\ become}}
\DoxyCodeLine{00119\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ *\ permanent\ like\ the\ initially\ defined\ ones.\ */}}
\DoxyCodeLine{00120\ \};}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00122\ \textcolor{comment}{/*\ twjit\ API:\ managing\ configuration\ structures\ */}}
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \textcolor{keyword}{struct\ }osmo\_twjit\_config\ *osmo\_twjit\_config\_alloc(\textcolor{keywordtype}{void}\ *ctx);}
\DoxyCodeLine{00125\ \textcolor{keywordtype}{void}\ osmo\_twjit\_config\_free(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf);}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_set\_buffer\_depth(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ bd\_start,\ uint16\_t\ bd\_hiwat);}
\DoxyCodeLine{00129\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_set\_thinning\_int(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ thinning\_int);}
\DoxyCodeLine{00131\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_set\_max\_future\_sec(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ max\_future\_sec);}
\DoxyCodeLine{00133\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_set\_start\_min\_delta(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ delta\_ms);}
\DoxyCodeLine{00135\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_set\_start\_max\_delta(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ delta\_ms);}
\DoxyCodeLine{00137\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_set\_handover\_on\_marker(\textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ hom);}
\DoxyCodeLine{00139\ }
\DoxyCodeLine{00140\ \textcolor{comment}{/*\ twjit\ API:\ actual\ twjit\ instances\ */}}
\DoxyCodeLine{00141\ }
\DoxyCodeLine{00142\ \textcolor{keyword}{struct\ }osmo\_twjit\ *osmo\_twjit\_create(\textcolor{keywordtype}{void}\ *ctx,\ uint16\_t\ clock\_khz,}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ uint16\_t\ quantum\_ms,}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ osmo\_twjit\_config\ *config);}
\DoxyCodeLine{00145\ \textcolor{keywordtype}{void}\ osmo\_twjit\_destroy(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit);}
\DoxyCodeLine{00146\ }
\DoxyCodeLine{00147\ \textcolor{keywordtype}{int}\ osmo\_twjit\_set\_config(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit,}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ osmo\_twjit\_config\ *config);}
\DoxyCodeLine{00149\ \textcolor{keywordtype}{void}\ osmo\_twjit\_reset(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit);}
\DoxyCodeLine{00150\ }
\DoxyCodeLine{00151\ \textcolor{comment}{/*\ RTP\ input,\ takes\ ownership\ of\ msgb\ */}}
\DoxyCodeLine{00152\ \textcolor{keywordtype}{void}\ osmo\_twjit\_input(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit,\ \textcolor{keyword}{struct}\ msgb\ *msg);}
\DoxyCodeLine{00153\ }
\DoxyCodeLine{00154\ \textcolor{comment}{/*\ output\ function,\ to\ be\ called\ by\ TDM/GSM/etc\ fixed-\/timing\ side\ */}}
\DoxyCodeLine{00155\ \textcolor{keyword}{struct\ }msgb\ *osmo\_twjit\_output(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit);}
\DoxyCodeLine{00156\ }
\DoxyCodeLine{00157\ \textcolor{comment}{/*\ Stats\ and\ RR\ info\ structures\ are\ contained\ inside\ opaque\ struct\ osmo\_twjit.}}
\DoxyCodeLine{00158\ \textcolor{comment}{\ *\ We\ need\ to\ provide\ access\ to\ these\ stats\ and\ RR\ info\ structures\ to\ API}}
\DoxyCodeLine{00159\ \textcolor{comment}{\ *\ users,\ but\ we\ don't\ want\ to\ make\ the\ whole\ twjit\ instance\ struct\ public.}}
\DoxyCodeLine{00160\ \textcolor{comment}{\ *\ Also\ we\ would\ like\ to\ have\ fast\ external\ access\ to\ these\ stats,\ hence\ an\ API}}
\DoxyCodeLine{00161\ \textcolor{comment}{\ *\ that\ copies\ our\ stats\ to\ caller-\/provided\ storage\ would\ be\ very\ inefficient.}}
\DoxyCodeLine{00162\ \textcolor{comment}{\ *\ Compromise:\ we\ allow\ direct\ external\ access\ to\ just\ these\ selected\ parts}}
\DoxyCodeLine{00163\ \textcolor{comment}{\ *\ of\ the\ full\ internal\ state\ structure\ by\ providing\ API\ functions\ that}}
\DoxyCodeLine{00164\ \textcolor{comment}{\ *\ return\ pointers\ to\ these\ selected\ parts.}}
\DoxyCodeLine{00165\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00166\ \textcolor{keyword}{const}\ \textcolor{keyword}{struct\ }osmo\_twjit\_stats\ *}
\DoxyCodeLine{00167\ osmo\_twjit\_get\_stats(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit);}
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \textcolor{keyword}{const}\ \textcolor{keyword}{struct\ }osmo\_twjit\_rr\_info\ *}
\DoxyCodeLine{00170\ osmo\_twjit\_get\_rr\_info(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit);}
\DoxyCodeLine{00171\ }
\DoxyCodeLine{00172\ \textcolor{comment}{/*\ When\ we\ compose\ outgoing\ RTCP\ packets\ in\ the\ upper\ layer\ of\ twrtp,}}
\DoxyCodeLine{00173\ \textcolor{comment}{\ *\ we\ need\ to\ know\ whether\ or\ not\ we\ have\ received\ at\ least\ one\ valid}}
\DoxyCodeLine{00174\ \textcolor{comment}{\ *\ RTP\ data\ packet\ so\ far.\ \ If\ we\ haven't\ received\ any\ RTP\ yet,\ then}}
\DoxyCodeLine{00175\ \textcolor{comment}{\ *\ we\ have\ no\ Rx\ SSRC,\ all\ data\ in\ struct\ osmo\_twjit\_rr\_info\ are\ invalid,}}
\DoxyCodeLine{00176\ \textcolor{comment}{\ *\ and\ we\ cannot\ send\ RTCP\ reception\ reports.}}
\DoxyCodeLine{00177\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00178\ \textcolor{keywordtype}{bool}\ osmo\_twjit\_rr\_info\_valid(\textcolor{keyword}{struct}\ osmo\_twjit\ *twjit);}
\DoxyCodeLine{00179\ }
\DoxyCodeLine{00180\ \textcolor{comment}{/*\ vty\ configuration\ functions\ */}}
\DoxyCodeLine{00181\ }
\DoxyCodeLine{00182\ \textcolor{keywordtype}{void}\ osmo\_twjit\_vty\_init(\textcolor{keywordtype}{int}\ twjit\_node);}
\DoxyCodeLine{00183\ }
\DoxyCodeLine{00184\ \textcolor{keyword}{struct\ }vty;}
\DoxyCodeLine{00185\ }
\DoxyCodeLine{00186\ \textcolor{keywordtype}{int}\ osmo\_twjit\_config\_write(\textcolor{keyword}{struct}\ vty\ *vty,}
\DoxyCodeLine{00187\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keyword}{struct}\ osmo\_twjit\_config\ *conf,}
\DoxyCodeLine{00188\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *prefix);}
\DoxyCodeLine{00189\ }

\end{DoxyCode}
