mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08: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
@ -351,18 +351,21 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
||||
: (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.
|
||||
if (supportedVideoEncoderSettings.operatingRate == VideoEncoderSettings.NO_VALUE
|
||||
&& supportedVideoEncoderSettings.priority == VideoEncoderSettings.NO_VALUE) {
|
||||
if (operatingRate == VideoEncoderSettings.NO_VALUE
|
||||
&& priority == VideoEncoderSettings.NO_VALUE) {
|
||||
adjustMediaFormatForEncoderPerformanceSettings(mediaFormat);
|
||||
} else {
|
||||
if (supportedVideoEncoderSettings.operatingRate != VideoEncoderSettings.NO_VALUE) {
|
||||
mediaFormat.setInteger(
|
||||
MediaFormat.KEY_OPERATING_RATE, supportedVideoEncoderSettings.operatingRate);
|
||||
if (operatingRate != VideoEncoderSettings.NO_VALUE) {
|
||||
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, operatingRate);
|
||||
}
|
||||
if (supportedVideoEncoderSettings.priority != VideoEncoderSettings.NO_VALUE) {
|
||||
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, supportedVideoEncoderSettings.priority);
|
||||
if (priority != VideoEncoderSettings.NO_VALUE) {
|
||||
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. */
|
||||
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. */
|
||||
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
|
||||
* 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
|
||||
* second.
|
||||
* @param priority The {@link MediaFormat#KEY_PRIORITY priority}.
|
||||
@ -176,6 +185,7 @@ public final class VideoEncoderSettings {
|
||||
@CanIgnoreReturnValue
|
||||
@VisibleForTesting
|
||||
public Builder setEncoderPerformanceParameters(int operatingRate, int priority) {
|
||||
checkArgument((operatingRate == RATE_UNSET) == (priority == RATE_UNSET));
|
||||
this.operatingRate = operatingRate;
|
||||
this.priority = priority;
|
||||
return this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user