Method and apparatus for determining jitter buffer size in a voice over packet communications system

Methods of the invention include determining packet size by comparing the RTP timestamps of two consecutive packets, determining the expected (no jitter) local arrival time for the next packet by comparing the difference between the local clock and the timestamp of the present packet and summing it with the timestamp difference of the last two packets, and determining network jitter by comparing the expected local arrival time with the actual local arrival time. Computed network jitter are averaged to determine the average network jitter. The average network jitter is used to set the size of the dynamic buffer. An apparatus for performing the methods is also disclosed.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Referring now to FIG. 1 , an apparatus 10 according to the invention is shown in conjunction with an RTP packet device 1 having a local clock 3 , an adjustable dynamic buffer 5 , and a packet I/O 7 . The apparatus 10 includes a packet sniffer 12 coupled to the packet I/O 7 for reading the RTP headers of incoming packets, a logic block 14 for performing the methods of the invention, and a group of registers 16 for storing values of variables. The logic block 14 takes input from the packet sniffer 12 and the local clock 3 , communicates bidirectionally with the registers 16 , and provides an adjustment output to the dynamic buffer 5 . The invention utilizes the thirty-two bit timestamp which occupies bytes 4 - 7 of the RTP packet header. The timestamp reflects the time of the first sample in the packet payload based on the local clock of the transmitting device. The sample period for G.711 A-law/&mgr;-law is always 125 &mgr;s (8000 hz). When the RTP device 1 is powered up, the timestamp is set to a random thirty-two bit value and is incremented by the local clock 3 until the device is shut down, wrapping to zero as the value overflows. The prior art devices only use the local clock to generate the timestamp in outgoing packets. The present invention uses the local clock and the timestamp on incoming packets to determine network jitter. Turning now to FIG. 2 , the methods of the invention are illustrated in a flow chart starting at 100 . The first step in the method is to determine the length of the decompressed voice signal. It is not sufficient to simply look at the packet size because different voice coders will produce different packet sizes for the same amount of time. For example, ADPCM coding compresses 1 ms to 4 bytes, whereas &mgr;-law coding compresses 1 ms to 8 bytes. By calculating the RTP timestamp difference (&Dgr;R) between two consecutive packets, the expanded packet size (length of the decompressed voice signal) can be determined. No matter what compression system is used, the RTP timestamps are always based on an 8 KHz clock. Therefore, the difference &Dgr;R is the duration in 125 &mgr;s periods. Thus, the first step shown in FIG. 2 is to calculate &Dgr;R as indicated at 102 . This value is stored in one of the registers ( 16 in FIG. 1 ). In a zero jitter network, the expected local arrival time of the next packet will be the local arrival time of the last packet plus &Dgr;R. In order to calculate the expected local arrival time of the next packet in a zero jitter network, the local arrival time (TL) of the last packet is determined at 104 in FIG. 2 . This value is also stored in one of the registers ( 16 in FIG. 1 ). The calculation of the expected local arrival time TE is illustrated at 106 . The value TE is also stored in one of the registers ( 16 in FIG. 1 ). When the next packet arrives, it will arrive at an actual local time TL′ which, in a network with jitter, will be different from the expected time TE. The actual arrival time of the next packet is determined at 108 and this value TL′ is stored in one of the registers ( 16 in FIG. 1 ). The difference between the actual arrival time TL′ and the expected arrival time TE is calculated at 110 and the difference &Dgr;N is considered an indication of network jitter. The absolute value of &Dgr;N is stored in another one of the registers (preferably an accumulator). A count of the number of &Dgr;Ns accumulated is stored in another register. The average value of the accumulated &Dgr;Ns is calculated at 112 and the result J is stored in a register. Before proceeding to set the initial buffer size, steps 102 - 112 are repeated for several hundred packets. For example, a loop counter at 114 causes the calculation of J to be updated until it is based on an average of several hundred packet arrivals. The buffer size is calculated at 116 . According to the presently preferred embodiment, the buffer size BS is calculated according to the formula BS&equals;C&plus;(S/2)&plus;2J where C is the minimum size of a buffer in a zero jitter network, S is the size of the packets, and J is the average network jitter as described above. The buffer size BS is initially set at 118 and the method continues at 102 through 112 to recalculate J based on the jitter detected in the next received packet. According to the presently preferred embodiment, if the calculation at 110 produces a &Dgr;N which differs greatly (e.g. by a packet size or more) from the last calculated &Dgr;N, the calculation is ignored. After the new buffer size BS′ is calculated at 116 , it is compared at 120 to the present buffer size BS. If the difference is insignificant (e.g. less than 8 ms), no change is made in the buffer size and the method returns to 102 . If the difference is substantial (e.g. more than 8 ms), the buffer size is adjusted at 122 and the process proceeds at 102 through continuing cycles. In the presently preferred implementation, the methods of the invention are separated into a foreground task and a background task. The foreground task calculates J and the background task updates the buffer size. Thus, in the Flow chart, the steps 118 , 120 , and 122 are run in a separate timed loop. Exemplary source code for the foreground task is illustrated in the code listing below which is separately line numbered for easy reference. 1 ; Detect Jitter ; ; don't detect jitter until channel has reached a steady state condition rsbx SXM ldm T, B stlm B, AR4 mpy &num;HEADER_SIZE, B add &num;_chnl_header, B stlm B, AR2 ld *AR4(_chnl_state), B and &num;RX_ON_MASK, B ; Once spigot is turned on, channel is in OK state bc UpdNPTime, BEQ ; Channel is (hopefully) in a steady State condition ; Compare Actual & Expected Arrival Times dld *AR3 (_LastPacketLTime), B ; Get Local Sample Time ; load recieved (remote) rtp timestamp into acc. A. ; This must be done as two loads because it may not be aligned for dld ld *AR2 (LOCALSTAMP−1) 16, A ; load high word OR *AR2 (LOCALSTAMP), A ; load low word ; ; B &equals; predicted time time, A &equals; actual time ; ssbx SXM nop ;xc 2, TC ;stm &num;Offh, AG ; correct AG for sign bit. sub A, B abs B sub &num;1000, B, A ; If we have a huge difference, ignore it. bc UpdNPTime, AGT dadd *AR3(_AvgTimeDiff), B ; add to the time diff's dst B, *AR3(_AvgTimeDiff) UpdNPTime: ;Update “Next Packet” Expected Arrival Time mvdk *AR1 (UDP_HEADER_SIZE&plus;RTP_TIMESTAMP_OFFSET−1), BH mvdk *AR1 (UDP_HEADER_SIZE&plus;RTP_TIMESTAMP_OFFSET), BL ld B, A dsub *AR3 (_LastPacketRTime), B st &num;0, *(BG) dst A, *AR3(_LastpacketRTime) mvdk *AR2 (ETHER_HEADER_SIZE&plus;IP_HEADER_SIZE&plus;UDP — HEADER_SIZE&plus;RTP_TIMESTAMP_OFFSET−1),AH mvdk *AR2 (ETHER_HEADER_SIZE&plus;IP_HEADER_SIZE&plus;UDP — HEADER_SIZE&plus;RTP_TIMESTAMP_OFFSET),AL nop add A, B dst B, *AR3(_LastPacketLTime) Lines 1 - 18 of the code listing determine whether the channel is in a steady enough state to begin calculating jitter. At lines 19 and 20 , the actual and expected arrival times are compared. The local sample time is obtained at lines 21 - 44 . The next packet expected arrival time is then updated at lines 46 - 60 and the process is repeated as described above with reference to FIG. 2 . Exemplary source code for the foreground task is illustrated in the code listing below which is separately line numbered for easy reference. 2 case RING_CADENCE: RingCadence&plus;&plus;; if (RingCadence >&equals; 3) RingCadence &equals; 0; writeFlag &equals; 1; msg &lsqb;0&rsqb; &equals; HEARTBEAT; msg &lsqb;1&rsqb; &equals; &equals; 0×FF; /* Use this opportunity to adjust jitter buffers for optimum quality */ /* AvgTimeDiff is sum of absolute value of *sample* time diffs */ for (line &equals; 0; line < NUMBER_OF_CHANNELS; line&plus;&plus;) if ((OctetsSent &lsqb;line&rsqb; > 32000) && ((chnl_state &lsqb;line&rsqb; >> RX_SHIFT) & STATE_MASK) &equals;&equals; ACTIVE_STATE) &lcub; if (CrashCount &lsqb;line&rsqb; > 0×100) CrashCount &lsqb;line&rsqb; &equals; 0×100; temp &equals; (AvgTimeDiff &lsqb;line&rsqb; / PacketsSent &lsqb;line&rsqb;) &plus; (DataRate &lsqb;line&rsqb; >> 3) &plus; 2 &plus; (AvgPacktRecvd &lsqb;line&rsqb; >>1) &plus; (CrashCount &lsqb;line&rsqb; <<3); if (temp > 0×180) temp &equals; 0×180; if (abs(temp − OptimalJBLevel &lsqb;line&rsqb;) > 32) OptimalJBLevel &lsqb;line&rsqb; &equals; temp; if (CrashCount &lsqb;line&rsqb; > 0) CrashCount &lsqb;line&rsqb;--; &rcub; break; The cycle time for resetting the buffer size is set at lines 1 - 7 using the variables RING_CADENCE and HEARTBEAT. The average time difference is determined at lines 8 - 20 . A possible new buffer size is calculated at lines 21 - 25 . At lines 26 - 27 , it is determined whether the difference between the old buffer size and the new buffer size is more than 32 words. If it is, the new buffer size is used to adjust the buffer. CrashCount is used to increase the minimum buffer size every time the buffer crashes so as to attempt to prevent another crash. There have been described and illustrated herein methods and apparatus for determining jitter buffer size and adjusting a dynamic buffer accordingly in a voice over packet communications system. While particular embodiments of the invention have been described, it is not intended that the invention be limited thereto, as it is intended that the invention be as broad in scope as the art will allow and that the specification be read likewise. It will therefore be appreciated by those skilled in the art that yet other modifications could be made to the provided invention without deviating from its spirit and scope as so claimed.