Skip to content

Commit

Permalink
move mainTrackId to parent Muxer
Browse files Browse the repository at this point in the history
  • Loading branch information
lastpeony committed Nov 27, 2024
1 parent c9b6a46 commit 044a876
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 60 deletions.
10 changes: 9 additions & 1 deletion src/main/java/io/antmedia/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,16 @@ public class AppSettings implements Serializable{
*
* If main track ID or stream ID are null, they are omitted.
*/
@Value( "${s3StreamsFolderPath:${"+SETTINGS_S3_STREAMS_FOLDER_PATH+":streams}}" )
private String s3StreamsFolderPath="streams";

/**
* It's S3 stream PNG files storage name .
* It's previews by default.
*
*/
@Value("${s3PreviewsFolderPath:${"+SETTINGS_S3_PREVIEWS_FOLDER_PATH+":previews}}")
private String s3PreviewsFolderPath="previews";
private String s3PreviewsFolderPath="previews";

/*
* Use http endpoint in CMAF/HLS.
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/io/antmedia/muxer/HLSMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public class HLSMuxer extends Muxer {
private String s3StreamsFolderPath = "streams";
private boolean uploadHLSToS3 = true;
private String segmentFilename;
private String mainTrackId = null;


/**
* HLS Segment Type. It can be "mpegts" or "fmp4"
*
Expand Down Expand Up @@ -136,11 +135,10 @@ public void setHlsParameters(String hlsListSize, String hlsTime, String hlsPlayL
public void init(IScope scope, String name, int resolutionHeight, String subFolder, int bitrate, String mainTrackId) {
if (!isInitialized) {

super.init(scope, name, resolutionHeight, subFolder, bitrate);
super.init(scope, name, resolutionHeight, subFolder, bitrate, mainTrackId);

streamId = name;
this.subFolder = subFolder;
this.mainTrackId = mainTrackId;
options.put("hls_list_size", hlsListSize);
options.put("hls_time", hlsTime);

Expand Down Expand Up @@ -660,11 +658,4 @@ public ByteBuffer getPendingSEIData() {
return pendingSEIData;
}

public String getMainTrackId() {
return mainTrackId;
}

public void setMainTrackId(String mainTrackId) {
this.mainTrackId = mainTrackId;
}
}
8 changes: 2 additions & 6 deletions src/main/java/io/antmedia/muxer/MuxAdaptor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.antmedia.muxer;

import static io.antmedia.muxer.IAntMediaStreamHandler.BROADCAST_STATUS_BROADCASTING;
import static org.bytedeco.ffmpeg.global.avcodec.AV_CODEC_ID_AAC;
import static org.bytedeco.ffmpeg.global.avcodec.AV_CODEC_ID_H264;
import static org.bytedeco.ffmpeg.global.avcodec.AV_CODEC_ID_H265;
Expand All @@ -18,15 +17,13 @@
import static org.bytedeco.ffmpeg.global.avutil.av_malloc;
import static org.bytedeco.ffmpeg.global.avutil.av_rescale_q;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -62,7 +59,6 @@
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.red5.server.api.stream.IStreamPacket;
import org.red5.server.net.rtmp.event.AudioData;
import org.red5.server.net.rtmp.event.CachedEvent;
import org.red5.server.net.rtmp.event.Notify;
import org.red5.server.net.rtmp.event.VideoData;
Expand Down Expand Up @@ -525,7 +521,7 @@ public boolean init(IScope scope, String streamId, boolean isAppend) {
}

for (Muxer muxer : muxerList) {
muxer.init(scope, streamId, 0, broadcast.getSubFolder(), 0);
muxer.init(scope, streamId, 0, broadcast.getSubFolder(), 0, null);
}
getStreamHandler().muxAdaptorAdded(this);
return true;
Expand Down Expand Up @@ -2226,7 +2222,7 @@ public boolean prepareMuxer(Muxer muxer, int resolutionHeight)
{
boolean streamAdded = false;

muxer.init(scope, streamId, resolutionHeight, broadcast != null ? broadcast.getSubFolder(): null, 0);
muxer.init(scope, streamId, resolutionHeight, broadcast != null ? broadcast.getSubFolder(): null, 0, null);
logger.info("prepareMuxer for stream:{} muxer:{}", streamId, muxer.getClass().getSimpleName());

if (streamSourceInputFormatContext != null)
Expand Down
42 changes: 24 additions & 18 deletions src/main/java/io/antmedia/muxer/Muxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.bytedeco.ffmpeg.global.avcodec;
import org.bytedeco.ffmpeg.global.avformat;
import org.bytedeco.javacpp.BytePointer;
import org.json.simple.JSONObject;
import org.red5.server.api.IContext;
import org.red5.server.api.scope.IScope;
import org.red5.server.api.stream.IStreamFilenameGenerator;
Expand Down Expand Up @@ -180,6 +179,7 @@ public abstract class Muxer {
}

protected String subFolder = null;
protected String mainTrackId = null;

/**
* This class is used generally to send direct video buffer to muxer
Expand Down Expand Up @@ -622,40 +622,38 @@ public String getFormat() {
* Inits the file to write. Multiple encoders can init the muxer. It is
* redundant to init multiple times.
*/
public void init(IScope scope, String name, int resolution, String subFolder, int videoBitrate) {
public void init(IScope scope, String name, int resolution, String subFolder, int videoBitrate, String mainTrackId) {
this.streamId = name;
init(scope, name, resolution, true, subFolder, videoBitrate);
init(scope, name, resolution, true, subFolder, videoBitrate, null);
}

/**
* Init file name
*
* <p>
* file format is NAME[-{DATETIME}][_{RESOLUTION_HEIGHT}p_{BITRATE}kbps].{EXTENSION}
*
* <p>
* Datetime format is yyyy-MM-dd_HH-mm
*
* <p>
* We are using "-" instead of ":" in HH:mm -> Stream filename must not contain ":" character.
*
* <p>
* sample naming -> stream1-yyyy-MM-dd_HH-mm_480p_500kbps.mp4 if datetime is added
* stream1_480p.mp4 if no datetime
*
* @param name, name of the stream
* @param scope
* @param name,
* name of the stream
* @param resolution
* height of the stream, if it is zero, then no resolution will
* be added to resource name
* @param overrideIfExist
* whether override if a file exists with the same name
* @param bitrate
* bitrate of the stream, if it is zero, no bitrate will
* be added to resource name
* @param resolution height of the stream, if it is zero, then no resolution will
* be added to resource name
* @param overrideIfExist whether override if a file exists with the same name
* @param bitrate bitrate of the stream, if it is zero, no bitrate will
* be added to resource name
* @param mainTrackId
*/
public void init(IScope scope, final String name, int resolution, boolean overrideIfExist, String subFolder, int bitrate) {
public void init(IScope scope, final String name, int resolution, boolean overrideIfExist, String subFolder, int bitrate, String mainTrackId) {
if (!isInitialized) {
isInitialized = true;
this.scope = scope;
this.resolution = resolution;
this.mainTrackId = mainTrackId;

//Refactor: Getting AppSettings smells here
AppSettings appSettings = getAppSettings();
Expand Down Expand Up @@ -1487,4 +1485,12 @@ public String getSubFolder() {
return subFolder;
}

public String getMainTrackId() {
return mainTrackId;
}

public void setMainTrackId(String mainTrackId) {
this.mainTrackId = mainTrackId;
}

}
4 changes: 2 additions & 2 deletions src/main/java/io/antmedia/muxer/RecordMuxer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public boolean isCodecSupported(int codecId) {
* {@inheritDoc}
*/
@Override
public void init(IScope scope, final String name, int resolutionHeight, String subFolder, int bitrate) {
super.init(scope, name, resolutionHeight, false, subFolder, bitrate);
public void init(IScope scope, final String name, int resolutionHeight, String subFolder, int bitrate, String mainTrackId) {
super.init(scope, name, resolutionHeight, false, subFolder, bitrate, null);

this.streamId = name;
this.resolution = resolutionHeight;
Expand Down
42 changes: 21 additions & 21 deletions src/test/java/io/antmedia/test/MuxerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void testAddAudioStream() {
Mp4Muxer mp4Muxer = new Mp4Muxer(Mockito.mock(StorageClient.class), vertx, "");
appScope = (WebScope) applicationContext.getBean("web.scope");

mp4Muxer.init(appScope, "test", 0, "", 0);
mp4Muxer.init(appScope, "test", 0, "", 0, null);
assertEquals(0, mp4Muxer.getOutputFormatContext().nb_streams());
AVChannelLayout layout = new AVChannelLayout();
av_channel_layout_default(layout, 1);
Expand All @@ -341,7 +341,7 @@ public void testAddAudioStream() {
public void testAddExtradata() {
Mp4Muxer mp4Muxer = new Mp4Muxer(Mockito.mock(StorageClient.class), vertx, "");
appScope = (WebScope) applicationContext.getBean("web.scope");
mp4Muxer.init(appScope, "test", 0, "", 0);
mp4Muxer.init(appScope, "test", 0, "", 0, null);

AVCodecContext codecContext = new AVCodecContext();
codecContext.width(640);
Expand Down Expand Up @@ -372,7 +372,7 @@ public void testAddExtradata() {
public void testInitVideoBitstreamFilter() {
Mp4Muxer mp4Muxer = new Mp4Muxer(Mockito.mock(StorageClient.class), vertx, "");
appScope = (WebScope) applicationContext.getBean("web.scope");
mp4Muxer.init(appScope, "test", 0, "", 0);
mp4Muxer.init(appScope, "test", 0, "", 0, null);
mp4Muxer.getOutputFormatContext();

mp4Muxer.setBitstreamFilter("h264_mp4toannexb");
Expand All @@ -392,9 +392,9 @@ public void testAddStream() {

mp4Muxer.clearResource();

mp4Muxer.init(appScope, "test", 0, "", 0);
mp4Muxer.init(appScope, "test", 0, "", 0, null);
//increase coverage
mp4Muxer.init(appScope, "test", 0, "", 0);
mp4Muxer.init(appScope, "test", 0, "", 0, null);

AVCodecContext codecContext = new AVCodecContext();
codecContext.width(640);
Expand Down Expand Up @@ -426,7 +426,7 @@ public void testContextChanged() {
Mp4Muxer mp4Muxer = new Mp4Muxer(Mockito.mock(StorageClient.class), vertx, "");
appScope = (WebScope) applicationContext.getBean("web.scope");

mp4Muxer.init(appScope, "test", 0, "", 0);
mp4Muxer.init(appScope, "test", 0, "", 0, null);
assertEquals(0, mp4Muxer.getOutputFormatContext().nb_streams());

AVCodecContext codecContext = new AVCodecContext();
Expand Down Expand Up @@ -804,11 +804,11 @@ public void testIsCodecSupported() {
appScope = (WebScope) applicationContext.getBean("web.scope");

Mp4Muxer mp4Muxer = new Mp4Muxer(null, null, "streams");
mp4Muxer.init(appScope, "test", 0, null, 0);
mp4Muxer.init(appScope, "test", 0, null, 0, null);


WebMMuxer webMMuxer = new WebMMuxer(null, null, "streams");
webMMuxer.init(appScope, "test", 0, null, 0);
webMMuxer.init(appScope, "test", 0, null, 0, null);


assertFalse(webMMuxer.isCodecSupported(AV_CODEC_ID_H264));
Expand All @@ -825,7 +825,7 @@ public void testStreamIndex() {
Mp4Muxer mp4Muxer = new Mp4Muxer(null, vertx, "streams");

appScope = (WebScope) applicationContext.getBean("web.scope");
mp4Muxer.init(appScope, "test", 0, null, 0);
mp4Muxer.init(appScope, "test", 0, null, 0, null);

SPSParser spsParser = new SPSParser(extradata_original, 5);

Expand Down Expand Up @@ -858,7 +858,7 @@ public void testStreamIndex() {


RtmpMuxer rtmpMuxer = new RtmpMuxer("any_url", vertx);
rtmpMuxer.init(appScope, "test", 0, null, 0);
rtmpMuxer.init(appScope, "test", 0, null, 0, null);
rtmpMuxer.addStream(codecParameters, rat, 50);

}
Expand Down Expand Up @@ -1236,7 +1236,7 @@ public void testAVWriteFrame() {

appScope = (WebScope) applicationContext.getBean("web.scope");

rtmpMuxer.init(appScope, "", 0, "", 0);
rtmpMuxer.init(appScope, "", 0, "", 0, null);

rtmpMuxer.avWriteFrame(pkt, context);

Expand Down Expand Up @@ -1417,7 +1417,7 @@ public void testRTMPWriteCrash() {

RtmpMuxer rtmpMuxer = new RtmpMuxer("any_url", vertx);

rtmpMuxer.init(appScope, "test", 0, null, 0);
rtmpMuxer.init(appScope, "test", 0, null, 0, null);
rtmpMuxer.addStream(codecParameters, rat, 50);
assertTrue(rtmpMuxer.openIO());

Expand Down Expand Up @@ -1510,7 +1510,7 @@ public void testMp4MuxerDirectStreaming() {

Mp4Muxer mp4Muxer = new Mp4Muxer(null, vertx, "streams");

mp4Muxer.init(appScope, "test", 0, null, 0);
mp4Muxer.init(appScope, "test", 0, null, 0, null);


SPSParser spsParser = new SPSParser(extradata_original, 5);
Expand Down Expand Up @@ -3061,7 +3061,7 @@ public void testMp4MuxingWithDirectParams() {

String streamName = "stream_name_" + (int) (Math.random() * 10000);
//init
mp4Muxer.init(appScope, streamName, 0, null, 0);
mp4Muxer.init(appScope, streamName, 0, null, 0, null);

//add stream
int width = 640;
Expand Down Expand Up @@ -3212,7 +3212,7 @@ public void testRecordMuxingWithDirectParams() {

String streamName = "stream_name_" + (int) (Math.random() * 10000);
//init
mp4Muxer.init(appScope, streamName, 0, null, 0);
mp4Muxer.init(appScope, streamName, 0, null, 0, null);

//add stream
int width = 640;
Expand Down Expand Up @@ -3302,7 +3302,7 @@ public void testMp4FinalName() {
{
Mp4Muxer mp4Muxer = new Mp4Muxer(client, vertx, "streams");
//init
mp4Muxer.init(appScope, streamName, 0, null, 0);
mp4Muxer.init(appScope, streamName, 0, null, 0, null);

//initialize tmp file
mp4Muxer.getOutputFormatContext();
Expand All @@ -3326,7 +3326,7 @@ public void testMp4FinalName() {

Mp4Muxer mp4Muxer = new Mp4Muxer(client, vertx, "streams");
//init
mp4Muxer.init(appScope, streamName, 0, null, 0);
mp4Muxer.init(appScope, streamName, 0, null, 0, null);

//initialize tmp file
mp4Muxer.getOutputFormatContext();
Expand Down Expand Up @@ -3360,7 +3360,7 @@ public void testMp4FinalName() {

Mp4Muxer mp4Muxer = new Mp4Muxer(client, vertx, "streams");
//init
mp4Muxer.init(appScope, streamName, 0, null, 0);
mp4Muxer.init(appScope, streamName, 0, null, 0, null);

//initialize tmp file
mp4Muxer.getOutputFormatContext();
Expand All @@ -3384,7 +3384,7 @@ public void testMp4FinalName() {

WebMMuxer webMMuxer = new WebMMuxer(client, vertx, "streams");
//init
webMMuxer.init(appScope, streamName, 0, null, 0);
webMMuxer.init(appScope, streamName, 0, null, 0, null);

//initialize tmp file
webMMuxer.getOutputFormatContext();
Expand Down Expand Up @@ -4721,7 +4721,7 @@ public void testMp4MuxingWithSameNameWhileRecording() {
doReturn(existingTempFile_1).when(mp4Muxer).getResourceFile(any(), eq(streamId + "_1"), eq(".mp4" + Muxer.TEMP_EXTENSION), eq(null));
doReturn(nonExistingTempFile_2).when(mp4Muxer).getResourceFile(any(), eq(streamId + "_2"), eq(".mp4" + Muxer.TEMP_EXTENSION), eq(null));

mp4Muxer.init(appScope, streamId, 0, false, null, 0);
mp4Muxer.init(appScope, streamId, 0, false, null, 0, null);

assertEquals(nonExistingFile_2, mp4Muxer.getFile());

Expand Down Expand Up @@ -4830,7 +4830,7 @@ public void testMp4MuxingWhileTempFileExist() {
doReturn(existingTempFile).when(mp4Muxer).getResourceFile(any(), eq(streamId), eq(".mp4" + Muxer.TEMP_EXTENSION), eq(null));
doReturn(nonExistingTempFile_1).when(mp4Muxer).getResourceFile(any(), eq(streamId + "_1"), eq(".mp4" + Muxer.TEMP_EXTENSION), eq(null));

mp4Muxer.init(appScope, streamId, 0, false, null, 0);
mp4Muxer.init(appScope, streamId, 0, false, null, 0, null);

assertEquals(nonExistingFile_1, mp4Muxer.getFile());

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/antmedia/test/StreamFetcherUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ public void testBugUnexpectedStream() throws InterruptedException

Mp4Muxer mp4Muxer = Mockito.spy(new Mp4Muxer(null, null, "streams"));

mp4Muxer.init(appScope, "test", 480, null, 750);
mp4Muxer.init(appScope, "test", 480, null, 750, null);


Mockito.doReturn(true).when(mp4Muxer).isCodecSupported(Mockito.anyInt());
Expand Down

0 comments on commit 044a876

Please sign in to comment.