Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run convert to hls asynch #128

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,16 @@ public void createRecordings()
{

List<Broadcast> broadcasts = dataStore.getLocalLiveBroadcasts(serverSettings.getHostAddress());
logger.info("createRecordings for active broadcasts size:{}", broadcasts.size());
for (Broadcast broadcast : broadcasts) {
convertHlsToMp4(broadcast, true);
logger.info("createRecordings for active broadcasts size:{} for app:{}", broadcasts.size(), appName);

for (Broadcast broadcast : broadcasts)
{
vertx.executeBlocking(() ->
{
convertHlsToMp4(broadcast, true);
return null;
}, false);

}
}

Expand Down Expand Up @@ -312,7 +319,7 @@ public synchronized Mp4CreationResponse convertHlsToMp4(Broadcast broadcast, boo
}

try {
logger.info("number of ts files: {} for streamId:{}", tsFilesToMerge.size(), streamId);
logger.info("number of ts files: {} for streamId:{} and startTime:{}", tsFilesToMerge.size(), streamId, dateFormat.format(new Date(startTime)));
File tsFileListTextFile = writeTsFilePathsToTxt(m3u8File, tsFilesToMerge);

String vodId = RandomStringUtils.randomNumeric(24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.antmedia.plugin.ClipCreatorPlugin;
import io.antmedia.plugin.ClipCreatorSettings;
import io.antmedia.plugin.Mp4CreationResponse;
import io.antmedia.settings.ServerSettings;
import io.lindstrom.m3u8.model.MediaPlaylist;
import io.lindstrom.m3u8.model.MediaSegment;
import io.lindstrom.m3u8.parser.MediaPlaylistParser;
Expand All @@ -25,8 +26,10 @@
import java.nio.file.Path;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import static io.smallrye.common.constraint.Assert.assertNotNull;
Expand All @@ -39,6 +42,41 @@ public class ClipCreatorPluginTest {


Vertx vertx = Vertx.vertx();

@Test
public void testCreateRecordingsAsync() throws Exception
{
ClipCreatorPlugin plugin = Mockito.spy(new ClipCreatorPlugin());

ApplicationContext context = Mockito.mock(ApplicationContext.class);

Vertx vertx =Mockito.mock(Vertx.class);
when(context.getBean("vertxCore")).thenReturn(vertx);

AntMediaApplicationAdapter applicationAdapter = Mockito.mock(AntMediaApplicationAdapter.class);
when(applicationAdapter.getScope()).thenReturn(Mockito.mock(org.red5.server.api.scope.IScope.class));

AppSettings appSettings = new AppSettings();
when(applicationAdapter.getAppSettings()).thenReturn(appSettings);

DataStore dataStore = Mockito.mock(io.antmedia.datastore.db.DataStore.class);
when(applicationAdapter.getDataStore()).thenReturn(dataStore);

when(context.getBean(AntMediaApplicationAdapter.BEAN_NAME)).thenReturn(applicationAdapter);
when(context.getBean(ServerSettings.BEAN_NAME)).thenReturn(new ServerSettings());

plugin.setApplicationContext(context);

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

when(dataStore.getLocalLiveBroadcasts(Mockito.anyString())).thenReturn(Arrays.asList(broadcast));

plugin.createRecordings();

verify(vertx, times(1)).executeBlocking((Callable)any(), eq(false));

}

@Test
public void testStartStopRecordingInInitialization() throws Exception
Expand Down