Commit 9d8e0cc6 authored by Yann Diorcet's avatar Yann Diorcet

Add rtp timestamp

parent 3b399c8f
......@@ -70,6 +70,18 @@ if test x$ipv6 = xtrue ; then
ORTP_DEFS="$ORTP_DEFS -DORTP_INET6"
fi
dnl enable timestamp support
AC_ARG_ENABLE(rtp-timestamp,
[ --enable-rtp-timestamp Turn on RTP packet timestamp],
[case "${enableval}" in
yes) rtptimestamp=true;;
no) rtptimestamp=false;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-rtp-timestamp) ;;
esac],[rtptimestamp=false])
if test x$rtptimestamp = xtrue ; then
ORTP_DEFS="$ORTP_DEFS -DORTP_TIMESTAMP"
fi
AC_ARG_ENABLE(mode64bit,
[ --enable-mode64bit=[yes/no] produce a 64-bit library. [default=no]],
[case "${enableval}" in
......@@ -157,14 +169,13 @@ fi
AC_ARG_WITH(thread-stack-size,
AC_HELP_STRING([--with-thread-stack-size=SIZE-IN-BYTES],[Set thread stack size [[default=os-default]]]),
[thread_stack_size=$withval], [thread_stack_size=0])
AC_DEFINE_UNQUOTED(ORTP_DEFAULT_THREAD_STACK_SIZE, $thread_stack_size, [Default thread stack size (0 = let operating system decide)])
AC_DEFINE_UNQUOTED(ORTP_DEFAULT_THREAD_STACK_SIZE, $thread_stack_size, [Default thread stack size (0 = let uperating system decide)])
dnl check for libsrtp support (secure rtp)
AC_ARG_WITH( srtp,
[ --with-srtp Set prefix where libsrtp can be found or "none" to disable (ex:/usr or /usr/local)[default=/usr] ],
[ srtp_prefix=${withval}],[ srtp_prefix=/usr ])
AC_ARG_WITH(srtp,
AC_HELP_STRING([--with-srtp],[Set prefix where libsrtp can be found or "none" to disable (ex:/usr or /usr/local) [[default=/usr]]]),
[srtp_prefix=$withval], [srtp_prefix=/usr])
if test "${srtp_prefix}" != "none" ; then
if test "${srtp_prefix}" != "/usr" || test "$mingw_found" = "yes" ; then
SRTP_CFLAGS="-I${srtp_prefix}/include -I${srtp_prefix}/include/srtp"
......
......@@ -22,7 +22,9 @@
#include <ortp/port.h>
#if defined(ORTP_TIMESTAMP)
#include <time.h>
#endif
typedef struct msgb
{
......@@ -34,8 +36,13 @@ typedef struct msgb
unsigned char *b_wptr;
uint32_t reserved1;
uint32_t reserved2;
#if defined(ORTP_TIMESTAMP)
struct timeval timestamp;
#endif
} mblk_t;
typedef struct datab
{
unsigned char *db_base;
......@@ -71,6 +78,8 @@ mblk_t * peekq(queue_t *q);
void flushq(queue_t *q, int how);
void mblk_init(mblk_t *mp);
void mblk_meta_copy(const mblk_t *source, mblk_t *dest);
/* allocates a mblk_t, that points to a datab_t, that points to a buffer of size size. */
mblk_t *allocb(int size, int unused);
......
......@@ -30,6 +30,7 @@
#undef PACKAGE_VERSION
#include "ortp/ortp_srtp.h"
#include "rtpsession_priv.h"
#ifdef HAVE_SRTP
#include "ortp/b64.h"
......@@ -55,7 +56,7 @@ static int srtp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr
srtp_t srtp=(srtp_t)t->data;
int err;
int slen;
err=recvfrom(t->session->rtp.socket,(void*)m->b_wptr,m->b_datap->db_lim-m->b_datap->db_base,flags,from,fromlen);
err=rtp_session_rtp_recv_abstract(t->session->rtp.socket,m,flags,from,fromlen);
if (err>0){
err_status_t srtp_err;
/* keep NON-RTP data unencrypted */
......@@ -100,7 +101,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=recvfrom(t->session->rtcp.socket,(void*)m->b_wptr,m->b_datap->db_lim-m->b_datap->db_base,flags,from,fromlen);
err=rtp_session_rtp_recv_abstract(t->session->rtcp.socket,m,flags,from,fromlen);
if (err>0){
err_status_t srtp_err;
slen=err;
......
......@@ -86,6 +86,14 @@ static ortp_socket_t create_and_bind(const char *addr, int port, int *sock_famil
ortp_warning ("Fail to set rtp address reusable: %s.", getSocketError());
}
}
#if defined(ORTP_TIMESTAMP)
err = setsockopt (sock, SOL_SOCKET, SO_TIMESTAMP,
(SOCKET_OPTION_VALUE)&optval, sizeof (optval));
if (err < 0)
{
ortp_warning ("Fail to set rtp timestamp: %s.",getSocketError());
}
#endif
*sock_family=res->ai_family;
err = bind (sock, res->ai_addr, res->ai_addrlen);
......@@ -156,6 +164,14 @@ static ortp_socket_t create_and_bind(const char *addr, int port, int *sock_famil
ortp_warning ("Fail to set rtp address reusable: %s.",getSocketError());
}
}
#if defined(ORTP_TIMESTAMP)
err = setsockopt (sock, SOL_SOCKET, SO_TIMESTAMP,
(SOCKET_OPTION_VALUE)&optval, sizeof (optval));
if (err < 0)
{
ortp_warning ("Fail to set rtp timestamp: %s.",getSocketError());
}
#endif
err = bind (sock,
(struct sockaddr *) &saddr,
......@@ -954,8 +970,50 @@ rtp_session_rtcp_send (RtpSession * session, mblk_t * m)
return error;
}
int
rtp_session_rtp_recv (RtpSession * session, uint32_t user_ts)
int rtp_session_rtp_recv_abstract(ortp_socket_t socket, mblk_t *msg, int flags, struct sockaddr *from, socklen_t *fromlen) {
int bufsz = (int) (msg->b_datap->db_lim - msg->b_datap->db_base);
struct iovec iov;
struct msghdr msghdr;
#if defined(ORTP_TIMESTAMP)
struct cmsghdr *cmsghdr;
struct {
struct cmsghdr cm;
char control[512];
} control;
#endif
memset(&msghdr, 0, sizeof(msghdr));
memset(&iov, 0, sizeof(iov));
iov.iov_base = msg->b_wptr;
iov.iov_len = bufsz;
if(from != NULL && fromlen != NULL) {
msghdr.msg_name = from;
msghdr.msg_namelen = *fromlen;
}
msghdr.msg_iov = &iov;
msghdr.msg_iovlen = 1;
#if defined(ORTP_TIMESTAMP)
msghdr.msg_control = &control;
msghdr.msg_controllen = sizeof(control);
#endif
int ret = recvmsg(socket, &msghdr, flags);
if(fromlen != NULL)
*fromlen = msghdr.msg_namelen;
#if defined(ORTP_TIMESTAMP)
memset(&msg->timestamp, 0, sizeof(struct timeval));
if(ret >= 0) {
for (cmsghdr = CMSG_FIRSTHDR(&msghdr); cmsghdr != NULL ; cmsghdr = CMSG_NXTHDR(&msghdr, cmsghdr)) {
if (cmsghdr->cmsg_level == SOL_SOCKET && cmsghdr->cmsg_type == SO_TIMESTAMP) {
memcpy(&msg->timestamp, (struct timeval *)CMSG_DATA(cmsghdr), sizeof(struct timeval));
}
}
}
#endif
return ret;
}
int rtp_session_rtp_recv (RtpSession * session, uint32_t user_ts)
{
int error;
ortp_socket_t sockfd=session->rtp.socket;
......@@ -971,23 +1029,21 @@ rtp_session_rtp_recv (RtpSession * session, uint32_t user_ts)
while (1)
{
int bufsz;
bool_t sock_connected=!!(session->flags & RTP_SOCKET_CONNECTED);
if (session->rtp.cached_mp==NULL)
session->rtp.cached_mp = msgb_allocator_alloc(&session->allocator,session->recv_buf_size);
mp=session->rtp.cached_mp;
bufsz=(int) (mp->b_datap->db_lim - mp->b_datap->db_base);
if (sock_connected){
error=recv(sockfd,(char*)mp->b_wptr,bufsz,0);
}else if (rtp_session_using_transport(session, rtp))
error=rtp_session_rtp_recv_abstract(sockfd, mp, 0, NULL, NULL);
}else if (rtp_session_using_transport(session, rtp)) {
error = (session->rtp.tr->t_recvfrom)(session->rtp.tr, mp, 0,
(struct sockaddr *) &remaddr,
&addrlen);
else error = recvfrom(sockfd, (char*)mp->b_wptr,
bufsz, 0,
} else { error = rtp_session_rtp_recv_abstract(sockfd, mp, 0,
(struct sockaddr *) &remaddr,
&addrlen);
}
if (error > 0){
if (session->symmetric_rtp && !sock_connected){
if (session->use_connect){
......@@ -1156,7 +1212,7 @@ rtp_session_rtcp_recv (RtpSession * session)
mp=session->rtcp.cached_mp;
if (sock_connected){
error=recv(session->rtcp.socket,(char*)mp->b_wptr,RTCP_MAX_RECV_BUFSIZE,0);
error=rtp_session_rtp_recv_abstract(session->rtcp.socket, mp, 0, NULL, NULL);
}else {
addrlen=sizeof (remaddr);
......@@ -1165,8 +1221,7 @@ rtp_session_rtcp_recv (RtpSession * session)
(struct sockaddr *) &remaddr,
&addrlen);
else
error=recvfrom (session->rtcp.socket,(char*) mp->b_wptr,
RTCP_MAX_RECV_BUFSIZE, 0,
error=rtp_session_rtp_recv_abstract (session->rtcp.socket,mp, 0,
(struct sockaddr *) &remaddr,
&addrlen);
}
......
......@@ -41,6 +41,8 @@ typedef enum {
#define rtp_session_using_transport(s, stream) (((s)->flags & RTP_SESSION_USING_TRANSPORT) && (s->stream.tr != 0))
int rtp_session_rtp_recv_abstract(ortp_socket_t socket, mblk_t *msg, int flags, struct sockaddr *from, socklen_t *fromlen);
void rtp_session_update_payload_type(RtpSession * session, int pt);
void rtp_putq(queue_t *q, mblk_t *mp);
mblk_t * rtp_getq(queue_t *q, uint32_t ts, int *rejected);
......
......@@ -37,6 +37,14 @@ void mblk_init(mblk_t *mp)
mp->reserved2=0;
}
void mblk_meta_copy(const mblk_t *source, mblk_t *dest) {
dest->reserved1 = source->reserved1;
dest->reserved2 = source->reserved2;
#if defined(ORTP_TIMESTAMP)
dest->timestamp = source->timestamp;
#endif
}
dblk_t *datab_alloc(int size){
dblk_t *db;
int total_size=sizeof(dblk_t)+size;
......
......@@ -665,7 +665,7 @@ static int ozrtp_rtp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sock
// Check if something to receive
rlen=recvfrom(t->session->rtp.socket,(void*)m->b_wptr,m->b_datap->db_lim-m->b_datap->db_base,flags,from,fromlen);
rlen=rtp_session_rtp_recv_abstract(t->session->rtp.socket,m,flags,from,fromlen);
if (rlen<=0) {
// nothing was received or error: pass the information to caller
return rlen;
......@@ -738,7 +738,7 @@ static int ozrtp_rtcp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct soc
ZrtpContext *zrtpContext = (ZrtpContext*) t->data;
OrtpZrtpContext *userData = (OrtpZrtpContext*) zrtpContext->userData;
int rlen = recvfrom(t->session->rtcp.socket,(void*)m->b_wptr,m->b_datap->db_lim-m->b_datap->db_base,flags,from,fromlen);
int rlen = rtp_session_rtp_recv_abstract(t->session->rtcp.socket,m,flags,from,fromlen);
if (rlen<=0) {
// nothing was received or error: pass the information to caller
return rlen;
......
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