--- res_srtp.c.orig 2011-06-25 18:24:10.000000000 +0200 +++ res_srtp.c 2011-06-25 18:25:17.000000000 +0200 @@ -398,21 +398,45 @@ static int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy) { - struct ast_srtp_policy *match; + struct ast_srtp_policy *match; + err_status_t status; + + if ((match = find_policy(srtp, &policy->sp, OBJ_POINTER))) { + if ( policy->sp.ssrc.type == ssrc_any_inbound ) { + if (srtp->session->stream_template) { + // TNE on clear pour faire un re-init attention possible pb de leak memory juste pour test + if ( policy->sp.ssrc.value == 0 ) + { + struct ast_rtp_instance_stats stats; + ast_rtp_instance_get_stats(srtp->rtp, &stats, AST_RTP_INSTANCE_STAT_REMOTE_SSRC); + ast_log(LOG_NOTICE, "Add specifc SRTP policy for SSRC 0x%x ,Key %s\n", stats.remote_ssrc, policy->sp.key); + // On positionne quand meme le specifique + policy->sp.ssrc.type = ssrc_specific; + policy->sp.ssrc.value = stats.remote_ssrc ; + srtp_add_stream(srtp->session, &policy->sp); + } + // On positionne le template + policy->sp.ssrc.type = ssrc_any_inbound; + policy->sp.ssrc.value = 0 ; + ast_free(srtp->session->stream_template); + srtp->session->stream_template=NULL; + ast_log(LOG_NOTICE, "Template to Null pour policy Key: %s\n", policy->sp.key); + } + }else { + return(0); + } + } + + + ast_log(LOG_NOTICE, "Add SRTP stream SSRC 0x%x Key:%s Type:%d.\n", policy->sp.ssrc.value,policy->sp.key,policy->sp.ssrc.type); + status = srtp_add_stream(srtp->session, &policy->sp); + if (status != err_status_ok) { + ast_log(LOG_ERROR, "Failed to add SRTP policy. Err=%d.\n", status); + return -1; + } + ao2_t_link(srtp->policies, policy, "Added additional stream"); - if ((match = find_policy(srtp, &policy->sp, OBJ_POINTER))) { - ast_debug(3, "Policy already exists, not re-adding\n"); - ao2_t_ref(match, -1, "Unreffing already existing policy"); - return -1; - } - - if (srtp_add_stream(srtp->session, &policy->sp) != err_status_ok) { - return -1; - } - - ao2_t_link(srtp->policies, policy, "Added additional stream"); - - return 0; + return 0; } static int ast_srtp_change_source(struct ast_srtp *srtp, unsigned int from_ssrc, unsigned int to_ssrc)