diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-04 20:53:57 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-04 20:53:57 +0200 |
commit | 082d700a8f66d74efcbb967116b22075b5c67caf (patch) | |
tree | 82471003025f121017ca014ff72f1f3807ce7766 | |
parent | 2cefb116d07a71cd15d2361f6e04385467e995e2 (diff) |
osmux: fix list ordering for RTP messages that will be included in batch
This fixes the algorithms to include the messages in order in the
batch based on the TRP SSRC (from lower to higher).
This is very important to reduce the amount of bytes that we
spend on the osmux header.
-rw-r--r-- | src/osmux.c | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/src/osmux.c b/src/osmux.c index ec43e8b..b1aaf6e 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -270,6 +270,7 @@ static int osmux_msgb_batch_queue_add(struct msgb *msg) struct rtp_hdr *rtph; struct msgb *cur; int found = 0, bytes = 0; + struct llist_head *list; rtph = osmo_rtp_get_hdr(msg); if (rtph == NULL) @@ -278,35 +279,21 @@ static int osmux_msgb_batch_queue_add(struct msgb *msg) llist_for_each_entry(cur, &batch.msgb_list, list) { struct rtp_hdr *rtph2; - rtph2 = osmo_rtp_get_hdr(msg); + rtph2 = osmo_rtp_get_hdr(cur); if (rtph2 == NULL) return -1; - /* inset messages in order based on the RTP SSRC */ - if (rtph->ssrc < rtph2->ssrc) - continue; - if (rtph->ssrc == rtph2->ssrc) { - found = 1; - continue; - } - - bytes += osmux_rtp_amr_payload_len(msg, rtph); - if (!found) - bytes += sizeof(struct osmux_hdr); - - /* Still room in this batch for this message? if there is not - * then deliver current batch. + /* We insert messages in order based on the RTP SSRC. This is + * useful to build the batch. */ - if (bytes > batch.remaining_bytes) - return 1; - - batch.remaining_bytes -= bytes; - llist_add(&msg->list, &cur->list); - - LOGP(DOSMUX, LOGL_DEBUG, "adding to batch (%p)\n", msg); - - return 0; + if (rtph->ssrc > rtph2->ssrc) + break; } + if (cur->list.next == batch.msgb_list.next) + list = cur->list.next; + else + list = cur->list.prev; + /* * ... adding to the tail or empty list case. */ @@ -321,7 +308,7 @@ static int osmux_msgb_batch_queue_add(struct msgb *msg) return 1; batch.remaining_bytes -= bytes; - llist_add_tail(&msg->list, &batch.msgb_list); + llist_add_tail(&msg->list, list); LOGP(DOSMUX, LOGL_DEBUG, "adding to batch (%p)\n", msg); |