Skip to content

Commit

Permalink
Fix failing test scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Dec 19, 2024
1 parent aa9ed83 commit a421fc9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 33 deletions.
55 changes: 37 additions & 18 deletions src/main/java/io/antmedia/AntMediaApplicationAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1014,30 +1014,50 @@ public static Broadcast saveUndefinedBroadcast(String streamId, String streamNam
return null;
}

//@Override
@Override
@Deprecated
public void muxingFinished(String streamId, File File, long startTime, long duration, int resolution,
String previewFilePath, String vodId)
{
muxingFinished(getDataStore().get(streamId), File, startTime, duration, resolution, previewFilePath, vodId);
muxingFinished(getDataStore().get(streamId), streamId, File, startTime, duration, resolution, previewFilePath, vodId);
}

@Override
public void muxingFinished(@Nonnull Broadcast broadcast, File file, long startTime, long duration, int resolution, String previewFilePath, String vodId) {
public void muxingFinished(@Nonnull Broadcast broadcast, String streamId, File file, long startTime, long duration, int resolution, String previewFilePath, String vodId) {

String listenerHookURL = null;
String streamName = file.getName();
String description = null;
String metadata = null;
String longitude = null;
String latitude = null;
String altitude = null;

if (broadcast != null) {
listenerHookURL = broadcast.getListenerHookURL();
if(StringUtils.isNotBlank(broadcast.getName())){
streamName = resolution != 0 ? broadcast.getName() + " (" + resolution + "p)" : broadcast.getName();
}
description = broadcast.getDescription();
metadata = broadcast.getMetaData();
longitude = broadcast.getLongitude();
latitude = broadcast.getLatitude();
altitude = broadcast.getAltitude();
}
else {
logger.error("Broadcast is null for muxing finished for stream: {} it's not supposed to happen", streamId);
}

String vodName = file.getName();
String filePath = file.getPath();
long fileSize = file.length();
long systemTime = System.currentTimeMillis();

String relativePath = getRelativePath(filePath);
String listenerHookURL = null;
String streamName = file.getName();


String streamId = broadcast.getStreamId();

listenerHookURL = broadcast.getListenerHookURL();
if(StringUtils.isNotBlank(broadcast.getName())){
streamName = resolution != 0 ? broadcast.getName() + " (" + resolution + "p)" : broadcast.getName();
}


logger.info("muxing finished for stream: {} with file: {}", streamId, file);

Expand All @@ -1051,12 +1071,12 @@ public void muxingFinished(@Nonnull Broadcast broadcast, File file, long startTi
vodId = RandomStringUtils.randomAlphanumeric(24);
}

VoD newVod = new VoD(streamName, broadcast.getStreamId(), relativePath, vodName, systemTime, startTime, duration, fileSize, VoD.STREAM_VOD, vodId, previewFilePath);
newVod.setDescription(broadcast.getDescription());
newVod.setMetadata(broadcast.getMetaData());
newVod.setLongitude(broadcast.getLongitude());
newVod.setLatitude(broadcast.getLatitude());
newVod.setAltitude(broadcast.getAltitude());
VoD newVod = new VoD(streamName, streamId, relativePath, vodName, systemTime, startTime, duration, fileSize, VoD.STREAM_VOD, vodId, previewFilePath);
newVod.setDescription(description);
newVod.setMetadata(metadata);
newVod.setLongitude(longitude);
newVod.setLatitude(latitude);
newVod.setAltitude(altitude);



Expand All @@ -1072,9 +1092,8 @@ public void muxingFinished(@Nonnull Broadcast broadcast, File file, long startTi
|| ((index = vodName.lastIndexOf(".webm")) != -1) )
{
final String baseName = vodName.substring(0, index);
final String metaData = broadcast.getMetaData();
logger.info("Setting timer for calling vod ready hook for stream:{}", streamId);
notifyHook(listenerHookURL, streamId, null, HOOK_ACTION_VOD_READY, null, null, baseName, vodId, metaData, null);
notifyHook(listenerHookURL, streamId, null, HOOK_ACTION_VOD_READY, null, null, baseName, vodId, metadata, null);
}

String muxerFinishScript = appSettings.getMuxerFinishScript();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/antmedia/muxer/IAntMediaStreamHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public interface IAntMediaStreamHandler {
* in some cases like there is already a file with that name
*
* @param broadcast object that muxed is finished
* @param streamId is the id of the stream
* @param file video file that muxed is finished
* @param duration of the video in milliseconds
* @param resolution height of the video
*
*/
public void muxingFinished(Broadcast broadcast, File file, long startTime, long duration , int resolution, String path, String vodId);
public void muxingFinished(Broadcast broadcast, String streamId, File file, long startTime, long duration , int resolution, String path, String vodId);

/**
* Update stream quality, speed and number of pending packet size and update time
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/antmedia/muxer/RecordMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public synchronized void writeTrailer() {

finalizeRecordFile(f);

adaptor.muxingFinished(broadcast, f, startTime, getDurationInMs(f,streamId), resolution, previewPath, vodId);
adaptor.muxingFinished(broadcast, streamId, f, startTime, getDurationInMs(f,streamId), resolution, previewPath, vodId);

logger.info("File: {} exist: {}", fileTmp.getAbsolutePath(), fileTmp.exists());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public void testSynchUserVoD() {
}

@Test
public void testMuxingFinishedWithPreview(){
public void testMuxingFinishedWithPreview() throws Exception{
AppSettings appSettings = new AppSettings();
appSettings.setGeneratePreview(true);
appSettings.setMuxerFinishScript("src/test/resources/echo.sh");
Expand All @@ -653,6 +653,9 @@ public void testMuxingFinishedWithPreview(){
DataStoreFactory dsf = Mockito.mock(DataStoreFactory.class);
Mockito.when(dsf.getDataStore()).thenReturn(dataStore);
adapter.setDataStoreFactory(dsf);
Broadcast broadcast = new Broadcast();
broadcast.setStreamId("streamId");
dataStore.save(broadcast);

adapter.setVertx(vertx);

Expand All @@ -662,7 +665,7 @@ public void testMuxingFinishedWithPreview(){

assertFalse(f.exists());

adapter.muxingFinished("streamId", anyFile, 0, 100, 480, "src/test/resources/preview.png", null);
adapter.muxingFinished(broadcast, "streamId", anyFile, 0, 100, 480, "src/test/resources/preview.png", null);

await().atMost(5, TimeUnit.SECONDS).until(()-> f.exists());

Expand All @@ -676,7 +679,7 @@ public void testMuxingFinishedWithPreview(){
}

@Test
public void testMuxingFinished() {
public void testMuxingFinished() throws Exception {

AppSettings appSettings = new AppSettings();
appSettings.setMuxerFinishScript("src/test/resources/echo.sh");
Expand All @@ -688,16 +691,19 @@ public void testMuxingFinished() {
DataStoreFactory dsf = Mockito.mock(DataStoreFactory.class);
Mockito.when(dsf.getDataStore()).thenReturn(dataStore);
adapter.setDataStoreFactory(dsf);

Broadcast broadcast = new Broadcast();
broadcast.setStreamId("streamId");
dataStore.save(broadcast);

adapter.setVertx(vertx);

File anyFile = new File("src/test/resources/sample_MP4_480.mp4");

{

assertFalse(f.exists());

adapter.muxingFinished("streamId", anyFile, 0, 100, 480, null, null);
adapter.muxingFinished(broadcast, broadcast.getStreamId(), anyFile, 0, 100, 480, null, null);

await().atMost(5, TimeUnit.SECONDS).until(()-> f.exists());

Expand All @@ -715,7 +721,7 @@ public void testMuxingFinished() {

assertFalse(f.exists());

adapter.muxingFinished("streamId", anyFile, 0, 100, 480, "", null);
adapter.muxingFinished(broadcast, broadcast.getStreamId(), anyFile, 0, 100, 480, "", null);

await().pollDelay(3, TimeUnit.SECONDS).atMost(4, TimeUnit.SECONDS).until(()-> !f.exists());
}
Expand Down Expand Up @@ -1121,7 +1127,6 @@ public void testNotifyHookFromMuxingFinished() {
* So, no hook is posted
*/


ArgumentCaptor<String> captureUrl = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> captureId = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> captureMainTrackId = ArgumentCaptor.forClass(String.class);
Expand All @@ -1137,7 +1142,7 @@ public void testNotifyHookFromMuxingFinished() {


//call muxingFinished function
spyAdaptor.muxingFinished(streamId, anyFile, 0, 100, 480, null, null);
spyAdaptor.muxingFinished(broadcast, broadcast.getStreamId(), anyFile, 0, 100, 480, null, null);

//verify that notifyHook is never called
verify(spyAdaptor, never()).notifyHook(captureUrl.capture(), captureId.capture(), captureMainTrackId.capture(), captureAction.capture(),
Expand All @@ -1162,7 +1167,7 @@ public void testNotifyHookFromMuxingFinished() {
dataStore.updateBroadcastFields(streamId, update);

//call muxingFinished function
spyAdaptor.muxingFinished(streamId, anyFile, 0, 100, 480, null, null);
spyAdaptor.muxingFinished(broadcast, broadcast.getStreamId(), anyFile, 0, 100, 480, null, null);

await().atMost(10, TimeUnit.SECONDS).until(()-> {
boolean called = false;
Expand Down Expand Up @@ -1196,7 +1201,7 @@ public void testNotifyHookFromMuxingFinished() {
dataStore.delete(streamId);

//call muxingFinished function
spyAdaptor.muxingFinished(streamId, anyFile, 0, 100, 480, null, null);
spyAdaptor.muxingFinished("streamId", anyFile, 0, 100, 480, null, null);

await().atMost(10, TimeUnit.SECONDS).until(()-> {
boolean called = false;
Expand Down Expand Up @@ -1225,7 +1230,7 @@ public void testNotifyHookFromMuxingFinished() {
appSettings.setListenerHookURL("listenerHookURL");

//call muxingFinished function
spyAdaptor.muxingFinished(streamId, anyFile, 0, 100, 480, null, null);
spyAdaptor.muxingFinished(broadcast, broadcast.getStreamId(), anyFile, 0, 100, 480, null, null);

await().atMost(10, TimeUnit.SECONDS).until(()-> {
boolean called = false;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/antmedia/test/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public class Application extends AntMediaApplicationAdapter implements IAntMedia


@Override
public void muxingFinished(Broadcast broadcast, File file, long startTime, long duration, int resolution, String previewPath, String vodId) {
super.muxingFinished(broadcast, file, startTime, duration, resolution, previewPath, vodId);
public void muxingFinished(Broadcast broadcast, String streamId, File file, long startTime, long duration, int resolution, String previewPath, String vodId) {
super.muxingFinished(broadcast, streamId, file, startTime, duration, resolution, previewPath, vodId);
Application.id.add(broadcast.getStreamId());
Application.file.add(file);
Application.duration.add(duration);
Expand Down

0 comments on commit a421fc9

Please sign in to comment.