Commit 5bf8cb07 authored by Ghislain MARY's avatar Ghislain MARY

Add method to disable dummy STUN packet sending + disable STUN sending when ICE is enabled.

parent bcd3042a
......@@ -174,6 +174,8 @@ MS2_PUBLIC void media_stream_set_adaptive_bitrate_algorithm(MediaStream *stream,
MS2_PUBLIC void media_stream_enable_adaptive_jittcomp(MediaStream *stream, bool_t enabled);
MS2_PUBLIC void media_stream_set_ice_check_list(MediaStream *stream, IceCheckList *cl);
/*
* deprecated, use media_stream_set_srtp_recv_key and media_stream_set_srtp_send_key.
**/
......
......@@ -44,7 +44,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MS_RTP_SEND_SET_RELAY_SESSION_ID MS_FILTER_METHOD(MS_RTP_SEND_ID,5,const char *)
#define MS_RTP_SEND_SEND_GENERIC_CN MS_FILTER_METHOD(MS_RTP_SEND_ID,5, const MSCngData)
#define MS_RTP_SEND_SEND_GENERIC_CN MS_FILTER_METHOD(MS_RTP_SEND_ID,6, const MSCngData)
#define MS_RTP_SEND_ENABLE_STUN MS_FILTER_METHOD(MS_RTP_SEND_ID, 7, bool_t)
......
......@@ -51,21 +51,26 @@ struct SenderData {
bool_t skip;
bool_t mute;
bool_t use_task;
bool_t stun_enabled;
};
typedef struct SenderData SenderData;
/* Send dummy STUN packet to open NAT ports ASAP. */
static void send_stun_packet(RtpSession *s, bool_t enable_rtp, bool_t enable_rtcp)
static void send_stun_packet(SenderData *d, bool_t enable_rtp, bool_t enable_rtcp)
{
StunMessage msg;
mblk_t *mp;
RtpSession *s = d->session;
char buf[STUN_MAX_MESSAGE_SIZE];
int len = STUN_MAX_MESSAGE_SIZE;
if (!d->stun_enabled) return;
if (ms_is_multicast_addr((const struct sockaddr *)&s->rtcp.gs.loc_addr)) {
ms_debug("Stun packet not sent for session [%p] because of multicast",s);
return;
}
memset(&msg, 0, sizeof(StunMessage));
stunBuildReqSimple(&msg, NULL, FALSE, FALSE, 1);
len = stunEncodeMessage(&msg, buf, len, NULL);
......@@ -112,6 +117,7 @@ static void sender_init(MSFilter * f)
d->last_ts=0;
d->use_task= tmp ? (!!atoi(tmp)) : FALSE;
if (d->use_task) ms_message("MSRtpSend will use tasks to send out packet at the beginning of ticks.");
d->stun_enabled = TRUE;
f->data = d;
}
......@@ -153,15 +159,15 @@ static int sender_set_session(MSFilter * f, void *arg)
PayloadType *pt =
rtp_profile_get_payload(rtp_session_get_profile(s),
rtp_session_get_send_payload_type(s));
d->session = s;
if (pt != NULL) {
d->rate = pt->clock_rate;
d->dtmf_duration=(default_dtmf_duration_ms*d->rate)/1000;
d->dtmf_ts_step=(20*d->rate)/1000;
send_stun_packet(s,TRUE,TRUE);
send_stun_packet(d,TRUE,TRUE);
} else {
ms_warning("Sending undefined payload type ?");
}
d->session = s;
return 0;
}
......@@ -367,14 +373,14 @@ static void check_stun_sending(MSFilter *f) {
if ((d->last_rtp_stun_sent_time == -1) || ((f->ticker->time- d->last_sent_time>2000) /*no need to send stun packets if media sent during last 2s*/
&& (f->ticker->time - d->last_rtp_stun_sent_time) >= 500)) {
d->last_rtp_stun_sent_time = f->ticker->time;
send_stun_packet(s,TRUE,FALSE);
send_stun_packet(d,TRUE,FALSE);
}
if ( rtp_session_rtcp_enabled(s) && (d->last_rtcp_stun_sent_time == -1
|| (rtp_session_get_stats(s)->recv_rtcp_packets == 0 /*no need to send stun packets if rtcp packet already received*/
&& (f->ticker->time - d->last_rtcp_stun_sent_time) >= 500))) {
d->last_rtcp_stun_sent_time = f->ticker->time;
send_stun_packet(s,FALSE,TRUE);
send_stun_packet(d,FALSE,TRUE);
}
}
......@@ -481,6 +487,12 @@ static int sender_send_generic_cn(MSFilter *f, void *data){
return 0;
}
static int sender_enable_stun(MSFilter *f, void *data) {
SenderData *d = (SenderData *)f->data;
d->stun_enabled = *((bool_t *)data);
return 0;
}
static MSFilterMethod sender_methods[] = {
{MS_RTP_SEND_MUTE, sender_mute},
{MS_RTP_SEND_UNMUTE, sender_unmute},
......@@ -491,6 +503,7 @@ static MSFilterMethod sender_methods[] = {
{MS_FILTER_GET_NCHANNELS, sender_get_ch },
{MS_RTP_SEND_SET_DTMF_DURATION, sender_set_dtmf_duration },
{MS_RTP_SEND_SEND_GENERIC_CN, sender_send_generic_cn },
{ MS_RTP_SEND_ENABLE_STUN, sender_enable_stun },
{0, NULL}
};
......
......@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ortp/port.h"
#include "mediastreamer2/mediastream.h"
#include "mediastreamer2/msrtp.h"
#include "private.h"
#include <ctype.h>
......@@ -224,6 +225,18 @@ void media_stream_enable_dtls(MediaStream *stream, MSDtlsSrtpParams *params){
}
}
void media_stream_set_ice_check_list(MediaStream *stream, IceCheckList *cl) {
bool_t stun_enabled = TRUE;
stream->ice_check_list = cl;
if (stream->ice_check_list != NULL) {
ice_check_list_set_rtp_session(stream->ice_check_list, stream->sessions.rtp_session);
stun_enabled = FALSE;
}
if (stream->rtpsend != NULL) {
ms_filter_call_method(stream->rtpsend, MS_RTP_SEND_ENABLE_STUN, &stun_enabled);
}
}
bool_t media_stream_dtls_supported(void){
return ms_dtls_srtp_available();
}
......
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