From 17ea55ad074e41e4785f9052d308a00463dbcef8 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Fri, 12 Mar 2021 10:16:17 +0100 Subject: [PATCH] openvidu-server: refactor unnecessary isOffer param --- .../kurento/core/KurentoMediaOptions.java | 18 +- .../kurento/core/KurentoParticipant.java | 13 +- .../kurento/core/KurentoSessionManager.java | 29 +- .../kurento/endpoint/PublisherEndpoint.java | 22 +- .../server/rest/SessionRestController.java | 4 +- .../io/openvidu/server/utils/SDPMunging.java | 291 +++++++++--------- 6 files changed, 179 insertions(+), 198 deletions(-) diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoMediaOptions.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoMediaOptions.java index 1e477356..3d2f019a 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoMediaOptions.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoMediaOptions.java @@ -24,7 +24,6 @@ import io.openvidu.server.kurento.endpoint.KurentoFilter; public class KurentoMediaOptions extends MediaOptions { - public boolean isOffer; public String sdpOffer; public boolean doLoopback; @@ -34,21 +33,19 @@ public class KurentoMediaOptions extends MediaOptions { public Boolean onlyPlayWithSubscribers; public Integer networkCache; - public KurentoMediaOptions(boolean isOffer, String sdpOffer, Boolean hasAudio, Boolean hasVideo, - Boolean audioActive, Boolean videoActive, String typeOfVideo, Integer frameRate, String videoDimensions, - KurentoFilter filter, boolean doLoopback) { + public KurentoMediaOptions(String sdpOffer, Boolean hasAudio, Boolean hasVideo, Boolean audioActive, + Boolean videoActive, String typeOfVideo, Integer frameRate, String videoDimensions, KurentoFilter filter, + boolean doLoopback) { super(hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, frameRate, videoDimensions, filter); - this.isOffer = isOffer; this.sdpOffer = sdpOffer; this.doLoopback = doLoopback; } - public KurentoMediaOptions(boolean isOffer, String sdpOffer, Boolean hasAudio, Boolean hasVideo, - Boolean audioActive, Boolean videoActive, String typeOfVideo, Integer frameRate, String videoDimensions, - KurentoFilter filter, boolean doLoopback, String rtspUri, Boolean adaptativeBitrate, - Boolean onlyPlayWithSubscribers, Integer networkCache) { + public KurentoMediaOptions(String sdpOffer, Boolean hasAudio, Boolean hasVideo, Boolean audioActive, + Boolean videoActive, String typeOfVideo, Integer frameRate, String videoDimensions, KurentoFilter filter, + boolean doLoopback, String rtspUri, Boolean adaptativeBitrate, Boolean onlyPlayWithSubscribers, + Integer networkCache) { super(hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, frameRate, videoDimensions, filter); - this.isOffer = isOffer; this.sdpOffer = sdpOffer; this.doLoopback = doLoopback; this.rtspUri = rtspUri; @@ -61,7 +58,6 @@ public class KurentoMediaOptions extends MediaOptions { String typeOfVideo, Integer frameRate, String videoDimensions, KurentoFilter filter, KurentoMediaOptions streamProperties) { super(hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, frameRate, videoDimensions, filter); - this.isOffer = streamProperties.isOffer; this.sdpOffer = streamProperties.sdpOffer; this.doLoopback = streamProperties.doLoopback; this.rtspUri = streamProperties.rtspUri; diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoParticipant.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoParticipant.java index 0680a7c4..d95fcdf5 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoParticipant.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoParticipant.java @@ -55,7 +55,6 @@ import io.openvidu.server.core.MediaOptions; import io.openvidu.server.core.Participant; import io.openvidu.server.kurento.endpoint.MediaEndpoint; import io.openvidu.server.kurento.endpoint.PublisherEndpoint; -import io.openvidu.server.kurento.endpoint.SdpType; import io.openvidu.server.kurento.endpoint.SubscriberEndpoint; import io.openvidu.server.recording.service.RecordingManager; @@ -172,15 +171,15 @@ public class KurentoParticipant extends Participant { return session; } - public String publishToRoom(SdpType sdpType, String sdpString, boolean doLoopback, boolean silent) { - log.info("PARTICIPANT {}: Request to publish video in room {} (sdp type {})", this.getParticipantPublicId(), - this.session.getSessionId(), sdpType); - log.trace("PARTICIPANT {}: Publishing Sdp ({}) is {}", this.getParticipantPublicId(), sdpType, sdpString); + public String publishToRoom(String sdpOffer, boolean doLoopback, boolean silent) { + log.info("PARTICIPANT {}: Request to publish video in room {})", this.getParticipantPublicId(), + this.session.getSessionId()); + log.trace("PARTICIPANT {}: Publishing SDPOffer is {}", this.getParticipantPublicId(), sdpOffer); - String sdpResponse = this.getPublisher().publish(sdpType, sdpString, doLoopback); + String sdpResponse = this.getPublisher().publish(sdpOffer, doLoopback); this.streaming = true; - log.trace("PARTICIPANT {}: Publishing Sdp ({}) is {}", this.getParticipantPublicId(), sdpType, sdpResponse); + log.trace("PARTICIPANT {}: Publishing Sdp is {}", this.getParticipantPublicId(), sdpResponse); log.info("PARTICIPANT {}: Is now publishing video in room {}", this.getParticipantPublicId(), this.session.getSessionId()); 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 7cd4ae51..34f4f284 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 @@ -72,7 +72,6 @@ import io.openvidu.server.core.SessionManager; import io.openvidu.server.core.Token; import io.openvidu.server.kurento.endpoint.KurentoFilter; import io.openvidu.server.kurento.endpoint.PublisherEndpoint; -import io.openvidu.server.kurento.endpoint.SdpType; import io.openvidu.server.kurento.kms.Kms; import io.openvidu.server.kurento.kms.KmsManager; import io.openvidu.server.rpc.RpcHandler; @@ -380,7 +379,6 @@ public class KurentoSessionManager extends SessionManager { KurentoMediaOptions kurentoOptions = (KurentoMediaOptions) mediaOptions; KurentoParticipant kParticipant = (KurentoParticipant) participant; KurentoSession kSession = kParticipant.getSession(); - SdpType sdpType = kurentoOptions.isOffer ? SdpType.OFFER : SdpType.ANSWER; boolean isTranscodingAllowed = kSession.getSessionProperties().isTranscodingAllowed(); VideoCodec forcedVideoCodec = kSession.getSessionProperties().forcedVideoCodec(); @@ -391,15 +389,13 @@ public class KurentoSessionManager extends SessionManager { // Modify sdp if forced codec is defined if (forcedVideoCodec != VideoCodec.NONE && !participant.isIpcam()) { - kurentoOptions.sdpOffer = sdpMunging.forceCodec(participant, kurentoOptions.sdpOffer, - kurentoOptions.isOffer, kSession, true, false, isTranscodingAllowed, forcedVideoCodec); + kurentoOptions.sdpOffer = sdpMunging.forceCodec(participant, kurentoOptions.sdpOffer, kSession, true, false, + isTranscodingAllowed, forcedVideoCodec); CDR.log(new WebrtcDebugEvent(participant, streamId, WebrtcDebugEventIssuer.client, WebrtcDebugEventOperation.publish, WebrtcDebugEventType.sdpOfferMunged, kurentoOptions.sdpOffer)); } - log.debug( - "Request [PUBLISH_MEDIA] isOffer={} sdp={} " - + "loopbackAltSrc={} lpbkConnType={} doLoopback={} rtspUri={} ({})", - kurentoOptions.isOffer, kurentoOptions.sdpOffer, kurentoOptions.doLoopback, kurentoOptions.rtspUri, + log.debug("Request [PUBLISH_MEDIA] sdpOffer={} loopbackAltSrc={} lpbkConnType={} doLoopback={} rtspUri={} ({})", + kurentoOptions.sdpOffer, kurentoOptions.doLoopback, kurentoOptions.rtspUri, participant.getParticipantPublicId()); kParticipant.createPublishingEndpoint(mediaOptions, streamId); @@ -426,7 +422,7 @@ public class KurentoSessionManager extends SessionManager { } } - sdpAnswer = kParticipant.publishToRoom(sdpType, kurentoOptions.sdpOffer, kurentoOptions.doLoopback, false); + sdpAnswer = kParticipant.publishToRoom(kurentoOptions.sdpOffer, kurentoOptions.doLoopback, false); if (sdpAnswer == null) { OpenViduException e = new OpenViduException(Code.MEDIA_SDP_ERROR_CODE, @@ -580,8 +576,8 @@ public class KurentoSessionManager extends SessionManager { // Modify sdp if forced codec is defined if (forcedVideoCodec != VideoCodec.NONE && !participant.isIpcam()) { - sdpOffer = sdpMunging.forceCodec(participant, sdpOffer, true, session, false, false, - isTranscodingAllowed, forcedVideoCodec); + sdpOffer = sdpMunging.forceCodec(participant, sdpOffer, session, false, false, isTranscodingAllowed, + forcedVideoCodec); CDR.log(new WebrtcDebugEvent(participant, subscriberEndpointName, WebrtcDebugEventIssuer.client, WebrtcDebugEventOperation.subscribe, WebrtcDebugEventType.sdpOfferMunged, sdpOffer)); @@ -788,8 +784,8 @@ public class KurentoSessionManager extends SessionManager { boolean doLoopback = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_DOLOOPBACK_PARAM); - return new KurentoMediaOptions(true, sdpOffer, hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, - frameRate, videoDimensions, kurentoFilter, doLoopback); + return new KurentoMediaOptions(sdpOffer, hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, frameRate, + videoDimensions, kurentoFilter, doLoopback); } @Override @@ -1123,8 +1119,8 @@ public class KurentoSessionManager extends SessionManager { // Modify sdp if forced codec is defined if (forcedVideoCodec != VideoCodec.NONE && !participant.isIpcam()) { sdpOfferHasBeenMunged = true; - sdpOffer = sdpMunging.forceCodec(participant, sdpOffer, true, kSession, isPublisher, true, - isTranscodingAllowed, forcedVideoCodec); + sdpOffer = sdpMunging.forceCodec(participant, sdpOffer, kSession, isPublisher, true, isTranscodingAllowed, + forcedVideoCodec); } if (isPublisher) { @@ -1151,8 +1147,7 @@ public class KurentoSessionManager extends SessionManager { // 3) Create a new PublisherEndpoint connecting it to the previous PassThrough kParticipant.resetPublisherEndpoint(kurentoOptions, passThru); kParticipant.createPublishingEndpoint(kurentoOptions, streamId); - SdpType sdpType = kurentoOptions.isOffer ? SdpType.OFFER : SdpType.ANSWER; - String sdpAnswer = kParticipant.publishToRoom(sdpType, sdpOffer, kurentoOptions.doLoopback, true); + String sdpAnswer = kParticipant.publishToRoom(sdpOffer, kurentoOptions.doLoopback, true); log.debug("SDP Answer for publishing reconnection PARTICIPANT {}: {}", participant.getParticipantPublicId(), sdpAnswer); diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/PublisherEndpoint.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/PublisherEndpoint.java index 40fbeffb..abd18100 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/PublisherEndpoint.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/PublisherEndpoint.java @@ -181,16 +181,14 @@ public class PublisherEndpoint extends MediaEndpoint { * itself (after applying the intermediate media elements and the * {@link PassThrough}) to allow loopback of the media stream. * - * @param sdpType indicates the type of the sdpString (offer or - * answer) - * @param sdpString offer or answer from the remote peer + * @param sdpOffer offer from the remote peer * @param doLoopback loopback flag * @param loopbackAlternativeSrc alternative loopback source * @param loopbackConnectionType how to connect the loopback source * @return the SDP response (the answer if processing an offer SDP, otherwise is * the updated offer generated previously by this endpoint) */ - public synchronized String publish(SdpType sdpType, String sdpString, boolean doLoopback) { + public synchronized String publish(String sdpOffer, boolean doLoopback) { registerOnIceCandidateEventListener(this.getOwner().getParticipantPublicId()); if (doLoopback) { connect(this.getEndpoint()); @@ -198,21 +196,7 @@ public class PublisherEndpoint extends MediaEndpoint { innerConnect(); } this.createdAt = System.currentTimeMillis(); - String sdpResponse = null; - switch (sdpType) { - case ANSWER: - - /** THIS IS CURRENTLY NEVER CALLED **/ - sdpResponse = processAnswer(sdpString); - /** THIS IS CURRENTLY NEVER CALLED **/ - - break; - case OFFER: - sdpResponse = processOffer(sdpString); - break; - default: - throw new OpenViduException(Code.MEDIA_SDP_ERROR_CODE, "Sdp type not supported: " + sdpType); - } + String sdpResponse = processOffer(sdpOffer); gatherCandidates(); return sdpResponse; } diff --git a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java index d6ea6ee5..b814a788 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java @@ -686,8 +686,8 @@ public class SessionRestController { String typeOfVideo = ConnectionType.IPCAM.name(); Integer frameRate = null; String videoDimensions = null; - KurentoMediaOptions mediaOptions = new KurentoMediaOptions(true, null, hasAudio, hasVideo, audioActive, - videoActive, typeOfVideo, frameRate, videoDimensions, null, false, connectionProperties.getRtspUri(), + KurentoMediaOptions mediaOptions = new KurentoMediaOptions(null, hasAudio, hasVideo, audioActive, videoActive, + typeOfVideo, frameRate, videoDimensions, null, false, connectionProperties.getRtspUri(), connectionProperties.adaptativeBitrate(), connectionProperties.onlyPlayWithSubscribers(), connectionProperties.getNetworkCache()); 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 6544f764..43073cf0 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 @@ -16,182 +16,189 @@ */ package io.openvidu.server.utils; -import io.openvidu.client.OpenViduException; -import io.openvidu.java.client.VideoCodec; -import io.openvidu.client.OpenViduException.Code; -import io.openvidu.server.core.Participant; -import io.openvidu.server.core.Session; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.openvidu.client.OpenViduException; +import io.openvidu.client.OpenViduException.Code; +import io.openvidu.java.client.VideoCodec; +import io.openvidu.server.core.Participant; +import io.openvidu.server.core.Session; + public class SDPMunging { - private static final Logger log = LoggerFactory.getLogger(SDPMunging.class); + private static final Logger log = LoggerFactory.getLogger(SDPMunging.class); - private Set supportedVideoCodecs = new HashSet<>(Arrays.asList( - VideoCodec.VP8, - VideoCodec.H264 - )); + private Set supportedVideoCodecs = new HashSet<>(Arrays.asList(VideoCodec.VP8, VideoCodec.H264)); - /** - * `codec` is a uppercase SDP-style codec name: "VP8", "H264". - * - * This looks for all video m-sections (lines starting with "m=video"), - * then searches all of its related PayloadTypes trying to find those which - * correspond to the preferred codec. If any is found, they are moved to the - * front of the PayloadTypes list in the m= line, without removing the other - * codecs that might be present. - * - * If our preferred codec is not found, the m= line is left without changes. - * - * This works based on the basis that RFC 3264 "Offer/Answer Model SDP" section - * 6.1 "Unicast Streams" allows the answerer to list media formats in a - * different order of preference from what it got in the offer: - * - * > Although the answerer MAY list the formats in their desired order of - * > preference, it is RECOMMENDED that unless there is a specific reason, - * > the answerer list formats in the same relative order they were - * > present in the offer. - * - * Here we have a specific reason, thus we use this allowance to change the - * 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 { - String codecStr = codec.name(); - log.info("[setCodecPreference] codec: {}", codecStr); + /** + * `codec` is a uppercase SDP-style codec name: "VP8", "H264". + * + * This looks for all video m-sections (lines starting with "m=video"), then + * searches all of its related PayloadTypes trying to find those which + * correspond to the preferred codec. If any is found, they are moved to the + * front of the PayloadTypes list in the m= line, without removing the other + * codecs that might be present. + * + * If our preferred codec is not found, the m= line is left without changes. + * + * This works based on the basis that RFC 3264 "Offer/Answer Model SDP" section + * 6.1 "Unicast Streams" allows the answerer to list media formats in a + * different order of preference from what it got in the offer: + * + * > Although the answerer MAY list the formats in their desired order of > + * preference, it is RECOMMENDED that unless there is a specific reason, > the + * answerer list formats in the same relative order they were > present in the + * offer. + * + * Here we have a specific reason, thus we use this allowance to change the + * 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 { + String codecStr = codec.name(); + log.info("[setCodecPreference] codec: {}", codecStr); - List codecPts = new ArrayList(); - String[] lines = sdp.split("\\R+"); - Pattern ptRegex = Pattern.compile(String.format("a=rtpmap:(\\d+) %s/90000", codecStr)); + List codecPts = new ArrayList(); + String[] lines = sdp.split("\\R+"); + Pattern ptRegex = Pattern.compile(String.format("a=rtpmap:(\\d+) %s/90000", codecStr)); - for (int sl = 0; sl < lines.length; sl++) { - String sdpLine = lines[sl]; + for (int sl = 0; sl < lines.length; sl++) { + String sdpLine = lines[sl]; - if (!sdpLine.startsWith("m=video")) { - continue; - } + if (!sdpLine.startsWith("m=video")) { + continue; + } - // m-section found. Prepare an array to store PayloadTypes. - codecPts.clear(); + // m-section found. Prepare an array to store PayloadTypes. + codecPts.clear(); - // Search the m-section to find our codec's PayloadType, if any. - for (int ml = sl + 1; ml < lines.length; ml++) { - String mediaLine = lines[ml]; + // Search the m-section to find our codec's PayloadType, if any. + for (int ml = sl + 1; ml < lines.length; ml++) { + String mediaLine = lines[ml]; - // Abort if we reach the next m-section. - if (mediaLine.startsWith("m=")) { - break; - } + // Abort if we reach the next m-section. + if (mediaLine.startsWith("m=")) { + break; + } - Matcher ptMatch = ptRegex.matcher(mediaLine); - if (ptMatch.find()) { - // PayloadType found. - String pt = ptMatch.group(1); - codecPts.add(pt); + Matcher ptMatch = ptRegex.matcher(mediaLine); + if (ptMatch.find()) { + // PayloadType found. + String pt = ptMatch.group(1); + codecPts.add(pt); - // Search the m-section to find the APT subtype, if any. - Pattern aptRegex = Pattern.compile(String.format("a=fmtp:(\\d+) apt=%s", pt)); + // Search the m-section to find the APT subtype, if any. + Pattern aptRegex = Pattern.compile(String.format("a=fmtp:(\\d+) apt=%s", pt)); - for (int al = sl + 1; al < lines.length; al++) { - String aptLine = lines[al]; + for (int al = sl + 1; al < lines.length; al++) { + String aptLine = lines[al]; - // Abort if we reach the next m-section. - if (aptLine.startsWith("m=")) { - break; - } + // Abort if we reach the next m-section. + if (aptLine.startsWith("m=")) { + break; + } - Matcher aptMatch = aptRegex.matcher(aptLine); - if (aptMatch.find()) { - // APT found. - String apt = aptMatch.group(1); - codecPts.add(apt); - } - } - } - } + Matcher aptMatch = aptRegex.matcher(aptLine); + if (aptMatch.find()) { + // APT found. + String apt = aptMatch.group(1); + codecPts.add(apt); + } + } + } + } - if (codecPts.isEmpty()) { - throw new OpenViduException(Code.FORCED_CODEC_NOT_FOUND_IN_SDPOFFER, "The specified forced codec " + codecStr + " is not present in the SDP"); - } + if (codecPts.isEmpty()) { + throw new OpenViduException(Code.FORCED_CODEC_NOT_FOUND_IN_SDPOFFER, + "The specified forced codec " + codecStr + " is not present in the SDP"); + } - // Build a new m= line where any PayloadTypes found have been moved - // to the front of the PT list. - StringBuilder newLine = new StringBuilder(sdpLine.length()); - List lineParts = new ArrayList(Arrays.asList(sdpLine.split(" "))); + // Build a new m= line where any PayloadTypes found have been moved + // to the front of the PT list. + StringBuilder newLine = new StringBuilder(sdpLine.length()); + List lineParts = new ArrayList(Arrays.asList(sdpLine.split(" "))); - if (lineParts.size() < 4) { - log.error("[setCodecPreference] BUG in m= line: Expects at least 4 fields: '{}'", sdpLine); - continue; - } + if (lineParts.size() < 4) { + log.error("[setCodecPreference] BUG in m= line: Expects at least 4 fields: '{}'", sdpLine); + continue; + } - // Add "m=video", Port, and Protocol. - for (int i = 0; i < 3; i++) { - newLine.append(lineParts.remove(0) + " "); - } + // Add "m=video", Port, and Protocol. + for (int i = 0; i < 3; i++) { + newLine.append(lineParts.remove(0) + " "); + } - // Add the PayloadTypes that correspond to our preferred codec. - for (String pt : codecPts) { - lineParts.remove(pt); - newLine.append(pt + " "); - } + // Add the PayloadTypes that correspond to our preferred codec. + for (String pt : codecPts) { + lineParts.remove(pt); + newLine.append(pt + " "); + } - // Replace the original m= line with the one we just built. - lines[sl] = newLine.toString().trim(); - } + // Replace the original m= line with the one we just built. + lines[sl] = newLine.toString().trim(); + } - return String.join("\r\n", lines) + "\r\n"; - } + return String.join("\r\n", lines) + "\r\n"; + } - /** - * Return a SDP modified to force a specific codec - */ - public String forceCodec(Participant participant, String sdp, boolean isOffer, Session session, boolean isPublisher, - boolean isReconnecting, boolean isTranscodingAllowed, VideoCodec forcedVideoCodec) throws OpenViduException { - try { - if (supportedVideoCodecs.contains(forcedVideoCodec)) { - String mungedSdpOffer; + /** + * Return a SDP modified to force a specific codec + */ + public String forceCodec(Participant participant, String sdp, Session session, boolean isPublisher, + boolean isReconnecting, boolean isTranscodingAllowed, VideoCodec forcedVideoCodec) + throws OpenViduException { + try { + if (supportedVideoCodecs.contains(forcedVideoCodec)) { + String mungedSdpOffer; - log.debug("PARTICIPANT '{}' in Session '{}'. Is Publisher: '{}'. Is Subscriber: '{}'." - + " Is Offer SDP: '{}'. Is Answer SDP: '{}'. Is Reconnecting '{}'." - + " SDP before munging: \n {}", participant.getParticipantPublicId(), - session.getSessionId(), isPublisher, !isPublisher, isOffer, !isOffer, isReconnecting, sdp); + log.debug( + "PARTICIPANT '{}' in Session '{}'. Is Publisher: '{}'. Is Subscriber: '{}'. Is Reconnecting '{}'." + + " SDP before munging: \n {}", + participant.getParticipantPublicId(), session.getSessionId(), isPublisher, !isPublisher, + isReconnecting, sdp); - mungedSdpOffer = this.setCodecPreference(forcedVideoCodec, sdp); + mungedSdpOffer = this.setCodecPreference(forcedVideoCodec, sdp); - log.debug("PARTICIPANT '{}' in Session '{}'. Is Publisher: '{}'. Is Subscriber: '{}'." - + " Is Offer SDP: '{}'. Is Answer SDP: '{}'. Is Reconnecting '{}'." - + " SDP after munging: \n {}", participant.getParticipantPublicId(), - session.getSessionId(), isPublisher, !isPublisher, isOffer, !isOffer, isReconnecting, mungedSdpOffer); + log.debug( + "PARTICIPANT '{}' in Session '{}'. Is Publisher: '{}'. Is Subscriber: '{}'." + + " Is Reconnecting '{}'." + " SDP after munging: \n {}", + participant.getParticipantPublicId(), session.getSessionId(), isPublisher, !isPublisher, + isReconnecting, mungedSdpOffer); - return mungedSdpOffer; - } else { - throw new OpenViduException(Code.FORCED_CODEC_NOT_FOUND_IN_SDPOFFER, "Codec not supported by Media Server"); - } + return mungedSdpOffer; + } else { + throw new OpenViduException(Code.FORCED_CODEC_NOT_FOUND_IN_SDPOFFER, + "Codec not supported by Media Server"); + } - } catch (OpenViduException e) { + } catch (OpenViduException e) { - String errorMessage = "Error forcing codec: '" + forcedVideoCodec + "', for PARTICIPANT: '" - + participant.getParticipantPublicId() + "' in Session: '" + session.getSessionId() - + "'. Is publishing: '" + isPublisher + "'. Is Subscriber: '" + !isPublisher - + "'. Is Offer: '" + isOffer + "'. Is Answer: '" + !isOffer + "'. Is Reconnecting: '" - + isReconnecting + "'.\nException: " + e.getMessage() + "\nSDP:\n" + sdp; + String errorMessage = "Error forcing codec: '" + forcedVideoCodec + "', for PARTICIPANT: '" + + participant.getParticipantPublicId() + "' in Session: '" + session.getSessionId() + + "'. Is publishing: '" + isPublisher + "'. Is Subscriber: '" + !isPublisher + + "'. Is Reconnecting: '" + isReconnecting + "'.\nException: " + e.getMessage() + "\nSDP:\n" + sdp; - if(!isTranscodingAllowed) { - throw new OpenViduException(Code.FORCED_CODEC_NOT_FOUND_IN_SDPOFFER, errorMessage); - } + if (!isTranscodingAllowed) { + throw new OpenViduException(Code.FORCED_CODEC_NOT_FOUND_IN_SDPOFFER, errorMessage); + } - log.info("Codec: '{}' is not supported for PARTICIPANT: '{}' in Session: '{}'. Is publishing: '{}'. " - + "Is Subscriber: '{}' Is Offer SDP: '{}'. Is Answer SDP: '{}'. Is Reconnecting: '{}'." - + " Transcoding will be allowed", forcedVideoCodec, participant.getParticipantPublicId(), - session.getSessionId(), isPublisher, !isPublisher, isOffer, !isOffer, isReconnecting); + log.info( + "Codec: '{}' is not supported for PARTICIPANT: '{}' in Session: '{}'. Is publishing: '{}'. " + + "Is Subscriber: '{}'. Is Reconnecting: '{}'." + " Transcoding will be allowed", + forcedVideoCodec, participant.getParticipantPublicId(), session.getSessionId(), isPublisher, + !isPublisher, isReconnecting); - return sdp; - } - } + return sdp; + } + } }