类android.media.MediaCodecInfo.VideoCapabilities源码实例Demo

下面列出了怎么用android.media.MediaCodecInfo.VideoCapabilities的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: MediaSDK   文件: MediaCodecInfo.java

/**
 * 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;
}
 
源代码2 项目: MediaSDK   文件: MediaCodecInfo.java

@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);
  }
}
 
源代码3 项目: TelePlus-Android   文件: MediaCodecInfo.java

/**
 * 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;
}
 
源代码4 项目: TelePlus-Android   文件: MediaCodecInfo.java

/**
 * 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);
}
 
源代码5 项目: TelePlus-Android   文件: MediaCodecInfo.java

/**
 * 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;
}
 
源代码6 项目: TelePlus-Android   文件: MediaCodecInfo.java

/**
 * 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);
}
 
源代码7 项目: K-Sonic   文件: MediaCodecInfo.java

/**
 * 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;
}
 
源代码8 项目: K-Sonic   文件: MediaCodecInfo.java

/**
 * 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);
}
 
源代码9 项目: 365browser   文件: MediaCodecUtil.java

/**
  * 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);
        }
    }
}
 
源代码10 项目: Telegram-FOSS   文件: MediaCodecInfo.java

/**
 * 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;
}
 
源代码11 项目: Telegram-FOSS   文件: MediaCodecInfo.java

@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);
  }
}
 
源代码12 项目: Telegram   文件: MediaCodecInfo.java

/**
 * 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;
}
 
源代码13 项目: Telegram   文件: MediaCodecInfo.java

@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);
  }
}
 
源代码14 项目: MediaSDK   文件: MediaCodecInfo.java

@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);
}
 
源代码15 项目: TelePlus-Android   文件: MediaCodecInfo.java

@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);
}
 
源代码16 项目: TelePlus-Android   文件: MediaCodecInfo.java

@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);
}
 
源代码17 项目: K-Sonic   文件: MediaCodecInfo.java

@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);
}
 
源代码18 项目: Telegram-FOSS   文件: MediaCodecInfo.java

@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);
}
 
源代码19 项目: Telegram   文件: MediaCodecInfo.java

@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);
}
 
源代码20 项目: MediaSDK   文件: MediaCodecInfo.java

/**
 * 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);
}
 
源代码21 项目: Telegram-FOSS   文件: MediaCodecInfo.java

/**
 * 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);
}
 
源代码22 项目: Telegram   文件: MediaCodecInfo.java

/**
 * 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);
}
 
 类所在包
 同包方法