pespin has uploaded this change for review.

View Change

osmux: Allocate struct osmux_out_handle through API

Until now, the osmux_out_handle was allocated by the client, and passed
to the API to initialize it. This makes it really hard to improve the
implementation without breaking the ABI.

Let's break the ABI now one last time (hopefully) by allocating the
struct through an API. With only this change, the already built users
(osmo-mgw, openbsc) can still work fine, since there's no change on the
struct osmux_out_handle. However, they will somehow break next time the
struct is changed until they are ported to the same API (easy to do).

Related: OS#5987
Change-Id: Ie8df581f375c9a183a7af60b431561bda82f6e34
---
M TODO-RELEASE
M examples/osmux-test-output.c
M include/osmocom/netif/osmux.h
M src/osmux.c
4 files changed, 50 insertions(+), 7 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/58/29258/1
diff --git a/TODO-RELEASE b/TODO-RELEASE
index d0852fc..52a8c49 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,4 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
+libosmo-netif osmux new osmux_xfrm_output_* APIs
diff --git a/examples/osmux-test-output.c b/examples/osmux-test-output.c
index d39277b..3f0e5a2 100644
--- a/examples/osmux-test-output.c
+++ b/examples/osmux-test-output.c
@@ -42,7 +42,7 @@
* This is the output handle for osmux, it stores last RTP sequence and
* timestamp that has been used. There should be one per circuit ID.
*/
-static struct osmux_out_handle h_output;
+static struct osmux_out_handle *h_output;

static int fd;

@@ -107,7 +107,7 @@
msg->len, buf);

while((osmuxh = osmux_xfrm_output_pull(msg)) != NULL)
- osmux_xfrm_output_sched(&h_output, osmuxh);
+ osmux_xfrm_output_sched(h_output, osmuxh);

return 0;
}
@@ -117,7 +117,7 @@
LOGP(DOSMUX_TEST, LOGL_NOTICE, "closing OSMUX.\n");
osmo_dgram_close(conn);
osmo_dgram_destroy(conn);
- osmux_xfrm_output_flush(&h_output);
+ talloc_free(h_output);
osmo_rtp_handle_free(rtp);
amr_close();
exit(EXIT_SUCCESS);
@@ -155,8 +155,10 @@
/*
* initialize OSMUX handlers.
*/
- osmux_xfrm_output_init2(&h_output, random(), 98);
- osmux_xfrm_output_set_tx_cb(&h_output, tx_cb, NULL);
+ h_output = osmux_xfrm_output_alloc(NULL);
+ osmux_xfrm_output_set_rtp_ssrc(h_output, random());
+ osmux_xfrm_output_set_rtp_pl_type(h_output, 98);
+ osmux_xfrm_output_set_tx_cb(h_output, tx_cb, NULL);
/*
* initialize datagram server.
*/
diff --git a/include/osmocom/netif/osmux.h b/include/osmocom/netif/osmux.h
index 8d39344..8742797 100644
--- a/include/osmocom/netif/osmux.h
+++ b/include/osmocom/netif/osmux.h
@@ -107,8 +107,11 @@
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, uint32_t rtp_ssrc) OSMO_DEPRECATED("Use osmux_xfrm_output_init2() instead");
-void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type);
+struct osmux_out_handle *osmux_xfrm_output_alloc(void *ctx);
+void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc) OSMO_DEPRECATED("Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead");
+void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type) OSMO_DEPRECATED("Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead");
+void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc);
+void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type);
void osmux_xfrm_output_set_tx_cb(struct osmux_out_handle *h, void (*tx_cb)(struct msgb *msg, void *data), void *data);
int osmux_xfrm_output_sched(struct osmux_out_handle *h, struct osmux_hdr *osmuxh);
void osmux_xfrm_output_flush(struct osmux_out_handle *h);
diff --git a/src/osmux.c b/src/osmux.c
index 7d26fe8..c9b20aa 100644
--- a/src/osmux.c
+++ b/src/osmux.c
@@ -870,6 +870,33 @@
void *data;
};

+static int osmux_xfrm_output_talloc_destructor(struct osmux_out_handle *h)
+{
+ osmux_xfrm_output_flush(h);
+ return 0;
+}
+
+/* Returned pointer can be freed with regular talloc_free, queue will be flushed
+ * and all internal data will be freed. */
+struct osmux_out_handle *osmux_xfrm_output_alloc(void *ctx)
+{
+ struct osmux_out_handle *h;
+
+ h = talloc_zero(ctx, struct osmux_out_handle);
+ OSMO_ASSERT(h);
+
+ h->rtp_seq = (uint16_t)random();
+ h->rtp_timestamp = (uint32_t)random();
+ h->rtp_ssrc = (uint32_t)random();
+ h->rtp_payload_type = 98;
+ INIT_LLIST_HEAD(&h->list);
+ osmo_timer_setup(&h->timer, osmux_xfrm_output_trigger, h);
+
+ talloc_set_destructor(h, osmux_xfrm_output_talloc_destructor);
+ return h;
+}
+
+/* DEPRECATED: Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead */
void osmux_xfrm_output_init2(struct osmux_out_handle *h, uint32_t rtp_ssrc, uint8_t rtp_payload_type)
{
memset(h, 0, sizeof(*h));
@@ -881,6 +908,7 @@
osmo_timer_setup(&h->timer, osmux_xfrm_output_trigger, h);
}

+/* DEPRECATED: Use osmux_xfrm_output_alloc() and osmux_xfrm_output_set_rtp_*() instead */
void osmux_xfrm_output_init(struct osmux_out_handle *h, uint32_t rtp_ssrc)
{
/* backward compatibility with old users, where 98 was harcoded in osmux_rebuild_rtp() */
@@ -903,6 +931,15 @@
h->data = data;
}

+void osmux_xfrm_output_set_rtp_ssrc(struct osmux_out_handle *h, uint32_t rtp_ssrc)
+{
+ h->rtp_ssrc = rtp_ssrc;
+}
+void osmux_xfrm_output_set_rtp_pl_type(struct osmux_out_handle *h, uint32_t rtp_payload_type)
+{
+ h->rtp_payload_type = rtp_payload_type;
+}
+
#define SNPRINTF_BUFFER_SIZE(ret, remain, offset) \
if (ret < 0) \
ret = 0; \

To view, visit change 29258. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: Ie8df581f375c9a183a7af60b431561bda82f6e34
Gerrit-Change-Number: 29258
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-MessageType: newchange