A minor change in function WebRtcNetEQ_PacketBufferFindLowestTimestamp for

NetEq, for performance reasons.
In Android platform, with an offline testing file, the function cycles was reduced by 25%.
This function was also reformatted.
Review URL: https://webrtc-codereview.appspot.com/367010

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1571 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
kma@webrtc.org 2012-01-30 15:37:33 +00:00
parent 7627843352
commit 89a100092a
2 changed files with 103 additions and 93 deletions

View File

@ -388,90 +388,100 @@ int WebRtcNetEQ_PacketBufferExtract(PacketBuf_t *bufferInst, RTPPacket_t *RTPpac
return (0); return (0);
} }
int WebRtcNetEQ_PacketBufferFindLowestTimestamp(PacketBuf_t* buffer_inst,
int WebRtcNetEQ_PacketBufferFindLowestTimestamp(PacketBuf_t *bufferInst, uint32_t current_time_stamp,
WebRtc_UWord32 currentTS, uint32_t* time_stamp,
WebRtc_UWord32 *timestamp, int* buffer_position,
int *bufferPosition, int eraseOldPkts, int erase_old_packets,
WebRtc_Word16 *payloadType) int16_t* payload_type) {
{ int32_t time_stamp_diff = WEBRTC_SPL_WORD32_MAX; /* Smallest diff found. */
WebRtc_Word32 timeStampDiff = WEBRTC_SPL_WORD32_MAX; /* Smallest diff found */ int32_t new_diff;
WebRtc_Word32 newDiff;
int i; int i;
WebRtc_Word16 rcuPlCntr; int16_t rcu_payload_cntr;
/* Sanity check */ if (buffer_inst->startPayloadMemory == NULL) {
if (bufferInst->startPayloadMemory == NULL) /* Packet buffer has not been initialized. */
{ return PBUFFER_NOT_INITIALIZED;
/* packet buffer has not been initialized */
return (PBUFFER_NOT_INITIALIZED);
} }
/* Initialize all return values */ /* Initialize all return values. */
*timestamp = 0; *time_stamp = 0;
*payloadType = -1; /* indicates that no packet was found */ *payload_type = -1; /* Indicates that no packet was found. */
*bufferPosition = -1; /* indicates that no packet was found */ *buffer_position = -1; /* Indicates that no packet was found. */
rcuPlCntr = WEBRTC_SPL_WORD16_MAX; /* indicates that no packet was found */ rcu_payload_cntr = WEBRTC_SPL_WORD16_MAX; /* Indicates no packet found. */
/* Check if buffer is empty */ /* Check if buffer is empty. */
if (bufferInst->numPacketsInBuffer <= 0) if (buffer_inst->numPacketsInBuffer <= 0) {
{ return 0;
/* Empty buffer */
return (0);
} }
/* Loop through all slots in buffer */ /* Loop through all slots in buffer. */
for (i = 0; i < bufferInst->maxInsertPositions; i++) if (erase_old_packets) { /* If old payloads should be discarded. */
{ for (i = 0; i < buffer_inst->maxInsertPositions; ++i) {
/* Calculate difference between this slot and currentTS */ /* Calculate difference between this slot and current_time_stamp. */
newDiff = (WebRtc_Word32) (bufferInst->timeStamp[i] - currentTS); new_diff = (int32_t)(buffer_inst->timeStamp[i] - current_time_stamp);
/* Check if payload should be discarded */ /* Check if payload should be discarded. */
if ((newDiff < 0) /* payload is too old */ if ((new_diff < 0) /* Payload is too old */
&& (newDiff > -30000) /* account for TS wrap-around */ && (new_diff > -30000) /* Account for TS wrap-around. */
&& (eraseOldPkts) /* old payloads should be discarded */ && (buffer_inst->payloadLengthBytes[i] > 0)) { /* Payload exists. */
&& (bufferInst->payloadLengthBytes[i] > 0)) /* the payload exists */ /* Throw away old packet. */
{
/* Throw away old packet */
/* Clear the position in the buffer */ /* Clear the position in the buffer. */
bufferInst->payloadType[i] = -1; buffer_inst->payloadType[i] = -1;
bufferInst->payloadLengthBytes[i] = 0; buffer_inst->payloadLengthBytes[i] = 0;
/* Reduce packet counter by one */ /* Reduce packet counter by one. */
bufferInst->numPacketsInBuffer--; buffer_inst->numPacketsInBuffer--;
/* Increase discard counter for in-call statistics. */
/* Increase discard counter for in-call statistics */ buffer_inst->discardedPackets++;
bufferInst->discardedPackets++; } else if (((new_diff < time_stamp_diff)
} || ((new_diff == time_stamp_diff)
else if (((newDiff < timeStampDiff) || ((newDiff == timeStampDiff) && (buffer_inst->rcuPlCntr[i] < rcu_payload_cntr)))
&& (bufferInst->rcuPlCntr[i] < rcuPlCntr))) && (bufferInst->payloadLengthBytes[i] && (buffer_inst->payloadLengthBytes[i] > 0)) {
> 0)) /* New diff is smaller than previous diffs or we have a candidate with a
{ * time stamp as previous candidate but better RCU-counter;
/* * and the payload exists.
* New diff is smaller than previous diffs or we have a candidate with a timestamp
* as previous candidate but better RCU-counter; and the payload exists.
*/ */
/* Save this position as the best candidate. */
/* Save this position as the best candidate */ *buffer_position = i;
*bufferPosition = i; time_stamp_diff = new_diff;
timeStampDiff = newDiff; *payload_type = buffer_inst->payloadType[i];
*payloadType = bufferInst->payloadType[i]; rcu_payload_cntr = buffer_inst->rcuPlCntr[i];
rcuPlCntr = bufferInst->rcuPlCntr[i];
} }
} /* end of for loop */ }
} else {
for (i = 0; i < buffer_inst->maxInsertPositions; ++i) {
/* Calculate difference between this slot and current_time_stamp. */
new_diff = (int32_t)(buffer_inst->timeStamp[i] - current_time_stamp);
/* check that we did find a real position */ /* Check if this is the oldest packet. */
if (*bufferPosition >= 0) if (((new_diff < time_stamp_diff)
{ || ((new_diff == time_stamp_diff)
/* get the timestamp for the best position */ && (buffer_inst->rcuPlCntr[i] < rcu_payload_cntr)))
*timestamp = bufferInst->timeStamp[*bufferPosition]; && (buffer_inst->payloadLengthBytes[i] > 0)) {
/* New diff is smaller than previous diffs or we have a candidate with a
* time_stamp as previous candidate but better RCU-counter;
* and the payload exists.
*/
/* Save this position as the best candidate. */
*buffer_position = i;
time_stamp_diff = new_diff;
*payload_type = buffer_inst->payloadType[i];
rcu_payload_cntr = buffer_inst->rcuPlCntr[i];
}
}
}
/* Check that we did find a real position. */
if (*buffer_position >= 0) {
/* Get the time_stamp for the best position. */
*time_stamp = buffer_inst->timeStamp[*buffer_position];
} }
return 0; return 0;
} }
WebRtc_Word32 WebRtcNetEQ_PacketBufferGetSize(const PacketBuf_t *bufferInst) WebRtc_Word32 WebRtcNetEQ_PacketBufferGetSize(const PacketBuf_t *bufferInst)
{ {
int i, count; int i, count;
@ -718,4 +728,3 @@ int WebRtcNetEQ_GetDefaultCodecSettings(const enum WebRtcNetEQDecoder *codecID,
return ok; return ok;
} }

View File

@ -146,25 +146,26 @@ int WebRtcNetEQ_PacketBufferExtract(PacketBuf_t *bufferInst, RTPPacket_t *RTPpac
* This function finds the next packet with the lowest timestamp. * This function finds the next packet with the lowest timestamp.
* *
* Input: * Input:
* - bufferInst : Buffer instance * - buffer_inst : Buffer instance.
* - currentTS : The timestamp to compare packet timestamps with * - current_time_stamp : The timestamp to compare packet timestamps with.
* - eraseOldPkts : If non-zero, erase packets older than currentTS * - erase_old_packets : If non-zero, erase packets older than currentTS.
* *
* Output: * Output:
* - timestamp : Lowest timestamp that was found * - time_stamp : Lowest timestamp that was found.
* - bufferPosition: Position of this packet (-1 if there are no packets * - buffer_position : Position of this packet (-1 if there are no
* in the buffer) * packets in the buffer).
* - payloadType : Payload type of the found payload * - payload_type : Payload type of the found payload.
* *
* Return value : 0 - Ok * Return value : 0 - Ok;
* <0 - Error * < 0 - Error.
*/ */
int WebRtcNetEQ_PacketBufferFindLowestTimestamp(PacketBuf_t *bufferInst, int WebRtcNetEQ_PacketBufferFindLowestTimestamp(PacketBuf_t* buffer_inst,
WebRtc_UWord32 currentTS, uint32_t current_time_stamp,
WebRtc_UWord32 *timestamp, uint32_t* time_stamp,
int *bufferPosition, int eraseOldPkts, int* buffer_position,
WebRtc_Word16 *payloadType); int erase_old_packets,
int16_t* payload_type);
/**************************************************************************** /****************************************************************************
* WebRtcNetEQ_PacketBufferGetSize(...) * WebRtcNetEQ_PacketBufferGetSize(...)