android.media.MediaCodecInfo.VideoCapabilities Java Examples

The following examples show how to use android.media.MediaCodecInfo.VideoCapabilities. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MediaCodecInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Whether the decoder supports video with a given width, height and frame rate.
 *
 * <p>Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param frameRate Optional frame rate in frames per second. Ignored if set to {@link
 *     Format#NO_VALUE} or any value less than or equal to 0.
 * @return Whether the decoder supports video with the given width, height and frame rate.
 */
@TargetApi(21)
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate) {
  if (capabilities == null) {
    logNoSupport("sizeAndRate.caps");
    return false;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("sizeAndRate.vCaps");
    return false;
  }
  if (!areSizeAndRateSupportedV21(videoCapabilities, width, height, frameRate)) {
    if (width >= height
        || !enableRotatedVerticalResolutionWorkaround(name)
        || !areSizeAndRateSupportedV21(videoCapabilities, height, width, frameRate)) {
      logNoSupport("sizeAndRate.support, " + width + "x" + height + "x" + frameRate);
      return false;
    }
    logAssumedSupport("sizeAndRate.rotated, " + width + "x" + height + "x" + frameRate);
  }
  return true;
}
 
Example #2
Source File: MediaCodecInfo.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  // Don't ever fail due to alignment. See: https://github.com/google/ExoPlayer/issues/6551.
  Point alignedSize = alignVideoSizeV21(capabilities, width, height);
  width = alignedSize.x;
  height = alignedSize.y;

  if (frameRate == Format.NO_VALUE || frameRate <= 0) {
    return capabilities.isSizeSupported(width, height);
  } else {
    // The signaled frame rate may be slightly higher than the actual frame rate, so we take the
    // floor to avoid situations where a range check in areSizeAndRateSupported fails due to
    // slightly exceeding the limits for a standard format (e.g., 1080p at 30 fps).
    double floorFrameRate = Math.floor(frameRate);
    return capabilities.areSizeAndRateSupported(width, height, floorFrameRate);
  }
}
 
Example #3
Source File: MediaCodecInfo.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  // Don't ever fail due to alignment. See: https://github.com/google/ExoPlayer/issues/6551.
  Point alignedSize = alignVideoSizeV21(capabilities, width, height);
  width = alignedSize.x;
  height = alignedSize.y;

  if (frameRate == Format.NO_VALUE || frameRate <= 0) {
    return capabilities.isSizeSupported(width, height);
  } else {
    // The signaled frame rate may be slightly higher than the actual frame rate, so we take the
    // floor to avoid situations where a range check in areSizeAndRateSupported fails due to
    // slightly exceeding the limits for a standard format (e.g., 1080p at 30 fps).
    double floorFrameRate = Math.floor(frameRate);
    return capabilities.areSizeAndRateSupported(width, height, floorFrameRate);
  }
}
 
Example #4
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Whether the decoder supports video with a given width, height and frame rate.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param frameRate Optional frame rate in frames per second. Ignored if set to
 *     {@link Format#NO_VALUE} or any value less than or equal to 0.
 * @return Whether the decoder supports video with the given width, height and frame rate.
 */
@TargetApi(21)
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate) {
  if (capabilities == null) {
    logNoSupport("sizeAndRate.caps");
    return false;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("sizeAndRate.vCaps");
    return false;
  }
  if (!areSizeAndRateSupportedV21(videoCapabilities, width, height, frameRate)) {
    // Capabilities are known to be inaccurately reported for vertical resolutions on some devices
    // (b/31387661). If the video is vertical and the capabilities indicate support if the width
    // and height are swapped, we assume that the vertical resolution is also supported.
    if (width >= height
        || !areSizeAndRateSupportedV21(videoCapabilities, height, width, frameRate)) {
      logNoSupport("sizeAndRate.support, " + width + "x" + height + "x" + frameRate);
      return false;
    }
    logAssumedSupport("sizeAndRate.rotated, " + width + "x" + height + "x" + frameRate);
  }
  return true;
}
 
Example #5
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the smallest video size greater than or equal to a specified size that also satisfies
 * the {@link MediaCodec}'s width and height alignment requirements.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @return The smallest video size greater than or equal to the specified size that also satisfies
 *     the {@link MediaCodec}'s width and height alignment requirements, or null if not a video
 *     codec.
 */
