From 32fd093cf35c5cc590256ca6a857b399453c9dac Mon Sep 17 00:00:00 2001 From: Juan Navarro Date: Wed, 10 Nov 2021 15:50:21 +0100 Subject: [PATCH] openvidu-server: add MEDIA_SERVER_PREFERRED as default for ForcedVideoCodec MEDIA_SERVER_PREFERRED: A recommended choice is done for you, based on the media server that is currently in use. This is the default setting, and is equivalent to these values: - For *mediasoup*, `NONE` is selected. - For *Kurento*, `VP8` is selected. --- .../java/client/SessionProperties.java | 23 +++++++++++-------- .../io/openvidu/java/client/VideoCodec.java | 4 ++-- openvidu-node-client/src/SessionProperties.ts | 21 ++++++++++------- openvidu-node-client/src/VideoCodec.ts | 7 +++--- .../deployments/ce/docker-compose/.env | 6 ++--- .../deployments/enterprise/master-node/.env | 6 ++--- .../docker-compose/openvidu-server-pro/.env | 6 ++--- .../kurento/core/KurentoSessionManager.java | 16 +++++++++++++ ...itional-spring-configuration-metadata.json | 2 +- .../src/main/resources/application.properties | 2 +- .../resources/integration-test.properties | 2 +- 11 files changed, 60 insertions(+), 35 deletions(-) diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java index 22bfbb21..27d85638 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/SessionProperties.java @@ -42,7 +42,7 @@ public class SessionProperties { private RecordingProperties defaultRecordingProperties = new RecordingProperties.Builder().build(); private String customSessionId = ""; private String mediaNode; - private VideoCodec forcedVideoCodec = VideoCodec.VP8; + private VideoCodec forcedVideoCodec = VideoCodec.MEDIA_SERVER_PREFERRED; private Boolean allowTranscoding = false; /** @@ -114,15 +114,20 @@ public class SessionProperties { } /** - * Call this method to define which video codec do you want to be forcibly used - * for this session. This allows browsers/clients to use the same codec avoiding - * transcoding in the media server. If the browser/client is not compatible with - * the specified codec and {@link #allowTranscoding(Boolean)} is - * false and exception will occur. If forcedVideoCodec is set to - * NONE, no codec will be forced.
+ * Define which video codec will be forcibly used for this session. + * This forces all browsers/clients to use the same codec, which would + * avoid transcoding in the media server (Kurento only). If + * forcedVideoCodec is set to NONE, no codec will be forced. + * + * If the browser/client is not compatible with the specified codec, and + * {@link #allowTranscoding(Boolean)} is false, an + * exception will occur. + * * If defined here, this parameter has prevalence over - * OPENVIDU_STREAMS_FORCED_VIDEO_CODEC. OPENVIDU_STREAMS_FORCED_VIDEO_CODEC - * default is {@link VideoCodec#VP8} + * OPENVIDU_STREAMS_FORCED_VIDEO_CODEC. + * + * Default is {@link VideoCodec#VP8} for Kurento, and + * {@link VideoCodec#NONE} for mediasoup. */ public SessionProperties.Builder forcedVideoCodec(VideoCodec forcedVideoCodec) { this.forcedVideoCodec = forcedVideoCodec; diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/VideoCodec.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/VideoCodec.java index 9db0e73c..24c8f30c 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/VideoCodec.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/VideoCodec.java @@ -22,5 +22,5 @@ package io.openvidu.java.client; * {@link io.openvidu.java.client.SessionProperties.Builder#forcedVideoCodec(VideoCodec)} */ public enum VideoCodec { - VP8, VP9, H264, NONE -} \ No newline at end of file + MEDIA_SERVER_PREFERRED, NONE, VP8, VP9, H264 +} diff --git a/openvidu-node-client/src/SessionProperties.ts b/openvidu-node-client/src/SessionProperties.ts index fed08292..adb4b145 100644 --- a/openvidu-node-client/src/SessionProperties.ts +++ b/openvidu-node-client/src/SessionProperties.ts @@ -56,7 +56,7 @@ export interface SessionProperties { customSessionId?: string; /** - * **This feature is part of OpenVidu Pro tier** PRO + * **This feature is part of OpenVidu Pro tier** PRO * * The Media Node where to host the session. The default option if this property is not defined is the less loaded * Media Node at the moment the first user joins the session. This object defines the following properties as Media Node selector: @@ -67,13 +67,19 @@ export interface SessionProperties { } /** - * It defines which video codec do you want to be forcibly used for this session. - * This allows browsers/clients to use the same codec avoiding transcoding in the media server. - * If the browser/client is not compatible with the specified codec and [[allowTranscoding]] is false - * and exception will occur. If forcedVideoCodec is set to [[VideoCodec.NONE]], no codec will be forced. + * Define which video codec will be forcibly used for this session. + * This forces all browsers/clients to use the same codec, which would + * avoid transcoding in the media server (Kurento only). If + * forcedVideoCodec is set to NONE, no codec will be forced. * - * If defined here, this parameter has prevalence over OPENVIDU_STREAMS_FORCED_VIDEO_CODEC. - * OPENVIDU_STREAMS_FORCED_VIDEO_CODEC default is [[VideoCodec.VP8]] + * If the browser/client is not compatible with the specified codec, and + * [[allowTranscoding]] is false, an exception will occur. + * + * If defined here, this parameter has prevalence over + * OPENVIDU_STREAMS_FORCED_VIDEO_CODEC. + * + * Default is [[VideoCodec.VP8]] for Kurento, and + * [[VideoCodec.NONE]] for mediasoup. */ forcedVideoCodec?: VideoCodec; @@ -85,5 +91,4 @@ export interface SessionProperties { * OPENVIDU_STREAMS_ALLOW_TRANSCODING default is 'false' */ allowTranscoding?: boolean; - } diff --git a/openvidu-node-client/src/VideoCodec.ts b/openvidu-node-client/src/VideoCodec.ts index 464bef34..bab98d28 100644 --- a/openvidu-node-client/src/VideoCodec.ts +++ b/openvidu-node-client/src/VideoCodec.ts @@ -2,10 +2,9 @@ * See [[SessionProperties.forcedVideoCodec]] */ export enum VideoCodec { - + MEDIA_SERVER_PREFERRED = 'MEDIA_SERVER_PREFERRED', + NONE = 'NONE', VP8 = 'VP8', VP9 = 'VP9', H264 = 'H264', - NONE = 'NONE' - -} \ No newline at end of file +} diff --git a/openvidu-server/deployments/ce/docker-compose/.env b/openvidu-server/deployments/ce/docker-compose/.env index ea16f6ee..83e14381 100644 --- a/openvidu-server/deployments/ce/docker-compose/.env +++ b/openvidu-server/deployments/ce/docker-compose/.env @@ -128,9 +128,9 @@ OPENVIDU_STREAMS_VIDEO_MIN_SEND_BANDWIDTH=300 # All sessions of OpenVidu will try to force this codec. If OPENVIDU_STREAMS_ALLOW_TRANSCODING=true # when a codec can not be forced, transcoding will be allowed -# Values: VP8, VP9, H264, NONE -# Default value is VP8 -# OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=VP8 +# Values: MEDIA_SERVER_PREFERRED, NONE, VP8, VP9, H264 +# Default value is MEDIA_SERVER_PREFERRED +# OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=MEDIA_SERVER_PREFERRED # Allow transcoding if codec specified in OPENVIDU_STREAMS_FORCED_VIDEO_CODEC can not be applied # Values: true | false diff --git a/openvidu-server/deployments/enterprise/master-node/.env b/openvidu-server/deployments/enterprise/master-node/.env index 1db77389..6af79b5a 100644 --- a/openvidu-server/deployments/enterprise/master-node/.env +++ b/openvidu-server/deployments/enterprise/master-node/.env @@ -259,9 +259,9 @@ OPENVIDU_STREAMS_VIDEO_MIN_SEND_BANDWIDTH=300 # All sessions of OpenVidu will try to force this codec. If OPENVIDU_STREAMS_ALLOW_TRANSCODING=true # when a codec can not be forced, transcoding will be allowed -# Values: VP8, VP9, H264, NONE -# Default value is VP8 -# OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=VP8 +# Values: MEDIA_SERVER_PREFERRED, NONE, VP8, VP9, H264 +# Default value is MEDIA_SERVER_PREFERRED +# OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=MEDIA_SERVER_PREFERRED # Allow transcoding if codec specified in OPENVIDU_STREAMS_FORCED_VIDEO_CODEC can not be applied # Values: true | false diff --git a/openvidu-server/deployments/pro/docker-compose/openvidu-server-pro/.env b/openvidu-server/deployments/pro/docker-compose/openvidu-server-pro/.env index fea37985..caba683d 100644 --- a/openvidu-server/deployments/pro/docker-compose/openvidu-server-pro/.env +++ b/openvidu-server/deployments/pro/docker-compose/openvidu-server-pro/.env @@ -246,9 +246,9 @@ OPENVIDU_STREAMS_VIDEO_MIN_SEND_BANDWIDTH=300 # All sessions of OpenVidu will try to force this codec. If OPENVIDU_STREAMS_ALLOW_TRANSCODING=true # when a codec can not be forced, transcoding will be allowed -# Values: VP8, VP9, H264, NONE -# Default value is VP8 -# OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=VP8 +# Values: MEDIA_SERVER_PREFERRED, NONE, VP8, VP9, H264 +# Default value is MEDIA_SERVER_PREFERRED +# OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=MEDIA_SERVER_PREFERRED # Allow transcoding if codec specified in OPENVIDU_STREAMS_FORCED_VIDEO_CODEC can not be applied # Values: true | false 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 fb551f02..e2fa865d 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 @@ -392,6 +392,22 @@ public class KurentoSessionManager extends SessionManager { log.warn("AllowTranscoding has no effect if the Media Server is not Kurento"); } + // Set appropriate value for the ForcedVideoCodec feature. + if (forcedVideoCodec == VideoCodec.MEDIA_SERVER_PREFERRED) { + final MediaServer mediaServer = openviduConfig.getMediaServer(); + switch (mediaServer) { + case mediasoup: + forcedVideoCodec = VideoCodec.NONE; + break; + case kurento: + default: + forcedVideoCodec = VideoCodec.VP8; + break; + } + + log.info("Media Server: {}, selected ForcedVideoCodec value: {}", mediaServer, forcedVideoCodec); + } + // Modify sdp if forced codec is defined if (forcedVideoCodec != VideoCodec.NONE && !participant.isIpcam()) { kurentoOptions.sdpOffer = sdpMunging.forceCodec(kurentoOptions.sdpOffer, participant, true, false, diff --git a/openvidu-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/openvidu-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json index e34d6a5e..fa97d8c5 100644 --- a/openvidu-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/openvidu-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -157,7 +157,7 @@ "name": "OPENVIDU_STREAMS_FORCED_VIDEO_CODEC", "type": "java.lang.String", "description": "Defines which video codec is being forced to be used in the browser/client", - "defaultValue": "VP8" + "defaultValue": "MEDIA_SERVER_PREFERRED" }, { "name": "OPENVIDU_STREAMS_ALLOW_TRANSCODING", diff --git a/openvidu-server/src/main/resources/application.properties b/openvidu-server/src/main/resources/application.properties index 6311b88a..c4c0c5cf 100644 --- a/openvidu-server/src/main/resources/application.properties +++ b/openvidu-server/src/main/resources/application.properties @@ -43,7 +43,7 @@ OPENVIDU_STREAMS_VIDEO_MIN_RECV_BANDWIDTH=300 OPENVIDU_STREAMS_VIDEO_MAX_SEND_BANDWIDTH=1000 OPENVIDU_STREAMS_VIDEO_MIN_SEND_BANDWIDTH=300 OPENVIDU_STREAMS_VIDEO_SIMULCAST=true -OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=VP8 +OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=MEDIA_SERVER_PREFERRED OPENVIDU_STREAMS_ALLOW_TRANSCODING=false OPENVIDU_SESSIONS_GARBAGE_INTERVAL=900 diff --git a/openvidu-server/src/test/resources/integration-test.properties b/openvidu-server/src/test/resources/integration-test.properties index 3c7d9ba3..1a1fd70d 100644 --- a/openvidu-server/src/test/resources/integration-test.properties +++ b/openvidu-server/src/test/resources/integration-test.properties @@ -36,7 +36,7 @@ OPENVIDU_STREAMS_VIDEO_MAX_RECV_BANDWIDTH=1000 OPENVIDU_STREAMS_VIDEO_MIN_RECV_BANDWIDTH=300 OPENVIDU_STREAMS_VIDEO_MAX_SEND_BANDWIDTH=1000 OPENVIDU_STREAMS_VIDEO_MIN_SEND_BANDWIDTH=300 -OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=VP8 +OPENVIDU_STREAMS_FORCED_VIDEO_CODEC=MEDIA_SERVER_PREFERRED OPENVIDU_STREAMS_ALLOW_TRANSCODING=false OPENVIDU_SESSIONS_GARBAGE_INTERVAL=900