Restrict operating rate workaround to SM8550
PiperOrigin-RevId: 585613041
This commit is contained in:
parent
8b38b34b9f
commit
e84a13fb54
@ -29,6 +29,7 @@ import static java.lang.Math.round;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
|
import android.os.Build;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.util.Size;
|
import android.util.Size;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -518,16 +519,21 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
|||||||
|
|
||||||
if (Util.SDK_INT == 26) {
|
if (Util.SDK_INT == 26) {
|
||||||
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, DEFAULT_FRAME_RATE);
|
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, DEFAULT_FRAME_RATE);
|
||||||
} else if (Util.SDK_INT <= 34) {
|
} else if (deviceNeedsLowerOperatingRateAvoidingOverflowWorkaround()) {
|
||||||
// On some devices setting Integer.MAX_VALUE will cause the encoder to throw at configuration
|
|
||||||
// time. Setting the operating to 1000 avoids being close to an integer overflow limit while
|
|
||||||
// being higher than a maximum feasible operating rate. See [internal b/311206113].
|
|
||||||
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, 1000);
|
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, 1000);
|
||||||
} else {
|
} else {
|
||||||
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, Integer.MAX_VALUE);
|
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean deviceNeedsLowerOperatingRateAvoidingOverflowWorkaround() {
|
||||||
|
// On this chipset, setting an operating rate close to Integer.MAX_VALUE will cause the encoder
|
||||||
|
// to throw at configuration time. Setting the operating rate to 1000 avoids being close to an
|
||||||
|
// integer overflow limit while being higher than a maximum feasible operating rate. See
|
||||||
|
// [internal b/311206113].
|
||||||
|
return Util.SDK_INT >= 31 && Util.SDK_INT <= 34 && Build.SOC_MODEL.equals("SM8550");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applying suggested profile/level settings from
|
* Applying suggested profile/level settings from
|
||||||
* https://developer.android.com/guide/topics/media/sharing-video#b-frames_and_encoding_profiles
|
* https://developer.android.com/guide/topics/media/sharing-video#b-frames_and_encoding_profiles
|
||||||
|
@ -231,7 +231,8 @@ public class DefaultEncoderFactoryTest {
|
|||||||
assertThat(configurationMediaFormat.containsKey(MediaFormat.KEY_PRIORITY)).isTrue();
|
assertThat(configurationMediaFormat.containsKey(MediaFormat.KEY_PRIORITY)).isTrue();
|
||||||
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_PRIORITY)).isEqualTo(1);
|
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_PRIORITY)).isEqualTo(1);
|
||||||
assertThat(configurationMediaFormat.containsKey(MediaFormat.KEY_OPERATING_RATE)).isTrue();
|
assertThat(configurationMediaFormat.containsKey(MediaFormat.KEY_OPERATING_RATE)).isTrue();
|
||||||
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_OPERATING_RATE)).isEqualTo(1000);
|
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_OPERATING_RATE))
|
||||||
|
.isEqualTo(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user