From bcb4d6b26fee6ef2147229b184e0ec0b657d02b0 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Wed, 5 Jul 2023 15:03:19 +0200 Subject: [PATCH] ASCI: Allow usage of rtp_stream with other FSM Allow the caller of rtp_stream_alloc() to define what events will be dispatched to the parent FSM. This allows other state machines to use rtp_stream. It is required for using RTP stream process with VGCS FSM. Drop the unused parent_call_leg member. Change-Id: I0991927b6d00da08dfd455980645e68281a73a9e Related: OS#4854 --- include/osmocom/msc/rtp_stream.h | 8 +++++--- src/libmsc/call_leg.c | 3 ++- src/libmsc/rtp_stream.c | 14 ++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/osmocom/msc/rtp_stream.h b/include/osmocom/msc/rtp_stream.h index c42657ad8..5bc01440f 100644 --- a/include/osmocom/msc/rtp_stream.h +++ b/include/osmocom/msc/rtp_stream.h @@ -26,7 +26,8 @@ static inline const char *rtp_direction_name(enum rtp_direction val) /* A single bidirectional RTP hop between remote and MGW's local RTP port. */ struct rtp_stream { struct osmo_fsm_inst *fi; - struct call_leg *parent_call_leg; + uint32_t event_avail; + uint32_t event_estab; enum rtp_direction dir; uint32_t call_id; @@ -60,8 +61,9 @@ struct rtp_stream { #define RTP_STREAM_FMT "local=" RTP_IP_PORT_FMT ",remote=" RTP_IP_PORT_FMT #define RTP_STREAM_ARGS(RS) RTP_IP_PORT_ARGS(&(RS)->local), RTP_IP_PORT_ARGS(&(RS)->remote), -struct rtp_stream *rtp_stream_alloc(struct call_leg *parent_call_leg, enum rtp_direction dir, - uint32_t call_id, struct gsm_trans *for_trans); +struct rtp_stream *rtp_stream_alloc(struct osmo_fsm_inst *parent_fi, uint32_t event_gone, uint32_t event_avail, + uint32_t event_estab, enum rtp_direction dir, uint32_t call_id, + struct gsm_trans *for_trans); int rtp_stream_ensure_ci(struct rtp_stream *rtps, struct osmo_mgcpc_ep *at_endpoint); int rtp_stream_do_mdcx(struct rtp_stream *rtps); diff --git a/src/libmsc/call_leg.c b/src/libmsc/call_leg.c index b078c770c..d0dc642a9 100644 --- a/src/libmsc/call_leg.c +++ b/src/libmsc/call_leg.c @@ -303,7 +303,8 @@ int call_leg_ensure_rtp_alloc(struct call_leg *cl, enum rtp_direction dir, uint3 return -EIO; } - cl->rtp[dir] = rtp_stream_alloc(cl, dir, call_id, for_trans); + cl->rtp[dir] = rtp_stream_alloc(cl->fi, CALL_LEG_EV_RTP_STREAM_GONE, CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE, + CALL_LEG_EV_RTP_STREAM_ESTABLISHED, dir, call_id, for_trans); OSMO_ASSERT(cl->rtp[dir]); return 0; } diff --git a/src/libmsc/rtp_stream.c b/src/libmsc/rtp_stream.c index dcb4ef08e..1f885c5f3 100644 --- a/src/libmsc/rtp_stream.c +++ b/src/libmsc/rtp_stream.c @@ -110,13 +110,14 @@ void rtp_stream_update_id(struct rtp_stream *rtps) /* Allocate RTP stream under a call leg. This is one RTP connection from some remote entity with address and port to a * local RTP address and port. call_id is stored for sending in MGCP transactions and as logging context. for_trans is * optional, merely stored for reference by callers, and appears as log context if not NULL. */ -struct rtp_stream *rtp_stream_alloc(struct call_leg *parent_call_leg, enum rtp_direction dir, - uint32_t call_id, struct gsm_trans *for_trans) +struct rtp_stream *rtp_stream_alloc(struct osmo_fsm_inst *parent_fi, uint32_t event_gone, uint32_t event_avail, + uint32_t event_estab, enum rtp_direction dir, uint32_t call_id, + struct gsm_trans *for_trans) { struct osmo_fsm_inst *fi; struct rtp_stream *rtps; - fi = osmo_fsm_inst_alloc_child(&rtp_stream_fsm, parent_call_leg->fi, CALL_LEG_EV_RTP_STREAM_GONE); + fi = osmo_fsm_inst_alloc_child(&rtp_stream_fsm, parent_fi, event_gone); OSMO_ASSERT(fi); rtps = talloc(fi, struct rtp_stream); @@ -124,7 +125,8 @@ struct rtp_stream *rtp_stream_alloc(struct call_leg *parent_call_leg, enum rtp_d fi->priv = rtps; *rtps = (struct rtp_stream){ .fi = fi, - .parent_call_leg = parent_call_leg, + .event_avail = event_avail, + .event_estab = event_estab, .call_id = call_id, .for_trans = for_trans, .dir = dir, @@ -172,7 +174,7 @@ static void rtp_stream_fsm_establishing_established(struct osmo_fsm_inst *fi, ui if (crcx_info->x_osmo_osmux_use) rtps->local_osmux_cid = crcx_info->x_osmo_osmux_cid; rtp_stream_update_id(rtps); - osmo_fsm_inst_dispatch(fi->proc.parent, CALL_LEG_EV_RTP_STREAM_ADDR_AVAILABLE, rtps); + osmo_fsm_inst_dispatch(fi->proc.parent, rtps->event_avail, rtps); check_established(rtps); if ((!rtps->remote_sent_to_mgw || !rtps->codecs_sent_to_mgw || !rtps->mode_sent_to_mgw) @@ -212,7 +214,7 @@ static void rtp_stream_fsm_establishing_established(struct osmo_fsm_inst *fi, ui void rtp_stream_fsm_established_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state) { struct rtp_stream *rtps = fi->priv; - osmo_fsm_inst_dispatch(fi->proc.parent, CALL_LEG_EV_RTP_STREAM_ESTABLISHED, rtps); + osmo_fsm_inst_dispatch(fi->proc.parent, rtps->event_estab, rtps); } static int rtp_stream_fsm_timer_cb(struct osmo_fsm_inst *fi)