com.google.android.exoplayer2.source.dash.DashSegmentIndex Java Examples
The following examples show how to use
com.google.android.exoplayer2.source.dash.DashSegmentIndex.
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: DashDownloader.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static @Nullable DashSegmentIndex getSegmentIndex( DataSource dataSource, int trackType, Representation representation) throws IOException, InterruptedException { DashSegmentIndex index = representation.getIndex(); if (index != null) { return index; } ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation); return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs); }
Example #2
Source File: DashDownloader.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static @Nullable DashSegmentIndex getSegmentIndex( DataSource dataSource, int trackType, Representation representation) throws IOException, InterruptedException { DashSegmentIndex index = representation.getIndex(); if (index != null) { return index; } ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation); return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs); }
Example #3
Source File: SegmentBase.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public int getSegmentCount(long periodDurationUs) { if (segmentTimeline != null) { return segmentTimeline.size(); } else if (endNumber != C.INDEX_UNSET) { return (int) (endNumber - startNumber + 1); } else if (periodDurationUs != C.TIME_UNSET) { long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; return (int) Util.ceilDivide(periodDurationUs, durationUs); } else { return DashSegmentIndex.INDEX_UNBOUNDED; } }
Example #4
Source File: SegmentBase.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getDurationUs(long, long) */ public final long getSegmentDurationUs(long sequenceNumber, long periodDurationUs) { if (segmentTimeline != null) { long duration = segmentTimeline.get((int) (sequenceNumber - startNumber)).duration; return (duration * C.MICROS_PER_SECOND) / timescale; } else { int segmentCount = getSegmentCount(periodDurationUs); return segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && sequenceNumber == (getFirstSegmentNum() + segmentCount - 1) ? (periodDurationUs - getSegmentTimeUs(sequenceNumber)) : ((duration * C.MICROS_PER_SECOND) / timescale); } }
Example #5
Source File: SegmentBase.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getSegmentNum(long, long) */ public long getSegmentNum(long timeUs, long periodDurationUs) { final long firstSegmentNum = getFirstSegmentNum(); final long segmentCount = getSegmentCount(periodDurationUs); if (segmentCount == 0) { return firstSegmentNum; } if (segmentTimeline == null) { // All segments are of equal duration (with the possible exception of the last one). long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; long segmentNum = startNumber + timeUs / durationUs; // Ensure we stay within bounds. return segmentNum < firstSegmentNum ? firstSegmentNum : segmentCount == DashSegmentIndex.INDEX_UNBOUNDED ? segmentNum : Math.min(segmentNum, firstSegmentNum + segmentCount - 1); } else { // The index cannot be unbounded. Identify the segment using binary search. long lowIndex = firstSegmentNum; long highIndex = firstSegmentNum + segmentCount - 1; while (lowIndex <= highIndex) { long midIndex = lowIndex + (highIndex - lowIndex) / 2; long midTimeUs = getSegmentTimeUs(midIndex); if (midTimeUs < timeUs) { lowIndex = midIndex + 1; } else if (midTimeUs > timeUs) { highIndex = midIndex - 1; } else { return midIndex; } } return lowIndex == firstSegmentNum ? lowIndex : highIndex; } }
Example #6
Source File: DashDownloader.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private static @Nullable DashSegmentIndex getSegmentIndex( DataSource dataSource, int trackType, Representation representation) throws IOException, InterruptedException { DashSegmentIndex index = representation.getIndex(); if (index != null) { return index; } ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation); return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs); }
Example #7
Source File: SegmentBase.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public int getSegmentCount(long periodDurationUs) { if (segmentTimeline != null) { return segmentTimeline.size(); } else if (endNumber != C.INDEX_UNSET) { return (int) (endNumber - startNumber + 1); } else if (periodDurationUs != C.TIME_UNSET) { long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; return (int) Util.ceilDivide(periodDurationUs, durationUs); } else { return DashSegmentIndex.INDEX_UNBOUNDED; } }
Example #8
Source File: SegmentBase.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getDurationUs(long, long) */ public final long getSegmentDurationUs(long sequenceNumber, long periodDurationUs) { if (segmentTimeline != null) { long duration = segmentTimeline.get((int) (sequenceNumber - startNumber)).duration; return (duration * C.MICROS_PER_SECOND) / timescale; } else { int segmentCount = getSegmentCount(periodDurationUs); return segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && sequenceNumber == (getFirstSegmentNum() + segmentCount - 1) ? (periodDurationUs - getSegmentTimeUs(sequenceNumber)) : ((duration * C.MICROS_PER_SECOND) / timescale); } }
Example #9
Source File: SegmentBase.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getSegmentNum(long, long) */ public long getSegmentNum(long timeUs, long periodDurationUs) { final long firstSegmentNum = getFirstSegmentNum(); final long segmentCount = getSegmentCount(periodDurationUs); if (segmentCount == 0) { return firstSegmentNum; } if (segmentTimeline == null) { // All segments are of equal duration (with the possible exception of the last one). long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; long segmentNum = startNumber + timeUs / durationUs; // Ensure we stay within bounds. return segmentNum < firstSegmentNum ? firstSegmentNum : segmentCount == DashSegmentIndex.INDEX_UNBOUNDED ? segmentNum : Math.min(segmentNum, firstSegmentNum + segmentCount - 1); } else { // The index cannot be unbounded. Identify the segment using binary search. long lowIndex = firstSegmentNum; long highIndex = firstSegmentNum + segmentCount - 1; while (lowIndex <= highIndex) { long midIndex = lowIndex + (highIndex - lowIndex) / 2; long midTimeUs = getSegmentTimeUs(midIndex); if (midTimeUs < timeUs) { lowIndex = midIndex + 1; } else if (midTimeUs > timeUs) { highIndex = midIndex - 1; } else { return midIndex; } } return lowIndex == firstSegmentNum ? lowIndex : highIndex; } }
Example #10
Source File: SegmentBase.java From K-Sonic with MIT License | 5 votes |
@Override public int getSegmentCount(long periodDurationUs) { if (segmentTimeline != null) { return segmentTimeline.size(); } else if (periodDurationUs != C.TIME_UNSET) { long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; return (int) Util.ceilDivide(periodDurationUs, durationUs); } else { return DashSegmentIndex.INDEX_UNBOUNDED; } }
Example #11
Source File: SegmentBase.java From K-Sonic with MIT License | 5 votes |
/** * @see DashSegmentIndex#getDurationUs(int, long) */ public final long getSegmentDurationUs(int sequenceNumber, long periodDurationUs) { if (segmentTimeline != null) { long duration = segmentTimeline.get(sequenceNumber - startNumber).duration; return (duration * C.MICROS_PER_SECOND) / timescale; } else { int segmentCount = getSegmentCount(periodDurationUs); return segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && sequenceNumber == (getFirstSegmentNum() + segmentCount - 1) ? (periodDurationUs - getSegmentTimeUs(sequenceNumber)) : ((duration * C.MICROS_PER_SECOND) / timescale); } }
Example #12
Source File: SegmentBase.java From K-Sonic with MIT License | 5 votes |
/** * @see DashSegmentIndex#getSegmentNum(long, long) */ public int getSegmentNum(long timeUs, long periodDurationUs) { final int firstSegmentNum = getFirstSegmentNum(); final int segmentCount = getSegmentCount(periodDurationUs); if (segmentCount == 0) { return firstSegmentNum; } if (segmentTimeline == null) { // All segments are of equal duration (with the possible exception of the last one). long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; int segmentNum = startNumber + (int) (timeUs / durationUs); // Ensure we stay within bounds. return segmentNum < firstSegmentNum ? firstSegmentNum : segmentCount == DashSegmentIndex.INDEX_UNBOUNDED ? segmentNum : Math.min(segmentNum, firstSegmentNum + segmentCount - 1); } else { // The index cannot be unbounded. Identify the segment using binary search. int lowIndex = firstSegmentNum; int highIndex = firstSegmentNum + segmentCount - 1; while (lowIndex <= highIndex) { int midIndex = lowIndex + (highIndex - lowIndex) / 2; long midTimeUs = getSegmentTimeUs(midIndex); if (midTimeUs < timeUs) { lowIndex = midIndex + 1; } else if (midTimeUs > timeUs) { highIndex = midIndex - 1; } else { return midIndex; } } return lowIndex == firstSegmentNum ? lowIndex : highIndex; } }
Example #13
Source File: SegmentBase.java From MediaSDK with Apache License 2.0 | 5 votes |
/** @see DashSegmentIndex#getSegmentNum(long, long) */ public long getSegmentNum(long timeUs, long periodDurationUs) { final long firstSegmentNum = getFirstSegmentNum(); final long segmentCount = getSegmentCount(periodDurationUs); if (segmentCount == 0) { return firstSegmentNum; } if (segmentTimeline == null) { // All segments are of equal duration (with the possible exception of the last one). long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; long segmentNum = startNumber + timeUs / durationUs; // Ensure we stay within bounds. return segmentNum < firstSegmentNum ? firstSegmentNum : segmentCount == DashSegmentIndex.INDEX_UNBOUNDED ? segmentNum : Math.min(segmentNum, firstSegmentNum + segmentCount - 1); } else { // The index cannot be unbounded. Identify the segment using binary search. long lowIndex = firstSegmentNum; long highIndex = firstSegmentNum + segmentCount - 1; while (lowIndex <= highIndex) { long midIndex = lowIndex + (highIndex - lowIndex) / 2; long midTimeUs = getSegmentTimeUs(midIndex); if (midTimeUs < timeUs) { lowIndex = midIndex + 1; } else if (midTimeUs > timeUs) { highIndex = midIndex - 1; } else { return midIndex; } } return lowIndex == firstSegmentNum ? lowIndex : highIndex; } }
Example #14
Source File: SegmentBase.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public int getSegmentCount(long periodDurationUs) { if (segmentTimeline != null) { return segmentTimeline.size(); } else if (periodDurationUs != C.TIME_UNSET) { long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; return (int) Util.ceilDivide(periodDurationUs, durationUs); } else { return DashSegmentIndex.INDEX_UNBOUNDED; } }
Example #15
Source File: SegmentBase.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getDurationUs(long, long) */ public final long getSegmentDurationUs(long sequenceNumber, long periodDurationUs) { if (segmentTimeline != null) { long duration = segmentTimeline.get((int) (sequenceNumber - startNumber)).duration; return (duration * C.MICROS_PER_SECOND) / timescale; } else { int segmentCount = getSegmentCount(periodDurationUs); return segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && sequenceNumber == (getFirstSegmentNum() + segmentCount - 1) ? (periodDurationUs - getSegmentTimeUs(sequenceNumber)) : ((duration * C.MICROS_PER_SECOND) / timescale); } }
Example #16
Source File: SegmentBase.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getSegmentNum(long, long) */ public long getSegmentNum(long timeUs, long periodDurationUs) { final long firstSegmentNum = getFirstSegmentNum(); final long segmentCount = getSegmentCount(periodDurationUs); if (segmentCount == 0) { return firstSegmentNum; } if (segmentTimeline == null) { // All segments are of equal duration (with the possible exception of the last one). long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; long segmentNum = startNumber + timeUs / durationUs; // Ensure we stay within bounds. return segmentNum < firstSegmentNum ? firstSegmentNum : segmentCount == DashSegmentIndex.INDEX_UNBOUNDED ? segmentNum : Math.min(segmentNum, firstSegmentNum + segmentCount - 1); } else { // The index cannot be unbounded. Identify the segment using binary search. long lowIndex = firstSegmentNum; long highIndex = firstSegmentNum + segmentCount - 1; while (lowIndex <= highIndex) { long midIndex = lowIndex + (highIndex - lowIndex) / 2; long midTimeUs = getSegmentTimeUs(midIndex); if (midTimeUs < timeUs) { lowIndex = midIndex + 1; } else if (midTimeUs > timeUs) { highIndex = midIndex - 1; } else { return midIndex; } } return lowIndex == firstSegmentNum ? lowIndex : highIndex; } }
Example #17
Source File: DashDownloader.java From MediaSDK with Apache License 2.0 | 5 votes |
private static @Nullable DashSegmentIndex getSegmentIndex( DataSource dataSource, int trackType, Representation representation) throws IOException, InterruptedException { DashSegmentIndex index = representation.getIndex(); if (index != null) { return index; } ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation); return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs); }
Example #18
Source File: SegmentBase.java From MediaSDK with Apache License 2.0 | 5 votes |
/** @see DashSegmentIndex#getDurationUs(long, long) */ public final long getSegmentDurationUs(long sequenceNumber, long periodDurationUs) { if (segmentTimeline != null) { long duration = segmentTimeline.get((int) (sequenceNumber - startNumber)).duration; return (duration * C.MICROS_PER_SECOND) / timescale; } else { int segmentCount = getSegmentCount(periodDurationUs); return segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && sequenceNumber == (getFirstSegmentNum() + segmentCount - 1) ? (periodDurationUs - getSegmentTimeUs(sequenceNumber)) : ((duration * C.MICROS_PER_SECOND) / timescale); } }
Example #19
Source File: SegmentBase.java From MediaSDK with Apache License 2.0 | 5 votes |
@Override public int getSegmentCount(long periodDurationUs) { if (segmentTimeline != null) { return segmentTimeline.size(); } else if (endNumber != C.INDEX_UNSET) { return (int) (endNumber - startNumber + 1); } else if (periodDurationUs != C.TIME_UNSET) { long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; return (int) Util.ceilDivide(periodDurationUs, durationUs); } else { return DashSegmentIndex.INDEX_UNBOUNDED; } }
Example #20
Source File: DashDownloader.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static @Nullable DashSegmentIndex getSegmentIndex( DataSource dataSource, int trackType, Representation representation) throws IOException, InterruptedException { DashSegmentIndex index = representation.getIndex(); if (index != null) { return index; } ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation); return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs); }
Example #21
Source File: SegmentBase.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getSegmentNum(long, long) */ public long getSegmentNum(long timeUs, long periodDurationUs) { final long firstSegmentNum = getFirstSegmentNum(); final long segmentCount = getSegmentCount(periodDurationUs); if (segmentCount == 0) { return firstSegmentNum; } if (segmentTimeline == null) { // All segments are of equal duration (with the possible exception of the last one). long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; long segmentNum = startNumber + timeUs / durationUs; // Ensure we stay within bounds. return segmentNum < firstSegmentNum ? firstSegmentNum : segmentCount == DashSegmentIndex.INDEX_UNBOUNDED ? segmentNum : Math.min(segmentNum, firstSegmentNum + segmentCount - 1); } else { // The index cannot be unbounded. Identify the segment using binary search. long lowIndex = firstSegmentNum; long highIndex = firstSegmentNum + segmentCount - 1; while (lowIndex <= highIndex) { long midIndex = lowIndex + (highIndex - lowIndex) / 2; long midTimeUs = getSegmentTimeUs(midIndex); if (midTimeUs < timeUs) { lowIndex = midIndex + 1; } else if (midTimeUs > timeUs) { highIndex = midIndex - 1; } else { return midIndex; } } return lowIndex == firstSegmentNum ? lowIndex : highIndex; } }
Example #22
Source File: SegmentBase.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** @see DashSegmentIndex#getDurationUs(long, long) */ public final long getSegmentDurationUs(long sequenceNumber, long periodDurationUs) { if (segmentTimeline != null) { long duration = segmentTimeline.get((int) (sequenceNumber - startNumber)).duration; return (duration * C.MICROS_PER_SECOND) / timescale; } else { int segmentCount = getSegmentCount(periodDurationUs); return segmentCount != DashSegmentIndex.INDEX_UNBOUNDED && sequenceNumber == (getFirstSegmentNum() + segmentCount - 1) ? (periodDurationUs - getSegmentTimeUs(sequenceNumber)) : ((duration * C.MICROS_PER_SECOND) / timescale); } }
Example #23
Source File: SegmentBase.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public int getSegmentCount(long periodDurationUs) { if (segmentTimeline != null) { return segmentTimeline.size(); } else if (periodDurationUs != C.TIME_UNSET) { long durationUs = (duration * C.MICROS_PER_SECOND) / timescale; return (int) Util.ceilDivide(periodDurationUs, durationUs); } else { return DashSegmentIndex.INDEX_UNBOUNDED; } }
Example #24
Source File: Representation.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override public DashSegmentIndex getIndex() { return segmentIndex; }
Example #25
Source File: DashDownloader.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private static void addSegmentsForAdaptationSet( DataSource dataSource, AdaptationSet adaptationSet, long periodStartUs, long periodDurationUs, boolean allowIncompleteList, ArrayList<Segment> out) throws IOException, InterruptedException { for (int i = 0; i < adaptationSet.representations.size(); i++) { Representation representation = adaptationSet.representations.get(i); DashSegmentIndex index; try { index = getSegmentIndex(dataSource, adaptationSet.type, representation); if (index == null) { // Loading succeeded but there was no index. throw new DownloadException("Missing segment index"); } } catch (IOException e) { if (!allowIncompleteList) { throw e; } // Loading failed, but generating an incomplete segment list is allowed. Advance to the next // representation. continue; } int segmentCount = index.getSegmentCount(periodDurationUs); if (segmentCount == DashSegmentIndex.INDEX_UNBOUNDED) { throw new DownloadException("Unbounded segment index"); } String baseUrl = representation.baseUrl; RangedUri initializationUri = representation.getInitializationUri(); if (initializationUri != null) { addSegment(periodStartUs, baseUrl, initializationUri, out); } RangedUri indexUri = representation.getIndexUri(); if (indexUri != null) { addSegment(periodStartUs, baseUrl, indexUri, out); } long firstSegmentNum = index.getFirstSegmentNum(); long lastSegmentNum = firstSegmentNum + segmentCount - 1; for (long j = firstSegmentNum; j <= lastSegmentNum; j++) { addSegment(periodStartUs + index.getTimeUs(j), baseUrl, index.getSegmentUrl(j), out); } } }
Example #26
Source File: DashDownloader.java From Telegram with GNU General Public License v2.0 | 4 votes |
private static void addSegmentsForAdaptationSet( DataSource dataSource, AdaptationSet adaptationSet, long periodStartUs, long periodDurationUs, boolean allowIncompleteList, ArrayList<Segment> out) throws IOException, InterruptedException { for (int i = 0; i < adaptationSet.representations.size(); i++) { Representation representation = adaptationSet.representations.get(i); DashSegmentIndex index; try { index = getSegmentIndex(dataSource, adaptationSet.type, representation); if (index == null) { // Loading succeeded but there was no index. throw new DownloadException("Missing segment index"); } } catch (IOException e) { if (!allowIncompleteList) { throw e; } // Generating an incomplete segment list is allowed. Advance to the next representation. continue; } int segmentCount = index.getSegmentCount(periodDurationUs); if (segmentCount == DashSegmentIndex.INDEX_UNBOUNDED) { throw new DownloadException("Unbounded segment index"); } String baseUrl = representation.baseUrl; RangedUri initializationUri = representation.getInitializationUri(); if (initializationUri != null) { addSegment(periodStartUs, baseUrl, initializationUri, out); } RangedUri indexUri = representation.getIndexUri(); if (indexUri != null) { addSegment(periodStartUs, baseUrl, indexUri, out); } long firstSegmentNum = index.getFirstSegmentNum(); long lastSegmentNum = firstSegmentNum + segmentCount - 1; for (long j = firstSegmentNum; j <= lastSegmentNum; j++) { addSegment(periodStartUs + index.getTimeUs(j), baseUrl, index.getSegmentUrl(j), out); } } }
Example #27
Source File: Representation.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public DashSegmentIndex getIndex() { return this; }
Example #28
Source File: Representation.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override public DashSegmentIndex getIndex() { return segmentIndex; }
Example #29
Source File: Representation.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public DashSegmentIndex getIndex() { return this; }
Example #30
Source File: Representation.java From MediaSDK with Apache License 2.0 | 4 votes |
/** Returns an index if the representation provides one directly, or null otherwise. */ @Nullable public abstract DashSegmentIndex getIndex();