From 7074771b4a5c64caffd21e036e6187c6d6f2f40c Mon Sep 17 00:00:00 2001 From: mekya Date: Mon, 30 Dec 2024 21:12:40 +0300 Subject: [PATCH] Add encoder parameters to AppSettings --- src/main/java/io/antmedia/AppSettings.java | 86 +++++++++++++++++-- .../antmedia/plugin/api/IStreamListener.java | 8 +- .../io/antmedia/test/AppSettingsUnitTest.java | 6 +- 3 files changed, 89 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/antmedia/AppSettings.java b/src/main/java/io/antmedia/AppSettings.java index 26403eed8..132363bbf 100644 --- a/src/main/java/io/antmedia/AppSettings.java +++ b/src/main/java/io/antmedia/AppSettings.java @@ -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> 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 = ""; @@ -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 = ""; @@ -1410,8 +1441,10 @@ 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; /** @@ -1419,8 +1452,11 @@ public class AppSettings implements Serializable{ * best * good * realtime + * + * @Deprecated use {@link #encoderParameters} */ @Value( "${vp8EncoderDeadline:${" + SETTINGS_ENCODING_VP8_DEADLINE +":realtime}}") + @Deprecated private String vp8EncoderDeadline = "realtime"; /** @@ -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; /** @@ -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"; /** @@ -4179,4 +4235,18 @@ public int getS3TransferBufferSizeInBytes() { public void setS3TransferBufferSizeInBytes(int s3TransferBufferSizeInBytes) { this.s3TransferBufferSizeInBytes = s3TransferBufferSizeInBytes; } + + /** + * @return the encoderParameters + */ + public Map> getEncoderParameters() { + return encoderParameters; + } + + /** + * @param encoderParameters the encoderParameters to set + */ + public void setEncoderParameters(Map> encoderParameters) { + this.encoderParameters = encoderParameters; + } } diff --git a/src/main/java/io/antmedia/plugin/api/IStreamListener.java b/src/main/java/io/antmedia/plugin/api/IStreamListener.java index 4fb3bd463..2fe30c30e 100644 --- a/src/main/java/io/antmedia/plugin/api/IStreamListener.java +++ b/src/main/java/io/antmedia/plugin/api/IStreamListener.java @@ -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. @@ -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. diff --git a/src/test/java/io/antmedia/test/AppSettingsUnitTest.java b/src/test/java/io/antmedia/test/AppSettingsUnitTest.java index 1f7dd9a0c..4fcac4d91 100644 --- a/src/test/java/io/antmedia/test/AppSettingsUnitTest.java +++ b/src/test/java/io/antmedia/test/AppSettingsUnitTest.java @@ -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); }