Skip to content

Commit

Permalink
Merge pull request #6347 from ant-media/recordSubfolder
Browse files Browse the repository at this point in the history
Add recording subfolder setting
  • Loading branch information
mekya authored May 28, 2024
2 parents 88adc23 + 2b45c36 commit 845967b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 10 deletions.
14 changes: 14 additions & 0 deletions src/main/java/io/antmedia/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,12 @@ public boolean isWriteStatsToDatastore() {
@Value("${webhookPlayAuthUrl:}")
private String webhookPlayAuthUrl = "";

/**
* Subfolder for the recording files (mp4 and webm)
*/
@Value("${recordingSubfolder:#{null}}")
private String recordingSubfolder;


public void setWriteStatsToDatastore(boolean writeStatsToDatastore) {
this.writeStatsToDatastore = writeStatsToDatastore;
Expand Down Expand Up @@ -2571,6 +2577,7 @@ public void resetDefaults() {
aacEncodingEnabled=true;
ipFilterEnabled=true;
ingestingStreamLimit = -1;
recordingSubfolder = null;
}

public int getWebRTCPortRangeMax() {
Expand Down Expand Up @@ -3730,4 +3737,11 @@ public void setHlsSegmentType(String hlsSegmentType) {
this.hlsSegmentType = hlsSegmentType;
}

public String getRecordingSubfolder() {
return recordingSubfolder;
}

public void setRecordingSubfolder(String recordingSubfolder) {
this.recordingSubfolder = recordingSubfolder;
}
}
1 change: 0 additions & 1 deletion src/main/java/io/antmedia/muxer/HLSMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class HLSMuxer extends Muxer {
private String hlsEncryptionKeyInfoFile = null;

protected StorageClient storageClient = null;
private String subFolder = null;
private String s3StreamsFolderPath = "streams";
private boolean uploadHLSToS3 = true;
private String segmentFilename;
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/io/antmedia/muxer/Muxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ public abstract class Muxer {
avRationalTimeBase.den(1);
}

protected String subFolder = null;

/**
* This class is used generally to send direct video buffer to muxer
* @author mekya
Expand Down Expand Up @@ -646,8 +648,8 @@ public void init(IScope scope, final String name, int resolution, boolean overri

initialResourceNameWithoutExtension = getExtendedName(name, resolution, bitrate, appSettings.getFileNameFormat());


file = getResourceFile(scope, initialResourceNameWithoutExtension, extension, subFolder);
setSubfolder(subFolder);
file = getResourceFile(scope, initialResourceNameWithoutExtension, extension, this.subFolder);

File parentFile = file.getParentFile();

Expand All @@ -657,14 +659,14 @@ public void init(IScope scope, final String name, int resolution, boolean overri
} else {
// if parent file exists,
// check overrideIfExist and file.exists
File tempFile = getResourceFile(scope, initialResourceNameWithoutExtension, extension+TEMP_EXTENSION, subFolder);
File tempFile = getResourceFile(scope, initialResourceNameWithoutExtension, extension+TEMP_EXTENSION, this.subFolder);

if (!overrideIfExist && (file.exists() || tempFile.exists())) {
String tmpName = initialResourceNameWithoutExtension;
int i = 1;
do {
tempFile = getResourceFile(scope, tmpName, extension+TEMP_EXTENSION, subFolder);
file = getResourceFile(scope, tmpName, extension, subFolder);
tempFile = getResourceFile(scope, tmpName, extension+TEMP_EXTENSION, this.subFolder);
file = getResourceFile(scope, tmpName, extension, this.subFolder);
tmpName = initialResourceNameWithoutExtension + "_" + i;
i++;
} while (file.exists() || tempFile.exists());
Expand All @@ -683,6 +685,10 @@ public void init(IScope scope, final String name, int resolution, boolean overri
}
}

public void setSubfolder(String subFolder) {
this.subFolder = subFolder;
}

public AppSettings getAppSettings() {
IContext context = this.scope.getContext();
ApplicationContext appCtx = context.getApplicationContext();
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/io/antmedia/muxer/RecordMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.nio.file.Files;

import org.apache.tika.utils.StringUtils;
import org.bytedeco.ffmpeg.avformat.AVFormatContext;
import org.bytedeco.ffmpeg.avformat.AVStream;
import org.red5.server.api.IContext;
Expand All @@ -29,8 +30,6 @@ public abstract class RecordMuxer extends Muxer {

protected String previewPath;

private String subFolder = null;

private static final int S3_CONSTANT = 0b001;

private String s3FolderPath = "streams";
Expand Down Expand Up @@ -75,7 +74,8 @@ public void init(IScope scope, final String name, int resolutionHeight, String s

this.streamId = name;
this.resolution = resolutionHeight;
this.subFolder = subFolder;



this.startTime = System.currentTimeMillis();

Expand Down Expand Up @@ -228,5 +228,19 @@ public void setVodId(String vodId) {
this.vodId = vodId;
}

public void setSubfolder(String subFolder) {
this.subFolder = subFolder;

String recordingSubfolder = getAppSettings().getRecordingSubfolder();
if(!StringUtils.isBlank(recordingSubfolder)) {
if(!StringUtils.isBlank(this.subFolder)) {
this.subFolder = subFolder + File.separator + recordingSubfolder;
}
else {
this.subFolder = recordingSubfolder;
}
}
}


}
10 changes: 9 additions & 1 deletion src/test/java/io/antmedia/test/AppSettingsUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ public void testSettings() {
appSettings.setWebhookPlayAuthUrl(webhookPlayAuthUrl);
assertEquals(webhookPlayAuthUrl, appSettings.getWebhookPlayAuthUrl());

String recordinfSubFolder = "subfolder";
appSettings.setRecordingSubfolder(recordinfSubFolder);
assertEquals(recordinfSubFolder, appSettings.getRecordingSubfolder());


}


Expand Down Expand Up @@ -556,12 +561,15 @@ public void testUnsetAppSettings(AppSettings appSettings) {
assertFalse(appSettings.isWebhookPlayAuthEnabled());
assertEquals("", appSettings.getWebhookPlayAuthUrl());

assertNull(appSettings.getRecordingSubfolder());


//if we add a new field, we just need to check its default value in this test
//When a new field is added or removed please update the number of fields and make this test pass
//by also checking its default value.

assertEquals("New field is added to settings. PAY ATTENTION: Please CHECK ITS DEFAULT VALUE and fix the number of fields.",
181, numberOfFields);
182, numberOfFields);


}
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/io/antmedia/test/MuxerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4555,4 +4555,11 @@ public void testSetSEIData() {
muxAdaptorReal.addSEIData(data);
verify(hlsMuxer, times(1)).setSeiData(data);
}

@Test
public void testRecordingWithRecordingSubfolder() {
appSettings.setRecordingSubfolder("records");
testMp4Muxing("record" + RandomUtils.nextInt(0, 10000));
}

}
7 changes: 7 additions & 0 deletions src/test/java/io/antmedia/test/StreamSchedularUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,13 @@ public void testSkipPlaylistItem() {
Awaitility.await().atMost(20, TimeUnit.SECONDS)
.until(() ->dataStore.get(streamId).getCurrentPlayIndex() == 0);

Awaitility.await().atMost(20, TimeUnit.SECONDS)
.until(() -> {
File f = new File("webapps/junit/streams/testPlaylistStreamId.m3u8");
return f.exists();
});


{
// It means that it will skip next playlist item
Result result = service.playNextItem(streamId, null);
Expand Down

0 comments on commit 845967b

Please sign in to comment.