mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add RATE_UNSET option to encoder performance setting
This is to allow not setting the MediaFormat OPERATING_RATE and PRIORITY altogether. The current behvaiour, if left the value `UNSET`, it'll apply the our optimizations, but apps might want to disable this optimization. PiperOrigin-RevId: 675923909
This commit is contained in:
parent
f0fb386224
commit
fd3d8e1782
2 changed files with 21 additions and 8 deletions
|
|
@ -351,18 +351,21 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
||||||
: (int) floor(iFrameIntervalSeconds));
|
: (int) floor(iFrameIntervalSeconds));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Util.SDK_INT >= 23) {
|
int operatingRate = supportedVideoEncoderSettings.operatingRate;
|
||||||
|
int priority = supportedVideoEncoderSettings.priority;
|
||||||
|
if (Util.SDK_INT >= 23
|
||||||
|
&& operatingRate != VideoEncoderSettings.RATE_UNSET
|
||||||
|
&& priority != VideoEncoderSettings.RATE_UNSET) {
|
||||||
// Setting operating rate and priority is supported from API 23.
|
// Setting operating rate and priority is supported from API 23.
|
||||||
if (supportedVideoEncoderSettings.operatingRate == VideoEncoderSettings.NO_VALUE
|
if (operatingRate == VideoEncoderSettings.NO_VALUE
|
||||||
&& supportedVideoEncoderSettings.priority == VideoEncoderSettings.NO_VALUE) {
|
&& priority == VideoEncoderSettings.NO_VALUE) {
|
||||||
adjustMediaFormatForEncoderPerformanceSettings(mediaFormat);
|
adjustMediaFormatForEncoderPerformanceSettings(mediaFormat);
|
||||||
} else {
|
} else {
|
||||||
if (supportedVideoEncoderSettings.operatingRate != VideoEncoderSettings.NO_VALUE) {
|
if (operatingRate != VideoEncoderSettings.NO_VALUE) {
|
||||||
mediaFormat.setInteger(
|
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, operatingRate);
|
||||||
MediaFormat.KEY_OPERATING_RATE, supportedVideoEncoderSettings.operatingRate);
|
|
||||||
}
|
}
|
||||||
if (supportedVideoEncoderSettings.priority != VideoEncoderSettings.NO_VALUE) {
|
if (priority != VideoEncoderSettings.NO_VALUE) {
|
||||||
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, supportedVideoEncoderSettings.priority);
|
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ public final class VideoEncoderSettings {
|
||||||
/** A value for various fields to indicate that the field's value is unknown or not applicable. */
|
/** A value for various fields to indicate that the field's value is unknown or not applicable. */
|
||||||
public static final int NO_VALUE = Format.NO_VALUE;
|
public static final int NO_VALUE = Format.NO_VALUE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value for {@link Builder#setEncoderPerformanceParameters(int, int)} to disable setting
|
||||||
|
* performance parameters.
|
||||||
|
*/
|
||||||
|
public static final int RATE_UNSET = NO_VALUE - 1;
|
||||||
|
|
||||||
/** The default I-frame interval in seconds. */
|
/** The default I-frame interval in seconds. */
|
||||||
public static final float DEFAULT_I_FRAME_INTERVAL_SECONDS = 1.0f;
|
public static final float DEFAULT_I_FRAME_INTERVAL_SECONDS = 1.0f;
|
||||||
|
|
||||||
|
|
@ -168,6 +174,9 @@ public final class VideoEncoderSettings {
|
||||||
* Sets encoding operating rate and priority. The default values are {@link #NO_VALUE}, which is
|
* Sets encoding operating rate and priority. The default values are {@link #NO_VALUE}, which is
|
||||||
* treated as configuring the encoder for maximum throughput.
|
* treated as configuring the encoder for maximum throughput.
|
||||||
*
|
*
|
||||||
|
* <p>To disable the configuration for operating rate and priority, use {@link #RATE_UNSET} for
|
||||||
|
* both arguments.
|
||||||
|
*
|
||||||
* @param operatingRate The {@link MediaFormat#KEY_OPERATING_RATE operating rate} in frames per
|
* @param operatingRate The {@link MediaFormat#KEY_OPERATING_RATE operating rate} in frames per
|
||||||
* second.
|
* second.
|
||||||
* @param priority The {@link MediaFormat#KEY_PRIORITY priority}.
|
* @param priority The {@link MediaFormat#KEY_PRIORITY priority}.
|
||||||
|
|
@ -176,6 +185,7 @@ public final class VideoEncoderSettings {
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public Builder setEncoderPerformanceParameters(int operatingRate, int priority) {
|
public Builder setEncoderPerformanceParameters(int operatingRate, int priority) {
|
||||||
|
checkArgument((operatingRate == RATE_UNSET) == (priority == RATE_UNSET));
|
||||||
this.operatingRate = operatingRate;
|
this.operatingRate = operatingRate;
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue