libmgcp: add enum mgcp_type and use it
This patch replaces the field 'is_transcoded' in the mgcp_endpoint structure by the enum mgcp_type, that can be further extended with new types.
This commit is contained in:
parent
1e61b25661
commit
46bd4244a1
|
@ -96,6 +96,11 @@ struct mgcp_rtp_tap {
|
|||
struct sockaddr_in forward;
|
||||
};
|
||||
|
||||
enum mgcp_type {
|
||||
MGCP_RTP_DEFAULT = 0,
|
||||
MGCP_RTP_TRANSCODED,
|
||||
};
|
||||
|
||||
struct mgcp_endpoint {
|
||||
int allocated;
|
||||
uint32_t ci;
|
||||
|
@ -119,7 +124,7 @@ struct mgcp_endpoint {
|
|||
*/
|
||||
struct mgcp_rtp_end trans_bts;
|
||||
struct mgcp_rtp_end trans_net;
|
||||
int is_transcoded;
|
||||
enum mgcp_type type;
|
||||
|
||||
/* sequence bits */
|
||||
struct mgcp_rtp_state net_state;
|
||||
|
|
|
@ -371,10 +371,19 @@ static int rtp_data_net(struct osmo_fd *fd, unsigned int what)
|
|||
endp->net_end.octets += rc;
|
||||
|
||||
forward_data(fd->fd, &endp->taps[MGCP_TAP_NET_IN], buf, rc);
|
||||
if (endp->is_transcoded)
|
||||
return send_transcoder(&endp->trans_net, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
|
||||
else
|
||||
return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
|
||||
switch (endp->type) {
|
||||
case MGCP_RTP_DEFAULT:
|
||||
return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr,
|
||||
buf, rc);
|
||||
case MGCP_RTP_TRANSCODED:
|
||||
return send_transcoder(&endp->trans_net, endp->cfg,
|
||||
proto == PROTO_RTP, buf, rc);
|
||||
}
|
||||
|
||||
LOGP(DMGCP, LOGL_ERROR, "Bad MGCP type %u on endpoint %u\n",
|
||||
endp->type, ENDPOINT_NUMBER(endp));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void discover_bts(struct mgcp_endpoint *endp, int proto, struct sockaddr_in *addr)
|
||||
|
@ -450,10 +459,19 @@ static int rtp_data_bts(struct osmo_fd *fd, unsigned int what)
|
|||
endp->bts_end.octets += rc;
|
||||
|
||||
forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc);
|
||||
if (endp->is_transcoded)
|
||||
return send_transcoder(&endp->trans_bts, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
|
||||
else
|
||||
return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc);
|
||||
|
||||
switch (endp->type) {
|
||||
case MGCP_RTP_DEFAULT:
|
||||
return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr,
|
||||
buf, rc);
|
||||
case MGCP_RTP_TRANSCODED:
|
||||
return send_transcoder(&endp->trans_bts, endp->cfg,
|
||||
proto == PROTO_RTP, buf, rc);
|
||||
}
|
||||
|
||||
LOGP(DMGCP, LOGL_ERROR, "Bad MGCP type %u on endpoint %u\n",
|
||||
endp->type, ENDPOINT_NUMBER(endp));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtp_data_transcoder(struct mgcp_rtp_end *end, struct mgcp_endpoint *_endp,
|
||||
|
|
|
@ -500,7 +500,7 @@ static int allocate_ports(struct mgcp_endpoint *endp)
|
|||
}
|
||||
|
||||
/* remember that we have set up transcoding */
|
||||
endp->is_transcoded = 1;
|
||||
endp->type = MGCP_RTP_TRANSCODED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1014,7 +1014,7 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
|
|||
mgcp_rtp_end_reset(&endp->net_end);
|
||||
mgcp_rtp_end_reset(&endp->trans_net);
|
||||
mgcp_rtp_end_reset(&endp->trans_bts);
|
||||
endp->is_transcoded = 0;
|
||||
endp->type = MGCP_RTP_DEFAULT;
|
||||
|
||||
memset(&endp->net_state, 0, sizeof(endp->net_state));
|
||||
memset(&endp->bts_state, 0, sizeof(endp->bts_state));
|
||||
|
@ -1118,7 +1118,7 @@ static void create_transcoder(struct mgcp_endpoint *endp)
|
|||
int in_endp = ENDPOINT_NUMBER(endp);
|
||||
int out_endp = endp_back_channel(in_endp);
|
||||
|
||||
if (!endp->is_transcoded)
|
||||
if (endp->type != MGCP_RTP_TRANSCODED)
|
||||
return;
|
||||
|
||||
send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "sendrecv");
|
||||
|
@ -1140,7 +1140,7 @@ static void delete_transcoder(struct mgcp_endpoint *endp)
|
|||
int in_endp = ENDPOINT_NUMBER(endp);
|
||||
int out_endp = endp_back_channel(in_endp);
|
||||
|
||||
if (!endp->is_transcoded)
|
||||
if (endp->type != MGCP_RTP_TRANSCODED)
|
||||
return;
|
||||
|
||||
send_dlcx(endp, in_endp);
|
||||
|
|
Loading…
Reference in New Issue