/** * @param sources One or more upstream sources from which the renderer can obtain samples. */ public SampleSourceTrackRenderer(SampleSource... sources) { this.sources = new SampleSourceReader[sources.length]; for (int i = 0; i < sources.length; i++) { this.sources[i] = sources[i].register(); } }
private void maybeThrowError(SampleSourceReader source) throws ExoPlaybackException { try { source.maybeThrowError(); } catch (IOException e) { throw new ExoPlaybackException(e); } }
@Override public SampleSourceReader register() { mRemainingReleaseCount++; return this; }
@Override public SampleSourceReader register() { remainingReleaseCount++; return this; }
@Override public SampleSourceReader register() { return this; }
@Override public SampleSourceReader register() { Assertions.checkState(state == STATE_IDLE); state = STATE_INITIALIZED; return this; }
@Override protected final boolean doPrepare(long positionUs) throws ExoPlaybackException { boolean allSourcesPrepared = true; for (int i = 0; i < sources.length; i++) { allSourcesPrepared &= sources[i].prepare(positionUs); } if (!allSourcesPrepared) { return false; } // The sources are all prepared. int totalSourceTrackCount = 0; for (int i = 0; i < sources.length; i++) { totalSourceTrackCount += sources[i].getTrackCount(); } long durationUs = 0; int handledTrackCount = 0; int[] handledSourceIndices = new int[totalSourceTrackCount]; int[] handledTrackIndices = new int[totalSourceTrackCount]; int sourceCount = sources.length; for (int sourceIndex = 0; sourceIndex < sourceCount; sourceIndex++) { SampleSourceReader source = sources[sourceIndex]; int sourceTrackCount = source.getTrackCount(); for (int trackIndex = 0; trackIndex < sourceTrackCount; trackIndex++) { MediaFormat format = source.getFormat(trackIndex); boolean handlesTrack; try { handlesTrack = handlesTrack(format); } catch (DecoderQueryException e) { throw new ExoPlaybackException(e); } if (handlesTrack) { handledSourceIndices[handledTrackCount] = sourceIndex; handledTrackIndices[handledTrackCount] = trackIndex; handledTrackCount++; if (durationUs == TrackRenderer.UNKNOWN_TIME_US) { // We've already encountered a track for which the duration is unknown, so the media // duration is unknown regardless of the duration of this track. } else { long trackDurationUs = format.durationUs; if (trackDurationUs == TrackRenderer.UNKNOWN_TIME_US) { durationUs = TrackRenderer.UNKNOWN_TIME_US; } else if (trackDurationUs == TrackRenderer.MATCH_LONGEST_US) { // Do nothing. } else { durationUs = Math.max(durationUs, trackDurationUs); } } } } } this.durationUs = durationUs; this.handledSourceIndices = Arrays.copyOf(handledSourceIndices, handledTrackCount); this.handledSourceTrackIndices = Arrays.copyOf(handledTrackIndices, handledTrackCount); return true; }
@Override protected final MediaFormat getFormat(int track) { SampleSourceReader source = sources[handledSourceIndices[track]]; return source.getFormat(handledSourceTrackIndices[track]); }