Java Code Examples for com.google.android.exoplayer2.C#BITS_PER_BYTE

The following examples show how to use com.google.android.exoplayer2.C#BITS_PER_BYTE . 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: TrackSelectionUtil.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns average bitrate for chunks in bits per second. Chunks are included in average until
 * {@code maxDurationMs} or the first unknown length chunk.
 *
 * @param iterator Iterator for media chunk sequences.
 * @param maxDurationUs Maximum duration of chunks to be included in average bitrate, in
 *     microseconds.
 * @return Average bitrate for chunks in bits per second, or {@link Format#NO_VALUE} if there are
 *     no chunks or the first chunk length is unknown.
 */
public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) {
  long totalDurationUs = 0;
  long totalLength = 0;
  while (iterator.next()) {
    long chunkLength = iterator.getDataSpec().length;
    if (chunkLength == C.LENGTH_UNSET) {
      break;
    }
    long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs();
    if (totalDurationUs + chunkDurationUs >= maxDurationUs) {
      totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs;
      totalDurationUs = maxDurationUs;
      break;
    }
    totalDurationUs += chunkDurationUs;
    totalLength += chunkLength;
  }
  return totalDurationUs == 0
      ? Format.NO_VALUE
      : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs);
}
 
Example 2
Source File: TrackSelectionUtil.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns average bitrate for chunks in bits per second. Chunks are included in average until
 * {@code maxDurationMs} or the first unknown length chunk.
 *
 * @param iterator Iterator for media chunk sequences.
 * @param maxDurationUs Maximum duration of chunks to be included in average bitrate, in
 *     microseconds.
 * @return Average bitrate for chunks in bits per second, or {@link Format#NO_VALUE} if there are
 *     no chunks or the first chunk length is unknown.
 */
public static int getAverageBitrate(MediaChunkIterator iterator, long maxDurationUs) {
  long totalDurationUs = 0;
  long totalLength = 0;
  while (iterator.next()) {
    long chunkLength = iterator.getDataSpec().length;
    if (chunkLength == C.LENGTH_UNSET) {
      break;
    }
    long chunkDurationUs = iterator.getChunkEndTimeUs() - iterator.getChunkStartTimeUs();
    if (totalDurationUs + chunkDurationUs >= maxDurationUs) {
      totalLength += chunkLength * (maxDurationUs - totalDurationUs) / chunkDurationUs;
      totalDurationUs = maxDurationUs;
      break;
    }
    totalDurationUs += chunkDurationUs;
    totalLength += chunkLength;
  }
  return totalDurationUs == 0
      ? Format.NO_VALUE
      : (int) (totalLength * C.BITS_PER_BYTE * C.MICROS_PER_SECOND / totalDurationUs);
}
 
Example 3
Source File: ConstantBitrateSeekMap.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private long getFramePositionForTimeUs(long timeUs) {
  long positionOffset = (timeUs * bitrate) / (C.MICROS_PER_SECOND * C.BITS_PER_BYTE);
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / frameSize) * frameSize;
  positionOffset =
      Util.constrainValue(positionOffset, /* min= */ 0, /* max= */ dataSize - frameSize);
  return firstFrameBytePosition + positionOffset;
}
 
Example 4
Source File: ConstantBitrateSeekMap.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private long getFramePositionForTimeUs(long timeUs) {
  long positionOffset = (timeUs * bitrate) / (C.MICROS_PER_SECOND * C.BITS_PER_BYTE);
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / frameSize) * frameSize;
  positionOffset =
      Util.constrainValue(positionOffset, /* min= */ 0, /* max= */ dataSize - frameSize);
  return firstFrameBytePosition + positionOffset;
}
 
Example 5
Source File: ConstantBitrateSeekMap.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private long getFramePositionForTimeUs(long timeUs) {
  long positionOffset = (timeUs * bitrate) / (C.MICROS_PER_SECOND * C.BITS_PER_BYTE);
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / frameSize) * frameSize;
  positionOffset =
      Util.constrainValue(positionOffset, /* min= */ 0, /* max= */ dataSize - frameSize);
  return firstFrameBytePosition + positionOffset;
}
 
Example 6
Source File: ConstantBitrateSeekMap.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private long getFramePositionForTimeUs(long timeUs) {
  long positionOffset = (timeUs * bitrate) / (C.MICROS_PER_SECOND * C.BITS_PER_BYTE);
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / frameSize) * frameSize;
  positionOffset =
      Util.constrainValue(positionOffset, /* min= */ 0, /* max= */ dataSize - frameSize);
  return firstFrameBytePosition + positionOffset;
}
 
