Java Code Examples for com.google.android.exoplayer.util.Util#scaleLargeTimestamp()

The following examples show how to use com.google.android.exoplayer.util.Util#scaleLargeTimestamp() . 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: CommonMp4AtomParsers.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a trak atom (defined in 14496-12)
 *
 * @param trak Atom to parse.
 * @param mvhd Movie header atom, used to get the timescale.
 * @return A {@link Track} instance.
 */
public static Track parseTrak(Atom.ContainerAtom trak, Atom.LeafAtom mvhd) {
  Atom.ContainerAtom mdia = trak.getContainerAtomOfType(Atom.TYPE_mdia);
  int trackType = parseHdlr(mdia.getLeafAtomOfType(Atom.TYPE_hdlr).data);
  Assertions.checkState(trackType == Track.TYPE_AUDIO || trackType == Track.TYPE_VIDEO
      || trackType == Track.TYPE_TEXT || trackType == Track.TYPE_TIME_CODE);

  Pair<Integer, Long> header = parseTkhd(trak.getLeafAtomOfType(Atom.TYPE_tkhd).data);
  int id = header.first;
  long duration = header.second;
  long movieTimescale = parseMvhd(mvhd.data);
  long durationUs;
  if (duration == -1) {
    durationUs = C.UNKNOWN_TIME_US;
  } else {
    durationUs = Util.scaleLargeTimestamp(duration, C.MICROS_PER_SECOND, movieTimescale);
  }
  Atom.ContainerAtom stbl = mdia.getContainerAtomOfType(Atom.TYPE_minf)
      .getContainerAtomOfType(Atom.TYPE_stbl);

  long mediaTimescale = parseMdhd(mdia.getLeafAtomOfType(Atom.TYPE_mdhd).data);
  Pair<MediaFormat, TrackEncryptionBox[]> sampleDescriptions =
      parseStsd(stbl.getLeafAtomOfType(Atom.TYPE_stsd).data);
  return new Track(id, trackType, mediaTimescale, durationUs, sampleDescriptions.first,
        sampleDescriptions.second);
}
 
Example 2
Source File: SmoothStreamingManifest.java    From Exoplayer_VLC with Apache License 2.0 6 votes vote down vote up
public StreamElement(Uri baseUri, String chunkTemplate, int type, String subType,
    long timescale, String name, int qualityLevels, int maxWidth, int maxHeight,
    int displayWidth, int displayHeight, String language, TrackElement[] tracks,
    List<Long> chunkStartTimes, long lastChunkDuration) {
  this.baseUri = baseUri;
  this.chunkTemplate = chunkTemplate;
  this.type = type;
  this.subType = subType;
  this.timescale = timescale;
  this.name = name;
  this.qualityLevels = qualityLevels;
  this.maxWidth = maxWidth;
  this.maxHeight = maxHeight;
  this.displayWidth = displayWidth;
  this.displayHeight = displayHeight;
  this.language = language;
  this.tracks = tracks;
  this.chunkCount = chunkStartTimes.size();
  this.chunkStartTimes = chunkStartTimes;
  lastChunkDurationUs =
      Util.scaleLargeTimestamp(lastChunkDuration, C.MICROS_PER_SECOND, timescale);
  chunkStartTimesUs =
      Util.scaleLargeTimestamps(chunkStartTimes, C.MICROS_PER_SECOND, timescale);
}
 
Example 3
Source File: SegmentBase.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
/**
 * @see DashSegmentIndex#getTimeUs(int)
 */
public final long getSegmentTimeUs(int sequenceNumber) {
  long unscaledSegmentTime;
  if (segmentTimeline != null) {
    unscaledSegmentTime = segmentTimeline.get(sequenceNumber - startNumber).startTime
        - presentationTimeOffset;
  } else {
    unscaledSegmentTime = (sequenceNumber - startNumber) * duration;
  }
  return Util.scaleLargeTimestamp(unscaledSegmentTime, C.MICROS_PER_SECOND, timescale);
}
 
Example 4
Source File: FragmentedMp4Extractor.java    From Exoplayer_VLC with Apache License 2.0 4 votes vote down vote up
/**
 * Parses a sidx atom (defined in 14496-12).
 */
