Add checks to HW codecs to ensure unsupported features are not used.
Add checks to ensure encoder is not used below API level 19. Removes global @TargetApi from MediaCodecUtils since it is also used by the decoder. Ensures that texture mode is never enabled below API level 18. Bug: webrtc:9821 Change-Id: I2ca1014bf8995719c970eb1449b0acbf7b3c883e Reviewed-on: https://webrtc-review.googlesource.com/c/103701 Reviewed-by: Paulina Hensman <phensman@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24990}
This commit is contained in:

committed by
Commit Bot

parent
24ee167a3d
commit
d5806b289f
@ -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<VideoCodecInfo> supportedCodecInfos = new ArrayList<VideoCodecInfo>();
|
||||
// Generate a list of supported codecs in order of preference:
|
||||
// VP8, VP9, H264 (high profile), and H264 (baseline profile).
|
||||
|
@ -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.
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user