Skip to content

Commit

Permalink
Merge pull request #323 from Red5/epic/GROGU
Browse files Browse the repository at this point in the history
Fixed broadcast scope lookups
  • Loading branch information
mondain authored May 9, 2022
2 parents d41845a + 43af354 commit c036f8a
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.2.23</version>
<version>1.2.24</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/org/red5/client/Red5Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class Red5Client {
/**
* Current server version with revision
*/
public static final String VERSION = "Red5 Client 1.2.23";
public static final String VERSION = "Red5 Client 1.2.24";

/**
* Create a new Red5Client object using the connection local to the current thread A bit of magic that lets you access the red5 scope
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.2.23</version>
<version>1.2.24</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-server-common</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/org/red5/server/api/Red5.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public final class Red5 {
/**
* Server version with revision
*/
public static final String VERSION = "Red5 Server 1.2.23";
public static final String VERSION = "Red5 Server 1.2.24";

/**
* Server version for fmsVer requests
*/
public static final String FMS_VERSION = "RED5/1,2,23,0";
public static final String FMS_VERSION = "RED5/1,2,24,0";

/**
* Server capabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ public void messageSent(Packet message) {
//log.info("messageSent: {}", message);
IRTMPEvent event = message.getMessage();
if (event instanceof VideoData) {
log.info("Video message sent");
log.debug("Video message sent");
Number streamId = message.getHeader().getStreamId();
AtomicInteger pending = pendingVideos.get(streamId.doubleValue());
if (isTrace) {
Expand All @@ -1621,11 +1621,11 @@ public void messageSent(Packet message) {
pending.decrementAndGet();
}
} else if (event instanceof AudioData) {
log.info("Audio message sent");
log.debug("Audio message sent");
} else if (event instanceof Notify) {
log.info("Notify message sent");
log.debug("Notify message sent");
} else {
log.warn("Message sent: {} data type: {}", event.getType(), event.getDataType());
log.debug("Message sent: {} data type: {}", event.getType(), event.getDataType());
}
writtenMessages.incrementAndGet();
}
Expand Down
29 changes: 26 additions & 3 deletions common/src/main/java/org/red5/server/scope/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -1444,14 +1444,37 @@ public IBasicScope getBasicScope(ScopeType type, String name) {
scope = stream().filter(child -> name.equals(child.getName())).findFirst();
} else {
// if its broadcast type then allow an alias match in addition to the name match
if (type == ScopeType.BROADCAST) {
if (ScopeType.BROADCAST.equals(type)) {
// checks publish and subscribe aliases
scope = stream().filter(child -> child.getType().equals(type) && (name.equals(child.getName()) || ((IBroadcastScope) child).getClientBroadcastStream().containsAlias(name))).findFirst();
for (IBasicScope child : this) {
// ensure type is broadcast type, since we'll pull out a cbs
if (child.getType().equals(type)) {
IClientBroadcastStream cbs = ((IBroadcastScope) child).getClientBroadcastStream();
if (cbs != null) {
String pubName = cbs.getPublishedName();
if (name.equals(child.getName())) {
log.debug("Scope found by name: {} on {}", name, pubName);
return child;
} else if (cbs.containsAlias(name)) {
log.debug("Scope found with alias: {} on {}", name, pubName);
return child;
} else {
log.debug("No match for name or alias of {} on published stream: {}", name, pubName);
}
} else {
//log.debug("Broadcast scope: {} has no stream attached", name);
if (name.equals(child.getName())) {
log.debug("Scope found by name: {} but has no stream", name);
return child;
}
}
}
}
} else {
scope = stream().filter(child -> child.getType().equals(type) && name.equals(child.getName())).findFirst();
}
}
if (scope.isPresent()) {
if (scope != null && scope.isPresent()) {
return scope.get();
}
return null;
Expand Down
2 changes: 1 addition & 1 deletion io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.2.23</version>
<version>1.2.24</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-io</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<name>Red5</name>
<description>The Red5 server</description>
<groupId>org.red5</groupId>
<version>1.2.23</version>
<version>1.2.24</version>
<url>https://github.com/Red5/red5-server</url>
<inceptionYear>2005</inceptionYear>
<organization>
Expand Down
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.2.23</version>
<version>1.2.24</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-server</artifactId>
Expand Down
37 changes: 30 additions & 7 deletions server/src/test/java/org/red5/server/scope/ScopeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
Expand All @@ -25,13 +26,14 @@
import org.red5.server.api.scope.ScopeType;
import org.red5.server.persistence.RamPersistence;
import org.red5.server.so.SharedObjectScope;
import org.red5.server.stream.ClientBroadcastStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@ContextConfiguration(locations = { "ScopeTest.xml" })
@ContextConfiguration("file:src/test/resources/org/red5/server/scope/ScopeTest.xml")
public class ScopeTest extends AbstractJUnit4SpringContextTests {

protected static Logger log = LoggerFactory.getLogger(ScopeTest.class);
Expand Down Expand Up @@ -78,10 +80,31 @@ public void testScopeCreation() throws InterruptedException {
//Room 0 /default/junit/room0 (created in the spring config)
assertNotNull(appScope.getScope("room0"));
IScope room0 = appScope.getScope("room0");
log.debug("Room#0: {}", room0);
log.debug(">>>>>>>>>>>> Room#0: {}", room0);
assertTrue(room0.getDepth() == 2);
// create a broadcast scope with a stream and add it to the app
BroadcastScope stream1 = new BroadcastScope(appScope, "stream1");
assertTrue("Stream failed to be added to the app scope", appScope.addChildScope(stream1));
assertNotNull(appScope.hasChildScope(ScopeType.BROADCAST, "stream1"));
IBasicScope stream1Scope = appScope.getBasicScope("stream1");
stream1Scope = appScope.getBasicScope(ScopeType.BROADCAST, "stream1");
log.debug(">>>>>>>>>>>> Stream#1: {}", stream1Scope);
ClientBroadcastStream stream = new ClientBroadcastStream();
stream1.setClientBroadcastStream(stream);
stream.setScope(appScope); // do this or jmx fails setting the publish name
stream.setPublishedName("stream1");
// check again after stream added no-aliases
stream1Scope = appScope.getBasicScope(ScopeType.BROADCAST, "stream1");
log.debug(">>>>>>>>>>>> Stream#1: {}", stream1Scope);
// add an alias
stream.addAlias("streamA");
// check again after stream added alias
stream1Scope = appScope.getBasicScope(ScopeType.BROADCAST, "streamA");
log.debug(">>>>>>>>>>>> Stream#1: {}", stream1Scope);
// XXX to test adding rooms etc, uncomment this section
/*
// test runnables represent worker threads creating scopes
int workerCount = 10, loops = 100;
int workerCount = 3, loops = 100;
List<Worker> workers = new ArrayList<>();
for (int s = 0; s < workerCount; s++) {
workers.add(new Worker(appScope, loops));
Expand All @@ -102,11 +125,11 @@ public void testScopeCreation() throws InterruptedException {
assertTrue(roomNames1.size() >= (workerCount + 1));
roomNames1.forEach(name -> {
IScope room = appScope.getScope(name);
log.info("First level room: {}", room);
//log.info("First level room: {}", room);
assertNotNull(room);
// each room is expected to have a minimum of 2 child scopes
Set<String> childNames = room.getScopeNames();
log.info("{} child rooms: {}", name, childNames);
//log.info("{} child rooms: {}", name, childNames);
// except for room0
if (!"room0".equals(name)) {
assertTrue(childNames.size() >= 2);
Expand All @@ -120,8 +143,8 @@ public void testScopeCreation() throws InterruptedException {
}
}
assertTrue(appScope.getBasicScopeNames(ScopeType.ROOM).size() == 1);
//appScope.removeChildren();
//assertTrue(appScope.getBasicScopeNames(ScopeType.ROOM).size() == 0);
*
*/
log.info("testScopeCreation-end");
}

Expand Down
7 changes: 7 additions & 0 deletions server/src/test/resources/org/red5/server/scope/ScopeTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@
<property name="handler" ref="web.handler" />
</bean>

<!--
<bean id="stream1" class="org.red5.server.scope.BroadcastScope">
<constructor-arg index="0" ref="web.scope"/>
<constructor-arg index="1" value="stream1"/>
</bean>
-->

</beans>
2 changes: 1 addition & 1 deletion service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.red5</groupId>
<artifactId>red5-parent</artifactId>
<version>1.2.23</version>
<version>1.2.24</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>red5-service</artifactId>
Expand Down

0 comments on commit c036f8a

Please sign in to comment.