Example 7
Source File: ConstantBitrateSeekMap.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private long getFramePositionForTimeUs(long timeUs) {
  long positionOffset = (timeUs * bitrate) / (C.MICROS_PER_SECOND * C.BITS_PER_BYTE);
  // Constrain to nearest preceding frame offset.
  positionOffset = (positionOffset / frameSize) * frameSize;
  positionOffset =
      Util.constrainValue(positionOffset, /* min= */ 0, /* max= */ dataSize - frameSize);
  return firstFrameBytePosition + positionOffset;
}
 
Example 8
Source File: ConstantBitrateSeekMap.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the stream time in microseconds for a given stream position.
 *
 * @param position The stream byte-position.
 * @param firstFrameBytePosition The position of the first frame in the stream.
 * @param bitrate The bitrate (which is assumed to be constant in the stream).
 * @return The stream time in microseconds for the given stream position.
 */
private static long getTimeUsAtPosition(long position, long firstFrameBytePosition, int bitrate) {
  return Math.max(0, position - firstFrameBytePosition)
      * C.BITS_PER_BYTE
      * C.MICROS_PER_SECOND
      / bitrate;
}
 
Example 9
Source File: ConstantBitrateSeekMap.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the stream time in microseconds for a given stream position.
 *
 * @param position The stream byte-position.
 * @param firstFrameBytePosition The position of the first frame in the stream.
 * @param bitrate The bitrate (which is assumed to be constant in the stream).
 * @return The stream time in microseconds for the given stream position.
 */
private static long getTimeUsAtPosition(long position, long firstFrameBytePosition, int bitrate) {
  return Math.max(0, position - firstFrameBytePosition)
      * C.BITS_PER_BYTE
      * C.MICROS_PER_SECOND
      / bitrate;
}
 
Example 10
Source File: ConstantBitrateSeekMap.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the stream time in microseconds for a given stream position.
 *
 * @param position The stream byte-position.
 * @param firstFrameBytePosition The position of the first frame in the stream.
 * @param bitrate The bitrate (which is assumed to be constant in the stream).
 * @return The stream time in microseconds for the given stream position.
 */
private static long getTimeUsAtPosition(long position, long firstFrameBytePosition, int bitrate) {
  return Math.max(0, position - firstFrameBytePosition)
      * C.BITS_PER_BYTE
      * C.MICROS_PER_SECOND
      / bitrate;
}
 
Example 11
Source File: ConstantBitrateSeekMap.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the stream time in microseconds for a given stream position.
 *
 * @param position The stream byte-position.
 * @param firstFrameBytePosition The position of the first frame in the stream.
 * @param bitrate The bitrate (which is assumed to be constant in the stream).
 * @return The stream time in microseconds for the given stream position.
 */
private static long getTimeUsAtPosition(long position, long firstFrameBytePosition, int bitrate) {
  return Math.max(0, position - firstFrameBytePosition)
      * C.BITS_PER_BYTE
      * C.MICROS_PER_SECOND
      / bitrate;
}
 
Example 12
Source File: ConstantBitrateSeekMap.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the stream time in microseconds for a given stream position.
 *
 * @param position The stream byte-position.
 * @param firstFrameBytePosition The position of the first frame in the stream.
 * @param bitrate The bitrate (which is assumed to be constant in the stream).
 * @return The stream time in microseconds for the given stream position.
 */
private static long getTimeUsAtPosition(long position, long firstFrameBytePosition, int bitrate) {
  return Math.max(0, position - firstFrameBytePosition)
      * C.BITS_PER_BYTE
      * C.MICROS_PER_SECOND
      / bitrate;
}
 
Example 13
Source File: AdtsExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 14
Source File: AmrExtractor.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 15
Source File: AdtsExtractor.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 16
Source File: AmrExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 17
Source File: AdtsExtractor.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 18
Source File: AmrExtractor.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 19
Source File: AmrExtractor.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}
 
Example 20
Source File: AmrExtractor.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the stream bitrate, given a frame size and the duration of that frame in microseconds.
 *
 * @param frameSize The size of each frame in the stream.
 * @param durationUsPerFrame The duration of the given frame in microseconds.
 * @return The stream bitrate.
 */
private static int getBitrateFromFrameSize(int frameSize, long durationUsPerFrame) {
  return (int) ((frameSize * C.BITS_PER_BYTE * C.MICROS_PER_SECOND) / durationUsPerFrame);
}