com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment Java Examples

The following examples show how to use com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist.Segment. 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: DefaultHlsPlaylistTracker.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private int getLoadedPlaylistDiscontinuitySequence(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasDiscontinuitySequence) {
    return loadedPlaylist.discontinuitySequence;
  }
  // TODO: Improve cross-playlist discontinuity adjustment.
  int primaryUrlDiscontinuitySequence =
      primaryMediaPlaylistSnapshot != null
          ? primaryMediaPlaylistSnapshot.discontinuitySequence
          : 0;
  if (oldPlaylist == null) {
    return primaryUrlDiscontinuitySequence;
  }
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.discontinuitySequence
        + firstOldOverlappingSegment.relativeDiscontinuitySequence
        - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
  }
  return primaryUrlDiscontinuitySequence;
}
 
Example #2
Source File: DefaultHlsPlaylistTracker.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private int getLoadedPlaylistDiscontinuitySequence(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasDiscontinuitySequence) {
    return loadedPlaylist.discontinuitySequence;
  }
  // TODO: Improve cross-playlist discontinuity adjustment.
  int primaryUrlDiscontinuitySequence =
      primaryMediaPlaylistSnapshot != null
          ? primaryMediaPlaylistSnapshot.discontinuitySequence
          : 0;
  if (oldPlaylist == null) {
    return primaryUrlDiscontinuitySequence;
  }
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.discontinuitySequence
        + firstOldOverlappingSegment.relativeDiscontinuitySequence
        - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
  }
  return primaryUrlDiscontinuitySequence;
}
 
Example #3
Source File: DefaultHlsPlaylistTracker.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private long getLoadedPlaylistStartTimeUs(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasProgramDateTime) {
    return loadedPlaylist.startTimeUs;
  }
  long primarySnapshotStartTimeUs =
      primaryMediaPlaylistSnapshot != null ? primaryMediaPlaylistSnapshot.startTimeUs : 0;
  if (oldPlaylist == null) {
    return primarySnapshotStartTimeUs;
  }
  int oldPlaylistSize = oldPlaylist.segments.size();
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.startTimeUs + firstOldOverlappingSegment.relativeStartTimeUs;
  } else if (oldPlaylistSize == loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence) {
    return oldPlaylist.getEndTimeUs();
  } else {
    // No segments overlap, we assume the new playlist start coincides with the primary playlist.
    return primarySnapshotStartTimeUs;
  }
}
 
Example #4
Source File: HlsPlaylistTracker.java    From K-Sonic with MIT License 6 votes vote down vote up
private int getLoadedPlaylistDiscontinuitySequence(HlsMediaPlaylist oldPlaylist,
    HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasDiscontinuitySequence) {
    return loadedPlaylist.discontinuitySequence;
  }
  // TODO: Improve cross-playlist discontinuity adjustment.
  int primaryUrlDiscontinuitySequence = primaryUrlSnapshot != null
      ? primaryUrlSnapshot.discontinuitySequence : 0;
  if (oldPlaylist == null) {
    return primaryUrlDiscontinuitySequence;
  }
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.discontinuitySequence
        + firstOldOverlappingSegment.relativeDiscontinuitySequence
        - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
  }
  return primaryUrlDiscontinuitySequence;
}
 
Example #5
Source File: HlsPlaylistTracker.java    From K-Sonic with MIT License 6 votes vote down vote up
private long getLoadedPlaylistStartTimeUs(HlsMediaPlaylist oldPlaylist,
    HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasProgramDateTime) {
    return loadedPlaylist.startTimeUs;
  }
  long primarySnapshotStartTimeUs = primaryUrlSnapshot != null
      ? primaryUrlSnapshot.startTimeUs : 0;
  if (oldPlaylist == null) {
    return primarySnapshotStartTimeUs;
  }
  int oldPlaylistSize = oldPlaylist.segments.size();
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.startTimeUs + firstOldOverlappingSegment.relativeStartTimeUs;
  } else if (oldPlaylistSize == loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence) {
    return oldPlaylist.getEndTimeUs();
  } else {
    // No segments overlap, we assume the new playlist start coincides with the primary playlist.
    return primarySnapshotStartTimeUs;
  }
}
 
Example #6
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int getLoadedPlaylistDiscontinuitySequence(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasDiscontinuitySequence) {
    return loadedPlaylist.discontinuitySequence;
  }
  // TODO: Improve cross-playlist discontinuity adjustment.
  int primaryUrlDiscontinuitySequence =
      primaryUrlSnapshot != null ? primaryUrlSnapshot.discontinuitySequence : 0;
  if (oldPlaylist == null) {
    return primaryUrlDiscontinuitySequence;
  }
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.discontinuitySequence
        + firstOldOverlappingSegment.relativeDiscontinuitySequence
        - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
  }
  return primaryUrlDiscontinuitySequence;
}
 
