diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java index 05c4b4e7..5859ffeb 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java @@ -380,7 +380,7 @@ public class KurentoSessionManager extends SessionManager { if (forcedVideoCodec != VideoCodec.NONE && !participant.isIpcam()) { String sdpOffer = kurentoOptions.sdpOffer; try { - kurentoOptions.sdpOffer = this.sdpMunging.setCodecPreference(forcedVideoCodec, sdpOffer); + kurentoOptions.sdpOffer = this.sdpMunging.setCodecPreference(forcedVideoCodec, sdpOffer, true); log.debug("PARTICIPANT '{}' in Session '{}' publishing SDP Offer after munging: \n {}", participant.getParticipantPublicId(), kSession.getSessionId(), kurentoOptions.sdpOffer); } catch (OpenViduException e) { @@ -571,7 +571,7 @@ public class KurentoSessionManager extends SessionManager { try { log.debug("PARTICIPANT '{}' in Session '{}' SDP Offer before munging: \n {}", participant.getParticipantPublicId(), session.getSessionId(), sdpOffer); - sdpOffer = this.sdpMunging.setCodecPreference(forcedVideoCodec, sdpOffer); + sdpOffer = this.sdpMunging.setCodecPreference(forcedVideoCodec, sdpOffer, false); if (forcedVideoCodec == VideoCodec.H264) { sdpOffer = this.sdpMunging.setfmtpH264(sdpOffer); } @@ -622,7 +622,7 @@ public class KurentoSessionManager extends SessionManager { // Modify sdp if forced codec is defined if (forcedVideoCodec != VideoCodec.NONE) { try { - sdpAnswer = this.sdpMunging.setCodecPreference(forcedVideoCodec, sdpAnswer); + sdpAnswer = this.sdpMunging.setCodecPreference(forcedVideoCodec, sdpAnswer, true); log.debug("PARTICIPANT '{}' subscribing in Session '{}' SDP Answer after munging: \n {}", participant.getParticipantPublicId(), session.getSessionId(), sdpAnswer); } catch (OpenViduException e) { @@ -1178,7 +1178,7 @@ public class KurentoSessionManager extends SessionManager { // Modify sdp if forced codec is defined if (forcedVideoCodec != VideoCodec.NONE) { try { - sdpString = sdpMunging.setCodecPreference(forcedVideoCodec, sdpString); + sdpString = sdpMunging.setCodecPreference(forcedVideoCodec, sdpString, true); log.debug("PARTICIPANT '{}' in Session '{}' reconnecting SDP after munging: \n {}", participant.getParticipantPublicId(), kSession.getSessionId(), sdpString); } catch (OpenViduException e) { diff --git a/openvidu-server/src/main/java/io/openvidu/server/utils/SDPMunging.java b/openvidu-server/src/main/java/io/openvidu/server/utils/SDPMunging.java index 254604ac..bee5cbd6 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/utils/SDPMunging.java +++ b/openvidu-server/src/main/java/io/openvidu/server/utils/SDPMunging.java @@ -42,7 +42,7 @@ public class SDPMunging { * ordering of formats. Browsers (tested with Chrome 84) honor this change and * use the first codec provided in the answer, so this operation actually works. */ - public String setCodecPreference(VideoCodec codec, String sdp) throws OpenViduException { + public String setCodecPreference(VideoCodec codec, String sdp, boolean removeCodecs) throws OpenViduException { String codecStr = codec.name(); log.info("[setCodecPreference] codec: {}", codecStr); @@ -121,11 +121,12 @@ public class SDPMunging { newLine.append(pt + " "); } - // Add the rest of PayloadTypes. - newLine.append(String.join(" ", lineParts)); - // Replace the original m= line with the one we just built. - lines[sl] = newLine.toString(); + if (!removeCodecs) { + // Add the rest of PayloadTypes. + newLine.append(String.join(" ", lineParts)); + } + lines[sl] = newLine.toString().trim(); } return String.join("\r\n", lines) + "\r\n"; diff --git a/openvidu-server/src/test/java/io/openvidu/server/test/unit/SDPMungingTest.java b/openvidu-server/src/test/java/io/openvidu/server/test/unit/SDPMungingTest.java index a60bd398..c0beff51 100644 --- a/openvidu-server/src/test/java/io/openvidu/server/test/unit/SDPMungingTest.java +++ b/openvidu-server/src/test/java/io/openvidu/server/test/unit/SDPMungingTest.java @@ -149,7 +149,7 @@ public class SDPMungingTest { private void initTestsSetCodecPrevalence(VideoCodec codec, String sdpNameFile) throws IOException { this.oldSdp = getSdpFile(sdpNameFile); - this.newSdp = this.sdpMungin.setCodecPreference(codec, oldSdp); + this.newSdp = this.sdpMungin.setCodecPreference(codec, oldSdp, true); this.forceCodecPayloads = new ArrayList<>(); // Get all Payload-Type for video Codec