Skip to content

Commit

Permalink
Add encoder parameters to AppSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
mekya committed Dec 30, 2024
1 parent a792d34 commit 7074771
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 11 deletions.
86 changes: 78 additions & 8 deletions src/main/java/io/antmedia/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1346,41 +1346,69 @@ public class AppSettings implements Serializable{
/**
* Name of the encoder to be used in adaptive bitrate,
* If there is a GPU, server tries to open h264_nvenc,
* If there is no GPU, server tries to open libx264 by default
* Can be h264_nvenc or libx264. If you set h264_nvenc but it cannot be opened then libx264 will be used,
* Name of the encoder to be used in adaptive bitrate,
* If there is a GPU, server tries to open h264_nvenc,
* If there is no GPU, server tries to open libx264 by default
* If there is no GPU, server tries to open openh264 by default
* Can be h264_nvenc or openh264. If you set h264_nvenc and then if it cannot be opened, libx264 will be used,
*/
@Value( "${encoderName:${" + SETTINGS_ENCODING_ENCODER_NAME +":}}")
private String encoderName = "";

/**
* Encoder specific parameters in key-value mapping way with JSON objects.
*
* Keys should match the encoder names officially in ffmpeg for instance libopenh264, h264_nvenc, vpx, hevc_nvenc
*
* Then you can have a json object like this which includes the parameters for the encoder
* {
* "libopenh264": {
* "profile":"main",
*
* },
* "vpx": {
* "deadline":"realtime",
* },
* "h264_nvenc": {
* "preset":"ll"
* }
* }
*/
@Value("${encoderParameters:{}}")
private Map<String, Map<String,String>> encoderParameters = new HashMap<>();

/**
* Encoder's preset value in adaptive bitrate
* Libx264 presets are there
* https://trac.ffmpeg.org/wiki/Encode/H.264
* Ant Media Server uses "veryfast" by default
*
* @Deprecated use {@link #encoderParameters}
*
*/
@Value("${encoderPreset:${" + SETTINGS_ENCODING_PRESET +":}}")
@Deprecated
private String encoderPreset = "";

/**
* Encoder profile in adaptive bitrate,
* It's baseline by default.
* @Deprecated use {@link #encoderParameters}
*/
@Value( "${encoderProfile:${" + SETTINGS_ENCODING_PROFILE +":}}")
@Deprecated
private String encoderProfile = "";

/**
* Encoder level in adaptive bitrate
* @Deprecated use {@link #encoderParameters}
*/
@Deprecated
@Value( "${encoderLevel:${" + SETTINGS_ENCODING_LEVEL +":}}")
private String encoderLevel = "";

/**
* Encoding rate control in adaptive bitrate
* @Deprecated use {@link #encoderParameters}
*/
@Deprecated
@Value( "${encoderRc:${" + SETTINGS_ENCODING_RC +":}}")
private String encoderRc = "";

Expand All @@ -1389,7 +1417,10 @@ public class AppSettings implements Serializable{
* This is the x264-params in ffmpeg
* Specific settings for selected encoder,
* For libx264 please check https://trac.ffmpeg.org/wiki/Encode/H.264
*
* @Deprecated use {@link #encoderParameters}
*/
@Deprecated
@Value( "${encoderSpecific:${" + SETTINGS_ENCODING_SPECIFIC +":}}")
private String encoderSpecific = "";

Expand All @@ -1410,17 +1441,22 @@ public class AppSettings implements Serializable{

/**
* Set quality/speed ratio modifier, Higher values speed up the encode at the cost of quality.
* @Deprecated use {@link #encoderParameters}
*/
@Value( "${vp8EncoderSpeed:${" + SETTINGS_ENCODING_VP8_SPEED +":4}}")
@Deprecated
private int vp8EncoderSpeed = 4;

/**
* VP8 Encoder deadline:
* best
* good
* realtime
*
* @Deprecated use {@link #encoderParameters}
*/
@Value( "${vp8EncoderDeadline:${" + SETTINGS_ENCODING_VP8_DEADLINE +":realtime}}")
@Deprecated
private String vp8EncoderDeadline = "realtime";

/**
Expand Down Expand Up @@ -1720,15 +1756,34 @@ public class AppSettings implements Serializable{
@Value("${dataChannelWebHookURL:${" + SETTINGS_DATA_CHANNEL_WEBHOOK_URL+":}}")
private String dataChannelWebHookURL = "";


/**
* @Deprecated. Please use {@link #encoderParameters}
*/
@Deprecated
private String h265EncoderPreset;


/**
* @Deprecated. Please use {@link #encoderParameters}
*/
@Deprecated
private String h265EncoderProfile;

/**
* @Deprecated. Please use {@link #encoderParameters}
*/
@Deprecated
private String h265EncoderRc;

/**
* @Deprecated. Please use {@link #encoderParameters}
*/
@Deprecated
private String h265EncoderSpecific;

/**
* @Deprecated. Please use {@link #encoderParameters}
*/
@Deprecated
private String h265EncoderLevel;

/**
Expand Down Expand Up @@ -1781,9 +1836,10 @@ public class AppSettings implements Serializable{
/**
* Constant Rate Factor used by x264, x265, VP8,
* Use values between 4-51
*
* @Deprecated. Please use {@link #encoderParameters}
*/
@Value("${constantRateFactor:${"+SETTINGS_CONSTANT_RATE_FACTOR+":23}}")
@Deprecated
private String constantRateFactor = "23";

/**
Expand Down Expand Up @@ -4179,4 +4235,18 @@ public int getS3TransferBufferSizeInBytes() {
public void setS3TransferBufferSizeInBytes(int s3TransferBufferSizeInBytes) {
this.s3TransferBufferSizeInBytes = s3TransferBufferSizeInBytes;
}

/**
* @return the encoderParameters
*/
public Map<String, Map<String,String>> getEncoderParameters() {
return encoderParameters;
}

/**
* @param encoderParameters the encoderParameters to set
*/
public void setEncoderParameters(Map<String, Map<String,String>> encoderParameters) {
this.encoderParameters = encoderParameters;
}
}
8 changes: 6 additions & 2 deletions src/main/java/io/antmedia/plugin/api/IStreamListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public interface IStreamListener {
* @Deprecated use {@link #streamStarted(Broadcast)} because Broadcast object may be deleted when this method is called
*/
@Deprecated (since="3.0", forRemoval = true)
public void streamStarted(String streamId);
public default void streamStarted(String streamId) {
//do nothing
}

/**
* AMS inform the plugins when a stream is started with this method.
Expand All @@ -31,7 +33,9 @@ public default void streamStarted(Broadcast broadcast) {
* @Deprecated use {@link #streamFinished(Broadcast)} because Broadcast object may be deleted when this method is called
*/
@Deprecated (since="3.0", forRemoval = true)
public void streamFinished(String streamId);
public default void streamFinished(String streamId) {
//do nothing
}

/**
* AMS inform the plugins when a stream is finished with this method.
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/io/antmedia/test/AppSettingsUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,17 @@ public void testUnsetAppSettings(AppSettings appSettings) {
assertEquals(10000000, appSettings.getS3TransferBufferSizeInBytes());
appSettings.setS3TransferBufferSizeInBytes(50000);
assertEquals(50000, appSettings.getS3TransferBufferSizeInBytes());

map = appSettings.getEncoderParameters();
assertNotNull(map);
assertEquals(0, map.size());

//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.",
198, numberOfFields);
199, numberOfFields);
}


Expand Down

0 comments on commit 7074771

Please sign in to comment.