Example #7
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private long getLoadedPlaylistStartTimeUs(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasProgramDateTime) {
    return loadedPlaylist.startTimeUs;
  }
  long primarySnapshotStartTimeUs =
      primaryUrlSnapshot != null ? primaryUrlSnapshot.startTimeUs : 0;
  if (oldPlaylist == null) {
    return primarySnapshotStartTimeUs;
  }
  int oldPlaylistSize = oldPlaylist.segments.size();
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.startTimeUs + firstOldOverlappingSegment.relativeStartTimeUs;
  } else if (oldPlaylistSize == loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence) {
    return oldPlaylist.getEndTimeUs();
  } else {
    // No segments overlap, we assume the new playlist start coincides with the primary playlist.
    return primarySnapshotStartTimeUs;
  }
}
 
Example #8
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private int getLoadedPlaylistDiscontinuitySequence(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasDiscontinuitySequence) {
    return loadedPlaylist.discontinuitySequence;
  }
  // TODO: Improve cross-playlist discontinuity adjustment.
  int primaryUrlDiscontinuitySequence =
      primaryUrlSnapshot != null ? primaryUrlSnapshot.discontinuitySequence : 0;
  if (oldPlaylist == null) {
    return primaryUrlDiscontinuitySequence;
  }
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.discontinuitySequence
        + firstOldOverlappingSegment.relativeDiscontinuitySequence
        - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
  }
  return primaryUrlDiscontinuitySequence;
}
 
Example #9
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private long getLoadedPlaylistStartTimeUs(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasProgramDateTime) {
    return loadedPlaylist.startTimeUs;
  }
  long primarySnapshotStartTimeUs =
      primaryUrlSnapshot != null ? primaryUrlSnapshot.startTimeUs : 0;
  if (oldPlaylist == null) {
    return primarySnapshotStartTimeUs;
  }
  int oldPlaylistSize = oldPlaylist.segments.size();
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.startTimeUs + firstOldOverlappingSegment.relativeStartTimeUs;
  } else if (oldPlaylistSize == loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence) {
    return oldPlaylist.getEndTimeUs();
  } else {
    // No segments overlap, we assume the new playlist start coincides with the primary playlist.
    return primarySnapshotStartTimeUs;
  }
}
 
Example #10
Source File: DefaultHlsPlaylistTracker.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private long getLoadedPlaylistStartTimeUs(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasProgramDateTime) {
    return loadedPlaylist.startTimeUs;
  }
  long primarySnapshotStartTimeUs =
      primaryMediaPlaylistSnapshot != null ? primaryMediaPlaylistSnapshot.startTimeUs : 0;
  if (oldPlaylist == null) {
    return primarySnapshotStartTimeUs;
  }
  int oldPlaylistSize = oldPlaylist.segments.size();
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.startTimeUs + firstOldOverlappingSegment.relativeStartTimeUs;
  } else if (oldPlaylistSize == loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence) {
    return oldPlaylist.getEndTimeUs();
  } else {
    // No segments overlap, we assume the new playlist start coincides with the primary playlist.
    return primarySnapshotStartTimeUs;
  }
}
 
Example #11
Source File: DefaultHlsPlaylistTracker.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private int getLoadedPlaylistDiscontinuitySequence(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasDiscontinuitySequence) {
    return loadedPlaylist.discontinuitySequence;
  }
  // TODO: Improve cross-playlist discontinuity adjustment.
  int primaryUrlDiscontinuitySequence =
      primaryMediaPlaylistSnapshot != null
          ? primaryMediaPlaylistSnapshot.discontinuitySequence
          : 0;
  if (oldPlaylist == null) {
    return primaryUrlDiscontinuitySequence;
  }
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.discontinuitySequence
        + firstOldOverlappingSegment.relativeDiscontinuitySequence
        - loadedPlaylist.segments.get(0).relativeDiscontinuitySequence;
  }
  return primaryUrlDiscontinuitySequence;
}
 
Example #12
Source File: DefaultHlsPlaylistTracker.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private long getLoadedPlaylistStartTimeUs(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  if (loadedPlaylist.hasProgramDateTime) {
    return loadedPlaylist.startTimeUs;
  }
  long primarySnapshotStartTimeUs =
      primaryMediaPlaylistSnapshot != null ? primaryMediaPlaylistSnapshot.startTimeUs : 0;
  if (oldPlaylist == null) {
    return primarySnapshotStartTimeUs;
  }
  int oldPlaylistSize = oldPlaylist.segments.size();
  Segment firstOldOverlappingSegment = getFirstOldOverlappingSegment(oldPlaylist, loadedPlaylist);
  if (firstOldOverlappingSegment != null) {
    return oldPlaylist.startTimeUs + firstOldOverlappingSegment.relativeStartTimeUs;
  } else if (oldPlaylistSize == loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence) {
    return oldPlaylist.getEndTimeUs();
  } else {
    // No segments overlap, we assume the new playlist start coincides with the primary playlist.
    return primarySnapshotStartTimeUs;
  }
}
 
