\doxysection{src/codec/gsm660.c File Reference} \label{gsm660_8c}\index{src/codec/gsm660.c@{src/codec/gsm660.c}} GSM 06.\+60 -\/ GSM EFR Codec. {\ttfamily \#include $<$stdint.\+h$>$}\newline {\ttfamily \#include $<$stdbool.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/bitvec.\+h$>$}\newline {\ttfamily \#include $<$osmocom/core/utils.\+h$>$}\newline {\ttfamily \#include $<$osmocom/codec/codec.\+h$>$}\newline \doxysubsection*{Functions} \begin{DoxyCompactItemize} \item bool \textbf{ osmo\+\_\+efr\+\_\+check\+\_\+sid} (const uint8\+\_\+t $\ast$rtp\+\_\+payload, size\+\_\+t payload\+\_\+len) \begin{DoxyCompactList}\small\item\em Check whether RTP frame contains EFR SID code word according to TS 101 318 §5.3.\+2. \end{DoxyCompactList}\item enum \textbf{ osmo\+\_\+gsm631\+\_\+sid\+\_\+class} \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+classify} (const uint8\+\_\+t $\ast$rtp\+\_\+payload) \begin{DoxyCompactList}\small\item\em Classify potentially-\/\+SID EFR codec frame in RTP format according to the rules of GSM 06.\+81 §6.1.\+1. \end{DoxyCompactList}\item void \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+reset} (uint8\+\_\+t $\ast$rtp\+\_\+payload) \begin{DoxyCompactList}\small\item\em Reset the SID field of a potentially corrupted, but still valid GSM-\/\+EFR SID frame in RTP encoding to its pristine state (full SID code word). \end{DoxyCompactList}\item bool \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+preen} (uint8\+\_\+t $\ast$rtp\+\_\+payload) \begin{DoxyCompactList}\small\item\em Preen potentially-\/\+SID EFR codec frame in RTP format, ensuring that it is either a speech frame or a valid SID, and if the latter, making it a perfect, error-\/free SID frame. \end{DoxyCompactList}\end{DoxyCompactItemize} \doxysubsection*{Variables} \begin{DoxyCompactItemize} \item const uint16\+\_\+t \textbf{ gsm660\+\_\+bitorder} [260] \item static const uint8\+\_\+t \textbf{ sid\+\_\+code\+\_\+word\+\_\+bits} [95] \end{DoxyCompactItemize} \doxysubsection{Detailed Description} GSM 06.\+60 -\/ GSM EFR Codec. \doxysubsection{Function Documentation} \mbox{\label{gsm660_8c_adc6010383adb5b47724576ac1ae07ae4}} \index{gsm660.c@{gsm660.c}!osmo\_efr\_check\_sid@{osmo\_efr\_check\_sid}} \index{osmo\_efr\_check\_sid@{osmo\_efr\_check\_sid}!gsm660.c@{gsm660.c}} \doxysubsubsection{osmo\_efr\_check\_sid()} {\footnotesize\ttfamily bool osmo\+\_\+efr\+\_\+check\+\_\+sid (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{rtp\+\_\+payload, }\item[{size\+\_\+t}]{payload\+\_\+len }\end{DoxyParamCaption})} Check whether RTP frame contains EFR SID code word according to TS 101 318 §5.3.\+2. \begin{DoxyParams}[1]{Parameters} \mbox{\texttt{ in}} & {\em rtp\+\_\+payload} & Buffer with RTP payload \\ \hline \mbox{\texttt{ in}} & {\em payload\+\_\+len} & Length of payload \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} true if code word is found, false otherwise \end{DoxyReturn} References \textbf{ ARRAY\+\_\+\+SIZE}, \textbf{ bitvec\+\_\+get\+\_\+bit\+\_\+pos()}, \textbf{ bitvec\+::data}, \textbf{ bitvec\+::data\+\_\+len}, \textbf{ ONE}, and \textbf{ sid\+\_\+code\+\_\+word\+\_\+bits}. \mbox{\label{gsm660_8c_a625616d18bff243c177ab5e388786858}} \index{gsm660.c@{gsm660.c}!osmo\_efr\_sid\_classify@{osmo\_efr\_sid\_classify}} \index{osmo\_efr\_sid\_classify@{osmo\_efr\_sid\_classify}!gsm660.c@{gsm660.c}} \doxysubsubsection{osmo\_efr\_sid\_classify()} {\footnotesize\ttfamily enum \textbf{ osmo\+\_\+gsm631\+\_\+sid\+\_\+class} osmo\+\_\+efr\+\_\+sid\+\_\+classify (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{rtp\+\_\+payload }\end{DoxyParamCaption})} Classify potentially-\/\+SID EFR codec frame in RTP format according to the rules of GSM 06.\+81 §6.1.\+1. \begin{DoxyParams}[1]{Parameters} \mbox{\texttt{ in}} & {\em rtp\+\_\+payload} & Buffer with RTP payload \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} enum osmo\+\_\+gsm631\+\_\+sid\+\_\+class, with symbolic values OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+SPEECH, OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+INVALID or OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+VALID corresponding to the 3 possible bit-\/counting classifications prescribed by the spec. \end{DoxyReturn} Differences between the more familiar \doxyref{osmo\+\_\+efr\+\_\+check\+\_\+sid()}{p.}{gsm660_8c_adc6010383adb5b47724576ac1ae07ae4} and the present function are\+: \begin{DoxyEnumerate} \item \doxyref{osmo\+\_\+efr\+\_\+check\+\_\+sid()}{p.}{gsm660_8c_adc6010383adb5b47724576ac1ae07ae4} returns true only if the SID frame is absolutely perfect, with all 95 bits of the SID code word set. However, the rules of GSM 06.\+81 §6.1.\+1 allow up to one bit to be in error, and the frame is still accepted as valid SID. \item The third possible state of invalid SID is not handled at all by the simpler \doxyref{osmo\+\_\+efr\+\_\+check\+\_\+sid()}{p.}{gsm660_8c_adc6010383adb5b47724576ac1ae07ae4} function. \item \doxyref{osmo\+\_\+efr\+\_\+check\+\_\+sid()}{p.}{gsm660_8c_adc6010383adb5b47724576ac1ae07ae4} includes a check for 0xC RTP signature, and returns false if that signature nibble is wrong. That check is not included in the present version because there is no place for it in the ETSI-\/prescribed classification, it is neither speech nor SID. The assumption is that this function is used to classify the bit content of received codec frames, not their RTP encoding -\/ the latter needs to be validated beforehand. \end{DoxyEnumerate} Which function should one use? The answer depends on the specific circumstances, and needs to be addressed on a case-\/by-\/case basis. References \textbf{ ARRAY\+\_\+\+SIZE}, \textbf{ bitvec\+\_\+get\+\_\+bit\+\_\+pos()}, \textbf{ bitvec\+::data}, \textbf{ bitvec\+::data\+\_\+len}, \textbf{ GSM\+\_\+\+EFR\+\_\+\+BYTES}, \textbf{ n}, \textbf{ ONE}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+INVALID}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+SPEECH}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+VALID}, and \textbf{ sid\+\_\+code\+\_\+word\+\_\+bits}. Referenced by \textbf{ osmo\+\_\+efr\+\_\+is\+\_\+any\+\_\+sid()}, and \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+preen()}. \mbox{\label{gsm660_8c_a6824b93700b9514c4c796826cf0b3904}} \index{gsm660.c@{gsm660.c}!osmo\_efr\_sid\_preen@{osmo\_efr\_sid\_preen}} \index{osmo\_efr\_sid\_preen@{osmo\_efr\_sid\_preen}!gsm660.c@{gsm660.c}} \doxysubsubsection{osmo\_efr\_sid\_preen()} {\footnotesize\ttfamily bool osmo\+\_\+efr\+\_\+sid\+\_\+preen (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{rtp\+\_\+payload }\end{DoxyParamCaption})} Preen potentially-\/\+SID EFR codec frame in RTP format, ensuring that it is either a speech frame or a valid SID, and if the latter, making it a perfect, error-\/free SID frame. \begin{DoxyParams}[1]{Parameters} \mbox{\texttt{ in}} & {\em rtp\+\_\+payload} & Buffer with RTP payload -\/ must be writable! \\ \hline \end{DoxyParams} \begin{DoxyReturn}{Returns} true if the frame is good, false otherwise \end{DoxyReturn} References \textbf{ OSMO\+\_\+\+ASSERT}, \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+classify()}, \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+reset()}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+INVALID}, \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+SPEECH}, and \textbf{ OSMO\+\_\+\+GSM631\+\_\+\+SID\+\_\+\+CLASS\+\_\+\+VALID}. \mbox{\label{gsm660_8c_a53ea5bc297fc25818f414ab2c0672603}} \index{gsm660.c@{gsm660.c}!osmo\_efr\_sid\_reset@{osmo\_efr\_sid\_reset}} \index{osmo\_efr\_sid\_reset@{osmo\_efr\_sid\_reset}!gsm660.c@{gsm660.c}} \doxysubsubsection{osmo\_efr\_sid\_reset()} {\footnotesize\ttfamily void osmo\+\_\+efr\+\_\+sid\+\_\+reset (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{rtp\+\_\+payload }\end{DoxyParamCaption})} Reset the SID field of a potentially corrupted, but still valid GSM-\/\+EFR SID frame in RTP encoding to its pristine state (full SID code word). \begin{DoxyParams}[1]{Parameters} \mbox{\texttt{ in}} & {\em rtp\+\_\+payload} & Buffer with RTP payload -\/ must be writable!\\ \hline \end{DoxyParams} Per GSM 06.\+62 section 5.\+3, a freshly minted SID frame consists of 58 bits of comfort noise parameters (LSF and 4 times fixed codebook gain), 95 bits of SID code word (all 1s) and 91 unused bits (all 0s). Network elements that receive SID frames from call leg A uplink and need to retransmit them on leg B downlink should \char`\"{}rejuvenate\char`\"{} received SID frames prior to retransmission by resetting the SID field to its pristine state of all 1s; this function does the job. Potential TODO\+: it would be nice to also zero out the remaining 91 bits which the spec leaves as reserved, clearing out leg A radio bit errors -\/ but do we really need to? Referenced by \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+preen()}. \doxysubsection{Variable Documentation} \mbox{\label{gsm660_8c_aec47844e1f821054c8e2a37c69c185c5}} \index{gsm660.c@{gsm660.c}!gsm660\_bitorder@{gsm660\_bitorder}} \index{gsm660\_bitorder@{gsm660\_bitorder}!gsm660.c@{gsm660.c}} \doxysubsubsection{gsm660\_bitorder} {\footnotesize\ttfamily const uint16\+\_\+t gsm660\+\_\+bitorder[260]} \mbox{\label{gsm660_8c_a685421e1e83b73225998cf89bb3a9792}} \index{gsm660.c@{gsm660.c}!sid\_code\_word\_bits@{sid\_code\_word\_bits}} \index{sid\_code\_word\_bits@{sid\_code\_word\_bits}!gsm660.c@{gsm660.c}} \doxysubsubsection{sid\_code\_word\_bits} {\footnotesize\ttfamily const uint8\+\_\+t sid\+\_\+code\+\_\+word\+\_\+bits[95]\hspace{0.3cm}{\ttfamily [static]}} {\bfseries Initial value\+:} \begin{DoxyCode}{0} \DoxyCodeLine{= \{} \DoxyCodeLine{ } \DoxyCodeLine{ 45, 46, 48, 49, 50, 51, 52, 53, 54, 55,} \DoxyCodeLine{ 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,} \DoxyCodeLine{ 66, 67, 68, 94, 95, 96, 98, 99, 100, 101,} \DoxyCodeLine{ 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,} \DoxyCodeLine{ 112, 113, 114, 115, 116, 117, 118, 148, 149, 150,} \DoxyCodeLine{ 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,} \DoxyCodeLine{ 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,} \DoxyCodeLine{ 171, 196, 197, 198, 199, 200, 201, 202, 203, 204,} \DoxyCodeLine{ 205, 206, 207, 208, 209, 212, 213, 214, 215, 216,} \DoxyCodeLine{ 217, 218, 219, 220, 221} \DoxyCodeLine{\}} \end{DoxyCode} Referenced by \textbf{ osmo\+\_\+efr\+\_\+check\+\_\+sid()}, and \textbf{ osmo\+\_\+efr\+\_\+sid\+\_\+classify()}.