mirror of
https://github.com/androidx/media.git
synced 2025-05-05 06:30:24 +08:00
Avoid value close to overflow for KEY_OPERATING_RATE
Using `Integer.MAX_VALUE` risks causing arithmetic overflow in the codec implementation. Issue: androidx/media#810 PiperOrigin-RevId: 585104621 (cherry picked from commit ad40db448943fef579879c9c2a988f514b254109)
This commit is contained in:
parent
36f634d8d1
commit
97c9e234d2
@ -8,6 +8,8 @@
|
||||
`LiveConfiguration.min/maxOffset` range keep adjusting the offset back
|
||||
to `min/maxOffset`.
|
||||
* Transformer:
|
||||
* Work around an issue where the encoder would throw at configuration time
|
||||
due to setting a high operating rate.
|
||||
* Track Selection:
|
||||
* Extractors:
|
||||
* Audio:
|
||||
|
@ -51,8 +51,6 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
||||
/** Best effort, or as-fast-as-possible priority setting for {@link MediaFormat#KEY_PRIORITY}. */
|
||||
private static final int PRIORITY_BEST_EFFORT = 1;
|
||||
|
||||
private static final String TAG = "DefaultEncoderFactory";
|
||||
|
||||
/** A builder for {@link DefaultEncoderFactory} instances. */
|
||||
public static final class Builder {
|
||||
private final Context context;
|
||||
@ -519,6 +517,11 @@ public final class DefaultEncoderFactory implements Codec.EncoderFactory {
|
||||
|
||||
if (Util.SDK_INT == 26) {
|
||||
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, DEFAULT_FRAME_RATE);
|
||||
} else if (Util.SDK_INT <= 34) {
|
||||
// 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);
|
||||
} else {
|
||||
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
@ -231,8 +231,7 @@ public class DefaultEncoderFactoryTest {
|
||||
assertThat(configurationMediaFormat.containsKey(MediaFormat.KEY_PRIORITY)).isTrue();
|
||||
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_PRIORITY)).isEqualTo(1);
|
||||
assertThat(configurationMediaFormat.containsKey(MediaFormat.KEY_OPERATING_RATE)).isTrue();
|
||||
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_OPERATING_RATE))
|
||||
.isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_OPERATING_RATE)).isEqualTo(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user