Skip to content

Commit c036f8a

Browse files
authored
Merge pull request #323 from Red5/epic/GROGU
Fixed broadcast scope lookups
2 parents d41845a + 43af354 commit c036f8a

File tree

12 files changed

+76
-23
lines changed

12 files changed

+76
-23
lines changed

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.2.23</version>
6+
<version>1.2.24</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-client</artifactId>

client/src/main/java/org/red5/client/Red5Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class Red5Client {
1818
/**
1919
* Current server version with revision
2020
*/
21-
public static final String VERSION = "Red5 Client 1.2.23";
21+
public static final String VERSION = "Red5 Client 1.2.24";
2222

2323
/**
2424
* Create a new Red5Client object using the connection local to the current thread A bit of magic that lets you access the red5 scope

common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.2.23</version>
6+
<version>1.2.24</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-server-common</artifactId>

common/src/main/java/org/red5/server/api/Red5.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public final class Red5 {
5555
/**
5656
* Server version with revision
5757
*/
58-
public static final String VERSION = "Red5 Server 1.2.23";
58+
public static final String VERSION = "Red5 Server 1.2.24";
5959

6060
/**
6161
* Server version for fmsVer requests
6262
*/
63-
public static final String FMS_VERSION = "RED5/1,2,23,0";
63+
public static final String FMS_VERSION = "RED5/1,2,24,0";
6464

6565
/**
6666
* Server capabilities

common/src/main/java/org/red5/server/net/rtmp/RTMPConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ public void messageSent(Packet message) {
16111611
//log.info("messageSent: {}", message);
16121612
IRTMPEvent event = message.getMessage();
16131613
if (event instanceof VideoData) {
1614-
log.info("Video message sent");
1614+
log.debug("Video message sent");
16151615
Number streamId = message.getHeader().getStreamId();
16161616
AtomicInteger pending = pendingVideos.get(streamId.doubleValue());
16171617
if (isTrace) {
@@ -1621,11 +1621,11 @@ public void messageSent(Packet message) {
16211621
pending.decrementAndGet();
16221622
}
16231623
} else if (event instanceof AudioData) {
1624-
log.info("Audio message sent");
1624+
log.debug("Audio message sent");
16251625
} else if (event instanceof Notify) {
1626-
log.info("Notify message sent");
1626+
log.debug("Notify message sent");
16271627
} else {
1628-
log.warn("Message sent: {} data type: {}", event.getType(), event.getDataType());
1628+
log.debug("Message sent: {} data type: {}", event.getType(), event.getDataType());
16291629
}
16301630
writtenMessages.incrementAndGet();
16311631
}

common/src/main/java/org/red5/server/scope/Scope.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,14 +1444,37 @@ public IBasicScope getBasicScope(ScopeType type, String name) {
14441444
scope = stream().filter(child -> name.equals(child.getName())).findFirst();
14451445
} else {
14461446
// if its broadcast type then allow an alias match in addition to the name match
1447-
if (type == ScopeType.BROADCAST) {
1447+
if (ScopeType.BROADCAST.equals(type)) {
14481448
// checks publish and subscribe aliases
1449-
scope = stream().filter(child -> child.getType().equals(type) && (name.equals(child.getName()) || ((IBroadcastScope) child).getClientBroadcastStream().containsAlias(name))).findFirst();
1449+
for (IBasicScope child : this) {
1450+
// ensure type is broadcast type, since we'll pull out a cbs
1451+
if (child.getType().equals(type)) {
1452+
IClientBroadcastStream cbs = ((IBroadcastScope) child).getClientBroadcastStream();
1453+
if (cbs != null) {
1454+
String pubName = cbs.getPublishedName();
1455+
if (name.equals(child.getName())) {
1456+
log.debug("Scope found by name: {} on {}", name, pubName);
1457+
return child;
1458+
} else if (cbs.containsAlias(name)) {
1459+
log.debug("Scope found with alias: {} on {}", name, pubName);
1460+
return child;
1461+
} else {
1462+
log.debug("No match for name or alias of {} on published stream: {}", name, pubName);
1463+
}
1464+
} else {
1465+
//log.debug("Broadcast scope: {} has no stream attached", name);
1466+
if (name.equals(child.getName())) {
1467+
log.debug("Scope found by name: {} but has no stream", name);
1468+
return child;
1469+
}
1470+
}
1471+
}
1472+
}
14501473
} else {
14511474
scope = stream().filter(child -> child.getType().equals(type) && name.equals(child.getName())).findFirst();
14521475
}
14531476
}
1454-
if (scope.isPresent()) {
1477+
if (scope != null && scope.isPresent()) {
14551478
return scope.get();
14561479
}
14571480
return null;

io/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.2.23</version>
6+
<version>1.2.24</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-io</artifactId>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<name>Red5</name>
2424
<description>The Red5 server</description>
2525
<groupId>org.red5</groupId>
26-
<version>1.2.23</version>
26+
<version>1.2.24</version>
2727
<url>https://github.com/Red5/red5-server</url>
2828
<inceptionYear>2005</inceptionYear>
2929
<organization>

server/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>org.red5</groupId>
55
<artifactId>red5-parent</artifactId>
6-
<version>1.2.23</version>
6+
<version>1.2.24</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99
<artifactId>red5-server</artifactId>

server/src/test/java/org/red5/server/scope/ScopeTest.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.concurrent.atomic.AtomicInteger;
1717

1818
import org.junit.After;
19+
import org.junit.Assert;
1920
import org.junit.Before;
2021
import org.junit.FixMethodOrder;
2122
import org.junit.Test;
@@ -25,13 +26,14 @@
2526
import org.red5.server.api.scope.ScopeType;
2627
import org.red5.server.persistence.RamPersistence;
2728
import org.red5.server.so.SharedObjectScope;
29+
import org.red5.server.stream.ClientBroadcastStream;
2830
import org.slf4j.Logger;
2931
import org.slf4j.LoggerFactory;
3032
import org.springframework.test.context.ContextConfiguration;
3133
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
3234

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

3739
protected static Logger log = LoggerFactory.getLogger(ScopeTest.class);
@@ -78,10 +80,31 @@ public void testScopeCreation() throws InterruptedException {
7880
//Room 0 /default/junit/room0 (created in the spring config)
7981
assertNotNull(appScope.getScope("room0"));
8082
IScope room0 = appScope.getScope("room0");
81-
log.debug("Room#0: {}", room0);
83+
log.debug(">>>>>>>>>>>> Room#0: {}", room0);
8284
assertTrue(room0.getDepth() == 2);
85+
// create a broadcast scope with a stream and add it to the app
86+
BroadcastScope stream1 = new BroadcastScope(appScope, "stream1");
87+
assertTrue("Stream failed to be added to the app scope", appScope.addChildScope(stream1));
88+
assertNotNull(appScope.hasChildScope(ScopeType.BROADCAST, "stream1"));
89+
IBasicScope stream1Scope = appScope.getBasicScope("stream1");
90+
stream1Scope = appScope.getBasicScope(ScopeType.BROADCAST, "stream1");
91+
log.debug(">>>>>>>>>>>> Stream#1: {}", stream1Scope);
92+
ClientBroadcastStream stream = new ClientBroadcastStream();
93+
stream1.setClientBroadcastStream(stream);
94+
stream.setScope(appScope); // do this or jmx fails setting the publish name
95+
stream.setPublishedName("stream1");
96+
// check again after stream added no-aliases
97+
stream1Scope = appScope.getBasicScope(ScopeType.BROADCAST, "stream1");
98+
log.debug(">>>>>>>>>>>> Stream#1: {}", stream1Scope);
99+
// add an alias
100+
stream.addAlias("streamA");
101+
// check again after stream added alias
102+
stream1Scope = appScope.getBasicScope(ScopeType.BROADCAST, "streamA");
103+
log.debug(">>>>>>>>>>>> Stream#1: {}", stream1Scope);
104+
// XXX to test adding rooms etc, uncomment this section
105+
/*
83106
// test runnables represent worker threads creating scopes
84-
int workerCount = 10, loops = 100;
107+
int workerCount = 3, loops = 100;
85108
List<Worker> workers = new ArrayList<>();
86109
for (int s = 0; s < workerCount; s++) {
87110
workers.add(new Worker(appScope, loops));
@@ -102,11 +125,11 @@ public void testScopeCreation() throws InterruptedException {
102125
assertTrue(roomNames1.size() >= (workerCount + 1));
103126
roomNames1.forEach(name -> {
104127
IScope room = appScope.getScope(name);
105-
log.info("First level room: {}", room);
128+
//log.info("First level room: {}", room);
106129
assertNotNull(room);
107130
// each room is expected to have a minimum of 2 child scopes
108131
Set<String> childNames = room.getScopeNames();
109-
log.info("{} child rooms: {}", name, childNames);
132+
//log.info("{} child rooms: {}", name, childNames);
110133
// except for room0
111134
if (!"room0".equals(name)) {
112135
assertTrue(childNames.size() >= 2);
@@ -120,8 +143,8 @@ public void testScopeCreation() throws InterruptedException {
120143
}
121144
}
122145
assertTrue(appScope.getBasicScopeNames(ScopeType.ROOM).size() == 1);
123-
//appScope.removeChildren();
124-
//assertTrue(appScope.getBasicScopeNames(ScopeType.ROOM).size() == 0);
146+
*
147+
*/
125148
log.info("testScopeCreation-end");
126149
}
127150

0 commit comments

Comments
 (0)