Commit 65325be8 authored by Ghislain MARY's avatar Ghislain MARY

Asynchronous ICE candidates gathering.

parent 4e611444
......@@ -109,8 +109,16 @@ typedef struct _IceSession {
uint8_t keepalive_timeout; /**< Configuration parameter to define the timeout between each keepalive packets (default is 15s) */
uint64_t event_time; /**< Time when an event must be sent */
bool_t send_event; /**< Boolean value telling whether an event must be sent or not */
struct sockaddr_storage ss; /**< STUN server address to use for the candidates gathering process */
socklen_t ss_len; /**< Length of the STUN server address to use for the candidates gathering process */
} IceSession;
typedef struct _IceStunServerCheck {
ortp_socket_t sock;
uint64_t transmission_time;
uint8_t nb_transmissions;
} IceStunServerCheck;
/**
* Structure representing an ICE transport address.
*/
......@@ -175,8 +183,10 @@ typedef struct _IceValidCandidatePair {
*/
typedef struct _IceCheckList {
IceSession *session; /**< Pointer to the ICE session */
RtpSession *rtp_session; /**< Pointer to the RTP session associated with this ICE check list */
char *remote_ufrag; /**< Remote username fragment for this check list (provided via SDP by the peer) */
char *remote_pwd; /**< Remote password for this check list (provided via SDP by the peer) */
MSList *stun_server_checks; /**< List of IceStunServerCheck structures */
MSList *local_candidates; /**< List of IceCandidate structures */
MSList *remote_candidates; /**< List of IceCandidate structures */
MSList *pairs; /**< List of IceCandidatePair structures */
......@@ -191,6 +201,7 @@ typedef struct _IceCheckList {
uint64_t keepalive_time; /**< Time when the last keepalive packet has been sent for this stream */
uint32_t foundation_generator; /**< Autoincremented integer to generate unique foundation values */
bool_t mismatch; /**< Boolean value telling whether there was a mismatch during the answer/offer process */
bool_t gathering_candidates; /**< Boolean value telling whether a candidate gathering process is running or not */
} IceCheckList;
......@@ -346,6 +357,15 @@ MS2_PUBLIC void ice_session_set_keepalive_timeout(IceSession *session, uint8_t t
*/
MS2_PUBLIC void ice_session_add_check_list(IceSession *session, IceCheckList *cl);
/**
* Gather ICE local candidates for an ICE session.
*
* @param session A pointer to a session
* @param ss The STUN server address
* @param ss_len The length of the STUN server address
*/
MS2_PUBLIC void ice_session_gather_candidates(IceSession *session, struct sockaddr_storage ss, socklen_t ss_len);
/**
* Get the state of an ICE check list.
*
......@@ -362,6 +382,14 @@ MS2_PUBLIC IceCheckListState ice_check_list_state(const IceCheckList *cl);
*/
MS2_PUBLIC void ice_check_list_set_state(IceCheckList *cl, IceCheckListState state);
/**
* Assign an RTP session to an ICE check list.
*
* @param cl A pointer to a check list
* @param rtp_session A pointer to the RTP session to assign to the check list
*/
MS2_PUBLIC void ice_check_list_set_rtp_session(IceCheckList *cl, RtpSession *rtp_session);
/**
* Get the local username fragment of an ICE check list.
*
......
......@@ -65,6 +65,7 @@ struct _AudioStream
MSFilter *write_resampler;
MSFilter *equalizer;
MSFilter *dummy;
MSFilter *voidsink;
uint64_t last_packet_count;
time_t last_packet_time;
EchoLimiterType el_type; /*use echo limiter: two MSVolume, measured input level controlling local output level*/
......@@ -149,6 +150,8 @@ MS2_PUBLIC int audio_stream_start_full(AudioStream *stream, RtpProfile *profile,
const char *rem_rtcp_ip, int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile,
MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec);
MS2_PUBLIC void audio_stream_start_ice_gathering(AudioStream *stream);
MS2_PUBLIC void audio_stream_play(AudioStream *st, const char *name);
MS2_PUBLIC void audio_stream_record(AudioStream *st, const char *name);
......@@ -305,6 +308,7 @@ struct _VideoStream
MSFilter *tee2;
MSFilter *jpegwriter;
MSFilter *output2;
MSFilter *voidsink;
OrtpEvQueue *evq;
MSVideoSize sent_vsize;
int corner; /*for selfview*/
......@@ -339,6 +343,7 @@ MS2_PUBLIC void video_stream_set_event_callback(VideoStream *s, VideoStreamEvent
MS2_PUBLIC void video_stream_set_display_filter_name(VideoStream *s, const char *fname);
MS2_PUBLIC int video_stream_start(VideoStream * stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port, const char *rem_rtcp_ip, int rem_rtcp_port,
int payload, int jitt_comp, MSWebCam *device);
MS2_PUBLIC void video_stream_start_ice_gathering(VideoStream *stream);
MS2_PUBLIC void video_stream_set_relay_session_id(VideoStream *stream, const char *relay_session_id);
......
......@@ -73,6 +73,7 @@ void audio_stream_free(AudioStream *stream)
if (stream->write_resampler!=NULL) ms_filter_destroy(stream->write_resampler);
if (stream->dtmfgen_rtp!=NULL) ms_filter_destroy(stream->dtmfgen_rtp);
if (stream->dummy) ms_filter_destroy(stream->dummy);
if (stream->voidsink) ms_filter_destroy(stream->voidsink);
if (stream->rc) ms_bitrate_controller_destroy(stream->rc);
if (stream->qi) ms_quality_indicator_destroy(stream->qi);
ms_free(stream);
......@@ -322,6 +323,14 @@ static void stop_preload_graph(AudioStream *stream){
stream->dummy=NULL;
}
static void stop_ice_gathering_graph(AudioStream *stream){
ms_ticker_detach(stream->ticker,stream->voidsink);
ms_filter_unlink(stream->rtprecv,0,stream->voidsink,0);
ms_filter_destroy(stream->voidsink);
ms_filter_destroy(stream->rtprecv);
stream->voidsink=stream->rtprecv=NULL;
}
bool_t audio_stream_started(AudioStream *stream){
return stream->start_time!=0;
}
......@@ -544,7 +553,7 @@ int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char
if (stream->ticker==NULL) start_ticker(stream);
else{
/*we were using the dummy preload graph, destroy it*/
stop_preload_graph(stream);
if (stream->dummy) stop_preload_graph(stream);
}
/* and then connect all */
......@@ -718,6 +727,17 @@ int audio_stream_start_now(AudioStream *stream, RtpProfile * prof, const char *
payload_type,jitt_comp,NULL,NULL,playcard,captcard,use_ec);
}
void audio_stream_start_ice_gathering(AudioStream *stream)
{
if (stream->ticker==NULL) start_ticker(stream);
stream->voidsink=ms_filter_new(MS_VOID_SINK_ID);
stream->rtprecv=ms_filter_new(MS_RTP_RECV_ID);
rtp_session_set_payload_type(stream->session,0);
ms_filter_call_method(stream->rtprecv,MS_RTP_RECV_SET_SESSION,stream->session);
ms_filter_link(stream->rtprecv,0,stream->voidsink,0);
ms_ticker_attach(stream->ticker,stream->rtprecv);
}
void audio_stream_set_relay_session_id(AudioStream *stream, const char *id){
ms_filter_call_method(stream->rtpsend, MS_RTP_SEND_SET_RELAY_SESSION_ID,(void*)id);
}
......@@ -794,6 +814,8 @@ void audio_stream_stop(AudioStream * stream)
if (stream->dummy){
stop_preload_graph(stream);
}else if (stream->voidsink){
stop_ice_gathering_graph(stream);
}else if (stream->start_time!=0){
ms_ticker_detach(stream->ticker,stream->soundread);
......
This diff is collapsed.
......@@ -69,6 +69,8 @@ void video_stream_free (VideoStream * stream)
ms_filter_destroy(stream->jpegwriter);
if (stream->output2!=NULL)
ms_filter_destroy(stream->output2);
if (stream->voidsink!=NULL)
ms_filter_destroy(stream->voidsink);
if (stream->ticker != NULL)
ms_ticker_destroy (stream->ticker);
if (stream->evq!=NULL)
......@@ -155,6 +157,14 @@ static void video_steam_process_rtcp(VideoStream *stream, mblk_t *m){
}while(rtcp_next_packet(m));
}
static void stop_ice_gathering_graph(VideoStream *stream){
ms_ticker_detach(stream->ticker,stream->voidsink);
ms_filter_unlink(stream->rtprecv,0,stream->voidsink,0);
ms_filter_destroy(stream->voidsink);
ms_filter_destroy(stream->rtprecv);
stream->voidsink=stream->rtprecv=NULL;
}
static void video_stream_set_remote_from_ice(VideoStream *stream){
char rtp_addr[64];
char rtcp_addr[64];
......@@ -369,6 +379,17 @@ static void configure_video_source(VideoStream *stream){
}
}
static void start_ticker(VideoStream *stream){
MSTickerParams params={0};
params.name="Video MSTicker";
#ifdef __ios
params.prio=MS_TICKER_PRIO_HIGH;
#else
params.prio=MS_TICKER_PRIO_NORMAL;
#endif
stream->ticker = ms_ticker_new_with_params(&params);
}
int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *rem_rtp_ip, int rem_rtp_port,
const char *rem_rtcp_ip, int rem_rtcp_port, int payload, int jitt_comp, MSWebCam *cam){
PayloadType *pt;
......@@ -520,14 +541,7 @@ int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *re
}
/* create the ticker */
MSTickerParams params={0};
params.name="Video MSTicker";
#ifdef __ios
params.prio=MS_TICKER_PRIO_HIGH;
#else
params.prio=MS_TICKER_PRIO_NORMAL;
#endif
stream->ticker = ms_ticker_new_with_params(&params);
start_ticker(stream);
/* attach the graphs */
if (stream->source)
......@@ -537,6 +551,16 @@ int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *re
return 0;
}
void video_stream_start_ice_gathering(VideoStream *stream){
if (stream->ticker==NULL) start_ticker(stream);
stream->voidsink=ms_filter_new(MS_VOID_SINK_ID);
stream->rtprecv=ms_filter_new(MS_RTP_RECV_ID);
rtp_session_set_payload_type(stream->session,0);
ms_filter_call_method(stream->rtprecv,MS_RTP_RECV_SET_SESSION,stream->session);
ms_filter_link(stream->rtprecv,0,stream->voidsink,0);
ms_ticker_attach(stream->ticker,stream->rtprecv);
}
void video_stream_update_video_params(VideoStream *stream){
/*calling video_stream_change_camera() does the job of unplumbing/replumbing and configuring the new graph*/
video_stream_change_camera(stream,stream->cam);
......@@ -593,37 +617,41 @@ video_stream_stop (VideoStream * stream)
stream->eventcb = NULL;
stream->event_pointer = NULL;
if (stream->ticker){
if (stream->source)
ms_ticker_detach(stream->ticker,stream->source);
if (stream->rtprecv)
ms_ticker_detach(stream->ticker,stream->rtprecv);
if (stream->ice_check_list != NULL) ice_check_list_print_route(stream->ice_check_list, "Video session's route");
rtp_stats_display(rtp_session_get_stats(stream->session),"Video session's RTP statistics");
if (stream->source){
ms_filter_unlink(stream->source,0,stream->pixconv,0);
ms_filter_unlink (stream->pixconv, 0, stream->sizeconv, 0);
ms_filter_unlink (stream->sizeconv, 0, stream->tee, 0);
ms_filter_unlink(stream->tee,0,stream->encoder,0);
ms_filter_unlink(stream->encoder, 0, stream->rtpsend,0);
if (stream->output2){
ms_filter_unlink(stream->tee,1,stream->output2,0);
if (stream->voidsink) {
stop_ice_gathering_graph(stream);
} else {
if (stream->source)
ms_ticker_detach(stream->ticker,stream->source);
if (stream->rtprecv)
ms_ticker_detach(stream->ticker,stream->rtprecv);
if (stream->ice_check_list != NULL) ice_check_list_print_route(stream->ice_check_list, "Video session's route");
rtp_stats_display(rtp_session_get_stats(stream->session),"Video session's RTP statistics");
if (stream->source){
ms_filter_unlink(stream->source,0,stream->pixconv,0);
ms_filter_unlink (stream->pixconv, 0, stream->sizeconv, 0);
ms_filter_unlink (stream->sizeconv, 0, stream->tee, 0);
ms_filter_unlink(stream->tee,0,stream->encoder,0);
ms_filter_unlink(stream->encoder, 0, stream->rtpsend,0);
if (stream->output2){
ms_filter_unlink(stream->tee,1,stream->output2,0);
}
}
}
if (stream->rtprecv){
MSConnectionHelper h;
ms_connection_helper_start (&h);
ms_connection_helper_unlink (&h,stream->rtprecv,-1,0);
ms_connection_helper_unlink (&h,stream->decoder,0,0);
if (stream->tee2){
ms_connection_helper_unlink (&h,stream->tee2,0,0);
ms_filter_unlink(stream->tee2,1,stream->jpegwriter,0);
if (stream->rtprecv){
MSConnectionHelper h;
ms_connection_helper_start (&h);
ms_connection_helper_unlink (&h,stream->rtprecv,-1,0);
ms_connection_helper_unlink (&h,stream->decoder,0,0);
if (stream->tee2){
ms_connection_helper_unlink (&h,stream->tee2,0,0);
ms_filter_unlink(stream->tee2,1,stream->jpegwriter,0);
}
if(stream->output)
ms_connection_helper_unlink (&h,stream->output,0,-1);
if (stream->tee && stream->output && stream->output2==NULL)
ms_filter_unlink(stream->tee,1,stream->output,1);
}
if(stream->output)
ms_connection_helper_unlink (&h,stream->output,0,-1);
if (stream->tee && stream->output && stream->output2==NULL)
ms_filter_unlink(stream->tee,1,stream->output,1);
}
}
video_stream_free (stream);
......
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