osmux: remove generic functions to register and get ccid
Remove these functions: - osmux_xfrm_input_get_ccid - osmux_xfrm_input_register_ccid The ccid will be managed by the BSC and it will be stored in the mgcp_endpoint structure. Also adjust all tests and examples using the API.
This commit is contained in:
parent
631c6fe0ad
commit
5654c43f80
|
@ -7,6 +7,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
|
@ -84,11 +85,51 @@ struct osmux_in_handle h_input = {
|
|||
.deliver = osmux_deliver,
|
||||
};
|
||||
|
||||
#define MAX_CONCURRENT_CALLS 8
|
||||
|
||||
static int ccid[MAX_CONCURRENT_CALLS];
|
||||
|
||||
static int get_ccid(uint32_t ssrc)
|
||||
{
|
||||
int i, found = 0;
|
||||
|
||||
for (i=0; i<MAX_CONCURRENT_CALLS; i++) {
|
||||
if (ccid[i] == ssrc) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found ? i : -1;
|
||||
}
|
||||
|
||||
static void register_ccid(uint32_t ssrc)
|
||||
{
|
||||
int i, found = 0;
|
||||
|
||||
for (i=0; i<MAX_CONCURRENT_CALLS; i++) {
|
||||
if (ccid[i] == ssrc)
|
||||
continue;
|
||||
if (ccid[i] < 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
ccid[i] = ssrc;
|
||||
LOGP(DOSMUX_TEST, LOGL_DEBUG, "mapping ssrc=%u to ccid=%d\n",
|
||||
ntohl(ssrc), i);
|
||||
} else {
|
||||
LOGP(DOSMUX_TEST, LOGL_ERROR, "cannot map ssrc to ccid!\n");
|
||||
}
|
||||
}
|
||||
|
||||
int read_cb(struct osmo_dgram *conn)
|
||||
{
|
||||
struct msgb *msg;
|
||||
struct rtp_hdr *rtph;
|
||||
int ret;
|
||||
int ret, ccid;
|
||||
|
||||
LOGP(DOSMUX_TEST, LOGL_DEBUG, "received message from datagram\n");
|
||||
|
||||
|
@ -113,11 +154,11 @@ int read_cb(struct osmo_dgram *conn)
|
|||
if (rtph->payload_type == RTP_PT_AMR)
|
||||
amr_write(msg);
|
||||
|
||||
/* now build the osmux frame */
|
||||
if (osmux_xfrm_input_get_ccid(&h_input, rtph->ssrc) < 0)
|
||||
osmux_xfrm_input_register_ccid(&h_input, rtph->ssrc);
|
||||
ccid = get_ccid(rtph->ssrc);
|
||||
if (ccid < 0)
|
||||
register_ccid(rtph->ssrc);
|
||||
|
||||
while ((ret = osmux_xfrm_input(&h_input, msg)) > 0) {
|
||||
while ((ret = osmux_xfrm_input(&h_input, msg, ccid)) > 0) {
|
||||
/* batch full, deliver it */
|
||||
osmux_xfrm_input_deliver(&h_input);
|
||||
}
|
||||
|
|
|
@ -61,10 +61,8 @@ static inline uint8_t *osmux_get_payload(struct osmux_hdr *osmuxh)
|
|||
}
|
||||
|
||||
void osmux_xfrm_input_init(struct osmux_in_handle *h);
|
||||
int osmux_xfrm_input_get_ccid(struct osmux_in_handle *h, uint32_t ssrc);
|
||||
void osmux_xfrm_input_register_ccid(struct osmux_in_handle *h, uint32_t ssrc);
|
||||
|
||||
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg);
|
||||
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid);
|
||||
void osmux_xfrm_input_deliver(struct osmux_in_handle *h);
|
||||
|
||||
void osmux_xfrm_output_init(struct osmux_out_handle *h);
|
||||
|
|
65
src/osmux.c
65
src/osmux.c
|
@ -138,14 +138,13 @@ struct osmux_batch {
|
|||
struct llist_head node_list;
|
||||
unsigned int remaining_bytes;
|
||||
uint8_t seq;
|
||||
int64_t ccid[OSMUX_MAX_CONCURRENT_CALLS];
|
||||
};
|
||||
|
||||
static int
|
||||
osmux_batch_add(struct osmux_in_handle *h, struct msgb *out_msg,
|
||||
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 add_osmux_header)
|
||||
int ccid, int add_osmux_header)
|
||||
{
|
||||
struct osmux_batch *batch = (struct osmux_batch *)h->data;
|
||||
struct osmux_hdr *osmuxh;
|
||||
|
@ -157,7 +156,7 @@ osmux_batch_add(struct osmux_in_handle *h, struct msgb *out_msg,
|
|||
osmuxh->amr_f = amrh->f;
|
||||
osmuxh->amr_q= amrh->q;
|
||||
osmuxh->seq = batch->seq++;
|
||||
osmuxh->circuit_id = osmux_xfrm_input_get_ccid(h, rtph->ssrc);
|
||||
osmuxh->circuit_id = ccid;
|
||||
osmuxh->amr_cmr = amrh->cmr;
|
||||
osmuxh->amr_ft = amrh->ft;
|
||||
msgb_put(out_msg, sizeof(struct osmux_hdr));
|
||||
|
@ -184,7 +183,7 @@ static int
|
|||
osmux_xfrm_encode_amr(struct osmux_in_handle *h,
|
||||
struct msgb *out_msg,
|
||||
struct rtp_hdr *rtph, struct msgb *msg,
|
||||
int add_osmux_header)
|
||||
int ccid, int add_osmux_header)
|
||||
{
|
||||
struct amr_hdr *amrh;
|
||||
uint32_t amr_len;
|
||||
|
@ -196,8 +195,8 @@ osmux_xfrm_encode_amr(struct osmux_in_handle *h,
|
|||
|
||||
amr_payload_len = amr_len - sizeof(struct amr_hdr);
|
||||
|
||||
if (osmux_batch_add(h, out_msg, msg, rtph, amrh, amr_payload_len,
|
||||
add_osmux_header) < 0)
|
||||
if (osmux_batch_put(h, out_msg, msg, rtph, amrh, amr_payload_len,
|
||||
ccid, add_osmux_header) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
@ -206,6 +205,7 @@ osmux_xfrm_encode_amr(struct osmux_in_handle *h,
|
|||
struct batch_list_node {
|
||||
struct llist_head head;
|
||||
uint32_t ssrc;
|
||||
int ccid;
|
||||
struct llist_head list;
|
||||
};
|
||||
|
||||
|
@ -245,7 +245,7 @@ static struct msgb *osmux_build_batch(struct osmux_in_handle *h)
|
|||
}
|
||||
|
||||
osmux_xfrm_encode_amr(h, batch_msg, rtph, cur,
|
||||
add_osmux_hdr);
|
||||
node->ccid, add_osmux_hdr);
|
||||
llist_del(&cur->list);
|
||||
msgb_free(cur);
|
||||
ctr++;
|
||||
|
@ -289,7 +289,7 @@ static int osmux_rtp_amr_payload_len(struct msgb *msg, struct rtp_hdr *rtph)
|
|||
}
|
||||
|
||||
static int
|
||||
osmux_msgb_batch_queue_add(struct osmux_batch *batch, struct msgb *msg)
|
||||
osmux_batch_add(struct osmux_batch *batch, struct msgb *msg, int ccid)
|
||||
{
|
||||
struct rtp_hdr *rtph;
|
||||
struct batch_list_node *node;
|
||||
|
@ -342,6 +342,7 @@ osmux_msgb_batch_queue_add(struct osmux_batch *batch, struct msgb *msg)
|
|||
if (node == NULL)
|
||||
return 0;
|
||||
|
||||
node->ccid = ccid;
|
||||
node->ssrc = rtph->ssrc;
|
||||
INIT_LLIST_HEAD(&node->list);
|
||||
llist_add_tail(&node->head, &batch->node_list);
|
||||
|
@ -365,7 +366,7 @@ osmux_msgb_batch_queue_add(struct osmux_batch *batch, struct msgb *msg)
|
|||
* an error occured and we have skipped the message. If 1 is returned, you
|
||||
* have to invoke osmux_xfrm_input_deliver and try again.
|
||||
*/
|
||||
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg)
|
||||
int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg, int ccid)
|
||||
{
|
||||
int ret;
|
||||
struct rtp_hdr *rtph;
|
||||
|
@ -389,7 +390,7 @@ int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg)
|
|||
osmo_timer_schedule(&batch->timer, 0,
|
||||
h->batch_factor * DELTA_RTP_MSG);
|
||||
}
|
||||
ret = osmux_msgb_batch_queue_add(batch, msg);
|
||||
ret = osmux_batch_add(batch, msg, ccid);
|
||||
break;
|
||||
default:
|
||||
/* Only AMR supported so far, sorry. */
|
||||
|
@ -402,7 +403,6 @@ int osmux_xfrm_input(struct osmux_in_handle *h, struct msgb *msg)
|
|||
void osmux_xfrm_input_init(struct osmux_in_handle *h)
|
||||
{
|
||||
struct osmux_batch *batch;
|
||||
int i;
|
||||
|
||||
LOGP(DLMIB, LOGL_DEBUG, "initialized osmux input converter\n");
|
||||
|
||||
|
@ -415,9 +415,6 @@ void osmux_xfrm_input_init(struct osmux_in_handle *h)
|
|||
batch->timer.cb = osmux_batch_timer_expired;
|
||||
batch->timer.data = h;
|
||||
|
||||
for (i=0; i<OSMUX_MAX_CONCURRENT_CALLS; i++)
|
||||
batch->ccid[i] = -1;
|
||||
|
||||
h->data = (void *)batch;
|
||||
}
|
||||
|
||||
|
@ -500,44 +497,6 @@ osmux_tx_sched(struct llist_head *list,
|
|||
}
|
||||
}
|
||||
|
||||
void osmux_xfrm_input_register_ccid(struct osmux_in_handle *h, uint32_t ssrc)
|
||||
{
|
||||
struct osmux_batch *batch = (struct osmux_batch *)h->data;;
|
||||
int i, found = 0;
|
||||
|
||||
for (i=0; i<OSMUX_MAX_CONCURRENT_CALLS; i++) {
|
||||
if (batch->ccid[i] == ssrc)
|
||||
continue;
|
||||
if (batch->ccid[i] < 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
batch->ccid[i] = ssrc;
|
||||
LOGP(DLMIB, LOGL_DEBUG, "mapping ssrc=%u to ccid=%d\n",
|
||||
ntohl(ssrc), i);
|
||||
} else {
|
||||
LOGP(DLMIB, LOGL_ERROR, "cannot map ssrc to ccid!\n");
|
||||
}
|
||||
}
|
||||
|
||||
int osmux_xfrm_input_get_ccid(struct osmux_in_handle *h, uint32_t ssrc)
|
||||
{
|
||||
struct osmux_batch *batch = (struct osmux_batch *)h->data;;
|
||||
int i, found = 0;
|
||||
|
||||
for (i=0; i<OSMUX_MAX_CONCURRENT_CALLS; i++) {
|
||||
if (batch->ccid[i] == ssrc) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found ? i : -1;
|
||||
}
|
||||
|
||||
void osmux_xfrm_output_init(struct osmux_out_handle *h)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -73,19 +73,60 @@ struct osmux_in_handle h_input = {
|
|||
.deliver = deliver,
|
||||
};
|
||||
|
||||
#define MAX_CONCURRENT_CALLS 8
|
||||
|
||||
static int ccid[MAX_CONCURRENT_CALLS];
|
||||
|
||||
static void register_ccid(uint32_t ssrc)
|
||||
{
|
||||
int i, found = 0;
|
||||
|
||||
for (i=0; i<MAX_CONCURRENT_CALLS; i++) {
|
||||
if (ccid[i] == ssrc)
|
||||
continue;
|
||||
if (ccid[i] < 0) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
ccid[i] = ssrc;
|
||||
LOGP(DOSMUXTEST, LOGL_DEBUG, "mapping ssrc=%u to ccid=%d\n",
|
||||
ntohl(ssrc), i);
|
||||
} else {
|
||||
LOGP(DOSMUXTEST, LOGL_ERROR, "cannot map ssrc to ccid!\n");
|
||||
}
|
||||
}
|
||||
|
||||
static int get_ccid(uint32_t ssrc)
|
||||
{
|
||||
int i, found = 0;
|
||||
|
||||
for (i=0; i<MAX_CONCURRENT_CALLS; i++) {
|
||||
if (ccid[i] == ssrc) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return found ? i : -1;
|
||||
}
|
||||
|
||||
static int pcap_test_run(struct msgb *msg)
|
||||
{
|
||||
int ret;
|
||||
int ret, ccid;
|
||||
struct rtp_hdr *rtph;
|
||||
|
||||
rtph = osmo_rtp_get_hdr(msg);
|
||||
if (rtph == NULL)
|
||||
return 0;
|
||||
|
||||
if (osmux_xfrm_input_get_ccid(&h_input, rtph->ssrc) < 0)
|
||||
osmux_xfrm_input_register_ccid(&h_input, rtph->ssrc);
|
||||
ccid = get_ccid(&h_input, rtph->ssrc);
|
||||
if (ccid < 0)
|
||||
register_ccid(&h_input, rtph->ssrc);
|
||||
|
||||
while ((ret = osmux_xfrm_input(&h_input, msg)) > 1) {
|
||||
while ((ret = osmux_xfrm_input(&h_input, msg, ccid)) > 1) {
|
||||
/* batch full, deliver it */
|
||||
osmux_xfrm_input_deliver(&h_input);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue