Commit cf526666 authored by Ghislain MARY's avatar Ghislain MARY

Share the common struct fields of RtpStream and RtcpStream + Compute RTCP bandwidths.

parent d8b09cdb
......@@ -186,20 +186,30 @@ typedef struct OrtpRtcpXrStats {
uint32_t discarded_count;
} OrtpRtcpXrStats;
typedef struct _RtpStream
{
typedef struct _OrtpStream {
ortp_socket_t socket;
struct _RtpTransport *tr;
int sockfamily;
int loc_port;
int rem_addrlen;
struct sockaddr_storage rem_addr;
struct _RtpTransport *tr;
mblk_t *cached_mp;
struct timeval send_bw_start; /* used for bandwidth estimation */
struct timeval recv_bw_start; /* used for bandwidth estimation */
unsigned int sent_bytes; /* used for bandwidth estimation */
unsigned int recv_bytes; /* used for bandwidth estimation */
float upload_bw;
float download_bw;
} OrtpStream;
typedef struct _RtpStream
{
OrtpStream gs;
int max_rq_size;
int time_jump;
uint32_t ts_jump;
queue_t rq;
queue_t tev_rq;
mblk_t *cached_mp;
int loc_port;
struct sockaddr_storage rem_addr;
int rem_addrlen;
void *QoSHandle;
unsigned long QoSFlowID;
JitterControl jittctl;
......@@ -221,12 +231,6 @@ typedef struct _RtpStream
uint16_t snd_seq; /* send sequence number */
uint32_t last_rtcp_packet_count; /*the sender's octet count in the last sent RTCP SR*/
uint32_t sent_payload_bytes; /*used for RTCP sender reports*/
unsigned int sent_bytes; /* used for bandwidth estimation */
struct timeval send_bw_start; /* used for bandwidth estimation */
unsigned int recv_bytes; /* used for bandwidth estimation */
struct timeval recv_bw_start; /* used for bandwidth estimation */
float upload_bw;
float download_bw;
rtp_stats_t stats;
int recv_errno;
int send_errno;
......@@ -238,13 +242,7 @@ typedef struct _RtpStream
typedef struct _RtcpStream
{
ortp_socket_t socket;
int sockfamily;
struct _RtpTransport *tr;
mblk_t *cached_mp;
int loc_port;
struct sockaddr_storage rem_addr;
int rem_addrlen;
OrtpStream gs;
int interval;
uint32_t last_rtcp_report_snt_r; /* the time of the last rtcp report sent, in recv timestamp unit */
uint32_t last_rtcp_report_snt_s; /* the time of the last rtcp report sent, in send timestamp unit */
......@@ -450,6 +448,10 @@ ORTP_PUBLIC float rtp_session_compute_send_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_compute_recv_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_get_send_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_get_recv_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_get_rtp_send_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_get_rtp_recv_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_get_rtcp_send_bandwidth(RtpSession *session);
ORTP_PUBLIC float rtp_session_get_rtcp_recv_bandwidth(RtpSession *session);
ORTP_PUBLIC void rtp_session_send_rtcp_APP(RtpSession *session, uint8_t subtype, const char *name, const uint8_t *data, int datalen);
......
......@@ -57,9 +57,6 @@ static int64_t elapsed_us(struct timeval *tv1, struct timeval *tv2){
return ((tv2->tv_sec-tv1->tv_sec)*1000000LL)+((tv2->tv_usec-tv1->tv_usec));
}
#define IP_UDP_OVERHEAD (20+8)
#define IP6_UDP_OVERHEAD (40+8)
static mblk_t * simulate_latency(RtpSession *session, mblk_t *input){
OrtpNetworkSimulatorCtx *sim=session->net_sim_ctx;
struct timeval current;
......@@ -95,7 +92,7 @@ static mblk_t *simulate_bandwidth_limit(RtpSession *session, mblk_t *input){
int64_t elapsed;
int bits;
mblk_t *output=NULL;
int overhead=(session->rtp.sockfamily==AF_INET6) ? IP6_UDP_OVERHEAD : IP_UDP_OVERHEAD;
int overhead=(session->rtp.gs.sockfamily==AF_INET6) ? IP6_UDP_OVERHEAD : IP_UDP_OVERHEAD;
ortp_gettimeofday(&current,NULL);
......
......@@ -59,10 +59,10 @@ static int srtp_sendto(RtpTransport *t, mblk_t *m, int flags, const struct socka
msgpullup(m,slen+SRTP_PAD_BYTES);
err=srtp_protect(srtp,m->b_rptr,&slen);
if (err==err_status_ok){
return sendto(t->session->rtp.socket,(void*)m->b_rptr,slen,flags,to,tolen);
return sendto(t->session->rtp.gs.socket,(void*)m->b_rptr,slen,flags,to,tolen);
}
ortp_error("srtp_protect() failed (%d)", err);
}else return sendto(t->session->rtp.socket,(void*)m->b_rptr,slen,flags,to,tolen);
}else return sendto(t->session->rtp.gs.socket,(void*)m->b_rptr,slen,flags,to,tolen);
return -1;
}
......@@ -95,7 +95,7 @@ static int srtp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr
int err;
int slen;
err=rtp_session_rtp_recv_abstract(t->session->rtp.socket,m,flags,from,fromlen);
err=rtp_session_rtp_recv_abstract(t->session->rtp.gs.socket,m,flags,from,fromlen);
if (err>0){
err_status_t srtp_err;
/* keep NON-RTP data unencrypted */
......@@ -129,7 +129,7 @@ static int srtcp_sendto(RtpTransport *t, mblk_t *m, int flags, const struct sock
msgpullup(m,slen+SRTP_PAD_BYTES);
srtp_err=srtp_protect_rtcp(srtp,m->b_rptr,&slen);
if (srtp_err==err_status_ok){
return sendto(t->session->rtcp.socket,(void*)m->b_rptr,slen,flags,to,tolen);
return sendto(t->session->rtcp.gs.socket,(void*)m->b_rptr,slen,flags,to,tolen);
}
ortp_error("srtp_protect_rtcp() failed (%d)", srtp_err);
return -1;
......@@ -139,7 +139,7 @@ static int srtcp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr
srtp_t srtp=(srtp_t)t->data;
int err;
int slen;
err=rtp_session_rtp_recv_abstract(t->session->rtcp.socket,m,flags,from,fromlen);
err=rtp_session_rtp_recv_abstract(t->session->rtcp.gs.socket,m,flags,from,fromlen);
if (err>0){
err_status_t srtp_err;
uint32_t new_ssrc;
......@@ -170,13 +170,13 @@ static int srtcp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr
ortp_socket_t
srtp_getsocket(RtpTransport *t)
{
return t->session->rtp.socket;
return t->session->rtp.gs.socket;
}
ortp_socket_t
srtcp_getsocket(RtpTransport *t)
{
return t->session->rtcp.socket;
return t->session->rtcp.gs.socket;
}
/**
......
......@@ -207,10 +207,10 @@ void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_t
/* store the sender rtp address to do symmetric RTP */
if (!session->use_connect){
if (session->rtp.socket>0 && session->symmetric_rtp){
if (session->rtp.gs.socket>0 && session->symmetric_rtp){
/* store the sender rtp address to do symmetric RTP */
memcpy(&session->rtp.rem_addr,addr,addrlen);
session->rtp.rem_addrlen=addrlen;
memcpy(&session->rtp.gs.rem_addr,addr,addrlen);
session->rtp.gs.rem_addrlen=addrlen;
}
}
session->rtp.rcv_last_ts = rtp->timestamp;
......@@ -234,10 +234,10 @@ void rtp_session_rtp_parse(RtpSession *session, mblk_t *mp, uint32_t local_str_t
session->rcv.ssrc=rtp->ssrc;
if (!session->use_connect){
if (session->rtp.socket>0 && session->symmetric_rtp){
if (session->rtp.gs.socket>0 && session->symmetric_rtp){
/* store the sender rtp address to do symmetric RTP */
memcpy(&session->rtp.rem_addr,addr,addrlen);
session->rtp.rem_addrlen=addrlen;
memcpy(&session->rtp.gs.rem_addr,addr,addrlen);
session->rtp.gs.rem_addrlen=addrlen;
}
}
}
......
......@@ -254,8 +254,8 @@ rtp_session_init (RtpSession * session, int mode)
session->snd.telephone_events_pt=-1; /* not defined a priori */
session->rcv.telephone_events_pt=-1; /* not defined a priori */
rtp_session_set_profile (session, &av_profile); /*the default profile to work with */
session->rtp.socket=-1;
session->rtcp.socket=-1;
session->rtp.gs.socket=-1;
session->rtcp.gs.socket=-1;
#ifndef WIN32
session->rtp.snd_socket_size=0; /*use OS default value unless on windows where they are definitely too short*/
session->rtp.rcv_socket_size=0;
......@@ -1393,31 +1393,31 @@ void rtp_session_set_time_jump_limit(RtpSession *session, int milisecs){
* Closes the rtp and rtcp sockets.
**/
void rtp_session_release_sockets(RtpSession *session){
if (session->rtp.socket!=(ortp_socket_t)-1) close_socket (session->rtp.socket);
if (session->rtcp.socket!=(ortp_socket_t)-1) close_socket (session->rtcp.socket);
session->rtp.socket=-1;
session->rtcp.socket=-1;
if (session->rtp.gs.socket!=(ortp_socket_t)-1) close_socket (session->rtp.gs.socket);
if (session->rtcp.gs.socket!=(ortp_socket_t)-1) close_socket (session->rtcp.gs.socket);
session->rtp.gs.socket=-1;
session->rtcp.gs.socket=-1;
if (session->rtp.tr && session->rtp.tr->t_close)
session->rtp.tr->t_close(session->rtp.tr, session->rtp.tr->data);
session->rtp.tr = 0;
if (session->rtp.gs.tr && session->rtp.gs.tr->t_close)
session->rtp.gs.tr->t_close(session->rtp.gs.tr, session->rtp.gs.tr->data);
session->rtp.gs.tr = 0;
if (session->rtcp.tr && session->rtcp.tr->t_close)
session->rtcp.tr->t_close(session->rtcp.tr, session->rtcp.tr->data);
session->rtcp.tr = 0;
if (session->rtcp.gs.tr && session->rtcp.gs.tr->t_close)
session->rtcp.gs.tr->t_close(session->rtcp.gs.tr, session->rtcp.gs.tr->data);
session->rtcp.gs.tr = 0;
/* don't discard remote addresses, then can be preserved for next use.
session->rtp.rem_addrlen=0;
session->rtcp.rem_addrlen=0;
session->rtp.gs.rem_addrlen=0;
session->rtcp.gs.rem_addrlen=0;
*/
}
ortp_socket_t rtp_session_get_rtp_socket(const RtpSession *session){
return rtp_session_using_transport(session, rtp) ? (session->rtp.tr->t_getsocket)(session->rtp.tr) : session->rtp.socket;
return rtp_session_using_transport(session, rtp) ? (session->rtp.gs.tr->t_getsocket)(session->rtp.gs.tr) : session->rtp.gs.socket;
}
ortp_socket_t rtp_session_get_rtcp_socket(const RtpSession *session){
return rtp_session_using_transport(session, rtcp) ? (session->rtcp.tr->t_getsocket)(session->rtcp.tr) : session->rtcp.socket;
return rtp_session_using_transport(session, rtcp) ? (session->rtcp.gs.tr->t_getsocket)(session->rtcp.gs.tr) : session->rtcp.gs.socket;
}
/**
......@@ -1460,8 +1460,8 @@ void rtp_session_uninit (RtpSession * session)
wait_point_uninit(&session->snd.wp);
wait_point_uninit(&session->rcv.wp);
if (session->current_tev!=NULL) freemsg(session->current_tev);
if (session->rtp.cached_mp!=NULL) freemsg(session->rtp.cached_mp);
if (session->rtcp.cached_mp!=NULL) freemsg(session->rtcp.cached_mp);
if (session->rtp.gs.cached_mp!=NULL) freemsg(session->rtp.gs.cached_mp);
if (session->rtcp.gs.cached_mp!=NULL) freemsg(session->rtcp.gs.cached_mp);
if (session->full_sdes != NULL)
freemsg(session->full_sdes);
if (session->minimal_sdes != NULL)
......@@ -1696,16 +1696,20 @@ static float compute_bw(struct timeval *orig, unsigned int bytes){
return bw;
}
float rtp_session_compute_recv_bandwidth(RtpSession *session){
session->rtp.download_bw=compute_bw(&session->rtp.recv_bw_start,session->rtp.recv_bytes);
session->rtp.recv_bytes=0;
return session->rtp.download_bw;
float rtp_session_compute_recv_bandwidth(RtpSession *session) {
session->rtp.gs.download_bw = compute_bw(&session->rtp.gs.recv_bw_start, session->rtp.gs.recv_bytes);
session->rtp.gs.recv_bytes = 0;
session->rtcp.gs.download_bw = compute_bw(&session->rtcp.gs.recv_bw_start, session->rtcp.gs.recv_bytes);
session->rtcp.gs.recv_bytes = 0;
return session->rtp.gs.download_bw + session->rtcp.gs.download_bw;
}
float rtp_session_compute_send_bandwidth(RtpSession *session){
session->rtp.upload_bw=compute_bw(&session->rtp.send_bw_start,session->rtp.sent_bytes);
session->rtp.sent_bytes=0;
return session->rtp.upload_bw;
float rtp_session_compute_send_bandwidth(RtpSession *session) {
session->rtp.gs.upload_bw = compute_bw(&session->rtp.gs.send_bw_start, session->rtp.gs.sent_bytes);
session->rtp.gs.sent_bytes = 0;
session->rtcp.gs.upload_bw = compute_bw(&session->rtcp.gs.send_bw_start, session->rtcp.gs.sent_bytes);
session->rtcp.gs.sent_bytes = 0;
return session->rtp.gs.upload_bw + session->rtcp.gs.upload_bw;
}
/**
......@@ -1713,7 +1717,7 @@ float rtp_session_compute_send_bandwidth(RtpSession *session){
* Computation must have been done with rtp_session_compute_recv_bandwidth()
**/
float rtp_session_get_recv_bandwidth(RtpSession *session){
return session->rtp.download_bw;
return session->rtp.gs.download_bw + session->rtcp.gs.download_bw;
}
/**
......@@ -1721,7 +1725,23 @@ float rtp_session_get_recv_bandwidth(RtpSession *session){
* Computation must have been done with rtp_session_compute_send_bandwidth()
**/
float rtp_session_get_send_bandwidth(RtpSession *session){
return session->rtp.upload_bw;
return session->rtp.gs.upload_bw + session->rtcp.gs.upload_bw;
}
float rtp_session_get_rtp_recv_bandwidth(RtpSession *session) {
return session->rtp.gs.download_bw;
}
float rtp_session_get_rtp_send_bandwidth(RtpSession *session) {
return session->rtp.gs.upload_bw;
}
float rtp_session_get_rtcp_recv_bandwidth(RtpSession *session) {
return session->rtcp.gs.download_bw;
}
float rtp_session_get_rtcp_send_bandwidth(RtpSession *session) {
return session->rtcp.gs.upload_bw;
}
int rtp_session_get_last_send_error_code(RtpSession *session){
......
This diff is collapsed.
......@@ -22,6 +22,9 @@
#include "ortp/rtpsession.h"
#define IP_UDP_OVERHEAD (20 + 8)
#define IP6_UDP_OVERHEAD (40 + 8)
#define RTCP_XR_GMIN 16 /* Recommended value of Gmin from RFC3611, section 4.7.6 */
typedef enum {
......@@ -41,7 +44,7 @@ typedef enum {
RTCP_OVERRIDE_DELAY=1<<13
}RtpSessionFlags;
#define rtp_session_using_transport(s, stream) (((s)->flags & RTP_SESSION_USING_TRANSPORT) && (s->stream.tr != 0))
#define rtp_session_using_transport(s, stream) (((s)->flags & RTP_SESSION_USING_TRANSPORT) && (s->stream.gs.tr != 0))
int rtp_session_rtp_recv_abstract(ortp_socket_t socket, mblk_t *msg, int flags, struct sockaddr *from, socklen_t *fromlen);
......
......@@ -90,9 +90,9 @@ static int32_t ozrtp_sendDataZRTP (void *clientData, uint8_t* data, int32_t leng
OrtpZrtpContext *userData = (OrtpZrtpContext *)clientData;
RtpSession *session = userData->session;
struct sockaddr *destaddr=(struct sockaddr*)&session->rtp.rem_addr;
socklen_t destlen=session->rtp.rem_addrlen;
ortp_socket_t sockfd=session->rtp.socket;
struct sockaddr *destaddr=(struct sockaddr*)&session->rtp.gs.rem_addr;
socklen_t destlen=session->rtp.gs.rem_addrlen;
ortp_socket_t sockfd=session->rtp.gs.socket;
ortp_message("ZRTP Send packet type %.8s", data+16);
// Send packet
......@@ -366,9 +366,9 @@ static int ozrtp_generic_sendto(stream_type stream, RtpTransport *t, mblk_t *m,
if (stream == rtp_stream) {
socket= t->session->rtp.socket;
socket= t->session->rtp.gs.socket;
} else {
socket= t->session->rtcp.socket;
socket= t->session->rtcp.gs.socket;
}
if (userData->srtpSend == NULL || !bzrtp_isSecure(zrtpContext, session->snd.ssrc)) {
......@@ -415,7 +415,7 @@ static int ozrtp_rtp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sock
bzrtp_iterate(zrtpContext, session->snd.ssrc, get_timeval_in_millis());
// Check if something to receive
rlen=rtp_session_rtp_recv_abstract(t->session->rtp.socket,m,flags,from,fromlen);
rlen=rtp_session_rtp_recv_abstract(t->session->rtp.gs.socket,m,flags,from,fromlen);
if (rlen<=0) {
// nothing was received or error: pass the information to caller
return rlen;
......@@ -457,7 +457,7 @@ static int ozrtp_rtcp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct soc
RtpSession *session = userData->session;
int rlen = rtp_session_rtp_recv_abstract(t->session->rtcp.socket,m,flags,from,fromlen);
int rlen = rtp_session_rtp_recv_abstract(t->session->rtcp.gs.socket,m,flags,from,fromlen);
if (rlen<=0) {
// nothing was received or error: pass the information to caller
return rlen;
......@@ -478,11 +478,11 @@ static int ozrtp_rtcp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct soc
static ortp_socket_t ozrtp_rtp_getsocket(RtpTransport *t){
return t->session->rtp.socket;
return t->session->rtp.gs.socket;
}
static ortp_socket_t ozrtp_rtcp_getsocket(RtpTransport *t){
return t->session->rtcp.socket;
return t->session->rtcp.gs.socket;
}
static OrtpZrtpContext* createUserData(bzrtpContext_t *context, OrtpZrtpParams *params) {
......@@ -507,7 +507,7 @@ static OrtpZrtpContext* ortp_zrtp_configure_context(OrtpZrtpContext *userData, R
bzrtpContext_t *context=userData->zrtpContext;
if (s->rtp.tr || s->rtcp.tr)
if (s->rtp.gs.tr || s->rtcp.gs.tr)
ortp_warning("Overwriting rtp or rtcp transport with ZRTP one");
userData->rtpt.data=userData; /* back link to get access to the other fields of the OrtoZrtpContext from the RtpTransport structure */
......
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