// Helper struct for findVp8HwEncoder() below.
private static class EncoderProperties {
- EncoderProperties(String codecName, int colorFormat) {
+ public EncoderProperties(String codecName, int colorFormat) {
this.codecName = codecName;
this.colorFormat = colorFormat;
}
continue; // No VP8 support in this codec; try the next one.
}
Log.d(TAG, "Found candidate encoder " + name);
+
+ // Check if this is supported HW encoder.
+ boolean supportedCodec = false;
+ for (String hwCodecPrefix : supportedHwCodecPrefixes) {
+ if (name.startsWith(hwCodecPrefix)) {
+ supportedCodec = true;
+ break;
+ }
+ }
+ if (!supportedCodec) {
+ continue;
+ }
+
CodecCapabilities capabilities =
info.getCapabilitiesForType(VP8_MIME_TYPE);
for (int colorFormat : capabilities.colorFormats) {
Log.d(TAG, " Color: 0x" + Integer.toHexString(colorFormat));
}
- // Check if this is supported HW encoder
- for (String hwCodecPrefix : supportedHwCodecPrefixes) {
- if (!name.startsWith(hwCodecPrefix)) {
- continue;
- }
- // Check if codec supports either yuv420 or nv12
- for (int supportedColorFormat : supportedColorList) {
- for (int codecColorFormat : capabilities.colorFormats) {
- if (codecColorFormat == supportedColorFormat) {
- // Found supported HW VP8 encoder
- Log.d(TAG, "Found target encoder " + name +
- ". Color: 0x" + Integer.toHexString(codecColorFormat));
- return new EncoderProperties(name, codecColorFormat);
- }
+ // Check if codec supports either yuv420 or nv12.
+ for (int supportedColorFormat : supportedColorList) {
+ for (int codecColorFormat : capabilities.colorFormats) {
+ if (codecColorFormat == supportedColorFormat) {
+ // Found supported HW VP8 encoder.
+ Log.d(TAG, "Found target encoder " + name +
+ ". Color: 0x" + Integer.toHexString(codecColorFormat));
+ return new EncoderProperties(name, codecColorFormat);
}
}
}
return findVp8HwEncoder() != null;
}
- private static int bitRate(int kbps) {
- // webrtc "kilo" means 1000, not 1024. Apparently.
- // (and the price for overshooting is frame-dropping as webrtc enforces its
- // bandwidth estimation, which is unpleasant).
- // Since the HW encoder in the N5 overshoots, we clamp to a bit less than
- // the requested rate. Sad but true. Bug 3194.
- return kbps * 950;
- }
-
private void checkOnMediaCodecThread() {
if (mediaCodecThread.getId() != Thread.currentThread().getId()) {
throw new RuntimeException(
try {
MediaFormat format =
MediaFormat.createVideoFormat(VP8_MIME_TYPE, width, height);
- format.setInteger(MediaFormat.KEY_BIT_RATE, bitRate(kbps));
+ format.setInteger(MediaFormat.KEY_BIT_RATE, 1000 * kbps);
format.setInteger("bitrate-mode", VIDEO_ControlRateConstant);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, properties.colorFormat);
// Default WebRTC settings
Log.v(TAG, "setRates: " + kbps + " kbps. Fps: " + frameRateIgnored);
try {
Bundle params = new Bundle();
- params.putInt(MediaCodec.PARAMETER_KEY_VIDEO_BITRATE, bitRate(kbps));
+ params.putInt(MediaCodec.PARAMETER_KEY_VIDEO_BITRATE, 1000 * kbps);
mediaCodec.setParameters(params);
return true;
} catch (IllegalStateException e) {