diff --git a/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java b/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java index 0664f5ebe1..4d782a968e 100644 --- a/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java +++ b/sdk/android/api/org/webrtc/HardwareVideoEncoderFactory.java @@ -64,6 +64,11 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory { @Nullable @Override public VideoEncoder createEncoder(VideoCodecInfo input) { + // HW encoding is not supported below Android Kitkat. + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + return null; + } + VideoCodecType type = VideoCodecType.valueOf(input.name); MediaCodecInfo info = findCodecForType(type); @@ -100,6 +105,11 @@ public class HardwareVideoEncoderFactory implements VideoEncoderFactory { @Override public VideoCodecInfo[] getSupportedCodecs() { + // HW encoding is not supported below Android Kitkat. + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { + return new VideoCodecInfo[0]; + } + List supportedCodecInfos = new ArrayList(); // Generate a list of supported codecs in order of preference: // VP8, VP9, H264 (high profile), and H264 (baseline profile). diff --git a/sdk/android/src/java/org/webrtc/AndroidVideoDecoder.java b/sdk/android/src/java/org/webrtc/AndroidVideoDecoder.java index c9ed406c1a..9956c3859d 100644 --- a/sdk/android/src/java/org/webrtc/AndroidVideoDecoder.java +++ b/sdk/android/src/java/org/webrtc/AndroidVideoDecoder.java @@ -27,7 +27,6 @@ import org.webrtc.ThreadUtils.ThreadChecker; /** * Android hardware video decoder. */ -@TargetApi(16) @SuppressWarnings("deprecation") // Cannot support API 16 without using deprecated methods. // TODO(sakal): Rename to MediaCodecVideoDecoder once the deprecated implementation is removed. diff --git a/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java b/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java index 0dd2101325..ebf9de374f 100644 --- a/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java +++ b/sdk/android/src/java/org/webrtc/HardwareVideoEncoder.java @@ -28,7 +28,11 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; import org.webrtc.ThreadUtils.ThreadChecker; -/** Android hardware video encoder. */ +/** + * Android hardware video encoder. + * + * @note This class is only supported on Android Kitkat and above. + */ @TargetApi(19) @SuppressWarnings("deprecation") // Cannot support API level 19 without using deprecated methods. class HardwareVideoEncoder implements VideoEncoder { diff --git a/sdk/android/src/java/org/webrtc/MediaCodecUtils.java b/sdk/android/src/java/org/webrtc/MediaCodecUtils.java index 8eb1b20ac1..13e2d06d2b 100644 --- a/sdk/android/src/java/org/webrtc/MediaCodecUtils.java +++ b/sdk/android/src/java/org/webrtc/MediaCodecUtils.java @@ -14,12 +14,12 @@ import android.annotation.TargetApi; import android.media.MediaCodec; import android.media.MediaCodecInfo; import android.media.MediaCodecInfo.CodecCapabilities; +import android.os.Build; import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; /** Container class for static constants and helpers used with MediaCodec. */ -@TargetApi(18) // We are forced to use the old API because we want to support API level < 21. @SuppressWarnings("deprecation") class MediaCodecUtils { @@ -56,7 +56,15 @@ class MediaCodecUtils { MediaCodecUtils.COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m}; // Color formats supported by texture mode encoding - in order of preference. - static final int[] TEXTURE_COLOR_FORMATS = {MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface}; + static final int[] TEXTURE_COLOR_FORMATS = getTextureColorFormats(); + + private static int[] getTextureColorFormats() { + if (Build.VERSION.SDK_INT >= 18) { + return new int[] {MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface}; + } else { + return new int[] {}; + } + } static @Nullable Integer selectColorFormat( int[] supportedColorFormats, CodecCapabilities capabilities) {