2012-07-09 17:39:55 +00:00
|
|
|
/*
|
|
|
|
* (C) 2012 by Pablo Neira Ayuso <pablo@gnumonks.org>
|
|
|
|
* (C) 2012 by On Waves ehf <http://www.on-waves.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/timer.h>
|
|
|
|
#include <osmocom/core/select.h>
|
2012-07-19 09:08:21 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2012-07-19 11:04:39 +00:00
|
|
|
#include <osmocom/core/logging.h>
|
2012-07-09 17:39:55 +00:00
|
|
|
|
|
|
|
#include <osmocom/netif/amr.h>
|
|
|
|
#include <osmocom/netif/rtp.h>
|
|
|
|
#include <osmocom/netif/osmux.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2017-04-08 18:00:47 +00:00
|
|
|
/*! \addtogroup osmux Osmocom Multiplex Protocol
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file osmux.c
|
|
|
|
* \brief Osmocom multiplex protocol helpers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-08-28 13:14:33 +00:00
|
|
|
/* This allows you to debug timing reconstruction in the output path */
|
|
|
|
#if 0
|
2013-05-26 23:30:36 +00:00
|
|
|
#define DEBUG_TIMING 0
|
2014-08-28 13:14:33 +00:00
|
|
|
#endif
|
2012-07-19 10:53:04 +00:00
|
|
|
|
2014-08-28 15:15:44 +00:00
|
|
|
/* This allows you to debug osmux message transformations (spamming) */
|
|
|
|
#if 0
|
|
|
|
#define DEBUG_MSG 0
|
|
|
|
#endif
|
|
|
|
|
2017-04-24 08:09:26 +00:00
|
|
|
/* delta time between two RTP messages (in microseconds) */
|
|
|
|
#define DELTA_RTP_MSG 20000
|
|
|
|
/* delta time between two RTP messages (in samples, 8kHz) */
|
2012-10-15 19:42:00 +00:00
|
|
|
#define DELTA_RTP_TIMESTAMP 160
|
2012-08-04 17:56:47 +00:00
|
|
|
|
2013-02-19 12:16:27 +00:00
|
|
|
static void *osmux_ctx;
|
|
|
|
|
2013-02-19 16:14:33 +00:00
|
|
|
static uint32_t osmux_get_payload_len(struct osmux_hdr *osmuxh)
|
|
|
|
{
|
|
|
|
return osmo_amr_bytes(osmuxh->amr_ft) * (osmuxh->ctr+1);
|
|
|
|
}
|
|
|
|
|
2017-04-25 15:27:13 +00:00
|
|
|
static uint32_t osmux_ft_dummy_size(uint8_t amr_ft, uint8_t batch_factor)
|
2012-07-09 17:39:55 +00:00
|
|
|
{
|
2015-07-17 18:47:04 +00:00
|
|
|
return sizeof(struct osmux_hdr) + (osmo_amr_bytes(amr_ft) * batch_factor);
|
|
|
|
}
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
struct osmux_hdr *osmux_xfrm_output_pull(struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct osmux_hdr *osmuxh;
|
|
|
|
next:
|
|
|
|
osmuxh = NULL;
|
2012-07-09 17:39:55 +00:00
|
|
|
if (msg->len > sizeof(struct osmux_hdr)) {
|
2013-05-24 08:47:50 +00:00
|
|
|
size_t len;
|
|
|
|
|
2012-07-09 17:39:55 +00:00
|
|
|
osmuxh = (struct osmux_hdr *)msg->data;
|
2013-05-24 09:56:07 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
switch (osmuxh->ft) {
|
|
|
|
case OSMUX_FT_VOICE_AMR:
|
|
|
|
break;
|
|
|
|
case OSMUX_FT_DUMMY:
|
|
|
|
msgb_pull(msg, osmux_ft_dummy_size(osmuxh->amr_ft,
|
|
|
|
osmuxh->ctr + 1));
|
|
|
|
goto next;
|
|
|
|
default:
|
2015-07-17 19:20:43 +00:00
|
|
|
LOGP(DLMIB, LOGL_ERROR, "Discarding unsupported Osmux FT %d\n",
|
|
|
|
osmuxh->ft);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-05-24 09:56:07 +00:00
|
|
|
if (!osmo_amr_ft_valid(osmuxh->amr_ft)) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "Discarding bad AMR FT %d\n",
|
|
|
|
osmuxh->amr_ft);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-24 08:47:50 +00:00
|
|
|
len = osmo_amr_bytes(osmuxh->amr_ft) * (osmuxh->ctr+1) +
|
|
|
|
sizeof(struct osmux_hdr);
|
|
|
|
|
|
|
|
if (len > msg->len) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "Discarding malformed "
|
|
|
|
"OSMUX message\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2013-05-24 08:47:50 +00:00
|
|
|
msgb_pull(msg, len);
|
2012-07-09 17:39:55 +00:00
|
|
|
} else if (msg->len > 0) {
|
2012-10-15 13:59:14 +00:00
|
|
|
LOGP(DLMIB, LOGL_ERROR,
|
2012-07-19 11:04:39 +00:00
|
|
|
"remaining %d bytes, broken osmuxhdr?\n", msg->len);
|
2012-07-09 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return osmuxh;
|
|
|
|
}
|
|
|
|
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
static struct msgb *
|
2017-04-25 15:20:38 +00:00
|
|
|
osmux_rebuild_rtp(struct osmux_out_handle *h, struct osmux_hdr *osmuxh,
|
|
|
|
void *payload, int payload_len, bool first_pkt)
|
2012-07-09 17:39:55 +00:00
|
|
|
{
|
|
|
|
struct msgb *out_msg;
|
|
|
|
struct rtp_hdr *rtph;
|
|
|
|
struct amr_hdr *amrh;
|
|
|
|
|
|
|
|
out_msg = msgb_alloc(sizeof(struct rtp_hdr) +
|
|
|
|
sizeof(struct amr_hdr) +
|
2013-02-12 18:22:45 +00:00
|
|
|
osmo_amr_bytes(osmuxh->amr_ft),
|
2012-07-13 19:16:30 +00:00
|
|
|
"OSMUX test");
|
2012-07-09 17:39:55 +00:00
|
|
|
if (out_msg == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Reconstruct RTP header */
|
|
|
|
rtph = (struct rtp_hdr *)out_msg->data;
|
2012-08-06 16:49:05 +00:00
|
|
|
rtph->csrc_count = 0;
|
2012-07-09 17:39:55 +00:00
|
|
|
rtph->extension = 0;
|
|
|
|
rtph->version = RTP_VERSION;
|
|
|
|
rtph->payload_type = 98;
|
|
|
|
/* ... emulate timestamp and ssrc */
|
2013-02-12 16:23:29 +00:00
|
|
|
rtph->timestamp = htonl(h->rtp_timestamp);
|
|
|
|
rtph->sequence = htons(h->rtp_seq);
|
2013-05-12 16:03:50 +00:00
|
|
|
rtph->ssrc = htonl(h->rtp_ssrc);
|
2017-04-25 15:20:38 +00:00
|
|
|
/* rtp packet with the marker bit is always warranted to be the first one */
|
|
|
|
rtph->marker = first_pkt && osmuxh->rtp_m;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
|
|
|
msgb_put(out_msg, sizeof(struct rtp_hdr));
|
|
|
|
|
|
|
|
/* Reconstruct AMR header */
|
|
|
|
amrh = (struct amr_hdr *)out_msg->tail;
|
|
|
|
amrh->cmr = osmuxh->amr_cmr;
|
|
|
|
amrh->f = osmuxh->amr_f;
|
|
|
|
amrh->ft = osmuxh->amr_ft;
|
|
|
|
amrh->q = osmuxh->amr_q;
|
|
|
|
|
|
|
|
msgb_put(out_msg, sizeof(struct amr_hdr));
|
|
|
|
|
|
|
|
/* add AMR speech data */
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
memcpy(out_msg->tail, payload, payload_len);
|
|
|
|
msgb_put(out_msg, payload_len);
|
2012-07-09 17:39:55 +00:00
|
|
|
|
|
|
|
/* bump last RTP sequence number and timestamp that has been used */
|
2013-02-12 16:23:29 +00:00
|
|
|
h->rtp_seq++;
|
|
|
|
h->rtp_timestamp += DELTA_RTP_TIMESTAMP;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
|
|
|
return out_msg;
|
|
|
|
}
|
|
|
|
|
2012-08-04 17:56:47 +00:00
|
|
|
int osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h,
|
|
|
|
struct llist_head *list)
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
{
|
2012-08-04 17:56:47 +00:00
|
|
|
struct msgb *msg;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
int i;
|
|
|
|
|
2012-08-04 17:56:47 +00:00
|
|
|
INIT_LLIST_HEAD(list);
|
|
|
|
|
|
|
|
for (i=0; i<osmuxh->ctr+1; i++) {
|
2012-10-15 18:33:32 +00:00
|
|
|
struct rtp_hdr *rtph;
|
|
|
|
|
2012-08-04 17:56:47 +00:00
|
|
|
msg = osmux_rebuild_rtp(h, osmuxh,
|
|
|
|
osmux_get_payload(osmuxh) +
|
2013-02-12 18:22:45 +00:00
|
|
|
i * osmo_amr_bytes(osmuxh->amr_ft),
|
2017-04-25 15:20:38 +00:00
|
|
|
osmo_amr_bytes(osmuxh->amr_ft), !i);
|
2012-08-04 17:56:47 +00:00
|
|
|
if (msg == NULL)
|
2012-10-15 18:33:32 +00:00
|
|
|
continue;
|
2012-08-04 17:56:47 +00:00
|
|
|
|
2012-10-15 18:33:32 +00:00
|
|
|
rtph = osmo_rtp_get_hdr(msg);
|
|
|
|
if (rtph == NULL)
|
|
|
|
continue;
|
2012-08-04 17:56:47 +00:00
|
|
|
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
osmo_rtp_snprintf(buf, sizeof(buf), msg);
|
|
|
|
buf[sizeof(buf)-1] = '\0';
|
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "to BTS: %s\n", buf);
|
|
|
|
}
|
|
|
|
#endif
|
2014-08-28 16:37:22 +00:00
|
|
|
llist_add_tail(&msg->list, list);
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
}
|
2012-08-04 17:56:47 +00:00
|
|
|
return i;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 16:41:49 +00:00
|
|
|
struct osmux_batch {
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
struct osmo_timer_list timer;
|
|
|
|
struct osmux_hdr *osmuxh;
|
2015-07-17 17:24:49 +00:00
|
|
|
struct llist_head circuit_list;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
unsigned int remaining_bytes;
|
|
|
|
uint8_t seq;
|
2015-07-17 18:23:25 +00:00
|
|
|
uint32_t nmsgs;
|
2015-08-18 22:19:53 +00:00
|
|
|
int ndummy;
|
2012-08-06 16:41:49 +00:00
|
|
|
};
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
struct osmux_circuit {
|
2013-12-16 10:44:47 +00:00
|
|
|
struct llist_head head;
|
|
|
|
int ccid;
|
2015-07-17 17:37:28 +00:00
|
|
|
struct llist_head msg_list;
|
2013-12-16 10:44:47 +00:00
|
|
|
int nmsgs;
|
2015-07-17 18:47:04 +00:00
|
|
|
int dummy;
|
2013-12-16 10:44:47 +00:00
|
|
|
};
|
|
|
|
|
2017-04-12 14:11:50 +00:00
|
|
|
static int osmux_batch_enqueue(struct msgb *msg, struct osmux_circuit *circuit,
|
|
|
|
uint8_t batch_factor)
|
2013-12-16 10:44:47 +00:00
|
|
|
{
|
|
|
|
/* Too many messages per batch, discard it. The counter field of the
|
|
|
|
* osmux header is just 3 bits long, so make sure it doesn't overflow.
|
|
|
|
*/
|
2017-04-12 14:11:50 +00:00
|
|
|
if (circuit->nmsgs >= batch_factor || circuit->nmsgs >= 8) {
|
2013-12-16 10:44:47 +00:00
|
|
|
struct rtp_hdr *rtph;
|
|
|
|
|
|
|
|
rtph = osmo_rtp_get_hdr(msg);
|
|
|
|
if (rtph == NULL)
|
2014-08-28 12:26:03 +00:00
|
|
|
return -1;
|
2013-12-16 10:44:47 +00:00
|
|
|
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "too many messages for this RTP "
|
|
|
|
"ssrc=%u\n", rtph->ssrc);
|
2014-08-28 12:26:03 +00:00
|
|
|
return -1;
|
2013-12-16 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 17:37:28 +00:00
|
|
|
llist_add_tail(&msg->list, &circuit->msg_list);
|
2015-07-17 17:24:49 +00:00
|
|
|
circuit->nmsgs++;
|
2014-08-28 12:26:03 +00:00
|
|
|
return 0;
|
2013-12-16 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
static void osmux_batch_dequeue(struct msgb *msg, struct osmux_circuit *circuit)
|
2013-12-16 10:44:47 +00:00
|
|
|
{
|
|
|
|
llist_del(&msg->list);
|
2015-07-17 17:24:49 +00:00
|
|
|
circuit->nmsgs--;
|
2013-12-16 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 15:44:39 +00:00
|
|
|
static void osmux_circuit_del_msgs(struct osmux_batch *batch, struct osmux_circuit *circuit)
|
|
|
|
{
|
|
|
|
struct msgb *cur, *tmp;
|
|
|
|
llist_for_each_entry_safe(cur, tmp, &circuit->msg_list, list) {
|
|
|
|
osmux_batch_dequeue(cur, circuit);
|
|
|
|
msgb_free(cur);
|
|
|
|
batch->nmsgs--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 14:58:31 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2015-07-17 18:13:16 +00:00
|
|
|
static int osmux_batch_put(struct osmux_batch *batch,
|
2015-07-17 14:58:31 +00:00
|
|
|
struct osmux_input_state *state)
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
{
|
|
|
|
struct osmux_hdr *osmuxh;
|
|
|
|
|
2015-07-17 14:58:31 +00:00
|
|
|
if (state->add_osmux_hdr) {
|
|
|
|
osmuxh = (struct osmux_hdr *)state->out_msg->tail;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
osmuxh->ft = OSMUX_FT_VOICE_AMR;
|
|
|
|
osmuxh->ctr = 0;
|
2017-04-25 15:20:38 +00:00
|
|
|
osmuxh->rtp_m = osmuxh->rtp_m || state->rtph->marker;
|
2015-07-17 14:58:31 +00:00
|
|
|
osmuxh->amr_f = state->amrh->f;
|
|
|
|
osmuxh->amr_q= state->amrh->q;
|
2012-08-06 16:41:49 +00:00
|
|
|
osmuxh->seq = batch->seq++;
|
2015-07-17 14:58:31 +00:00
|
|
|
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));
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
|
|
|
/* annotate current osmux header */
|
2012-08-06 16:41:49 +00:00
|
|
|
batch->osmuxh = osmuxh;
|
2012-08-04 18:52:45 +00:00
|
|
|
} else {
|
2012-08-06 16:41:49 +00:00
|
|
|
if (batch->osmuxh->ctr == 0x7) {
|
2012-10-15 13:59:14 +00:00
|
|
|
LOGP(DLMIB, LOGL_ERROR, "cannot add msg=%p, "
|
2015-07-17 14:58:31 +00:00
|
|
|
"too many messages for this RTP ssrc=%u\n",
|
|
|
|
state->msg, state->rtph->ssrc);
|
2012-08-04 18:52:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-08-06 16:41:49 +00:00
|
|
|
batch->osmuxh->ctr++;
|
2012-08-04 18:52:45 +00:00
|
|
|
}
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2015-07-17 14:58:31 +00:00
|
|
|
memcpy(state->out_msg->tail, osmo_amr_get_payload(state->amrh),
|
|
|
|
state->amr_payload_len);
|
|
|
|
msgb_put(state->out_msg, state->amr_payload_len);
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-17 18:13:16 +00:00
|
|
|
static int osmux_xfrm_encode_amr(struct osmux_batch *batch,
|
2015-07-17 14:58:31 +00:00
|
|
|
struct osmux_input_state *state)
|
2012-07-09 17:39:55 +00:00
|
|
|
{
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
uint32_t amr_len;
|
|
|
|
|
2015-07-17 14:58:31 +00:00
|
|
|
state->amrh = osmo_rtp_get_payload(state->rtph, state->msg, &amr_len);
|
|
|
|
if (state->amrh == NULL)
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-07-17 14:58:31 +00:00
|
|
|
state->amr_payload_len = amr_len - sizeof(struct amr_hdr);
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2015-07-17 18:13:16 +00:00
|
|
|
if (osmux_batch_put(batch, state) < 0)
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-25 15:27:13 +00:00
|
|
|
static void osmux_encode_dummy(struct osmux_batch *batch, uint8_t batch_factor,
|
2015-07-17 18:47:04 +00:00
|
|
|
struct osmux_input_state *state)
|
|
|
|
{
|
|
|
|
struct osmux_hdr *osmuxh;
|
|
|
|
/* TODO: This should be configurable at some point. */
|
|
|
|
uint32_t payload_size = osmux_ft_dummy_size(AMR_FT_3, batch_factor) -
|
|
|
|
sizeof(struct osmux_hdr);
|
|
|
|
|
|
|
|
osmuxh = (struct osmux_hdr *)state->out_msg->tail;
|
|
|
|
osmuxh->ft = OSMUX_FT_DUMMY;
|
|
|
|
osmuxh->ctr = batch_factor - 1;
|
|
|
|
osmuxh->amr_f = 0;
|
|
|
|
osmuxh->amr_q= 0;
|
|
|
|
osmuxh->seq = 0;
|
|
|
|
osmuxh->circuit_id = state->ccid;
|
|
|
|
osmuxh->amr_cmr = 0;
|
|
|
|
osmuxh->amr_ft = AMR_FT_3;
|
|
|
|
msgb_put(state->out_msg, sizeof(struct osmux_hdr));
|
|
|
|
|
|
|
|
memset(state->out_msg->tail, 0xff, payload_size);
|
|
|
|
msgb_put(state->out_msg, payload_size);
|
|
|
|
}
|
|
|
|
|
2015-07-17 18:13:16 +00:00
|
|
|
static struct msgb *osmux_build_batch(struct osmux_batch *batch,
|
2017-04-25 15:27:13 +00:00
|
|
|
uint32_t batch_size, uint8_t batch_factor)
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
{
|
2012-10-15 18:33:32 +00:00
|
|
|
struct msgb *batch_msg;
|
2015-07-17 17:55:18 +00:00
|
|
|
struct osmux_circuit *circuit;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2014-08-28 15:30:01 +00:00
|
|
|
#ifdef DEBUG_MSG
|
2012-10-15 18:33:32 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "Now building batch\n");
|
2014-08-28 15:30:01 +00:00
|
|
|
#endif
|
2012-10-15 18:33:32 +00:00
|
|
|
|
2015-07-17 18:13:16 +00:00
|
|
|
batch_msg = msgb_alloc(batch_size, "osmux");
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
if (batch_msg == NULL) {
|
2012-10-15 13:59:14 +00:00
|
|
|
LOGP(DLMIB, LOGL_ERROR, "Not enough memory\n");
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:55:18 +00:00
|
|
|
llist_for_each_entry(circuit, &batch->circuit_list, head) {
|
2012-10-15 18:33:32 +00:00
|
|
|
struct msgb *cur, *tmp;
|
|
|
|
int ctr = 0;
|
2012-08-04 18:56:53 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
if (circuit->dummy) {
|
|
|
|
struct osmux_input_state state = {
|
|
|
|
.out_msg = batch_msg,
|
|
|
|
.ccid = circuit->ccid,
|
|
|
|
};
|
|
|
|
osmux_encode_dummy(batch, batch_factor, &state);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:37:28 +00:00
|
|
|
llist_for_each_entry_safe(cur, tmp, &circuit->msg_list, list) {
|
2015-07-17 14:58:31 +00:00
|
|
|
struct osmux_input_state state = {
|
|
|
|
.msg = cur,
|
|
|
|
.out_msg = batch_msg,
|
2015-07-17 17:24:49 +00:00
|
|
|
.ccid = circuit->ccid,
|
2015-07-17 14:58:31 +00:00
|
|
|
};
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
|
|
|
char buf[4096];
|
|
|
|
|
2012-10-15 18:33:32 +00:00
|
|
|
osmo_rtp_snprintf(buf, sizeof(buf), cur);
|
2013-05-24 10:49:52 +00:00
|
|
|
buf[sizeof(buf)-1] = '\0';
|
2014-04-25 13:02:26 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "to BSC-NAT: %s\n", buf);
|
2014-08-28 15:15:44 +00:00
|
|
|
#endif
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2015-07-17 14:58:31 +00:00
|
|
|
state.rtph = osmo_rtp_get_hdr(cur);
|
|
|
|
if (state.rtph == NULL)
|
2012-10-15 18:33:32 +00:00
|
|
|
return NULL;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2012-10-15 18:33:32 +00:00
|
|
|
if (ctr == 0) {
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
2012-10-15 18:33:32 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "add osmux header\n");
|
2014-08-28 15:15:44 +00:00
|
|
|
#endif
|
2015-07-17 14:58:31 +00:00
|
|
|
state.add_osmux_hdr = 1;
|
2012-10-15 18:33:32 +00:00
|
|
|
}
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2015-07-17 18:13:16 +00:00
|
|
|
osmux_xfrm_encode_amr(batch, &state);
|
2015-07-17 17:24:49 +00:00
|
|
|
osmux_batch_dequeue(cur, circuit);
|
2012-10-15 18:33:32 +00:00
|
|
|
msgb_free(cur);
|
|
|
|
ctr++;
|
2015-07-17 18:23:25 +00:00
|
|
|
batch->nmsgs--;
|
2012-10-15 18:33:32 +00:00
|
|
|
}
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
}
|
|
|
|
return batch_msg;
|
2012-07-09 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void osmux_xfrm_input_deliver(struct osmux_in_handle *h)
|
|
|
|
{
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
struct msgb *batch_msg;
|
2013-02-11 21:49:27 +00:00
|
|
|
struct osmux_batch *batch = (struct osmux_batch *)h->internal_data;
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
2012-10-15 13:59:14 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "invoking delivery function\n");
|
2014-08-28 15:15:44 +00:00
|
|
|
#endif
|
2015-07-17 18:47:04 +00:00
|
|
|
batch_msg = osmux_build_batch(batch, h->batch_size, h->batch_factor);
|
2017-02-07 10:46:41 +00:00
|
|
|
if (!batch_msg)
|
|
|
|
return;
|
2014-08-28 14:14:16 +00:00
|
|
|
h->stats.output_osmux_msgs++;
|
|
|
|
h->stats.output_osmux_bytes += batch_msg->len;
|
|
|
|
|
2013-02-11 21:49:27 +00:00
|
|
|
h->deliver(batch_msg, h->data);
|
2012-08-06 16:41:49 +00:00
|
|
|
osmo_timer_del(&batch->timer);
|
2014-08-28 13:01:03 +00:00
|
|
|
batch->remaining_bytes = h->batch_size;
|
2015-07-17 18:47:04 +00:00
|
|
|
|
2015-08-18 22:19:53 +00:00
|
|
|
if (batch->ndummy) {
|
2015-07-17 18:47:04 +00:00
|
|
|
osmo_timer_schedule(&batch->timer, 0,
|
|
|
|
h->batch_factor * DELTA_RTP_MSG);
|
|
|
|
}
|
2012-07-09 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void osmux_batch_timer_expired(void *data)
|
|
|
|
{
|
|
|
|
struct osmux_in_handle *h = data;
|
|
|
|
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
2012-10-15 18:33:32 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "osmux_batch_timer_expired\n");
|
2014-08-28 15:15:44 +00:00
|
|
|
#endif
|
2012-07-09 17:39:55 +00:00
|
|
|
osmux_xfrm_input_deliver(h);
|
|
|
|
}
|
|
|
|
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
static int osmux_rtp_amr_payload_len(struct msgb *msg, struct rtp_hdr *rtph)
|
2012-07-09 17:39:55 +00:00
|
|
|
{
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
struct amr_hdr *amrh;
|
|
|
|
unsigned int amr_len;
|
2013-12-16 12:36:13 +00:00
|
|
|
int amr_payload_len;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
amrh = osmo_rtp_get_payload(rtph, msg, &amr_len);
|
|
|
|
if (amrh == NULL)
|
|
|
|
return -1;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2013-05-24 09:56:07 +00:00
|
|
|
if (!osmo_amr_ft_valid(amrh->ft))
|
|
|
|
return -1;
|
|
|
|
|
2013-12-16 12:36:13 +00:00
|
|
|
amr_payload_len = amr_len - sizeof(struct amr_hdr);
|
|
|
|
|
|
|
|
/* The AMR payload does not fit with what we expect */
|
|
|
|
if (osmo_amr_bytes(amrh->ft) != amr_payload_len) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR,
|
|
|
|
"Bad AMR frame, expected %zd bytes, got %d bytes\n",
|
|
|
|
osmo_amr_bytes(amrh->ft), amr_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return amr_payload_len;
|
2012-07-09 17:39:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
static void osmux_replay_lost_packets(struct osmux_circuit *circuit,
|
2017-04-12 14:11:50 +00:00
|
|
|
struct rtp_hdr *cur_rtph, int batch_factor)
|
2013-05-20 22:28:13 +00:00
|
|
|
{
|
2013-12-16 11:14:31 +00:00
|
|
|
int16_t diff;
|
2013-05-20 22:28:13 +00:00
|
|
|
struct msgb *last;
|
|
|
|
struct rtp_hdr *rtph;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Have we see any RTP packet in this batch before? */
|
2015-07-17 17:37:28 +00:00
|
|
|
if (llist_empty(&circuit->msg_list))
|
2013-05-20 22:28:13 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get last RTP packet seen in this batch */
|
2015-07-17 17:37:28 +00:00
|
|
|
last = llist_entry(circuit->msg_list.prev, struct msgb, list);
|
2013-05-20 22:28:13 +00:00
|
|
|
rtph = osmo_rtp_get_hdr(last);
|
|
|
|
if (rtph == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
diff = ntohs(cur_rtph->sequence) - ntohs(rtph->sequence);
|
|
|
|
|
2013-09-12 11:18:19 +00:00
|
|
|
/* Lifesaver: make sure bugs don't spawn lots of clones */
|
|
|
|
if (diff > 16)
|
|
|
|
diff = 16;
|
|
|
|
|
2013-05-20 22:28:13 +00:00
|
|
|
/* If diff between last RTP packet seen and this one is > 1,
|
|
|
|
* then we lost several RTP packets, let's replay them.
|
|
|
|
*/
|
|
|
|
for (i=1; i<diff; i++) {
|
|
|
|
struct msgb *clone;
|
|
|
|
|
|
|
|
/* Clone last RTP packet seen */
|
|
|
|
clone = msgb_alloc(last->data_len, "RTP clone");
|
|
|
|
if (!clone)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memcpy(clone->data, last->data, last->len);
|
|
|
|
msgb_put(clone, last->len);
|
|
|
|
|
2014-08-28 12:28:23 +00:00
|
|
|
/* The original RTP message has been already sanity check. */
|
2013-05-20 22:28:13 +00:00
|
|
|
rtph = osmo_rtp_get_hdr(clone);
|
|
|
|
|
|
|
|
/* Adjust sequence number and timestamp */
|
|
|
|
rtph->sequence = htons(ntohs(rtph->sequence) + i);
|
|
|
|
rtph->timestamp = htonl(ntohl(rtph->timestamp) +
|
|
|
|
DELTA_RTP_TIMESTAMP);
|
|
|
|
|
2014-08-28 12:26:03 +00:00
|
|
|
/* No more room in this batch, skip padding with more clones */
|
2017-04-12 14:11:50 +00:00
|
|
|
if (osmux_batch_enqueue(clone, circuit, batch_factor) < 0) {
|
2014-08-28 17:24:00 +00:00
|
|
|
msgb_free(clone);
|
2014-08-28 12:26:03 +00:00
|
|
|
break;
|
2014-08-28 17:24:00 +00:00
|
|
|
}
|
2014-08-28 12:26:03 +00:00
|
|
|
|
2013-05-20 22:28:13 +00:00
|
|
|
LOGP(DLMIB, LOGL_ERROR, "adding cloned RTP\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
static struct osmux_circuit *
|
2015-07-17 17:15:42 +00:00
|
|
|
osmux_batch_find_circuit(struct osmux_batch *batch, int ccid)
|
|
|
|
{
|
2015-07-17 17:24:49 +00:00
|
|
|
struct osmux_circuit *circuit;
|
2015-07-17 17:15:42 +00:00
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
llist_for_each_entry(circuit, &batch->circuit_list, head) {
|
2015-07-17 17:15:42 +00:00
|
|
|
if (circuit->ccid == ccid)
|
|
|
|
return circuit;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
static struct osmux_circuit *
|
2015-07-17 18:47:04 +00:00
|
|
|
osmux_batch_add_circuit(struct osmux_batch *batch, int ccid, int dummy,
|
2017-04-25 15:27:13 +00:00
|
|
|
uint8_t batch_factor)
|
2015-07-17 17:15:42 +00:00
|
|
|
{
|
2015-07-17 17:24:49 +00:00
|
|
|
struct osmux_circuit *circuit;
|
2015-07-17 17:15:42 +00:00
|
|
|
|
|
|
|
circuit = osmux_batch_find_circuit(batch, ccid);
|
|
|
|
if (circuit != NULL) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "circuit %u already exists!\n", ccid);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
circuit = talloc_zero(osmux_ctx, struct osmux_circuit);
|
2015-07-17 17:15:42 +00:00
|
|
|
if (circuit == NULL) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "OOM on circuit %u\n", ccid);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
circuit->ccid = ccid;
|
2015-07-17 17:37:28 +00:00
|
|
|
INIT_LLIST_HEAD(&circuit->msg_list);
|
2015-07-17 17:24:49 +00:00
|
|
|
llist_add_tail(&circuit->head, &batch->circuit_list);
|
2015-07-17 17:15:42 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
if (dummy) {
|
|
|
|
circuit->dummy = dummy;
|
2015-08-18 22:19:53 +00:00
|
|
|
batch->ndummy++;
|
2015-07-17 18:47:04 +00:00
|
|
|
if (!osmo_timer_pending(&batch->timer))
|
|
|
|
osmo_timer_schedule(&batch->timer, 0,
|
|
|
|
batch_factor * DELTA_RTP_MSG);
|
|
|
|
}
|
2015-07-17 17:15:42 +00:00
|
|
|
return circuit;
|
|
|
|
}
|
|
|
|
|
2016-05-25 15:44:37 +00:00
|
|
|
static void osmux_batch_del_circuit(struct osmux_batch *batch, struct osmux_circuit *circuit)
|
2015-07-17 17:55:18 +00:00
|
|
|
{
|
2015-07-17 18:47:04 +00:00
|
|
|
if (circuit->dummy)
|
2015-08-18 22:19:53 +00:00
|
|
|
batch->ndummy--;
|
2015-07-17 17:55:18 +00:00
|
|
|
llist_del(&circuit->head);
|
2016-05-25 15:44:39 +00:00
|
|
|
osmux_circuit_del_msgs(batch, circuit);
|
2015-07-17 17:55:18 +00:00
|
|
|
talloc_free(circuit);
|
|
|
|
}
|
|
|
|
|
2012-08-06 16:41:49 +00:00
|
|
|
static int
|
2017-04-25 15:27:13 +00:00
|
|
|
osmux_batch_add(struct osmux_batch *batch, uint32_t batch_factor, struct msgb *msg,
|
2013-12-15 21:35:28 +00:00
|
|
|
struct rtp_hdr *rtph, int ccid)
|
2012-07-09 17:39:55 +00:00
|
|
|
{
|
2015-07-17 17:15:42 +00:00
|
|
|
int bytes = 0, amr_payload_len;
|
2015-07-17 17:24:49 +00:00
|
|
|
struct osmux_circuit *circuit;
|
2015-07-17 18:47:04 +00:00
|
|
|
struct msgb *cur;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2015-07-17 17:15:42 +00:00
|
|
|
circuit = osmux_batch_find_circuit(batch, ccid);
|
2015-07-17 18:47:04 +00:00
|
|
|
if (!circuit)
|
|
|
|
return -1;
|
2012-08-04 18:53:57 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
/* We've seen the first RTP message, disable dummy padding */
|
|
|
|
if (circuit->dummy) {
|
|
|
|
circuit->dummy = 0;
|
2015-08-18 22:19:53 +00:00
|
|
|
batch->ndummy--;
|
2015-07-17 18:47:04 +00:00
|
|
|
}
|
2013-05-24 09:56:07 +00:00
|
|
|
amr_payload_len = osmux_rtp_amr_payload_len(msg, rtph);
|
|
|
|
if (amr_payload_len < 0)
|
2014-08-28 17:24:00 +00:00
|
|
|
return -1;
|
2013-05-24 09:56:07 +00:00
|
|
|
|
2012-10-15 18:33:32 +00:00
|
|
|
/* First check if there is room for this message in the batch */
|
2013-05-24 09:56:07 +00:00
|
|
|
bytes += amr_payload_len;
|
2015-07-17 18:47:04 +00:00
|
|
|
if (circuit->nmsgs == 0)
|
osmux: major rework to reduce batch message size (add counter field)
This patch adds the counter field to the osmux header, so we can
reduce the size of the batch even further, eg.
osmuxhdr (ctr=3)
speech
speech
speech
osmuxhdr (ctr=2)
speech
speech
...
The new header is the following:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| FT | CTR |F|Q| SeqNR | Circuit ID |AMR-FT |AMR-CMR|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter field is 3 bits long, thus, we can batch up to 8
RTP speech frames into one single batch per circuit ID.
I have also removed the RTP marker, since it can be reconstructed
from the AMR information.
Moreover, the entire workflow has been also reworked. Whenever a
packet arrives, we introduce it into the batch list. This batch
list contains a list of RTP messages ordered by RTP SSRC. Then,
once the batch timer expires or the it gets full, we build the
batch from the list of RTP messages.
Note that this allows us to put several speech frame into one
single osmux header without actually worrying about the amount
of messages that we'll receive.
The functions that reconstruct the RTP messages has been also
adjusted. Now, it returns a list of RTP messages per RTP SSRC
that has been extracted from the batch.
2012-08-02 18:24:57 +00:00
|
|
|
bytes += sizeof(struct osmux_hdr);
|
|
|
|
|
2012-10-15 18:33:32 +00:00
|
|
|
/* No room, sorry. You'll have to retry */
|
2012-08-06 16:41:49 +00:00
|
|
|
if (bytes > batch->remaining_bytes)
|
2012-07-09 17:39:55 +00:00
|
|
|
return 1;
|
|
|
|
|
2017-04-25 15:20:38 +00:00
|
|
|
/* Init of talkspurt (RTP M marker bit) needs to be in the first AMR slot
|
|
|
|
* of the OSMUX packet, enforce sending previous batch if required:
|
|
|
|
*/
|
|
|
|
if (rtph->marker && circuit->nmsgs != 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
/* Extra validation: check if this message already exists, should not
|
|
|
|
* happen but make sure we don't propagate duplicated messages.
|
|
|
|
*/
|
|
|
|
llist_for_each_entry(cur, &circuit->msg_list, list) {
|
|
|
|
struct rtp_hdr *rtph2 = osmo_rtp_get_hdr(cur);
|
|
|
|
if (rtph2 == NULL)
|
|
|
|
return -1;
|
2013-05-20 22:28:13 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
/* Already exists message with this sequence, skip */
|
|
|
|
if (rtph2->sequence == rtph->sequence) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "already exists "
|
|
|
|
"message with seq=%u, skip it\n",
|
|
|
|
rtph->sequence);
|
2014-08-28 17:24:00 +00:00
|
|
|
return -1;
|
2015-07-17 18:47:04 +00:00
|
|
|
}
|
2012-10-15 18:33:32 +00:00
|
|
|
}
|
2015-07-17 18:47:04 +00:00
|
|
|
/* Handle RTP packet loss scenario */
|
2017-04-12 14:11:50 +00:00
|
|
|
osmux_replay_lost_packets(circuit, rtph, batch_factor);
|
2012-10-15 18:33:32 +00:00
|
|
|
|
2014-08-28 12:26:03 +00:00
|
|
|
/* This batch is full, force batch delivery */
|
2017-04-12 14:11:50 +00:00
|
|
|
if (osmux_batch_enqueue(msg, circuit, batch_factor) < 0)
|
2014-08-28 12:26:03 +00:00
|
|
|
return 1;
|
|
|
|
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
2012-10-15 18:33:32 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "adding msg with ssrc=%u to batch\n",
|
|
|
|
rtph->ssrc);
|
2014-08-28 15:15:44 +00:00
|
|
|
#endif
|
2012-10-15 18:33:32 +00:00
|
|
|
|
|
|
|
/* Update remaining room in this batch */
|
|
|
|
batch->remaining_bytes -= bytes;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2015-07-17 18:23:25 +00:00
|
|
|
if (batch->nmsgs == 0) {
|
|
|
|
#ifdef DEBUG_MSG
|
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "osmux start timer batch\n");
|
|
|
|
#endif
|
|
|
|
osmo_timer_schedule(&batch->timer, 0,
|
|
|
|
batch_factor * DELTA_RTP_MSG);
|
|
|
|
}
|
|
|
|
batch->nmsgs++;
|
|
|
|
|
2012-07-09 17:39:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* osmux_xfrm_input - add RTP message to OSmux batch
|
|
|
|
* \param msg: RTP message that you want to batch into one OSmux message
|
|
|
|
*
|
2012-10-15 18:33:32 +00:00
|
|
|
* If 0 is returned, this indicates that the message has been batched or that
|
|
|
|
* an error occured and we have skipped the message. If 1 is returned, you
|
|
|
|
* have to invoke osmux_xfrm_input_deliver and try again.
|
2014-08-28 18:18:19 +00:00
|
|
|
*
|
|
|
|
* The function takes care of releasing the messages in case of error and
|
|
|
|
* when building the batch.
|
2012-07-09 17:39:55 +00:00
|
|
|
*/
|
2012-10-20 18:10:31 +00:00
|
|
|
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
|
2012-07-09 17:39:55 +00:00
|
|
|
{
|
2015-07-17 18:23:25 +00:00
|
|
|
int ret;
|
2012-07-09 17:39:55 +00:00
|
|
|
struct rtp_hdr *rtph;
|
2013-02-11 21:49:27 +00:00
|
|
|
struct osmux_batch *batch = (struct osmux_batch *)h->internal_data;
|
2012-07-09 17:39:55 +00:00
|
|
|
|
2013-08-27 15:15:27 +00:00
|
|
|
/* Ignore too big RTP/RTCP messages, most likely forged. Sanity check
|
|
|
|
* to avoid a possible forever loop in the caller.
|
|
|
|
*/
|
2014-08-28 18:18:19 +00:00
|
|
|
if (msg->len > h->batch_size - sizeof(struct osmux_hdr)) {
|
|
|
|
msgb_free(msg);
|
2013-12-15 21:20:13 +00:00
|
|
|
return 0;
|
2014-08-28 18:18:19 +00:00
|
|
|
}
|
2013-08-27 15:15:27 +00:00
|
|
|
|
2012-07-09 17:39:55 +00:00
|
|
|
rtph = osmo_rtp_get_hdr(msg);
|
2014-08-28 18:18:19 +00:00
|
|
|
if (rtph == NULL) {
|
|
|
|
msgb_free(msg);
|
2012-10-15 18:33:32 +00:00
|
|
|
return 0;
|
2014-08-28 18:18:19 +00:00
|
|
|
}
|
2012-07-09 17:39:55 +00:00
|
|
|
|
|
|
|
switch(rtph->payload_type) {
|
|
|
|
case RTP_PT_RTCP:
|
2014-08-28 18:18:19 +00:00
|
|
|
msgb_free(msg);
|
2012-07-09 17:39:55 +00:00
|
|
|
return 0;
|
2013-02-19 15:14:32 +00:00
|
|
|
default:
|
|
|
|
/* The RTP payload type is dynamically allocated,
|
|
|
|
* although we use static ones. Assume that we always
|
|
|
|
* receive AMR traffic.
|
|
|
|
*/
|
|
|
|
|
2013-05-24 09:56:07 +00:00
|
|
|
/* Add this RTP to the OSMUX batch */
|
2015-07-17 18:23:25 +00:00
|
|
|
ret = osmux_batch_add(batch, h->batch_factor,
|
|
|
|
msg, rtph, ccid);
|
2014-08-28 17:24:00 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
/* Cannot put this message into the batch.
|
|
|
|
* Malformed, duplicated, OOM. Drop it and tell
|
|
|
|
* the upper layer that we have digest it.
|
|
|
|
*/
|
|
|
|
msgb_free(msg);
|
2013-05-24 09:56:07 +00:00
|
|
|
return 0;
|
2014-08-28 17:24:00 +00:00
|
|
|
}
|
2013-05-24 09:56:07 +00:00
|
|
|
|
2014-08-28 14:14:16 +00:00
|
|
|
h->stats.input_rtp_msgs++;
|
|
|
|
h->stats.input_rtp_bytes += msg->len;
|
2012-07-09 17:39:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void osmux_xfrm_input_init(struct osmux_in_handle *h)
|
|
|
|
{
|
2012-08-06 16:41:49 +00:00
|
|
|
struct osmux_batch *batch;
|
|
|
|
|
2014-08-28 13:01:03 +00:00
|
|
|
/* Default to osmux packet size if not specified */
|
|
|
|
if (h->batch_size == 0)
|
2014-08-29 13:20:56 +00:00
|
|
|
h->batch_size = OSMUX_BATCH_DEFAULT_MAX;
|
2012-08-06 16:41:49 +00:00
|
|
|
|
2013-02-19 12:16:27 +00:00
|
|
|
batch = talloc_zero(osmux_ctx, struct osmux_batch);
|
2012-08-06 16:41:49 +00:00
|
|
|
if (batch == NULL)
|
|
|
|
return;
|
|
|
|
|
2015-07-17 17:24:49 +00:00
|
|
|
INIT_LLIST_HEAD(&batch->circuit_list);
|
2014-08-28 13:01:03 +00:00
|
|
|
batch->remaining_bytes = h->batch_size;
|
2017-06-07 16:38:21 +00:00
|
|
|
osmo_timer_setup(&batch->timer, osmux_batch_timer_expired, h);
|
2012-08-06 16:41:49 +00:00
|
|
|
|
2013-02-11 21:49:27 +00:00
|
|
|
h->internal_data = (void *)batch;
|
2014-08-28 13:01:03 +00:00
|
|
|
|
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "initialized osmux input converter\n");
|
2012-07-09 17:39:55 +00:00
|
|
|
}
|
2012-07-19 09:08:21 +00:00
|
|
|
|
2015-07-17 18:47:04 +00:00
|
|
|
int osmux_xfrm_input_open_circuit(struct osmux_in_handle *h, int ccid,
|
|
|
|
int dummy)
|
|
|
|
{
|
|
|
|
struct osmux_batch *batch = (struct osmux_batch *)h->internal_data;
|
|
|
|
|
|
|
|
return osmux_batch_add_circuit(batch, ccid, dummy, h->batch_factor) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2015-07-17 17:55:18 +00:00
|
|
|
void osmux_xfrm_input_close_circuit(struct osmux_in_handle *h, int ccid)
|
|
|
|
{
|
|
|
|
struct osmux_batch *batch = (struct osmux_batch *)h->internal_data;
|
2016-05-25 15:44:37 +00:00
|
|
|
struct osmux_circuit *circuit;
|
2015-07-17 17:55:18 +00:00
|
|
|
|
2016-05-25 15:44:37 +00:00
|
|
|
circuit = osmux_batch_find_circuit(batch, ccid);
|
|
|
|
if (circuit == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
osmux_batch_del_circuit(batch, circuit);
|
2015-07-17 17:55:18 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 10:45:04 +00:00
|
|
|
void osmux_xfrm_input_fini(struct osmux_in_handle *h)
|
|
|
|
{
|
|
|
|
struct osmux_batch *batch = (struct osmux_batch *)h->internal_data;
|
2015-07-17 17:24:49 +00:00
|
|
|
struct osmux_circuit *circuit, *next;
|
2014-08-28 10:45:04 +00:00
|
|
|
|
2016-05-25 15:44:37 +00:00
|
|
|
llist_for_each_entry_safe(circuit, next, &batch->circuit_list, head)
|
|
|
|
osmux_batch_del_circuit(batch, circuit);
|
|
|
|
|
2014-08-28 17:59:15 +00:00
|
|
|
osmo_timer_del(&batch->timer);
|
2014-08-28 10:45:04 +00:00
|
|
|
talloc_free(batch);
|
|
|
|
}
|
|
|
|
|
2012-07-19 09:08:21 +00:00
|
|
|
struct osmux_tx_handle {
|
2012-08-04 17:56:47 +00:00
|
|
|
struct osmo_timer_list timer;
|
|
|
|
struct msgb *msg;
|
|
|
|
void (*tx_cb)(struct msgb *msg, void *data);
|
|
|
|
void *data;
|
2012-07-19 10:53:04 +00:00
|
|
|
#ifdef DEBUG_TIMING
|
|
|
|
struct timeval start;
|
2012-08-04 19:11:44 +00:00
|
|
|
struct timeval when;
|
2012-07-19 10:53:04 +00:00
|
|
|
#endif
|
2012-07-19 09:08:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void osmux_tx_cb(void *data)
|
|
|
|
{
|
|
|
|
struct osmux_tx_handle *h = data;
|
2012-07-19 10:53:04 +00:00
|
|
|
#ifdef DEBUG_TIMING
|
|
|
|
struct timeval now, diff;
|
|
|
|
|
2017-04-26 14:00:03 +00:00
|
|
|
osmo_gettimeofday(&now, NULL);
|
2012-07-19 10:53:04 +00:00
|
|
|
timersub(&now, &h->start, &diff);
|
2012-08-04 19:11:44 +00:00
|
|
|
timersub(&diff,&h->when, &diff);
|
2012-10-15 13:59:14 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "we are lagging %lu.%.6lu in scheduled "
|
2012-08-04 19:11:44 +00:00
|
|
|
"transmissions\n", diff.tv_sec, diff.tv_usec);
|
2012-07-19 10:53:04 +00:00
|
|
|
#endif
|
2012-07-19 09:08:21 +00:00
|
|
|
|
|
|
|
h->tx_cb(h->msg, h->data);
|
|
|
|
|
|
|
|
talloc_free(h);
|
|
|
|
}
|
|
|
|
|
2012-08-04 17:56:47 +00:00
|
|
|
static void
|
|
|
|
osmux_tx(struct msgb *msg, struct timeval *when,
|
|
|
|
void (*tx_cb)(struct msgb *msg, void *data), void *data)
|
2012-07-19 09:08:21 +00:00
|
|
|
{
|
|
|
|
struct osmux_tx_handle *h;
|
|
|
|
|
2013-02-19 12:16:27 +00:00
|
|
|
h = talloc_zero(osmux_ctx, struct osmux_tx_handle);
|
2012-07-19 09:08:21 +00:00
|
|
|
if (h == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
h->msg = msg;
|
|
|
|
h->tx_cb = tx_cb;
|
|
|
|
h->data = data;
|
2017-06-07 16:38:21 +00:00
|
|
|
osmo_timer_setup(&h->timer, osmux_tx_cb, h);
|
2012-07-19 09:08:21 +00:00
|
|
|
|
2012-07-19 10:53:04 +00:00
|
|
|
#ifdef DEBUG_TIMING
|
2017-04-26 14:00:03 +00:00
|
|
|
osmo_gettimeofday(&h->start, NULL);
|
2012-08-04 19:11:44 +00:00
|
|
|
h->when.tv_sec = when->tv_sec;
|
|
|
|
h->when.tv_usec = when->tv_usec;
|
2012-07-19 10:53:04 +00:00
|
|
|
#endif
|
2012-07-19 10:49:55 +00:00
|
|
|
/* send it now */
|
|
|
|
if (when->tv_sec == 0 && when->tv_usec == 0) {
|
|
|
|
osmux_tx_cb(h);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-19 09:08:21 +00:00
|
|
|
osmo_timer_schedule(&h->timer, when->tv_sec, when->tv_usec);
|
|
|
|
}
|
2012-08-04 17:56:47 +00:00
|
|
|
|
|
|
|
void
|
2012-08-04 19:03:56 +00:00
|
|
|
osmux_tx_sched(struct llist_head *list,
|
2012-08-04 17:56:47 +00:00
|
|
|
void (*tx_cb)(struct msgb *msg, void *data), void *data)
|
|
|
|
{
|
|
|
|
struct msgb *cur, *tmp;
|
|
|
|
struct timeval delta = { .tv_sec = 0, .tv_usec = DELTA_RTP_MSG };
|
2012-08-04 19:03:56 +00:00
|
|
|
struct timeval when;
|
|
|
|
|
|
|
|
timerclear(&when);
|
2012-08-04 17:56:47 +00:00
|
|
|
|
|
|
|
llist_for_each_entry_safe(cur, tmp, list, list) {
|
|
|
|
|
2014-08-28 15:15:44 +00:00
|
|
|
#ifdef DEBUG_MSG
|
2012-10-15 13:59:14 +00:00
|
|
|
LOGP(DLMIB, LOGL_DEBUG, "scheduled transmision in %lu.%6lu "
|
2012-08-04 19:03:56 +00:00
|
|
|
"seconds, msg=%p\n", when.tv_sec, when.tv_usec, cur);
|
2014-08-28 15:15:44 +00:00
|
|
|
#endif
|
2013-12-13 14:18:56 +00:00
|
|
|
llist_del(&cur->list);
|
2012-10-21 02:12:29 +00:00
|
|
|
osmux_tx(cur, &when, tx_cb, data);
|
2012-08-04 19:03:56 +00:00
|
|
|
timeradd(&when, &delta, &when);
|
2012-08-04 17:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 16:56:36 +00:00
|
|
|
|
2013-05-12 16:03:50 +00:00
|
|
|
void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc)
|
2012-08-06 18:15:46 +00:00
|
|
|
{
|
2013-02-12 16:23:29 +00:00
|
|
|
h->rtp_seq = (uint16_t)random();
|
|
|
|
h->rtp_timestamp = (uint32_t)random();
|
2013-05-12 16:03:50 +00:00
|
|
|
h->rtp_ssrc = rtp_ssrc;
|
2012-08-06 18:15:46 +00:00
|
|
|
}
|
2013-02-19 16:14:33 +00:00
|
|
|
|
|
|
|
#define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \
|
2017-08-14 15:19:55 +00:00
|
|
|
size -= ret; \
|
2013-02-19 16:14:33 +00:00
|
|
|
if (ret > len) \
|
|
|
|
ret = len; \
|
|
|
|
offset += ret; \
|
|
|
|
len -= ret;
|
|
|
|
|
|
|
|
static int osmux_snprintf_header(char *buf, size_t size, struct osmux_hdr *osmuxh)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int len = size, offset = 0;
|
|
|
|
|
|
|
|
ret = snprintf(buf, len, "OSMUX seq=%03u ccid=%03u "
|
|
|
|
"ft=%01u ctr=%01u "
|
|
|
|
"amr_f=%01u amr_q=%01u "
|
|
|
|
"amr_ft=%02u amr_cmr=%02u ",
|
|
|
|
osmuxh->seq, osmuxh->circuit_id,
|
|
|
|
osmuxh->ft, osmuxh->ctr,
|
|
|
|
osmuxh->amr_f, osmuxh->amr_q,
|
|
|
|
osmuxh->amr_ft, osmuxh->amr_cmr);
|
|
|
|
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int osmux_snprintf_payload(char *buf, size_t size,
|
|
|
|
const uint8_t *payload, int payload_len)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
int len = size, offset = 0;
|
|
|
|
|
2017-08-14 15:23:05 +00:00
|
|
|
ret = snprintf(buf+offset, len, "[ ");
|
|
|
|
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
|
|
|
|
|
2013-02-19 16:14:33 +00:00
|
|
|
for (i=0; i<payload_len; i++) {
|
|
|
|
ret = snprintf(buf+offset, len, "%02x ", payload[i]);
|
|
|
|
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:23:05 +00:00
|
|
|
ret = snprintf(buf+offset, len, "] ");
|
2013-02-19 16:14:33 +00:00
|
|
|
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned int offset = 0;
|
|
|
|
int msg_len = msg->len, len = size;
|
2013-05-22 00:05:28 +00:00
|
|
|
struct osmux_hdr *osmuxh;
|
2013-12-13 14:27:21 +00:00
|
|
|
int this_len, msg_off = 0;
|
2013-02-19 16:14:33 +00:00
|
|
|
|
|
|
|
while (msg_len > 0) {
|
2013-05-12 18:43:26 +00:00
|
|
|
if (msg_len < sizeof(struct osmux_hdr)) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR,
|
|
|
|
"No room for OSMUX header: only %d bytes\n",
|
|
|
|
msg_len);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-13 14:27:21 +00:00
|
|
|
osmuxh = (struct osmux_hdr *)((uint8_t *)msg->data + msg_off);
|
2013-02-19 16:14:33 +00:00
|
|
|
|
2013-12-14 21:32:09 +00:00
|
|
|
if (!osmo_amr_ft_valid(osmuxh->amr_ft)) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR, "Bad AMR FT %d, skipping\n",
|
|
|
|
osmuxh->amr_ft);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-19 16:14:33 +00:00
|
|
|
ret = osmux_snprintf_header(buf+offset, size, osmuxh);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
|
|
|
|
|
2013-05-12 18:43:26 +00:00
|
|
|
this_len = sizeof(struct osmux_hdr) +
|
|
|
|
osmux_get_payload_len(osmuxh);
|
2013-12-13 14:27:21 +00:00
|
|
|
msg_off += this_len;
|
2013-05-12 18:43:26 +00:00
|
|
|
|
|
|
|
if (msg_len < this_len) {
|
|
|
|
LOGP(DLMIB, LOGL_ERROR,
|
|
|
|
"No room for OSMUX payload: only %d bytes\n",
|
|
|
|
msg_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-19 16:14:33 +00:00
|
|
|
ret = osmux_snprintf_payload(buf+offset, size,
|
|
|
|
osmux_get_payload(osmuxh),
|
|
|
|
osmux_get_payload_len(osmuxh));
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
|
|
|
|
|
|
|
|
msg_len -= this_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
2017-04-08 18:00:47 +00:00
|
|
|
|
|
|
|
/*! @} */
|