diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index a6f497568b3916631b31dc9002c77a67bf9df76b..d422f017946cc552e0892b71d2fcb6b617cb6aca 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -1458,6 +1458,29 @@ static void process_extmap_attributes(struct ast_sip_session *session, struct as
 	}
 }
 
+static void set_session_media_remotely_held(struct ast_sip_session_media *session_media,
+											const struct ast_sip_session *session,
+											const pjmedia_sdp_media *media,
+											const struct ast_stream *stream,
+											const struct ast_sockaddr *addrs)
+{
+	if (ast_sip_session_is_pending_stream_default(session, stream) &&
+		(session_media->type == AST_MEDIA_TYPE_AUDIO)) {
+		if (((addrs != NULL) && ast_sockaddr_isnull(addrs)) ||
+			((addrs != NULL) && ast_sockaddr_is_any(addrs)) ||
+			pjmedia_sdp_media_find_attr2(media, "sendonly", NULL) ||
+			pjmedia_sdp_media_find_attr2(media, "inactive", NULL)) {
+			if (!session_media->remotely_held) {
+				session_media->remotely_held = 1;
+				session_media->remotely_held_changed = 1;
+			}
+		} else if (session_media->remotely_held) {
+			session_media->remotely_held = 0;
+			session_media->remotely_held_changed = 1;
+		}
+	}
+}
+
 /*! \brief Function which negotiates an incoming media stream */
 static int negotiate_incoming_sdp_stream(struct ast_sip_session *session,
 	struct ast_sip_session_media *session_media, const pjmedia_sdp_session *sdp,
@@ -1551,21 +1574,8 @@ static int negotiate_incoming_sdp_stream(struct ast_sip_session *session,
 		process_ice_auth_attrb(session, session_media, sdp, stream);
 	}
 
-	if (ast_sip_session_is_pending_stream_default(session, asterisk_stream) && media_type == AST_MEDIA_TYPE_AUDIO) {
-		/* Check if incomming SDP is changing the remotely held state */
-		if (ast_sockaddr_isnull(addrs) ||
-			ast_sockaddr_is_any(addrs) ||
-			pjmedia_sdp_media_find_attr2(stream, "sendonly", NULL) ||
-			pjmedia_sdp_media_find_attr2(stream, "inactive", NULL)) {
-			if (!session_media->remotely_held) {
-				session_media->remotely_held = 1;
-				session_media->remotely_held_changed = 1;
-			}
-		} else if (session_media->remotely_held) {
-			session_media->remotely_held = 0;
-			session_media->remotely_held_changed = 1;
-		}
-	}
+	/* Check if incoming SDP is changing the remotely held state */
+	set_session_media_remotely_held(session_media, session, stream, asterisk_stream, addrs);
 
 	joint = set_incoming_call_offer_cap(session, session_media, stream);
 	res = apply_cap_to_bundled(session_media, session_media_transport, asterisk_stream, joint);
@@ -2164,6 +2174,8 @@ static int apply_negotiated_sdp_stream(struct ast_sip_session *session,
 		SCOPE_EXIT_RTN_VALUE(1, "moh\n");
 	}
 
+	set_session_media_remotely_held(session_media, session, remote_stream, asterisk_stream, addrs);
+
 	if (session_media->remotely_held_changed) {
 		if (session_media->remotely_held) {
 			/* The remote side has put us on hold */