Skip to content

Commit

Permalink
Separate enabling/setting TrackStreams in renderers (playlists #1).
Browse files Browse the repository at this point in the history
This is in preparation for changing the TrackStream while keeping the renderer
enabled, to give seamless transitions for playlists.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123394733
  • Loading branch information
andrewlewis authored and ojw28 committed Jun 15, 2016
1 parent 17f8ac8 commit 5cf7c2e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected void reset(long positionUs) {
}

@Override
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters.reset();
eventDispatcher.enabled(codecCounters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ protected void onAudioSessionId(int audioSessionId) {
}

@Override
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters.reset();
eventDispatcher.enabled(codecCounters);
super.onEnabled(formats, joining);
super.onEnabled(joining);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,18 @@ protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format forma
}

@Override
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters.reset();
eventDispatcher.enabled(codecCounters);
super.onEnabled(formats, joining);
super.onEnabled(joining);
if (joining && allowedJoiningTimeMs > 0) {
joiningDeadlineMs = SystemClock.elapsedRealtime() + allowedJoiningTimeMs;
}
frameReleaseTimeHelper.enable();
}

@Override
protected void onStreamChanged(Format[] formats) throws ExoPlaybackException {
adaptiveMaxWidth = Format.NO_VALUE;
adaptiveMaxHeight = Format.NO_VALUE;
if (formats.length > 1) {
Expand All @@ -226,10 +234,7 @@ protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackEx
adaptiveMaxHeight = 1080;
}
}
if (joining && allowedJoiningTimeMs > 0) {
joiningDeadlineMs = SystemClock.elapsedRealtime() + allowedJoiningTimeMs;
}
frameReleaseTimeHelper.enable();
super.onStreamChanged(formats);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ protected int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
boolean joining) throws ExoPlaybackException {
Assertions.checkState(state == STATE_DISABLED);
state = STATE_ENABLED;
this.stream = stream;
onEnabled(formats, joining);
onEnabled(joining);
replaceTrackStream(formats, stream);
reset(positionUs);
}

Expand All @@ -184,11 +184,35 @@ protected int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException {
* <p>
* The default implementation is a no-op.
*
* @param formats The enabled formats.
* @param joining Whether this renderer is being enabled to join an ongoing playback.
* @throws ExoPlaybackException If an error occurs.
*/
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
protected void onEnabled(boolean joining) throws ExoPlaybackException {
// Do nothing.
}

/**
* Replaces the {@link TrackStream} from which samples will be consumed.
*
* @param formats The enabled formats.
* @param trackStream The track stream from which the renderer should consume.
* @throws ExoPlaybackException If an error occurs.
*/
/* package */ final void replaceTrackStream(Format[] formats, TrackStream trackStream)
throws ExoPlaybackException {
stream = trackStream;
onStreamChanged(formats);
}

/**
* Called when the renderer's stream has changed.
* <p>
* The default implementation is a no-op.
*
* @param formats The enabled formats.
* @throws ExoPlaybackException Thrown if an error occurs.
*/
protected void onStreamChanged(Format[] formats) throws ExoPlaybackException {
// Do nothing.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ protected void onAudioSessionId(int audioSessionId) {
}

@Override
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
protected void onEnabled(boolean joining) throws ExoPlaybackException {
codecCounters.reset();
eventDispatcher.enabled(codecCounters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ protected int supportsFormat(Format format) {
}

@Override
protected void onEnabled(Format[] formats, boolean joining) throws ExoPlaybackException {
super.onEnabled(formats, joining);
protected void onStreamChanged(Format[] formats) throws ExoPlaybackException {
if (parser != null) {
parser.release();
}
parser = parserFactory.createParser(formats[0]);
}

Expand Down

0 comments on commit 5cf7c2e

Please sign in to comment.