Skip to content

Commit

Permalink
Refactor code to call the same method to create mainTrack broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Nov 25, 2024
1 parent 6f6330e commit 93e9efc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/main/java/io/antmedia/AntMediaApplicationAdapter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.antmedia;

import static io.antmedia.muxer.IAntMediaStreamHandler.BROADCAST_STATUS_BROADCASTING;
import static org.bytedeco.ffmpeg.global.avcodec.avcodec_get_name;

import java.io.File;
Expand Down Expand Up @@ -687,6 +688,22 @@ public void closeBroadcast(String streamId) {
logger.error(ExceptionUtils.getStackTrace(e));
}
}

public static Broadcast saveMainBroadcast(String streamId, String mainTrackId, DataStore dataStore) {
Broadcast mainBroadcast = new Broadcast();
try {
mainBroadcast.setStreamId(mainTrackId);
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
}
mainBroadcast.setZombi(true);
mainBroadcast.setStatus(BROADCAST_STATUS_BROADCASTING);
mainBroadcast.getSubTrackStreamIds().add(streamId);
// don't set setOriginAdress because it's not a real stream and it causes extra delay -> mainBroadcast.setOriginAdress(serverSettings.getHostAddress())
mainBroadcast.setStartTime(System.currentTimeMillis());

return StringUtils.isNotBlank(dataStore.save(mainBroadcast)) ? mainBroadcast : null;
}

public static boolean isInstanceAlive(String originAdress, String hostAddress, int httpPort, String appName) {
if (StringUtils.isBlank(originAdress) || StringUtils.equals(originAdress, hostAddress)) {
Expand Down
11 changes: 1 addition & 10 deletions src/main/java/io/antmedia/muxer/MuxAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,16 +814,7 @@ public void registerToMainTrackIfExists() {
Broadcast mainBroadcast = getDataStore().get(mainTrack);
if(mainBroadcast == null)
{
mainBroadcast = new Broadcast();
try {
mainBroadcast.setStreamId(mainTrack);
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e));
}
mainBroadcast.setZombi(true);
mainBroadcast.setStatus(BROADCAST_STATUS_BROADCASTING);
mainBroadcast.getSubTrackStreamIds().add(streamId);
getDataStore().save(mainBroadcast);
mainBroadcast = AntMediaApplicationAdapter.saveMainBroadcast(streamId, mainTrack, getDataStore());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,16 @@ public void testAddRemovePacketListener() {


}

@Test
public void testSaveMainBroadcast()
{
DataStore dataStore = new InMemoryDataStore("test");
Broadcast mainTrack = AntMediaApplicationAdapter.saveMainBroadcast("streamId", "mainTrackId", dataStore);
assertNotNull(mainTrack);
//origin address must be null because main track is not a real stream
assertNull(mainTrack.getOriginAdress());
}

@Test
public void testAppDeletion()
Expand Down

0 comments on commit 93e9efc

Please sign in to comment.