@TargetApi(21)
public Point alignVideoSizeV21(int width, int height) {
  if (capabilities == null) {
    logNoSupport("align.caps");
    return null;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("align.vCaps");
    return null;
  }
  int widthAlignment = videoCapabilities.getWidthAlignment();
  int heightAlignment = videoCapabilities.getHeightAlignment();
  return new Point(Util.ceilDivide(width, widthAlignment) * widthAlignment,
      Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
 
Example #6
Source File: MediaCodecInfo.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Whether the decoder supports video with a given width, height and frame rate.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param frameRate Optional frame rate in frames per second. Ignored if set to
 *     {@link Format#NO_VALUE} or any value less than or equal to 0.
 * @return Whether the decoder supports video with the given width, height and frame rate.
 */
@TargetApi(21)
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate) {
  if (capabilities == null) {
    logNoSupport("sizeAndRate.caps");
    return false;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("sizeAndRate.vCaps");
    return false;
  }
  if (!areSizeAndRateSupportedV21(videoCapabilities, width, height, frameRate)) {
    // Capabilities are known to be inaccurately reported for vertical resolutions on some devices
    // (b/31387661). If the video is vertical and the capabilities indicate support if the width
    // and height are swapped, we assume that the vertical resolution is also supported.
    if (width >= height
        || !areSizeAndRateSupportedV21(videoCapabilities, height, width, frameRate)) {
      logNoSupport("sizeAndRate.support, " + width + "x" + height + "x" + frameRate);
      return false;
    }
    logAssumedSupport("sizeAndRate.rotated, " + width + "x" + height + "x" + frameRate);
  }
  return true;
}
 
Example #7
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Whether the decoder supports video with a given width, height and frame rate.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param frameRate Optional frame rate in frames per second. Ignored if set to
 *     {@link Format#NO_VALUE} or any value less than or equal to 0.
 * @return Whether the decoder supports video with the given width, height and frame rate.
 */
@TargetApi(21)
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate) {
  if (capabilities == null) {
    logNoSupport("sizeAndRate.caps");
    return false;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("sizeAndRate.vCaps");
    return false;
  }
  if (!areSizeAndRateSupportedV21(videoCapabilities, width, height, frameRate)) {
    // Capabilities are known to be inaccurately reported for vertical resolutions on some devices
    // (b/31387661). If the video is vertical and the capabilities indicate support if the width
    // and height are swapped, we assume that the vertical resolution is also supported.
    if (width >= height
        || !areSizeAndRateSupportedV21(videoCapabilities, height, width, frameRate)) {
      logNoSupport("sizeAndRate.support, " + width + "x" + height + "x" + frameRate);
      return false;
    }
    logAssumedSupport("sizeAndRate.rotated, " + width + "x" + height + "x" + frameRate);
  }
  return true;
}
 
Example #8
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the smallest video size greater than or equal to a specified size that also satisfies
 * the {@link MediaCodec}'s width and height alignment requirements.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @return The smallest video size greater than or equal to the specified size that also satisfies
 *     the {@link MediaCodec}'s width and height alignment requirements, or null if not a video
 *     codec.
 */
@TargetApi(21)
public Point alignVideoSizeV21(int width, int height) {
  if (capabilities == null) {
    logNoSupport("align.caps");
    return null;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("align.vCaps");
    return null;
  }
  int widthAlignment = videoCapabilities.getWidthAlignment();
  int heightAlignment = videoCapabilities.getHeightAlignment();
  return new Point(Util.ceilDivide(width, widthAlignment) * widthAlignment,
      Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
 
Example #9
Source File: MediaCodecInfo.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Whether the decoder supports video with a given width, height and frame rate.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param frameRate Optional frame rate in frames per second. Ignored if set to
 *     {@link Format#NO_VALUE} or any value less than or equal to 0.
 * @return Whether the decoder supports video with the given width, height and frame rate.
 */
@TargetApi(21)
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate) {
  if (capabilities == null) {
    logNoSupport("sizeAndRate.caps");
    return false;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("sizeAndRate.vCaps");
    return false;
  }
  if (!areSizeAndRateSupported(videoCapabilities, width, height, frameRate)) {
    // Capabilities are known to be inaccurately reported for vertical resolutions on some devices
    // (b/31387661). If the video is vertical and the capabilities indicate support if the width
    // and height are swapped, we assume that the vertical resolution is also supported.
    if (width >= height
        || !areSizeAndRateSupported(videoCapabilities, height, width, frameRate)) {
      logNoSupport("sizeAndRate.support, " + width + "x" + height + "x" + frameRate);
      return false;
    }
    logAssumedSupport("sizeAndRate.rotated, " + width + "x" + height + "x" + frameRate);
  }
  return true;
}
 
Example #10
Source File: MediaCodecInfo.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * Returns the smallest video size greater than or equal to a specified size that also satisfies
 * the {@link MediaCodec}'s width and height alignment requirements.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @return The smallest video size greater than or equal to the specified size that also satisfies
 *     the {@link MediaCodec}'s width and height alignment requirements, or null if not a video
 *     codec.
 */
@TargetApi(21)
public Point alignVideoSizeV21(int width, int height) {
  if (capabilities == null) {
    logNoSupport("align.caps");
    return null;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("align.vCaps");
    return null;
  }
  int widthAlignment = videoCapabilities.getWidthAlignment();
  int heightAlignment = videoCapabilities.getHeightAlignment();
  return new Point(Util.ceilDivide(width, widthAlignment) * widthAlignment,
      Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
 
Example #11
Source File: MediaCodecInfo.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  // Don't ever fail due to alignment. See: https://github.com/google/ExoPlayer/issues/6551.
  Point alignedSize = alignVideoSizeV21(capabilities, width, height);
  width = alignedSize.x;
  height = alignedSize.y;

  if (frameRate == Format.NO_VALUE || frameRate <= 0) {
    return capabilities.isSizeSupported(width, height);
  } else {
    // The signaled frame rate may be slightly higher than the actual frame rate, so we take the
    // floor to avoid situations where a range check in areSizeAndRateSupported fails due to
    // slightly exceeding the limits for a standard format (e.g., 1080p at 30 fps).
    double floorFrameRate = Math.floor(frameRate);
    return capabilities.areSizeAndRateSupported(width, height, floorFrameRate);
  }
}
 
Example #12
Source File: MediaCodecUtil.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
  * Needed on M and older to get correct information about VP9 support.
  * @param profileLevels The CodecProfileLevelList to add supported profile levels to.
  * @param videoCapabilities The MediaCodecInfo.VideoCapabilities used to infer support.
  */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void addVp9CodecProfileLevels(CodecProfileLevelList profileLevels,
        MediaCodecInfo.CodecCapabilities codecCapabilities) {
    // https://www.webmproject.org/vp9/levels
    final int[][] bitrateMapping = {
            {200, 10}, {800, 11}, {1800, 20}, {3600, 21}, {7200, 30}, {12000, 31}, {18000, 40},
            {30000, 41}, {60000, 50}, {120000, 51}, {180000, 52},
    };
    VideoCapabilities videoCapabilities = codecCapabilities.getVideoCapabilities();
    for (int[] entry : bitrateMapping) {
        int bitrate = entry[0];
        int level = entry[1];
        if (videoCapabilities.getBitrateRange().contains(bitrate)) {
            // Assume all platforms before N only support VP9 profile 0.
            profileLevels.addCodecProfileLevel(
                    VideoCodec.CODEC_VP9, VideoCodecProfile.VP9PROFILE_PROFILE0, level);
        }
    }
}
 
Example #13
Source File: MediaCodecInfo.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Whether the decoder supports video with a given width, height and frame rate.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @param frameRate Optional frame rate in frames per second. Ignored if set to
 *     {@link Format#NO_VALUE} or any value less than or equal to 0.
 * @return Whether the decoder supports video with the given width, height and frame rate.
 */
@TargetApi(21)
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate) {
  if (capabilities == null) {
    logNoSupport("sizeAndRate.caps");
    return false;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    logNoSupport("sizeAndRate.vCaps");
    return false;
  }
  if (!areSizeAndRateSupportedV21(videoCapabilities, width, height, frameRate)) {
    // Capabilities are known to be inaccurately reported for vertical resolutions on some devices
    // (b/31387661). If the video is vertical and the capabilities indicate support if the width
    // and height are swapped, we assume that the vertical resolution is also supported.
    if (width >= height
        || !areSizeAndRateSupportedV21(videoCapabilities, height, width, frameRate)) {
      logNoSupport("sizeAndRate.support, " + width + "x" + height + "x" + frameRate);
      return false;
    }
    logAssumedSupport("sizeAndRate.rotated, " + width + "x" + height + "x" + frameRate);
  }
  return true;
}
 
Example #14
Source File: MediaCodecInfo.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(21)
private static Point alignVideoSizeV21(VideoCapabilities capabilities, int width, int height) {
  int widthAlignment = capabilities.getWidthAlignment();
  int heightAlignment = capabilities.getHeightAlignment();
  return new Point(
      Util.ceilDivide(width, widthAlignment) * widthAlignment,
      Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
 
Example #15
Source File: MediaCodecInfo.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(21)
private static Point alignVideoSizeV21(VideoCapabilities capabilities, int width, int height) {
  int widthAlignment = capabilities.getWidthAlignment();
  int heightAlignment = capabilities.getHeightAlignment();
  return new Point(
      Util.ceilDivide(width, widthAlignment) * widthAlignment,
      Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
 
Example #16
Source File: MediaCodecInfo.java    From K-Sonic with MIT License 5 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupported(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  return frameRate == Format.NO_VALUE || frameRate <= 0
      ? capabilities.isSizeSupported(width, height)
      : capabilities.areSizeAndRateSupported(width, height, frameRate);
}
 
Example #17
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  return frameRate == Format.NO_VALUE || frameRate <= 0
      ? capabilities.isSizeSupported(width, height)
      : capabilities.areSizeAndRateSupported(width, height, frameRate);
}
 
Example #18
Source File: MediaCodecInfo.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(21)
private static boolean areSizeAndRateSupportedV21(VideoCapabilities capabilities, int width,
    int height, double frameRate) {
  return frameRate == Format.NO_VALUE || frameRate <= 0
      ? capabilities.isSizeSupported(width, height)
      : capabilities.areSizeAndRateSupported(width, height, frameRate);
}
 
Example #19
Source File: MediaCodecInfo.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@TargetApi(21)
private static Point alignVideoSizeV21(VideoCapabilities capabilities, int width, int height) {
  int widthAlignment = capabilities.getWidthAlignment();
  int heightAlignment = capabilities.getHeightAlignment();
  return new Point(
      Util.ceilDivide(width, widthAlignment) * widthAlignment,
      Util.ceilDivide(height, heightAlignment) * heightAlignment);
}
 
Example #20
Source File: MediaCodecInfo.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the smallest video size greater than or equal to a specified size that also satisfies
 * the {@link MediaCodec}'s width and height alignment requirements.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @return The smallest video size greater than or equal to the specified size that also satisfies
 *     the {@link MediaCodec}'s width and height alignment requirements, or null if not a video
 *     codec.
 */
@TargetApi(21)
public Point alignVideoSizeV21(int width, int height) {
  if (capabilities == null) {
    return null;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    return null;
  }
  return alignVideoSizeV21(videoCapabilities, width, height);
}
 
Example #21
Source File: MediaCodecInfo.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the smallest video size greater than or equal to a specified size that also satisfies
 * the {@link MediaCodec}'s width and height alignment requirements.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @return The smallest video size greater than or equal to the specified size that also satisfies
 *     the {@link MediaCodec}'s width and height alignment requirements, or null if not a video
 *     codec.
 */
@TargetApi(21)
public Point alignVideoSizeV21(int width, int height) {
  if (capabilities == null) {
    return null;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    return null;
  }
  return alignVideoSizeV21(videoCapabilities, width, height);
}
 
Example #22
Source File: MediaCodecInfo.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the smallest video size greater than or equal to a specified size that also satisfies
 * the {@link MediaCodec}'s width and height alignment requirements.
 * <p>
 * Must not be called if the device SDK version is less than 21.
 *
 * @param width Width in pixels.
 * @param height Height in pixels.
 * @return The smallest video size greater than or equal to the specified size that also satisfies
 *     the {@link MediaCodec}'s width and height alignment requirements, or null if not a video
 *     codec.
 */
@TargetApi(21)
public Point alignVideoSizeV21(int width, int height) {
  if (capabilities == null) {
    return null;
  }
  VideoCapabilities videoCapabilities = capabilities.getVideoCapabilities();
  if (videoCapabilities == null) {
    return null;
  }
  return alignVideoSizeV21(videoCapabilities, width, height);
}