Skip to content

Commit

Permalink
Remove MultiStreamConfig, always enable multi-stream mode. (#1948)
Browse files Browse the repository at this point in the history
* Remove MultiStreamConfig, always enable multi-stream mode.

* ref: Remove "2" from class and function names.

* squash: Remove "new" from class names.
  • Loading branch information
bgrozev committed Sep 15, 2022
1 parent 739c394 commit ce94dbb
Show file tree
Hide file tree
Showing 26 changed files with 569 additions and 3,360 deletions.
115 changes: 24 additions & 91 deletions jvb/src/main/java/org/jitsi/videobridge/AbstractEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
import org.jitsi.nlj.format.*;
import org.jitsi.nlj.rtp.*;
import org.jitsi.nlj.util.*;
import org.jitsi.utils.*;
import org.jitsi.utils.event.*;
import org.jitsi.utils.logging2.*;
import org.jitsi.videobridge.cc.allocation.*;
import org.jitsi.xmpp.extensions.colibri.*;
import org.json.simple.*;

import java.io.*;
import java.time.*;
import java.util.*;

Expand Down Expand Up @@ -61,15 +59,10 @@ public abstract class AbstractEndpoint
*/
private final Conference conference;

/**
* The map of receiver endpoint id -> video constraints.
*/
private final ReceiverConstraintsMap receiverVideoConstraintsMap = new ReceiverConstraintsMap();

/**
* The map of source name -> ReceiverConstraintsMap.
*/
private final Map<String, ReceiverConstraintsMap> receiverVideoConstraintsMapV2 = new HashMap<>();
private final Map<String, ReceiverConstraintsMap> receiverVideoConstraints = new HashMap<>();

/**
* The statistic Id of this <tt>Endpoint</tt>.
Expand Down Expand Up @@ -248,6 +241,8 @@ public String getStatsId()
*
* @return the (unique) identifier/ID of this instance
*/
@NotNull
@Override
public final String getId()
{
return id;
Expand Down Expand Up @@ -380,49 +375,20 @@ public JSONObject getDebugState()
{
JSONObject debugState = new JSONObject();

if (MultiStreamConfig.config.getEnabled())
{
JSONObject receiverVideoConstraints = new JSONObject();
JSONObject receiverVideoConstraints = new JSONObject();

receiverVideoConstraintsMapV2.forEach(
(sourceName, receiverConstraints) ->
receiverVideoConstraints.put(sourceName, receiverConstraints.getDebugState()));
this.receiverVideoConstraints.forEach(
(sourceName, receiverConstraints) ->
receiverVideoConstraints.put(sourceName, receiverConstraints.getDebugState()));

debugState.put("receiverVideoConstraints", receiverVideoConstraints);
debugState.put("maxReceiverVideoConstraintsMap", new HashMap<>(maxReceiverVideoConstraintsMap));
}
else
{
debugState.put("maxReceiverVideoConstraints", maxReceiverVideoConstraints);
debugState.put("receiverVideoConstraints", receiverVideoConstraintsMap.getDebugState());
}
debugState.put("receiverVideoConstraints", receiverVideoConstraints);
debugState.put("maxReceiverVideoConstraintsMap", new HashMap<>(maxReceiverVideoConstraintsMap));
debugState.put("expired", expired);
debugState.put("statsId", statsId);

return debugState;
}

/**
* Computes and sets the {@link #maxReceiverVideoConstraints} from the
* specified video constraints.
*
* @param newMaxHeight the maximum height resulting from the current set of constraints.
* (Currently we only support constraining the height, and not frame rate.)
*/
private void receiverVideoConstraintsChanged(int newMaxHeight)
{
VideoConstraints oldReceiverMaxVideoConstraints = this.maxReceiverVideoConstraints;


VideoConstraints newReceiverMaxVideoConstraints = new VideoConstraints(newMaxHeight, -1.0);

if (!newReceiverMaxVideoConstraints.equals(oldReceiverMaxVideoConstraints))
{
maxReceiverVideoConstraints = newReceiverMaxVideoConstraints;
sendVideoConstraints(newReceiverMaxVideoConstraints);
}
}

/**
* Computes and sets the {@link #maxReceiverVideoConstraints} from the specified video constraints of the media
* source identified by the given source name.
Expand All @@ -431,7 +397,7 @@ private void receiverVideoConstraintsChanged(int newMaxHeight)
* @param newMaxHeight the maximum height resulting from the current set of constraints.
* (Currently we only support constraining the height, and not frame rate.)
*/
private void receiverVideoConstraintsChangedV2(String sourceName, int newMaxHeight)
private void receiverVideoConstraintsChanged(String sourceName, int newMaxHeight)
{
VideoConstraints oldReceiverMaxVideoConstraints = this.maxReceiverVideoConstraintsMap.get(sourceName);

Expand Down Expand Up @@ -487,28 +453,6 @@ private void receiverVideoConstraintsChangedV2(String sourceName, int newMaxHeig
protected abstract void
sendVideoConstraintsV2(@NotNull String sourceName, @NotNull VideoConstraints maxVideoConstraints);

/**
* Notifies this instance that a specified received wants to receive
* the specified video constraints from the endpoint attached to this
* instance (the sender).
*
* The receiver can be either another endpoint, or a remote bridge.
*
* @param receiverId the id that specifies the receiver endpoint
* @param newVideoConstraints the video constraints that the receiver
* wishes to receive.
*/
public void addReceiver(String receiverId, VideoConstraints newVideoConstraints)
{
VideoConstraints oldVideoConstraints = receiverVideoConstraintsMap.put(receiverId, newVideoConstraints);
if (oldVideoConstraints == null || !oldVideoConstraints.equals(newVideoConstraints))
{
logger.debug(
() -> "Changed receiver constraints: " + receiverId + ": " + newVideoConstraints.getMaxHeight());
receiverVideoConstraintsChanged(receiverVideoConstraintsMap.getMaxHeight());
}
}

/**
* Notifies this instance that a specified received wants to receive the specified video constraints from the media
* source with the given source name.
Expand All @@ -519,18 +463,18 @@ public void addReceiver(String receiverId, VideoConstraints newVideoConstraints)
* @param sourceName the name of the media source for which the constraints are to be applied.
* @param newVideoConstraints the video constraints that the receiver wishes to receive.
*/
public void addReceiverV2(
public void addReceiver(
@NotNull String receiverId,
@NotNull String sourceName,
@NotNull VideoConstraints newVideoConstraints
)
{
ReceiverConstraintsMap sourceConstraints = receiverVideoConstraintsMapV2.get(sourceName);
ReceiverConstraintsMap sourceConstraints = receiverVideoConstraints.get(sourceName);

if (sourceConstraints == null)
{
sourceConstraints = new ReceiverConstraintsMap();
receiverVideoConstraintsMapV2.put(sourceName, sourceConstraints);
receiverVideoConstraints.put(sourceName, sourceConstraints);
}

VideoConstraints oldVideoConstraints = sourceConstraints.put(receiverId, newVideoConstraints);
Expand All @@ -540,7 +484,7 @@ public void addReceiverV2(
logger.debug(
() -> "Changed receiver constraints: " + receiverId + "->" + sourceName + ": " +
newVideoConstraints.getMaxHeight());
receiverVideoConstraintsChangedV2(sourceName, sourceConstraints.getMaxHeight());
receiverVideoConstraintsChanged(sourceName, sourceConstraints.getMaxHeight());
}
}

Expand All @@ -553,27 +497,16 @@ public void addReceiverV2(
*/
public void removeReceiver(String receiverId)
{
if (MultiStreamConfig.config.getEnabled())
for (Map.Entry<String, ReceiverConstraintsMap> sourceConstraintsEntry
: receiverVideoConstraints.entrySet())
{
for (Map.Entry<String, ReceiverConstraintsMap> sourceConstraintsEntry
: receiverVideoConstraintsMapV2.entrySet())
{
String sourceName = sourceConstraintsEntry.getKey();
ReceiverConstraintsMap sourceConstraints = sourceConstraintsEntry.getValue();

if (sourceConstraints.remove(receiverId) != null)
{
logger.debug(() -> "Removed receiver " + receiverId + " for " + sourceName);
receiverVideoConstraintsChangedV2(sourceName, sourceConstraints.getMaxHeight());
}
}
}
else
{
if (receiverVideoConstraintsMap.remove(receiverId) != null)
String sourceName = sourceConstraintsEntry.getKey();
ReceiverConstraintsMap sourceConstraints = sourceConstraintsEntry.getValue();

if (sourceConstraints.remove(receiverId) != null)
{
logger.debug(() -> "Removed receiver " + receiverId);
receiverVideoConstraintsChanged(receiverVideoConstraintsMap.getMaxHeight());
logger.debug(() -> "Removed receiver " + receiverId + " for " + sourceName);
receiverVideoConstraintsChanged(sourceName, sourceConstraints.getMaxHeight());
}
}
}
Expand All @@ -587,14 +520,14 @@ public void removeReceiver(String receiverId)
*/
public void removeSourceReceiver(String receiverId, String sourceName)
{
ReceiverConstraintsMap sourceConstraints = receiverVideoConstraintsMapV2.get(sourceName);
ReceiverConstraintsMap sourceConstraints = receiverVideoConstraints.get(sourceName);

if (sourceConstraints != null)
{
if (sourceConstraints.remove(receiverId) != null)
{
logger.debug(() -> "Removed receiver " + receiverId + " for " + sourceName);
receiverVideoConstraintsChangedV2(sourceName, sourceConstraints.getMaxHeight());
receiverVideoConstraintsChanged(sourceName, sourceConstraints.getMaxHeight());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,44 +129,17 @@ public BridgeChannelMessage clientHello(ClientHelloMessage message)
@Override
public BridgeChannelMessage videoType(VideoTypeMessage videoTypeMessage)
{
if (MultiStreamConfig.config.getEnabled())
{
sourceVideoType(
return sourceVideoType(
new SourceVideoTypeMessage(
videoTypeMessage.getVideoType(),
endpointIdToSourceName(endpoint.getId()),
videoTypeMessage.getEndpointId())
);

return null;
}

endpoint.setVideoType(videoTypeMessage.getVideoType());

Conference conference = endpoint.getConference();

if (conference == null || conference.isExpired())
{
getLogger().warn("Unable to forward VideoTypeMessage, conference is null or expired");
return null;
}

videoTypeMessage.setEndpointId(endpoint.getId());

/* Forward videoType messages to Relays. */
conference.sendMessage(videoTypeMessage, Collections.emptyList(), true);

return null;
videoTypeMessage.getVideoType(),
endpointIdToSourceName(endpoint.getId()),
videoTypeMessage.getEndpointId())
);
}

@Override
public BridgeChannelMessage sourceVideoType(SourceVideoTypeMessage sourceVideoTypeMessage)
{
if (!MultiStreamConfig.config.getEnabled())
{
return null;
}

String sourceName = sourceVideoTypeMessage.getSourceName();

if (getLogger().isDebugEnabled())
Expand Down
Loading

0 comments on commit ce94dbb

Please sign in to comment.