www.pudn.com > streamrtp.rar > rtpqueueinternal.c
/*------------------------------------------------------------------------- * rtpqueueinternal.c - _rtpqclear, _rtpqinsert, rtpqueueextract *------------------------------------------------------------------------- */ #include#include #include #include /*------------------------------------------------------------------------ * _rtpqclear - free all packets from a stream's RTP queue. * Assumes queue already locked. *------------------------------------------------------------------------ */ int _rtpqclear(struct rtpqueue *pq) { struct rtpln *p, *q; p = pq->rq_tail; while (p != NULL) { q = p->rln_next; bufpoolfreebuf(p); p = q; } pq->rq_tail = NULL; pq->rq_head = NULL; return OK; } /*------------------------------------------------------------------------ * _rtpqinsert - insert a node into a stream's RTP queue. * Assumes queue already locked. *------------------------------------------------------------------------ */ int _rtpqinsert(struct rtpqueue *pq, struct rtpln *pln, bool *head) { struct rtpln *p, *q; if (head != NULL) *head = FALSE; p = pq->rq_tail; q = NULL; while (p != NULL && p->rln_seq > pln->rln_seq) { q = p; p = p->rln_next; } if (q != NULL) { q->rln_next = pln; pln->rln_prev = q; } else { pq->rq_tail = pln; pln->rln_prev = NULL; } if (p != NULL) { p->rln_prev = pln; pln->rln_next = p; } else { pq->rq_head = pln; pln->rln_next = NULL; if (head != NULL) *head = TRUE; } pq->rq_len += pln->rln_len; return OK; } /*------------------------------------------------------------------------ * rtpqextract - extrace a packet from the doubly-linked list * Assumes queue already locked. *------------------------------------------------------------------------ */ struct rtpln * rtpqextract(struct rtpqueue *pq, struct rtpln *pln) { struct rtpln *n, *p; if (pln == NULL) return NULL; n = pln->rln_next; p = pln->rln_prev; if (n != NULL) n->rln_prev = p; else pq->rq_head = p; if (p != NULL) p->rln_next = n; else pq->rq_tail = n; pln->rln_next = NULL; pln->rln_prev = NULL; pq->rq_len -= pln->rln_len; return pln; }