當前位置: 首頁>>代碼示例>>Java>>正文


Java Util.ceilDivide方法代碼示例

本文整理匯總了Java中com.google.android.exoplayer2.util.Util.ceilDivide方法的典型用法代碼示例。如果您正苦於以下問題:Java Util.ceilDivide方法的具體用法?Java Util.ceilDivide怎麽用?Java Util.ceilDivide使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.exoplayer2.util.Util的用法示例。


在下文中一共展示了Util.ceilDivide方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMaxVideoSizeInViewport

import com.google.android.exoplayer2.util.Util; //導入方法依賴的package包/類
/**
 * Given viewport dimensions and video dimensions, computes the maximum size of the video as it
 * will be rendered to fit inside of the viewport.
 */
private static Point getMaxVideoSizeInViewport(boolean orientationMayChange, int viewportWidth,
    int viewportHeight, int videoWidth, int videoHeight) {
  if (orientationMayChange && (videoWidth > videoHeight) != (viewportWidth > viewportHeight)) {
    // Rotation is allowed, and the video will be larger in the rotated viewport.
    int tempViewportWidth = viewportWidth;
    viewportWidth = viewportHeight;
    viewportHeight = tempViewportWidth;
  }

  if (videoWidth * viewportHeight >= videoHeight * viewportWidth) {
    // Horizontal letter-boxing along top and bottom.
    return new Point(viewportWidth, Util.ceilDivide(viewportWidth * videoHeight, videoWidth));
  } else {
    // Vertical letter-boxing along edges.
    return new Point(Util.ceilDivide(viewportHeight * videoWidth, videoHeight), viewportHeight);
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:22,代碼來源:DefaultTrackSelector.java

示例2: alignVideoSizeV21

import com.google.android.exoplayer2.util.Util; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:29,代碼來源:MediaCodecInfo.java

示例3: getCodecMaxSize

import com.google.android.exoplayer2.util.Util; //導入方法依賴的package包/類
/**
 * Returns a maximum video size to use when configuring a codec for {@code format} in a way
 * that will allow possible adaptation to other compatible formats that are expected to have the
 * same aspect ratio, but whose sizes are unknown.
 *
 * @param codecInfo Information about the {@link MediaCodec} being configured.
 * @param format The format for which the codec is being configured.
 * @return The maximum video size to use, or null if the size of {@code format} should be used.
 * @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
 */
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format)
    throws DecoderQueryException {
  boolean isVerticalVideo = format.height > format.width;
  int formatLongEdgePx = isVerticalVideo ? format.height : format.width;
  int formatShortEdgePx = isVerticalVideo ? format.width : format.height;
  float aspectRatio = (float) formatShortEdgePx / formatLongEdgePx;
  for (int longEdgePx : STANDARD_LONG_EDGE_VIDEO_PX) {
    int shortEdgePx = (int) (longEdgePx * aspectRatio);
    if (longEdgePx <= formatLongEdgePx || shortEdgePx <= formatShortEdgePx) {
      // Don't return a size not larger than the format for which the codec is being configured.
      return null;
    } else if (Util.SDK_INT >= 21) {
      Point alignedSize = codecInfo.alignVideoSizeV21(isVerticalVideo ? shortEdgePx : longEdgePx,
          isVerticalVideo ? longEdgePx : shortEdgePx);
      float frameRate = format.frameRate;
      if (codecInfo.isVideoSizeAndRateSupportedV21(alignedSize.x, alignedSize.y, frameRate)) {
        return alignedSize;
      }
    } else {
      // Conservatively assume the codec requires 16px width and height alignment.
      longEdgePx = Util.ceilDivide(longEdgePx, 16) * 16;
      shortEdgePx = Util.ceilDivide(shortEdgePx, 16) * 16;
      if (longEdgePx * shortEdgePx <= MediaCodecUtil.maxH264DecodableFrameSize()) {
        return new Point(isVerticalVideo ? shortEdgePx : longEdgePx,
            isVerticalVideo ? longEdgePx : shortEdgePx);
      }
    }
  }
  return null;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:41,代碼來源:MediaCodecVideoRenderer.java

示例4: rechunk

import com.google.android.exoplayer2.util.Util; //導入方法依賴的package包/類
/**
 * Rechunk the given fixed sample size input to produce a new sequence of samples.
 *
 * @param fixedSampleSize Size in bytes of each sample.
 * @param chunkOffsets Chunk offsets in the MP4 stream to rechunk.
 * @param chunkSampleCounts Sample counts for each of the MP4 stream's chunks.
 * @param timestampDeltaInTimeUnits Timestamp delta between each sample in time units.
 */
public static Results rechunk(int fixedSampleSize, long[] chunkOffsets, int[] chunkSampleCounts,
    long timestampDeltaInTimeUnits) {
  int maxSampleCount = MAX_SAMPLE_SIZE / fixedSampleSize;

  // Count the number of new, rechunked buffers.
  int rechunkedSampleCount = 0;
  for (int chunkSampleCount : chunkSampleCounts) {
    rechunkedSampleCount += Util.ceilDivide(chunkSampleCount, maxSampleCount);
  }

  long[] offsets = new long[rechunkedSampleCount];
  int[] sizes = new int[rechunkedSampleCount];
  int maximumSize = 0;
  long[] timestamps = new long[rechunkedSampleCount];
  int[] flags = new int[rechunkedSampleCount];

  int originalSampleIndex = 0;
  int newSampleIndex = 0;
  for (int chunkIndex = 0; chunkIndex < chunkSampleCounts.length; chunkIndex++) {
    int chunkSamplesRemaining = chunkSampleCounts[chunkIndex];
    long sampleOffset = chunkOffsets[chunkIndex];

    while (chunkSamplesRemaining > 0) {
      int bufferSampleCount = Math.min(maxSampleCount, chunkSamplesRemaining);

      offsets[newSampleIndex] = sampleOffset;
      sizes[newSampleIndex] = fixedSampleSize * bufferSampleCount;
      maximumSize = Math.max(maximumSize, sizes[newSampleIndex]);
      timestamps[newSampleIndex] = (timestampDeltaInTimeUnits * originalSampleIndex);
      flags[newSampleIndex] = C.BUFFER_FLAG_KEY_FRAME;

      sampleOffset += sizes[newSampleIndex];
      originalSampleIndex += bufferSampleCount;

      chunkSamplesRemaining -= bufferSampleCount;
      newSampleIndex++;
    }
  }

  return new Results(offsets, sizes, maximumSize, timestamps, flags);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:50,代碼來源:FixedSampleSizeRechunker.java

示例5: trim

import com.google.android.exoplayer2.util.Util; //導入方法依賴的package包/類
@Override
public synchronized void trim() {
  int targetAllocationCount = Util.ceilDivide(targetBufferSize, individualAllocationSize);
  int targetAvailableCount = Math.max(0, targetAllocationCount - allocatedCount);
  if (targetAvailableCount >= availableCount) {
    // We're already at or below the target.
    return;
  }

  if (initialAllocationBlock != null) {
    // Some allocations are backed by an initial block. We need to make sure that we hold onto all
    // such allocations. Re-order the available allocations so that the ones backed by the initial
    // block come first.
    int lowIndex = 0;
    int highIndex = availableCount - 1;
    while (lowIndex <= highIndex) {
      Allocation lowAllocation = availableAllocations[lowIndex];
      if (lowAllocation.data == initialAllocationBlock) {
        lowIndex++;
      } else {
        Allocation highAllocation = availableAllocations[highIndex];
        if (highAllocation.data != initialAllocationBlock) {
          highIndex--;
        } else {
          availableAllocations[lowIndex++] = highAllocation;
          availableAllocations[highIndex--] = lowAllocation;
        }
      }
    }
    // lowIndex is the index of the first allocation not backed by an initial block.
    targetAvailableCount = Math.max(targetAvailableCount, lowIndex);
    if (targetAvailableCount >= availableCount) {
      // We're already at or below the target.
      return;
    }
  }

  // Discard allocations beyond the target.
  Arrays.fill(availableAllocations, targetAvailableCount, availableCount, null);
  availableCount = targetAvailableCount;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:42,代碼來源:DefaultAllocator.java

示例6: getMaxInputSize

import com.google.android.exoplayer2.util.Util; //導入方法依賴的package包/類
/**
 * Returns a maximum input size for a given mime type, width and height.
 *
 * @param sampleMimeType The format mime type.
 * @param width The width in pixels.
 * @param height The height in pixels.
 * @return A maximum input size in bytes, or {@link Format#NO_VALUE} if a maximum could not be
 *     determined.
 */
private static int getMaxInputSize(String sampleMimeType, int width, int height) {
  if (width == Format.NO_VALUE || height == Format.NO_VALUE) {
    // We can't infer a maximum input size without video dimensions.
    return Format.NO_VALUE;
  }

  // Attempt to infer a maximum input size from the format.
  int maxPixels;
  int minCompressionRatio;
  switch (sampleMimeType) {
    case MimeTypes.VIDEO_H263:
    case MimeTypes.VIDEO_MP4V:
      maxPixels = width * height;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_H264:
      if ("BRAVIA 4K 2015".equals(Util.MODEL)) {
        // The Sony BRAVIA 4k TV has input buffers that are too small for the calculated 4k video
        // maximum input size, so use the default value.
        return Format.NO_VALUE;
      }
      // Round up width/height to an integer number of macroblocks.
      maxPixels = Util.ceilDivide(width, 16) * Util.ceilDivide(height, 16) * 16 * 16;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_VP8:
      // VPX does not specify a ratio so use the values from the platform's SoftVPX.cpp.
      maxPixels = width * height;
      minCompressionRatio = 2;
      break;
    case MimeTypes.VIDEO_H265:
    case MimeTypes.VIDEO_VP9:
      maxPixels = width * height;
      minCompressionRatio = 4;
      break;
    default:
      // Leave the default max input size.
      return Format.NO_VALUE;
  }
  // Estimate the maximum input size assuming three channel 4:2:0 subsampled input frames.
  return (maxPixels * 3) / (2 * minCompressionRatio);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:52,代碼來源:MediaCodecVideoRenderer.java


注:本文中的com.google.android.exoplayer2.util.Util.ceilDivide方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。