Commit 7fb94bc4 authored by Simon Morlat's avatar Simon Morlat

implement RtpSession splicing

parent 051fb048
......@@ -403,6 +403,8 @@ struct _RtpSession
float rtt;/*last round trip delay calculated*/
int cum_loss;
OrtpNetworkSimulatorCtx *net_sim_ctx;
RtpSession *spliced_session; /*a RtpSession that will retransmit everything received on this session*/
rtp_stats_t stats;
bool_t symmetric_rtp;
bool_t permissive; /*use the permissive algorithm*/
bool_t use_connect; /* use connect() on the socket */
......@@ -412,7 +414,9 @@ struct _RtpSession
bool_t rtcp_mux;
unsigned char avpf_features; /**< A bitmask of ORTP_AVPF_FEATURE_* macros. */
bool_t use_pktinfo;
rtp_stats_t stats;
bool_t is_spliced;
};
......@@ -688,19 +692,11 @@ ORTP_PUBLIC void meta_rtp_transport_set_endpoint(RtpTransport *transport,RtpTran
ORTP_PUBLIC void meta_rtp_transport_destroy(RtpTransport *tp);
ORTP_PUBLIC void meta_rtp_transport_append_modifier(RtpTransport *tp,RtpTransportModifier *tpm);
/*
* Update remote addr is the following case:
* rtp symetric == TRUE && socket not connected && remote addr has changed && ((rtp/rtcp packet && not onlyat start) or (no rtp/rtcp packets received))
* @param[in] session on which to perform change
* @param[in] mp packet where remote addr is retreived
* @param[in] is_rtp true if rtp
* @param[in] only_at_start only perform changes if no valid packets received yet
* @return 0 if chaged was performed
*
*/
ORTP_PUBLIC int rtp_session_update_remote_sock_addr(RtpSession * session, mblk_t * mp, bool_t is_rtp,bool_t only_at_start);
ORTP_PUBLIC int rtp_session_splice(RtpSession *session, RtpSession *to_session);
ORTP_PUBLIC int rtp_session_unsplice(RtpSession *session, RtpSession *to_session);
#ifdef __cplusplus
}
#endif
......
......@@ -472,9 +472,6 @@ void av_profile_init(RtpProfile *profile)
rtp_profile_set_payload(profile,31,&payload_type_h261);
rtp_profile_set_payload(profile,32,&payload_type_mpv);
rtp_profile_set_payload(profile,34,&payload_type_h263);
rtp_profile_set_payload(profile,96,&payload_type_t140);
rtp_profile_set_payload(profile,97,&payload_type_t140_red);
//rtp_profile_set_payload(profile,127,&payload_type_bv16);
}
......
......@@ -2326,3 +2326,37 @@ void meta_rtp_transport_append_modifier(RtpTransport *tp,RtpTransportModifier *t
bool_t rtp_session_get_symmetric_rtp(const RtpSession *session) {
return session->symmetric_rtp;
}
int rtp_session_splice(RtpSession *session, RtpSession *to_session){
if (session->spliced_session){
ortp_error("rtp_session_splice(): session %p already splicing into session %p", session, session->spliced_session);
return -1;
}
session->spliced_session = to_session;
to_session->is_spliced = TRUE;
ortp_message("rtp_session_splice(): session %p splicing to %p", session, to_session);
return 0;
}
int rtp_session_unsplice(RtpSession *session, RtpSession *to_session){
if (session->spliced_session != to_session){
ortp_error("rtp_session_unsplice() session %p is not spliced to session %p", session, to_session);
return -1;
}
session->spliced_session = NULL;
to_session->is_spliced = FALSE;
ortp_message("rtp_session_unsplice(): session %p no longer splicing to %p", session, to_session);
return 0;
}
/*
* send packet through the peered session, the mblk_t is not freed.
**/
void rtp_session_do_splice(RtpSession *session, mblk_t *packet, bool_t is_rtp){
RtpSession *peer = session->spliced_session;
if (peer){
OrtpStream *os = is_rtp ? &session->rtp.gs : &session->rtcp.gs;
_ortp_sendto(os->socket, packet, 0, (struct sockaddr*)&os->rem_addr, os->rem_addrlen);
}
}
......@@ -1070,6 +1070,7 @@ int _rtp_session_sendto(RtpSession *session, bool_t is_rtp, mblk_t *m, int flags
int ret;
_rtp_session_check_socket_refresh(session);
if (session->net_sim_ctx && (session->net_sim_ctx->params.mode==OrtpNetworkSimulatorOutbound
|| session->net_sim_ctx->params.mode==OrtpNetworkSimulatorOutboundControlled)){
ret=(int)msgdsize(m);
......@@ -1114,6 +1115,7 @@ static void log_send_error(RtpSession *session, const char *type, mblk_t *m, str
static int rtp_session_rtp_sendto(RtpSession * session, mblk_t * m, struct sockaddr *destaddr, socklen_t destlen, bool_t is_aux){
int error;
if (rtp_session_using_transport(session, rtp)){
error = (session->rtp.gs.tr->t_sendto) (session->rtp.gs.tr,m,0,destaddr,destlen);
}else{
......@@ -1140,6 +1142,11 @@ int rtp_session_rtp_send (RtpSession * session, mblk_t * m){
struct sockaddr *destaddr=(struct sockaddr*)&session->rtp.gs.rem_addr;
socklen_t destlen=session->rtp.gs.rem_addrlen;
OList *elem=NULL;
if (session->is_spliced) {
freemsg(m);
return 0;
}
hdr = (rtp_header_t *) m->b_rptr;
if (hdr->version == 0) {
......@@ -1202,6 +1209,10 @@ rtp_session_rtcp_send (RtpSession * session, mblk_t * m){
OList *elem=NULL;
bool_t using_connected_socket=(session->flags & RTCP_SOCKET_CONNECTED)!=0;
if (session->is_spliced) {
freemsg(m);
return 0;
}
if (using_connected_socket) {
destaddr=NULL;
destlen=0;
......@@ -1538,6 +1549,11 @@ static void rtp_process_incoming_packet(RtpSession * session, mblk_t * mp, bool_
}
}
if (session->spliced_session){
/*this will forward all traffic to the spliced session*/
rtp_session_do_splice(session, mp, is_rtp_packet);
}
/* store the sender RTP address to do symmetric RTP at start mainly for stun packets.
* --For rtp packet symmetric RTP is handled in rtp_session_rtp_parse() after first valid rtp packet received.
* --For rtcp, only swicth if valid rtcp packet && first rtcp packet received*/
......
......@@ -91,4 +91,19 @@ ORTP_PUBLIC bool_t rtp_profile_is_telephone_event(const RtpProfile *prof, int pt
ortp_socket_t rtp_session_get_socket(RtpSession *session, bool_t is_rtp);
void rtp_session_do_splice(RtpSession *session, mblk_t *packet, bool_t is_rtp);
/*
* Update remote addr in the following case:
* rtp symetric == TRUE && socket not connected && remote addr has changed && ((rtp/rtcp packet && not only at start) or (no rtp/rtcp packets received))
* @param[in] session on which to perform change
* @param[in] mp packet where remote addr is retreived
* @param[in] is_rtp true if rtp
* @param[in] only_at_start only perform changes if no valid packets received yet
* @return 0 if chaged was performed
*
*/
ORTP_PUBLIC int rtp_session_update_remote_sock_addr(RtpSession * session, mblk_t * mp, bool_t is_rtp,bool_t only_at_start);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment