diff --git a/linphone/mediastreamer2/build/win32native/alldescs.h b/linphone/mediastreamer2/build/win32native/alldescs.h index 9419c4a47..2b70f5b11 100755 --- a/linphone/mediastreamer2/build/win32native/alldescs.h +++ b/linphone/mediastreamer2/build/win32native/alldescs.h @@ -42,6 +42,7 @@ extern MSFilterDesc ms_volume_desc; extern MSFilterDesc ms_static_image_desc; extern MSFilterDesc ms_mire_desc; extern MSFilterDesc ms_vfw_desc; +extern MSFilterDesc ms_ice_desc; MSFilterDesc * ms_filter_descs[]={ &ms_alaw_dec_desc, &ms_alaw_enc_desc, @@ -87,6 +88,7 @@ MSFilterDesc * ms_filter_descs[]={ &ms_static_image_desc, &ms_mire_desc, &ms_vfw_desc, +&ms_ice_desc, NULL }; diff --git a/linphone/mediastreamer2/build/win32native/mediastreamer2.def b/linphone/mediastreamer2/build/win32native/mediastreamer2.def index 667a4fe59..8de94f72d 100755 --- a/linphone/mediastreamer2/build/win32native/mediastreamer2.def +++ b/linphone/mediastreamer2/build/win32native/mediastreamer2.def @@ -89,9 +89,6 @@ EXPORTS ms_list_append ms_list_remove - ice_sound_send_stun_request - ice_process_stun_message - ms_discover_mtu ms_set_mtu diff --git a/linphone/mediastreamer2/include/mediastreamer2/allfilters.h b/linphone/mediastreamer2/include/mediastreamer2/allfilters.h index 9e2c0a231..25d04967b 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/allfilters.h +++ b/linphone/mediastreamer2/include/mediastreamer2/allfilters.h @@ -80,7 +80,8 @@ typedef enum MSFilterId{ MS_H263_OLD_DEC_ID, MS_H263_OLD_ENC_ID, MS_MIRE_ID, - MS_VFW_ID + MS_VFW_ID, + MS_ICE_ID } MSFilterId; diff --git a/linphone/mediastreamer2/include/mediastreamer2/ice.h b/linphone/mediastreamer2/include/mediastreamer2/ice.h index 002f02964..cc3e8e620 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/ice.h +++ b/linphone/mediastreamer2/include/mediastreamer2/ice.h @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef ice_hh #define ice_hh +#include "msfilter.h" #include "ortp/stun_udp.h" #include "ortp/stun.h" #include "ortp/ortp.h" @@ -87,18 +88,9 @@ struct IceCheckList { uint64_t keepalive_time; }; -#ifdef __cplusplus -extern "C"{ -#endif +#define MS_ICE_SET_SESSION MS_FILTER_METHOD(MS_ICE_ID,0,RtpSession*) +#define MS_ICE_SET_CANDIDATEPAIRS MS_FILTER_METHOD(MS_ICE_ID,1,struct CandidatePair*) -int ice_sound_send_stun_request(RtpSession *session, struct IceCheckList *checklist, uint64_t ctime); - -int ice_process_stun_message(RtpSession *session, struct IceCheckList *checklist, OrtpEvent *evt); - -int ice_restart(struct IceCheckList *checklist); - -#ifdef __cplusplus -} -#endif +extern MSFilterDesc ms_ice_desc; #endif diff --git a/linphone/mediastreamer2/include/mediastreamer2/msrtp.h b/linphone/mediastreamer2/include/mediastreamer2/msrtp.h index 76a4e1c3b..9c1171551 100644 --- a/linphone/mediastreamer2/include/mediastreamer2/msrtp.h +++ b/linphone/mediastreamer2/include/mediastreamer2/msrtp.h @@ -31,10 +31,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MS_RTP_SEND_SEND_DTMF MS_FILTER_METHOD(MS_RTP_SEND_ID,1,const char) -#define MS_RTP_RECV_SET_CANDIDATEPAIRS MS_FILTER_METHOD(MS_RTP_RECV_ID,1,struct CandidatePair*) - -#define MS_RTP_SEND_SET_CANDIDATEPAIRS MS_FILTER_METHOD(MS_RTP_SEND_ID,2,struct CandidatePair*) - #define MS_RTP_SEND_MUTE_MIC MS_FILTER_METHOD_NO_ARG(MS_RTP_SEND_ID,3) #define MS_RTP_SEND_UNMUTE_MIC MS_FILTER_METHOD_NO_ARG(MS_RTP_SEND_ID,4) diff --git a/linphone/mediastreamer2/src/ice.c b/linphone/mediastreamer2/src/ice.c index b2aaff3e4..5372dd613 100644 --- a/linphone/mediastreamer2/src/ice.c +++ b/linphone/mediastreamer2/src/ice.c @@ -25,16 +25,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #endif +#include "mediastreamer2/msticker.h" #include "mediastreamer2/ice.h" #include "mediastreamer2/mscommon.h" #include -static void -ice_sendtest( struct IceCheckList *checklist, struct CandidatePair *remote_candidate, Socket myFd, StunAddress4 *dest, - const StunAtrString *username, const StunAtrString *password, - UInt96 *tid); - static void ice_sendtest( struct IceCheckList *checklist, struct CandidatePair *remote_candidate, Socket myFd, StunAddress4 *dest, const StunAtrString *username, const StunAtrString *password, @@ -82,7 +78,7 @@ ice_sendtest( struct IceCheckList *checklist, struct CandidatePair *remote_candi sendMessage( myFd, buf, len, dest->addr, dest->port ); } -int ice_restart(struct IceCheckList *checklist) +static int ice_restart(struct IceCheckList *checklist) { struct CandidatePair *remote_candidates = NULL; int pos; @@ -148,7 +144,7 @@ int ice_restart(struct IceCheckList *checklist) return 0; } -int ice_sound_send_stun_request(RtpSession *session, struct IceCheckList *checklist, uint64_t ctime) +static int ice_sound_send_stun_request(RtpSession *session, struct IceCheckList *checklist, uint64_t ctime) { struct CandidatePair *remote_candidates = NULL; @@ -476,7 +472,7 @@ _ice_createErrorResponse(StunMessage *response, int cl, int number, const char* response->hasFingerprint = TRUE; } -int ice_process_stun_message(RtpSession *session, struct IceCheckList *checklist, OrtpEvent *evt) +static int ice_process_stun_message(RtpSession *session, struct IceCheckList *checklist, OrtpEvent *evt) { struct CandidatePair *remote_candidates = NULL; StunMessage msg; @@ -1215,3 +1211,157 @@ int ice_process_stun_message(RtpSession *session, struct IceCheckList *checklist return 0; } + + + +struct IceData { + RtpSession *session; + OrtpEvQueue *ortp_event; + struct IceCheckList *check_lists; /* table of 10 cpair */ + int rate; +}; + +typedef struct IceData IceData; + +static void ice_init(MSFilter * f) +{ + IceData *d = (IceData *)ms_new(IceData, 1); + + d->ortp_event = ortp_ev_queue_new(); + d->session = NULL; + d->check_lists = NULL; + d->rate = 8000; + f->data = d; +} + +static void ice_postprocess(MSFilter * f) +{ + IceData *d = (IceData *) f->data; + if (d->session!=NULL && d->ortp_event!=NULL) + rtp_session_unregister_event_queue(d->session, d->ortp_event); +} + +static void ice_uninit(MSFilter * f) +{ + IceData *d = (IceData *) f->data; + if (d->ortp_event!=NULL) + ortp_ev_queue_destroy(d->ortp_event); + ms_free(f->data); +} + +static int ice_set_session(MSFilter * f, void *arg) +{ + IceData *d = (IceData *) f->data; + RtpSession *s = (RtpSession *) arg; + PayloadType *pt = rtp_profile_get_payload(rtp_session_get_profile(s), + rtp_session_get_recv_payload_type + (s)); + if (pt != NULL) { + if (strcasecmp("g722", pt->mime_type)==0 ) + d->rate=8000; + else d->rate = pt->clock_rate; + } else { + ms_warning("Receiving undefined payload type ?"); + } + d->session = s; + + return 0; +} + +static int ice_set_sdpcandidates(MSFilter * f, void *arg) +{ + IceData *d = (IceData *) f->data; + struct IceCheckList *scs = NULL; + + if (d == NULL) + return -1; + + scs = (struct IceCheckList *) arg; + d->check_lists = scs; + ice_restart(d->check_lists); + return 0; +} + +static void ice_preprocess(MSFilter * f){ + IceData *d = (IceData *) f->data; + if (d->session!=NULL && d->ortp_event!=NULL) + rtp_session_register_event_queue(d->session, d->ortp_event); +} + +static void ice_process(MSFilter * f) +{ + IceData *d = (IceData *) f->data; + + if (d->session == NULL) + return; + + /* check received STUN request */ + if (d->ortp_event!=NULL) + { + OrtpEvent *evt = ortp_ev_queue_get(d->ortp_event); + + while (evt != NULL) { + if (ortp_event_get_type(evt) == + ORTP_EVENT_STUN_PACKET_RECEIVED) { + ice_process_stun_message(d->session, d->check_lists, evt); + } + if (ortp_event_get_type(evt) == + ORTP_EVENT_TELEPHONE_EVENT) { + } + + ortp_event_destroy(evt); + evt = ortp_ev_queue_get(d->ortp_event); + } + } + +#if !defined(_WIN32_WCE) + ice_sound_send_stun_request(d->session, d->check_lists, f->ticker->time); +#else + ice_sound_send_stun_request(d->session, d->check_lists, f->ticker->time)); +#endif +} + +static MSFilterMethod ice_methods[] = { + {MS_ICE_SET_SESSION, ice_set_session}, + {MS_ICE_SET_CANDIDATEPAIRS, ice_set_sdpcandidates}, + {0, NULL} +}; + +#ifdef _MSC_VER + +MSFilterDesc ms_ice_desc = { + MS_ICE_ID, + "MSIce", + N_("ICE filter"), + MS_FILTER_OTHER, + NULL, + 0, + 0, + ice_init, + ice_preprocess, + ice_process, + ice_postprocess, + ice_uninit, + ice_methods +}; + +#else + +MSFilterDesc ms_ice_desc = { + .id = MS_ICE_ID, + .name = "MSIce", + .text = N_("ICE filter"), + .category = MS_FILTER_OTHER, + .ninputs = 0, + .noutputs = 0, + .init = ice_init, + .preprocess = ice_preprocess, + .process = ice_process, + .postprocess=ice_postprocess, + .uninit = ice_uninit, + .methods = ice_methods +}; + +#endif + +MS_FILTER_DESC_EXPORT(ms_ice_desc) diff --git a/linphone/mediastreamer2/src/msfilter.c b/linphone/mediastreamer2/src/msfilter.c index 5358156d6..aa448216f 100644 --- a/linphone/mediastreamer2/src/msfilter.c +++ b/linphone/mediastreamer2/src/msfilter.c @@ -83,8 +83,6 @@ MSFilter *ms_filter_new_from_desc(MSFilterDesc *desc){ obj->desc=desc; if (desc->ninputs>0) obj->inputs=(MSQueue**)ms_new0(MSQueue*,desc->ninputs); if (desc->noutputs>0) obj->outputs=(MSQueue**)ms_new0(MSQueue*,desc->noutputs); - if (desc->ninputs==0 && desc->noutputs==0) - ms_fatal("A filter cannot have no inputs and outputs"); if (obj->desc->init!=NULL) obj->desc->init(obj); return obj; diff --git a/linphone/mediastreamer2/src/msrtp.c b/linphone/mediastreamer2/src/msrtp.c index 3178662cf..2925966f4 100644 --- a/linphone/mediastreamer2/src/msrtp.c +++ b/linphone/mediastreamer2/src/msrtp.c @@ -29,7 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct SenderData { RtpSession *session; - struct IceCheckList *check_lists; /* table of 10 cpair */ uint32_t tsoff; uint32_t skip_until; int rate; @@ -48,7 +47,6 @@ static void sender_init(MSFilter * f) SenderData *d = (SenderData *)ms_new(SenderData, 1); d->session = NULL; - d->check_lists = NULL; d->tsoff = 0; d->skip_until = 0; d->skip = FALSE; @@ -78,20 +76,6 @@ static int sender_send_dtmf(MSFilter * f, void *arg) return 0; } -static int sender_set_sdpcandidates(MSFilter * f, void *arg) -{ - SenderData *d = (SenderData *) f->data; - struct IceCheckList *scs = NULL; - - if (d == NULL) - return -1; - - scs = (struct IceCheckList *) arg; - d->check_lists = scs; - ice_restart(d->check_lists); - return 0; -} - static int sender_set_session(MSFilter * f, void *arg) { SenderData *d = (SenderData *) f->data; @@ -178,7 +162,6 @@ static void sender_process(MSFilter * f) SenderData *d = (SenderData *) f->data; RtpSession *s = d->session; - struct IceCheckList *cp = d->check_lists; mblk_t *im; uint32_t timestamp; @@ -230,12 +213,6 @@ static void sender_process(MSFilter * f) } ms_filter_unlock(f); } - -#if !defined(_WIN32_WCE) - ice_sound_send_stun_request(s, cp, f->ticker->time); -#else - ice_sound_send_stun_request(s, cp, f->ticker->time)); -#endif } static MSFilterMethod sender_methods[] = { @@ -243,7 +220,6 @@ static MSFilterMethod sender_methods[] = { {MS_RTP_SEND_UNMUTE_MIC, sender_unmute_mic}, {MS_RTP_SEND_SET_SESSION, sender_set_session}, {MS_RTP_SEND_SEND_DTMF, sender_send_dtmf}, - {MS_RTP_SEND_SET_CANDIDATEPAIRS, sender_set_sdpcandidates}, {MS_RTP_SEND_SET_RELAY_SESSION_ID, sender_set_relay_session_id}, {0, NULL} }; @@ -285,8 +261,6 @@ MSFilterDesc ms_rtp_send_desc = { struct ReceiverData { RtpSession *session; - OrtpEvQueue *ortp_event; - struct IceCheckList *check_lists; /* table of 10 cpair */ int rate; }; @@ -296,9 +270,7 @@ static void receiver_init(MSFilter * f) { ReceiverData *d = (ReceiverData *)ms_new(ReceiverData, 1); - d->ortp_event = ortp_ev_queue_new(); d->session = NULL; - d->check_lists = NULL; d->rate = 8000; f->data = d; } @@ -306,15 +278,11 @@ static void receiver_init(MSFilter * f) static void receiver_postprocess(MSFilter * f) { ReceiverData *d = (ReceiverData *) f->data; - if (d->session!=NULL && d->ortp_event!=NULL) - rtp_session_unregister_event_queue(d->session, d->ortp_event); } static void receiver_uninit(MSFilter * f) { ReceiverData *d = (ReceiverData *) f->data; - if (d->ortp_event!=NULL) - ortp_ev_queue_destroy(d->ortp_event); ms_free(f->data); } @@ -337,20 +305,6 @@ static int receiver_set_session(MSFilter * f, void *arg) return 0; } -static int receiver_set_sdpcandidates(MSFilter * f, void *arg) -{ - ReceiverData *d = (ReceiverData *) f->data; - struct IceCheckList *scs = NULL; - - if (d == NULL) - return -1; - - scs = (struct IceCheckList *) arg; - d->check_lists = scs; - ice_restart(d->check_lists); - return 0; -} - static void receiver_preprocess(MSFilter * f){ ReceiverData *d = (ReceiverData *) f->data; if (d->session){ @@ -362,8 +316,6 @@ static void receiver_preprocess(MSFilter * f){ rtp_session_flush_sockets(d->session); } } - if (d->session!=NULL && d->ortp_event!=NULL) - rtp_session_register_event_queue(d->session, d->ortp_event); } static void receiver_process(MSFilter * f) @@ -383,30 +335,10 @@ static void receiver_process(MSFilter * f) rtp_get_payload(m,&m->b_rptr); ms_queue_put(f->outputs[0], m); } - - /* check received STUN request */ - if (d->ortp_event!=NULL) - { - OrtpEvent *evt = ortp_ev_queue_get(d->ortp_event); - - while (evt != NULL) { - if (ortp_event_get_type(evt) == - ORTP_EVENT_STUN_PACKET_RECEIVED) { - ice_process_stun_message(d->session, d->check_lists, evt); - } - if (ortp_event_get_type(evt) == - ORTP_EVENT_TELEPHONE_EVENT) { - } - - ortp_event_destroy(evt); - evt = ortp_ev_queue_get(d->ortp_event); - } - } } static MSFilterMethod receiver_methods[] = { {MS_RTP_RECV_SET_SESSION, receiver_set_session}, - {MS_RTP_RECV_SET_CANDIDATEPAIRS, receiver_set_sdpcandidates}, {0, NULL} };