Skip to content

Commit

Permalink
Add one more stopStreaming in testApplicationStreamLimit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SelimEmre committed May 18, 2021
1 parent bdeaa27 commit c72a98d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/main/java/io/antmedia/filter/TokenFilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static String getStreamId(String requestURI) {

requestURI = requestURI.split("streams")[1];

//if request is adaptive file ( ending with _adaptive.m3u8)
//if request is adaptive file (ending with _adaptive.m3u8)
endIndex = requestURI.lastIndexOf(MuxAdaptor.ADAPTIVE_SUFFIX + ".m3u8");
if (endIndex != -1) {
return requestURI.substring(startIndex+1, endIndex);
Expand All @@ -205,30 +205,32 @@ public static String getStreamId(String requestURI) {
}

//if specific ts file requested
String tsRegex = "(.*)_[0-9]+p+[0-9][0-9][0-9][0-9].ts$"; // matches ending with _[resolution]p.m3u8
String tsRegex = "(.*)_[0-9]+p+[0-9][0-9][0-9][0-9].ts$"; // matches ending with _[_240p0000].ts or default ts file extension _[_0p0000].ts
if (requestURI.matches(tsRegex)) {
endIndex = requestURI.lastIndexOf('_'); //because file format is [NAME]_[RESOLUTION]p.m3u8
endIndex = requestURI.lastIndexOf('_'); //because file format is [NAME]_[RESOLUTION]p[0000].ts
return requestURI.substring(startIndex+1, endIndex);
}

//if multiple files with same id requested such as : 541211332342978513714151_480p_1.mp4
//if multiple files with same id requested such as : 541211332342978513714151_480p_1.mp4 or 541211332342978513714151_480p.mp4
String mp4Regex2 = "(.*)+(_[0-9]+p+_[0-9]|_|_[0-9])+.mp4$";
if (requestURI.matches(mp4Regex2)) {
endIndex = requestURI.lastIndexOf('_'); //if multiple files with same id requested such as : 541211332342978513714151_480p_1.mp4
//480p regex
String mp4resolutionRegex = "(.*)+[0-9]+p$";
//_480p regex
String mp4resolutionRegex = "(.*)+_[0-9]+p$";
if(requestURI.substring(startIndex+1, endIndex).matches(mp4resolutionRegex)) {
endIndex = requestURI.substring(startIndex, endIndex).lastIndexOf('_');
}
return requestURI.substring(startIndex+1, endIndex);
}

//if mp4 file requested
//if default mp4 file requested such as: 541211332342978513714151.mp4
endIndex = requestURI.lastIndexOf(".mp4");
if (endIndex != -1) {
return requestURI.substring(startIndex+1, endIndex);
}

return null;
}


}
3 changes: 2 additions & 1 deletion src/test/java/io/antmedia/test/MuxerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,11 +973,12 @@ public void testApplicationStreamLimit()
return activeBroadcastCountFinal + 2 == appAdaptor.getDataStore().getActiveBroadcastCount();
});

Mockito.verify(appAdaptor, timeout(1000)).stopStreaming(Mockito.any());

streamId = "stream " + (int)(Math.random()*10000);
appAdaptor.startPublish(streamId, 0, null);

Mockito.verify(appAdaptor, Mockito.times(2)).stopStreaming(Mockito.any());
Mockito.verify(appAdaptor, timeout(1000)).stopStreaming(Mockito.any());

}

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/antmedia/test/token/TokenFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ public void testGetStreamId() {

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+ MuxAdaptor.ADAPTIVE_SUFFIX +".m3u8"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+".m3u8"));

assertEquals("streamId_underline_test", TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+ "_underline_test" +".m3u8"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+".mp4"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+"_1"+".mp4"));
assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+".m3u8"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+"_480p_1"+".mp4"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+"_1"+".mp4"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+".mp4"));

assertEquals(streamId, TokenFilterManager.getStreamId("/liveapp/streams/"+streamId+"_240p.m3u8"));

Expand Down

0 comments on commit c72a98d

Please sign in to comment.