Let's look at this function: maid
-
Code: select all
-
gint
gst_rtp_buffer_compare_seqnum (guint16 seqnum1, guint16 seqnum2)
{
return (gint16) (seqnum2 - seqnum1);
}
A simple code can be used to determine whether seqnum1 and seqnum2 have wraparound. The key point is the gint16 type conversion after return. Seqnum1, seqnum2 are all guint16, that is, unsigned short, and the return value is forcibly converted to gint16, that is, signed short. In this case, if seqnum2-seqnum1 <-32768, that is, wraparound occurs, the return value is a positive number. In other cases, if seqnum2-seqnum1> =-32768, in this case, a negative number is returned. Therefore, if the returned value is <0, seqnum2 <seqnum1 does not have wraparound. If the returned value is> 0, seqnum2> seqnum1 or wraparound occurs. In RTP, if wraparound occurs, seqnum2 is larger than seqnum1 logically even if seqnum2 is smaller than seqnum1, because seqnum2 is generated later.
As to why seqnum2-seqnum1 <-32768 is converted to gint16, it becomes a positive number. For more information, see the concept of negative numbers and supplementary codes in C.