openvidu-server: configuration parameters for max and min video send and recv (kbps)

pull/88/merge
pabloFuente 2018-07-06 13:18:34 +02:00
parent 2571a8a33c
commit e615ff7ec4
9 changed files with 136 additions and 32 deletions

View File

@ -44,19 +44,28 @@ public class OpenviduConfig {
private String openviduRecordingPath; private String openviduRecordingPath;
@Value("${openvidu.recording.public-access}") @Value("${openvidu.recording.public-access}")
boolean openviduRecordingPublicAccess; private boolean openviduRecordingPublicAccess;
@Value("${openvidu.recording.notification}") @Value("${openvidu.recording.notification}")
String openviduRecordingNotification; private String openviduRecordingNotification;
@Value("${openvidu.recording.custom-layout}") @Value("${openvidu.recording.custom-layout}")
String openviduRecordingCustomLayout; private String openviduRecordingCustomLayout;
@Value("${openvidu.recording.version}") @Value("${openvidu.recording.version}")
String openviduRecordingVersion; private String openviduRecordingVersion;
@Value("#{'${spring.profiles.active:}'.length() > 0 ? '${spring.profiles.active:}'.split(',') : \"default\"}") @Value("${openvidu.streams.video.max-recv-bandwidth}")
private String springProfile; private int openviduStreamsVideoMaxRecvBandwidth;
@Value("${openvidu.streams.video.min-recv-bandwidth}")
private int openviduStreamsVideoMinRecvBandwidth;
@Value("${openvidu.streams.video.max-send-bandwidth}")
private int openviduStreamsVideoMaxSendBandwidth;
@Value("${openvidu.streams.video.min-send-bandwidth}")
private int openviduStreamsVideoMinSendBandwidth;
@Value("${coturn.redis.ip}") @Value("${coturn.redis.ip}")
private String coturnRedisIp; private String coturnRedisIp;
@ -70,6 +79,9 @@ public class OpenviduConfig {
@Value("${coturn.redis.connect-timeout}") @Value("${coturn.redis.connect-timeout}")
private String coturnRedisConnectTimeout; private String coturnRedisConnectTimeout;
@Value("#{'${spring.profiles.active:}'.length() > 0 ? '${spring.profiles.active:}'.split(',') : \"default\"}")
private String springProfile;
private String finalUrl; private String finalUrl;
public String getOpenViduPublicUrl() { public String getOpenViduPublicUrl() {
@ -132,11 +144,27 @@ public class OpenviduConfig {
return springProfile; return springProfile;
} }
public int getVideoMaxRecvBandwidth() {
return this.openviduStreamsVideoMaxRecvBandwidth;
}
public int getVideoMinRecvBandwidth() {
return this.openviduStreamsVideoMinRecvBandwidth;
}
public int getVideoMaxSendBandwidth() {
return this.openviduStreamsVideoMaxSendBandwidth;
}
public int getVideoMinSendBandwidth() {
return this.openviduStreamsVideoMinSendBandwidth;
}
public String getCoturnDatabaseString() { public String getCoturnDatabaseString() {
return "\"ip=" + this.coturnRedisIp + " dbname=" + this.coturnRedisDbname + " password=" return "\"ip=" + this.coturnRedisIp + " dbname=" + this.coturnRedisDbname + " password="
+ this.coturnRedisPassword + " connect_timeout=" + this.coturnRedisConnectTimeout + "\""; + this.coturnRedisPassword + " connect_timeout=" + this.coturnRedisConnectTimeout + "\"";
} }
public String getCoturnDatabaseDbname() { public String getCoturnDatabaseDbname() {
return this.coturnRedisDbname; return this.coturnRedisDbname;
} }

View File

@ -39,7 +39,6 @@ import org.kurento.client.SdpEndpoint;
import org.kurento.client.internal.server.KurentoServerException; import org.kurento.client.internal.server.KurentoServerException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code; import io.openvidu.client.OpenViduException.Code;
@ -60,8 +59,7 @@ public class KurentoParticipant extends Participant {
private static final Logger log = LoggerFactory.getLogger(KurentoParticipant.class); private static final Logger log = LoggerFactory.getLogger(KurentoParticipant.class);
@Autowired private OpenviduConfig openviduConfig;
protected OpenviduConfig openviduConfig;
private InfoHandler infoHandler; private InfoHandler infoHandler;
private CallDetailRecord CDR; private CallDetailRecord CDR;
@ -78,12 +76,14 @@ public class KurentoParticipant extends Participant {
private final ConcurrentMap<String, SubscriberEndpoint> subscribers = new ConcurrentHashMap<String, SubscriberEndpoint>(); private final ConcurrentMap<String, SubscriberEndpoint> subscribers = new ConcurrentHashMap<String, SubscriberEndpoint>();
public KurentoParticipant(Participant participant, KurentoSession kurentoSession, MediaPipeline pipeline, public KurentoParticipant(Participant participant, KurentoSession kurentoSession, MediaPipeline pipeline,
InfoHandler infoHandler, CallDetailRecord CDR) { InfoHandler infoHandler, CallDetailRecord CDR, OpenviduConfig openviduConfig) {
super(participant.getParticipantPrivateId(), participant.getParticipantPublicId(), participant.getToken(), super(participant.getParticipantPrivateId(), participant.getParticipantPublicId(), participant.getToken(),
participant.getClientMetadata()); participant.getClientMetadata());
this.openviduConfig = openviduConfig;
this.session = kurentoSession; this.session = kurentoSession;
this.pipeline = pipeline; this.pipeline = pipeline;
this.publisher = new PublisherEndpoint(webParticipant, this, participant.getParticipantPublicId(), pipeline); this.publisher = new PublisherEndpoint(webParticipant, this, participant.getParticipantPublicId(), pipeline,
this.openviduConfig);
for (Participant other : session.getParticipants()) { for (Participant other : session.getParticipants()) {
if (!other.getParticipantPublicId().equals(this.getParticipantPublicId())) { if (!other.getParticipantPublicId().equals(this.getParticipantPublicId())) {
@ -250,7 +250,8 @@ public class KurentoParticipant extends Participant {
log.info("PARTICIPANT {}: unpublishing media stream from room {}", this.getParticipantPublicId(), log.info("PARTICIPANT {}: unpublishing media stream from room {}", this.getParticipantPublicId(),
this.session.getSessionId()); this.session.getSessionId());
releasePublisherEndpoint(reason); releasePublisherEndpoint(reason);
this.publisher = new PublisherEndpoint(webParticipant, this, this.getParticipantPublicId(), pipeline); this.publisher = new PublisherEndpoint(webParticipant, this, this.getParticipantPublicId(), pipeline,
this.openviduConfig);
log.info("PARTICIPANT {}: released publisher endpoint and left it initialized (ready for future streaming)", log.info("PARTICIPANT {}: released publisher endpoint and left it initialized (ready for future streaming)",
this.getParticipantPublicId()); this.getParticipantPublicId());
} }
@ -394,7 +395,8 @@ public class KurentoParticipant extends Participant {
*/ */
public SubscriberEndpoint getNewOrExistingSubscriber(String senderPublicId) { public SubscriberEndpoint getNewOrExistingSubscriber(String senderPublicId) {
SubscriberEndpoint sendingEndpoint = new SubscriberEndpoint(webParticipant, this, senderPublicId, pipeline); SubscriberEndpoint sendingEndpoint = new SubscriberEndpoint(webParticipant, this, senderPublicId, pipeline,
this.openviduConfig);
SubscriberEndpoint existingSendingEndpoint = this.subscribers.putIfAbsent(senderPublicId, sendingEndpoint); SubscriberEndpoint existingSendingEndpoint = this.subscribers.putIfAbsent(senderPublicId, sendingEndpoint);
if (existingSendingEndpoint != null) { if (existingSendingEndpoint != null) {

View File

@ -42,6 +42,7 @@ import io.openvidu.client.OpenViduException.Code;
import io.openvidu.client.internal.ProtocolElements; import io.openvidu.client.internal.ProtocolElements;
import io.openvidu.java.client.SessionProperties; import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.cdr.CallDetailRecord; import io.openvidu.server.cdr.CallDetailRecord;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.Participant; import io.openvidu.server.core.Participant;
import io.openvidu.server.core.Session; import io.openvidu.server.core.Session;
@ -53,6 +54,8 @@ public class KurentoSession implements Session {
private final static Logger log = LoggerFactory.getLogger(Session.class); private final static Logger log = LoggerFactory.getLogger(Session.class);
public static final int ASYNC_LATCH_TIMEOUT = 30; public static final int ASYNC_LATCH_TIMEOUT = 30;
private OpenviduConfig openviduConfig;
private final ConcurrentMap<String, KurentoParticipant> participants = new ConcurrentHashMap<>(); private final ConcurrentMap<String, KurentoParticipant> participants = new ConcurrentHashMap<>();
private String sessionId; private String sessionId;
private SessionProperties sessionProperties; private SessionProperties sessionProperties;
@ -74,17 +77,19 @@ public class KurentoSession implements Session {
private boolean destroyKurentoClient; private boolean destroyKurentoClient;
private CallDetailRecord CDR; private CallDetailRecord CDR;
public final ConcurrentHashMap<String, String> publishedStreamIds = new ConcurrentHashMap<>(); public final ConcurrentHashMap<String, String> publishedStreamIds = new ConcurrentHashMap<>();
public KurentoSession(String sessionId, SessionProperties sessionProperties, KurentoClient kurentoClient, public KurentoSession(String sessionId, SessionProperties sessionProperties, KurentoClient kurentoClient,
KurentoSessionEventsHandler kurentoSessionHandler, boolean destroyKurentoClient, CallDetailRecord CDR) { KurentoSessionEventsHandler kurentoSessionHandler, boolean destroyKurentoClient, CallDetailRecord CDR,
OpenviduConfig openviduConfig) {
this.sessionId = sessionId; this.sessionId = sessionId;
this.sessionProperties = sessionProperties; this.sessionProperties = sessionProperties;
this.kurentoClient = kurentoClient; this.kurentoClient = kurentoClient;
this.destroyKurentoClient = destroyKurentoClient; this.destroyKurentoClient = destroyKurentoClient;
this.kurentoSessionHandler = kurentoSessionHandler; this.kurentoSessionHandler = kurentoSessionHandler;
this.CDR = CDR; this.CDR = CDR;
this.openviduConfig = openviduConfig;
log.debug("New SESSION instance with id '{}'", sessionId); log.debug("New SESSION instance with id '{}'", sessionId);
} }
@ -104,7 +109,7 @@ public class KurentoSession implements Session {
createPipeline(); createPipeline();
KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, getPipeline(), KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, getPipeline(),
kurentoSessionHandler.getInfoHandler(), this.CDR); kurentoSessionHandler.getInfoHandler(), this.CDR, this.openviduConfig);
participants.put(participant.getParticipantPrivateId(), kurentoParticipant); participants.put(participant.getParticipantPrivateId(), kurentoParticipant);
filterStates.forEach((filterId, state) -> { filterStates.forEach((filterId, state) -> {

View File

@ -441,7 +441,7 @@ public class KurentoSessionManager extends SessionManager {
} }
KurentoClient kurentoClient = kcProvider.getKurentoClient(kcSessionInfo); KurentoClient kurentoClient = kcProvider.getKurentoClient(kcSessionInfo);
session = new KurentoSession(sessionId, sessionProperties, kurentoClient, kurentoSessionEventsHandler, session = new KurentoSession(sessionId, sessionProperties, kurentoClient, kurentoSessionEventsHandler,
kcProvider.destroyWhenUnused(), this.CDR); kcProvider.destroyWhenUnused(), this.CDR, this.openviduConfig);
KurentoSession oldSession = (KurentoSession) sessions.putIfAbsent(sessionId, session); KurentoSession oldSession = (KurentoSession) sessions.putIfAbsent(sessionId, session);
if (oldSession != null) { if (oldSession != null) {

View File

@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code; import io.openvidu.client.OpenViduException.Code;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.Participant; import io.openvidu.server.core.Participant;
import io.openvidu.server.kurento.core.KurentoParticipant; import io.openvidu.server.kurento.core.KurentoParticipant;
@ -57,12 +58,18 @@ import io.openvidu.server.kurento.core.KurentoParticipant;
*/ */
public abstract class MediaEndpoint { public abstract class MediaEndpoint {
private static Logger log; private static Logger log;
private OpenviduConfig openviduConfig;
private boolean web = false; private boolean web = false;
private WebRtcEndpoint webEndpoint = null; private WebRtcEndpoint webEndpoint = null;
private RtpEndpoint endpoint = null; private RtpEndpoint endpoint = null;
private final int maxRecvKbps;
private final int minRecvKbps;
private final int maxSendKbps;
private final int minSendKbps;
private KurentoParticipant owner; private KurentoParticipant owner;
private String endpointName; private String endpointName;
@ -89,7 +96,7 @@ public abstract class MediaEndpoint {
* @param log * @param log
*/ */
public MediaEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline, public MediaEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline,
Logger log) { OpenviduConfig openviduConfig, Logger log) {
if (log == null) { if (log == null) {
MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class); MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class);
} else { } else {
@ -99,6 +106,12 @@ public abstract class MediaEndpoint {
this.owner = owner; this.owner = owner;
this.setEndpointName(endpointName); this.setEndpointName(endpointName);
this.setMediaPipeline(pipeline); this.setMediaPipeline(pipeline);
this.openviduConfig = openviduConfig;
this.maxRecvKbps = this.openviduConfig.getVideoMaxRecvBandwidth();
this.minRecvKbps = this.openviduConfig.getVideoMinRecvBandwidth();
this.maxSendKbps = this.openviduConfig.getVideoMaxSendBandwidth();
this.minSendKbps = this.openviduConfig.getVideoMinSendBandwidth();
} }
public boolean isWeb() { public boolean isWeb() {
@ -218,10 +231,10 @@ public abstract class MediaEndpoint {
public void onSuccess(WebRtcEndpoint result) throws Exception { public void onSuccess(WebRtcEndpoint result) throws Exception {
webEndpoint = result; webEndpoint = result;
webEndpoint.setMaxVideoRecvBandwidth(600); webEndpoint.setMaxVideoRecvBandwidth(maxRecvKbps);
webEndpoint.setMinVideoRecvBandwidth(300); webEndpoint.setMinVideoRecvBandwidth(minRecvKbps);
webEndpoint.setMaxVideoSendBandwidth(600); webEndpoint.setMaxVideoSendBandwidth(maxSendKbps);
webEndpoint.setMinVideoSendBandwidth(300); webEndpoint.setMinVideoSendBandwidth(minSendKbps);
endpointLatch.countDown(); endpointLatch.countDown();
log.trace("EP {}: Created a new WebRtcEndpoint", endpointName); log.trace("EP {}: Created a new WebRtcEndpoint", endpointName);

View File

@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code; import io.openvidu.client.OpenViduException.Code;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.MediaOptions; import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.kurento.TrackType; import io.openvidu.server.kurento.TrackType;
import io.openvidu.server.kurento.core.KurentoParticipant; import io.openvidu.server.kurento.core.KurentoParticipant;
@ -60,8 +61,8 @@ public class PublisherEndpoint extends MediaEndpoint {
private Map<String, ListenerSubscription> elementsErrorSubscriptions = new HashMap<String, ListenerSubscription>(); private Map<String, ListenerSubscription> elementsErrorSubscriptions = new HashMap<String, ListenerSubscription>();
public PublisherEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline) { public PublisherEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline, OpenviduConfig openviduConfig) {
super(web, owner, endpointName, pipeline, log); super(web, owner, endpointName, pipeline, openviduConfig, log);
} }
@Override @Override

View File

@ -22,6 +22,7 @@ import org.kurento.client.MediaPipeline;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.kurento.core.KurentoParticipant; import io.openvidu.server.kurento.core.KurentoParticipant;
/** /**
@ -36,8 +37,8 @@ public class SubscriberEndpoint extends MediaEndpoint {
private PublisherEndpoint publisher = null; private PublisherEndpoint publisher = null;
public SubscriberEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline) { public SubscriberEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline, OpenviduConfig openviduConfig) {
super(web, owner, endpointName, pipeline, log); super(web, owner, endpointName, pipeline, openviduConfig, log);
} }
public synchronized String subscribe(String sdpOffer, PublisherEndpoint publisher) { public synchronized String subscribe(String sdpOffer, PublisherEndpoint publisher) {

View File

@ -64,6 +64,54 @@
"type": "java.lang.String", "type": "java.lang.String",
"description": "Path to COTURN sqlite database to add and remove TURN user credentials", "description": "Path to COTURN sqlite database to add and remove TURN user credentials",
"defaultValue": "/opt/openvidu/coturn/turndb" "defaultValue": "/opt/openvidu/coturn/turndb"
},
{
"name": "openvidu.streams.video.max-recv-bandwidth",
"type": "java.lang.Integer",
"description": "Maximum video bandwith sent from clients to OpenVidu Server, in kbps. 0 means unconstrained",
"defaultValue": 600
},
{
"name": "openvidu.streams.video.min-recv-bandwidth",
"type": "java.lang.Integer",
"description": "Minimum video bandwith sent from clients to OpenVidu Server, in kbps. 0 means unconstrained",
"defaultValue": 300
},
{
"name": "openvidu.streams.video.max-send-bandwidth",
"type": "java.lang.Integer",
"description": "Maximum video bandwith sent from OpenVidu Server to clients, in kbps. 0 means unconstrained",
"defaultValue": 600
},
{
"name": "openvidu.streams.video.min-send-bandwidth",
"type": "java.lang.Integer",
"description": "Minimum video bandwith sent from OpenVidu Server to clients, in kbps. 0 means unconstrained",
"defaultValue": 300
},
{
"name": "coturn.redis.ip",
"type": "java.lang.String",
"description": "Redis IP where OpenVidu Server should connect to store TURN credentials",
"defaultValue": "127.0.0.1"
},
{
"name": "coturn.redis.dbname",
"type": "java.lang.String",
"description": "Redis database where to store TURN credentials",
"defaultValue": "0"
},
{
"name": "coturn.redis.password",
"type": "java.lang.String",
"description": "Password to connect OpenVidu Server to Redis database to store TURN credentials",
"defaultValue": "turn"
},
{
"name": "coturn.redis.connect-timeout",
"type": "java.lang.Integer",
"description": "Timeout in seconds when OpenVidu Server is connecting to Redis database to store TURN credentials",
"defaultValue": 30
} }
] ]
} }

View File

@ -13,15 +13,21 @@ server.ssl.key-alias: openvidu-selfsigned
openvidu.secret: MY_SECRET openvidu.secret: MY_SECRET
openvidu.publicurl: local openvidu.publicurl: local
openvidu.cdr: false openvidu.cdr: false
openvidu.recording: false openvidu.recording: false
openvidu.recording.path: /opt/openvidu/recordings openvidu.recording.path: /opt/openvidu/recordings
openvidu.recording.public-access: false openvidu.recording.public-access: false
openvidu.recording.notification: publisher_moderator openvidu.recording.notification: publisher_moderator
openvidu.recording.custom-layout: /opt/openvidu/custom-layout openvidu.recording.custom-layout: /opt/openvidu/custom-layout
kms.uris=[\"ws://localhost:8888/kurento\"] openvidu.streams.video.max-recv-bandwidth: 600
openvidu.streams.video.min-recv-bandwidth: 300
openvidu.streams.video.max-send-bandwidth: 600
openvidu.streams.video.min-send-bandwidth: 300
coturn.redis.ip=127.0.0.1 kms.uris: [\"ws://localhost:8888/kurento\"]
coturn.redis.dbname=0
coturn.redis.password=turn coturn.redis.ip: 127.0.0.1
coturn.redis.connect-timeout=30 coturn.redis.dbname: 0
coturn.redis.password: turn
coturn.redis.connect-timeout: 30