Example #13
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getChunkEndTimeUs() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  long segmentStartTimeInPeriodUs = startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
  return segmentStartTimeInPeriodUs + segment.durationUs;
}
 
Example #14
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DataSpec getDataSpec() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
  return new DataSpec(
      chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
}
 
Example #15
Source File: HlsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Nullable
private static Uri getFullEncryptionKeyUri(HlsMediaPlaylist playlist, @Nullable Segment segment) {
  if (segment == null || segment.fullSegmentEncryptionKeyUri == null) {
    return null;
  }
  return UriUtil.resolveToUri(playlist.baseUri, segment.fullSegmentEncryptionKeyUri);
}
 
Example #16
Source File: HlsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public DataSpec getDataSpec() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
  return new DataSpec(
      chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
}
 
Example #17
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Nullable
private static Uri getFullEncryptionKeyUri(HlsMediaPlaylist playlist, @Nullable Segment segment) {
  if (segment == null || segment.fullSegmentEncryptionKeyUri == null) {
    return null;
  }
  return UriUtil.resolveToUri(playlist.baseUri, segment.fullSegmentEncryptionKeyUri);
}
 
Example #18
Source File: HlsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getChunkEndTimeUs() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  long segmentStartTimeInPeriodUs = startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
  return segmentStartTimeInPeriodUs + segment.durationUs;
}
 
Example #19
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long getChunkEndTimeUs() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  long segmentStartTimeInPeriodUs = startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
  return segmentStartTimeInPeriodUs + segment.durationUs;
}
 
Example #20
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public DataSpec getDataSpec() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  Uri chunkUri = UriUtil.resolveToUri(playlist.baseUri, segment.url);
  return new DataSpec(
      chunkUri, segment.byterangeOffset, segment.byterangeLength, /* key= */ null);
}
 
Example #21
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Uri getFullEncryptionKeyUri(HlsMediaPlaylist playlist, @Nullable Segment segment) {
  if (segment == null || segment.fullSegmentEncryptionKeyUri == null) {
    return null;
  }
  return UriUtil.resolveToUri(playlist.baseUri, segment.fullSegmentEncryptionKeyUri);
}
 
Example #22
Source File: DefaultHlsPlaylistTracker.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static Segment getFirstOldOverlappingSegment(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  int mediaSequenceOffset = (int) (loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence);
  List<Segment> oldSegments = oldPlaylist.segments;
  return mediaSequenceOffset < oldSegments.size() ? oldSegments.get(mediaSequenceOffset) : null;
}
 
Example #23
Source File: HlsPlaylistTracker.java    From K-Sonic with MIT License 4 votes vote down vote up
private static Segment getFirstOldOverlappingSegment(HlsMediaPlaylist oldPlaylist,
    HlsMediaPlaylist loadedPlaylist) {
  int mediaSequenceOffset = loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence;
  List<Segment> oldSegments = oldPlaylist.segments;
  return mediaSequenceOffset < oldSegments.size() ? oldSegments.get(mediaSequenceOffset) : null;
}
 
Example #24
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static Segment getFirstOldOverlappingSegment(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  int mediaSequenceOffset = (int) (loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence);
  List<Segment> oldSegments = oldPlaylist.segments;
  return mediaSequenceOffset < oldSegments.size() ? oldSegments.get(mediaSequenceOffset) : null;
}
 
Example #25
Source File: HlsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public long getChunkStartTimeUs() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  return startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
}
 
Example #26
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private static Segment getFirstOldOverlappingSegment(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  int mediaSequenceOffset = (int) (loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence);
  List<Segment> oldSegments = oldPlaylist.segments;
  return mediaSequenceOffset < oldSegments.size() ? oldSegments.get(mediaSequenceOffset) : null;
}
 
Example #27
Source File: HlsChunkSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public long getChunkStartTimeUs() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  return startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
}
 
Example #28
Source File: DefaultHlsPlaylistTracker.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static Segment getFirstOldOverlappingSegment(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  int mediaSequenceOffset = (int) (loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence);
  List<Segment> oldSegments = oldPlaylist.segments;
  return mediaSequenceOffset < oldSegments.size() ? oldSegments.get(mediaSequenceOffset) : null;
}
 
Example #29
Source File: HlsChunkSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public long getChunkStartTimeUs() {
  checkInBounds();
  Segment segment = playlist.segments.get((int) getCurrentIndex());
  return startOfPlaylistInPeriodUs + segment.relativeStartTimeUs;
}
 
Example #30
Source File: DefaultHlsPlaylistTracker.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static Segment getFirstOldOverlappingSegment(
    HlsMediaPlaylist oldPlaylist, HlsMediaPlaylist loadedPlaylist) {
  int mediaSequenceOffset = (int) (loadedPlaylist.mediaSequence - oldPlaylist.mediaSequence);
  List<Segment> oldSegments = oldPlaylist.segments;
  return mediaSequenceOffset < oldSegments.size() ? oldSegments.get(mediaSequenceOffset) : null;
}