From patchwork Tue Jul 21 14:23:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 498242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (tmp.osmocom.org [144.76.43.76]) by ozlabs.org (Postfix) with ESMTP id 440F2140E10 for ; Wed, 22 Jul 2015 00:24:44 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 517A38417; Tue, 21 Jul 2015 14:24:43 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from mail.us.es (mail.us.es [193.147.175.20]) by lists.osmocom.org (Postfix) with ESMTP id 8648483F6 for ; Tue, 21 Jul 2015 14:24:42 +0000 (UTC) Received: (qmail 7753 invoked from network); 21 Jul 2015 16:18:01 +0200 Received: from unknown (HELO us.es) (192.168.2.12) by us.es with SMTP; 21 Jul 2015 16:18:01 +0200 Received: (qmail 3797 invoked by uid 507); 21 Jul 2015 14:18:01 -0000 X-Qmail-Scanner-Diagnostics: from 127.0.0.1 by antivirus2 (envelope-from , uid 501) with qmail-scanner-2.10 (clamdscan: 0.98.7/20703. spamassassin: 3.4.0. Clear:RC:1(127.0.0.1):SA:0(-103.2/7.5):. Processed in 4.8626 secs); 21 Jul 2015 14:18:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on antivirus2 X-Spam-Level: X-Spam-Status: No, score=-103.2 required=7.5 tests=BAYES_50,SMTPAUTH_US, USER_IN_WHITELIST autolearn=disabled version=3.4.0 X-Spam-ASN: AS12715 87.216.0.0/16 X-Envelope-From: pablo@gnumonks.org Received: from unknown (HELO antivirus2) (127.0.0.1) by us.es with SMTP; 21 Jul 2015 14:17:56 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus2 (F-Secure/fsigk_smtp/412/antivirus2); Tue, 21 Jul 2015 16:17:56 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/412/antivirus2) Received: (qmail 12665 invoked from network); 21 Jul 2015 16:17:56 +0200 Received: from 129.166.216.87.static.jazztel.es (HELO salvia.here) (pneira@us.es@87.216.166.129) by mail.us.es with SMTP; 21 Jul 2015 16:17:56 +0200 From: pablo@gnumonks.org To: openbsc@lists.osmocom.org Subject: [PATCH libosmo-netif 02/18] osmux: add osmux_input_state structure Date: Tue, 21 Jul 2015 16:23:17 +0200 Message-Id: <1437488613-3943-3-git-send-email-pablo@gnumonks.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1437488613-3943-1-git-send-email-pablo@gnumonks.org> References: <1437488613-3943-1-git-send-email-pablo@gnumonks.org> X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" From: Pablo Neira Ayuso This new structure serves as container of the internal osmux state during transformation from RTP AMR to the compressed osmux format. This reduces the footprint of several functions and it makes them easier to extend if we need to pass new information between functions. --- src/osmux.c | 77 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/src/osmux.c b/src/osmux.c index a3eccaa..938b9a6 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -221,63 +221,65 @@ static void osmux_batch_dequeue(struct msgb *msg, struct batch_list_node *node) node->nmsgs--; } -static int -osmux_batch_put(struct osmux_in_handle *h, struct msgb *out_msg, - struct msgb *msg, struct rtp_hdr *rtph, - struct amr_hdr *amrh, uint32_t amr_payload_len, - int ccid, int add_osmux_header) +struct osmux_input_state { + struct msgb *out_msg; + struct msgb *msg; + struct rtp_hdr *rtph; + struct amr_hdr *amrh; + uint32_t amr_payload_len; + int ccid; + int add_osmux_hdr; +}; + +static int osmux_batch_put(struct osmux_in_handle *h, + struct osmux_input_state *state) { struct osmux_batch *batch = (struct osmux_batch *)h->internal_data; struct osmux_hdr *osmuxh; - if (add_osmux_header) { - osmuxh = (struct osmux_hdr *)out_msg->tail; + if (state->add_osmux_hdr) { + osmuxh = (struct osmux_hdr *)state->out_msg->tail; osmuxh->ft = OSMUX_FT_VOICE_AMR; osmuxh->ctr = 0; - osmuxh->amr_f = amrh->f; - osmuxh->amr_q= amrh->q; + osmuxh->amr_f = state->amrh->f; + osmuxh->amr_q= state->amrh->q; osmuxh->seq = batch->seq++; - osmuxh->circuit_id = ccid; - osmuxh->amr_cmr = amrh->cmr; - osmuxh->amr_ft = amrh->ft; - msgb_put(out_msg, sizeof(struct osmux_hdr)); + osmuxh->circuit_id = state->ccid; + osmuxh->amr_cmr = state->amrh->cmr; + osmuxh->amr_ft = state->amrh->ft; + msgb_put(state->out_msg, sizeof(struct osmux_hdr)); /* annotate current osmux header */ batch->osmuxh = osmuxh; } else { if (batch->osmuxh->ctr == 0x7) { LOGP(DLMIB, LOGL_ERROR, "cannot add msg=%p, " - "too many messages for this RTP ssrc=%u\n", - msg, rtph->ssrc); + "too many messages for this RTP ssrc=%u\n", + state->msg, state->rtph->ssrc); return 0; } batch->osmuxh->ctr++; } - memcpy(out_msg->tail, osmo_amr_get_payload(amrh), amr_payload_len); - msgb_put(out_msg, amr_payload_len); + memcpy(state->out_msg->tail, osmo_amr_get_payload(state->amrh), + state->amr_payload_len); + msgb_put(state->out_msg, state->amr_payload_len); return 0; } -static int -osmux_xfrm_encode_amr(struct osmux_in_handle *h, - struct msgb *out_msg, - struct rtp_hdr *rtph, struct msgb *msg, - int ccid, int add_osmux_header) +static int osmux_xfrm_encode_amr(struct osmux_in_handle *h, + struct osmux_input_state *state) { - struct amr_hdr *amrh; uint32_t amr_len; - uint32_t amr_payload_len; - amrh = osmo_rtp_get_payload(rtph, msg, &amr_len); - if (amrh == NULL) + state->amrh = osmo_rtp_get_payload(state->rtph, state->msg, &amr_len); + if (state->amrh == NULL) return -1; - amr_payload_len = amr_len - sizeof(struct amr_hdr); + state->amr_payload_len = amr_len - sizeof(struct amr_hdr); - if (osmux_batch_put(h, out_msg, msg, rtph, amrh, amr_payload_len, - ccid, add_osmux_header) < 0) + if (osmux_batch_put(h, state) < 0) return -1; return 0; @@ -304,9 +306,11 @@ static struct msgb *osmux_build_batch(struct osmux_in_handle *h) int ctr = 0; llist_for_each_entry_safe(cur, tmp, &node->list, list) { - struct rtp_hdr *rtph; - int add_osmux_hdr = 0; - + struct osmux_input_state state = { + .msg = cur, + .out_msg = batch_msg, + .ccid = node->ccid, + }; #ifdef DEBUG_MSG char buf[4096]; @@ -315,19 +319,18 @@ static struct msgb *osmux_build_batch(struct osmux_in_handle *h) LOGP(DLMIB, LOGL_DEBUG, "to BSC-NAT: %s\n", buf); #endif - rtph = osmo_rtp_get_hdr(cur); - if (rtph == NULL) + state.rtph = osmo_rtp_get_hdr(cur); + if (state.rtph == NULL) return NULL; if (ctr == 0) { #ifdef DEBUG_MSG LOGP(DLMIB, LOGL_DEBUG, "add osmux header\n"); #endif - add_osmux_hdr = 1; + state.add_osmux_hdr = 1; } - osmux_xfrm_encode_amr(h, batch_msg, rtph, cur, - node->ccid, add_osmux_hdr); + osmux_xfrm_encode_amr(h, &state); osmux_batch_dequeue(cur, node); msgb_free(cur); ctr++;