private static SegmentIndex parseSidx(ParsableByteArray atom) {
  atom.setPosition(Mp4Util.ATOM_HEADER_SIZE);
  int fullAtom = atom.readInt();
  int version = Mp4Util.parseFullAtomVersion(fullAtom);

  atom.skip(4);
  long timescale = atom.readUnsignedInt();
  long earliestPresentationTime;
  long firstOffset;
  if (version == 0) {
    earliestPresentationTime = atom.readUnsignedInt();
    firstOffset = atom.readUnsignedInt();
  } else {
    earliestPresentationTime = atom.readUnsignedLongToLong();
    firstOffset = atom.readUnsignedLongToLong();
  }

  atom.skip(2);

  int referenceCount = atom.readUnsignedShort();
  int[] sizes = new int[referenceCount];
  long[] offsets = new long[referenceCount];
  long[] durationsUs = new long[referenceCount];
  long[] timesUs = new long[referenceCount];

  long offset = firstOffset;
  long time = earliestPresentationTime;
  long timeUs = Util.scaleLargeTimestamp(time, C.MICROS_PER_SECOND, timescale);
  for (int i = 0; i < referenceCount; i++) {
    int firstInt = atom.readInt();

    int type = 0x80000000 & firstInt;
    if (type != 0) {
      throw new IllegalStateException("Unhandled indirect reference");
    }
    long referenceDuration = atom.readUnsignedInt();

    sizes[i] = 0x7fffffff & firstInt;
    offsets[i] = offset;

    // Calculate time and duration values such that any rounding errors are consistent. i.e. That
    // timesUs[i] + durationsUs[i] == timesUs[i + 1].
    timesUs[i] = timeUs;
    time += referenceDuration;
    timeUs = Util.scaleLargeTimestamp(time, C.MICROS_PER_SECOND, timescale);
    durationsUs[i] = timeUs - timesUs[i];

    atom.skip(4);
    offset += sizes[i];
  }

  return new SegmentIndex(atom.limit(), sizes, offsets, durationsUs, timesUs);
}
 
Example 5
Source File: SmoothStreamingManifest.java    From Exoplayer_VLC with Apache License 2.0 3 votes vote down vote up
/**
 * @param majorVersion The client manifest major version.
 * @param minorVersion The client manifest minor version.
 * @param timescale The timescale of the media as the number of units that pass in one second.
 * @param duration The overall presentation duration in units of the timescale attribute, or 0
 *     if the duration is unknown.
 * @param dvrWindowLength The length of the trailing window in units of the timescale attribute,
 *     or 0 if this attribute is unspecified or not applicable.
 * @param lookAheadCount The number of fragments in a lookahead, or -1 if this attribute is
 *     unspecified or not applicable.
 * @param isLive True if the manifest describes a live presentation still in progress. False
 *     otherwise.
 * @param protectionElement Content protection information, or null if the content is not
 *     protected.
 * @param streamElements The contained stream elements.
 */
public SmoothStreamingManifest(int majorVersion, int minorVersion, long timescale, long duration,
    long dvrWindowLength, int lookAheadCount, boolean isLive, ProtectionElement protectionElement,
    StreamElement[] streamElements) {
  this.majorVersion = majorVersion;
  this.minorVersion = minorVersion;
  this.lookAheadCount = lookAheadCount;
  this.isLive = isLive;
  this.protectionElement = protectionElement;
  this.streamElements = streamElements;
  dvrWindowLengthUs = dvrWindowLength == 0 ? C.UNKNOWN_TIME_US
      : Util.scaleLargeTimestamp(dvrWindowLength, C.MICROS_PER_SECOND, timescale);
  durationUs = duration == 0 ? C.UNKNOWN_TIME_US
      : Util.scaleLargeTimestamp(duration, C.MICROS_PER_SECOND, timescale);
}
 
Example 6
Source File: SegmentBase.java    From Exoplayer_VLC with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the presentation time offset, in microseconds.
 *
 * @return The presentation time offset, in microseconds.
 */
public long getPresentationTimeOffsetUs() {
  return Util.scaleLargeTimestamp(presentationTimeOffset, C.MICROS_PER_SECOND, timescale);
}