diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 3b040363fcbf72601690c9cca500d99e03304f7f..98a43b979b28d2cff131728579414e8713d6dfa5 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -17830,7 +17830,7 @@ static int sip_sipredirect(struct sip_pvt *p, const char *dest)
 static int sip_get_codec(struct ast_channel *chan)
 {
 	struct sip_pvt *p = chan->tech_pvt;
-	return p->peercapability;	
+	return p->peercapability ? p->peercapability : p->capability;	
 }
 
 /*! \brief Send a poke to all known peers 
diff --git a/main/rtp.c b/main/rtp.c
index acd139418aad26f72399b3c68965be527294259a..1ff0a453d365960b4a52d25e73213d0de932caf8 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -1537,7 +1537,7 @@ int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
 	struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL;
 	enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED, text_dest_res = AST_RTP_GET_FAILED;
 	enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED, text_src_res = AST_RTP_GET_FAILED;
-	int srccodec, nat_active = 0;
+	int srccodec, destcodec, nat_active = 0;
 
 	/* Lock channels */
 	ast_channel_lock(c0);
@@ -1592,6 +1592,17 @@ int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
 		srccodec = srcpr->get_codec(c1);
 	else
 		srccodec = 0;
+	if (audio_dest_res == AST_RTP_TRY_NATIVE && destpr->get_codec)
+		destcodec = destpr->get_codec(c0);
+	else
+		destcodec = 0;
+	/* Ensure we have at least one matching codec */
+	if (!(srccodec & destcodec)) {
+		ast_channel_unlock(c0);
+		if (c1)
+			ast_channel_unlock(c1);
+		return 0;
+	}
 	/* Consider empty media as non-existant */
 	if (audio_src_res == AST_RTP_TRY_NATIVE && !srcp->them.sin_addr.s_addr)
 		srcp = NULL;