Skip to content

Commit

Permalink
Restrict operating rate workaround to SM8550
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 585613041
  • Loading branch information
andrewlewis authored and copybara-github committed Nov 27, 2023
1 parent 8b38b34 commit e84a13f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.content.Context;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.os.Build;
import android.util.Pair;
import android.util.Size;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -518,16 +519,21 @@ private static void adjustMediaFormatForEncoderPerformanceSettings(MediaFormat m

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].
} else if (deviceNeedsLowerOperatingRateAvoidingOverflowWorkaround()) {
mediaFormat.setInteger(MediaFormat.KEY_OPERATING_RATE, 1000);
} else {
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
* https://developer.android.com/guide/topics/media/sharing-video#b-frames_and_encoding_profiles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public void createForVideoEncoding_withFallbackOnAndUnsupportedResolution_config
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(1000);
assertThat(configurationMediaFormat.getInteger(MediaFormat.KEY_OPERATING_RATE))
.isEqualTo(Integer.MAX_VALUE);
}

@Test
Expand Down

0 comments on commit e84a13f

Please sign in to comment.