This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Calculate time with Opus codec

0

Hello

i have captured some RTP traffic and I can see using Wireshark that the codec used is Opus. And from the SDP it should use a sample rate of 48000 Hz. Now the problem. If I have an RTP timestamp value, is 1/48000 its timestamp unit? I have problems while calculating the jitter. According to the RTP statistics tab, the value should be around 3 ms. With a max of 9.

I use the formula D = (Ri - Rj) - (Si - Sj) and multiplie the timestamp value with 1/48000 sec for Si and Sj. Is that wrong?

Hope you could help me

asked 06 Jun '16, 10:40

Haumea's gravatar image

Haumea
11224
accept rate: 0%


One Answer:

1

The timestamp unit should normally be 1/(sample rate from SDP) (in seconds) as you expect. You can check that the implementation you capture is correct by taking frames i and j far enough from each other (like 50 packets or more), calculating the difference of RTP timestamps between them, and dividing the value by 48000. If the implementation is correct, the result you get should almost match the difference of frame (capture) timestamps which are expressed in seconds and their decimal fractions. If these two values differ by order of magnitude, something is wrong.

But I don't understand what is the actual problem, do you disagree with the jitter values as calculated by Wireshark?

answered 06 Jun '16, 12:31

sindy's gravatar image

sindy
6.0k4851
accept rate: 24%

I did some errors during calculation! I got two values that differed by order of magnitude! Thanks!

(07 Jun '16, 01:50) Haumea

Has the rate rtp packets come at to do with the bandwidth the implementation has? I got a rate of 0.08 ms, which corresponds to a 12KHz band (1/12000*1000). Is it correct?

(07 Jun '16, 06:17) Haumea

As it my originally comment came out to actually be an Answer, I've converted it as such. If it has answered your Question, please accept it by clicking the checkmark icon next to the Answer.

To your additional question, what bandwidth do you talk about, the audio one or the network one?

Just a remark first, the value you have stated (0,08 ms) seems to be a rounded value of 1/48000 kHz, i.e. not time between packets but duration represented by a single sample.

Opus is a compressing codec which may use constant packet rate but uses a variable bit rate - e.g. you may see that the packets' RTP timestamps are always 20 ms = 960 "samples" apart but their size varies. BTW, you need a specific post-process to extract the audio from the RTP capture, as you need to convey to the Opus decoder the information about packet borders which is not part of its bit stream itself.

As for the audio bandwidth, Shannon-Kotelnik's theorem says that the maximum frequency which can be sampled safely is 1/2 of the sampling rate, which means 0-24 kHz (not 12) theoretical audio bandwidth in case of 48 kHz sampling rate. But the trouble with Opus is that it dynamically changes even the sampling rate, so the 48000 is stated in the SDP solely for the purpose of scaling the RTP timestamps and does not express the actual sampling rate used.

You can determine the audio bandwidth from packet rate only for codecs whose compression ratio is constant and known and which compress the input signal regardless what it actually is. E. g. PCMA compresses each original (11-bit) sample into one byte, so if you have 160 bytes of payload every 20 milliseconds, you know that there are 8000 samples/second so the audio bandwidth is 0-4 kHz. But already with G.729, which also has a constant bit rate, you cannot really talk about audio bandwidth because it is a speech-optimized codec and it doesn't transmit an image of the full frequency spectrum.

(07 Jun '16, 07:12) sindy

Thanks a lot!

(08 Jun '16, 08:05) Haumea