Skip to content

Commit

Permalink
Always set PARAMETER_KEY_TUNNEL_PEEK when tunneling
Browse files Browse the repository at this point in the history
This should already be the default, but some devices seem
to not adhere to this contract and assume the default is unset.

Issue: androidx/media#1169
PiperOrigin-RevId: 614697283
  • Loading branch information
tonihei authored and Copybara-Service committed Mar 12, 2024
1 parent 40a7b7d commit f4ca703
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ protected void onPositionReset(long positionUs, boolean joining) throws ExoPlayb
if (joining) {
videoFrameReleaseControl.join();
}
maybeUpdateOnFrameRenderedListener();
maybeSetupTunnelingForFirstFrame();
consecutiveDroppedFrameCount = 0;
}

Expand Down Expand Up @@ -710,7 +710,7 @@ protected void onStopped() {
protected void onDisabled() {
reportedVideoSize = null;
videoFrameReleaseControl.onDisabled();
maybeUpdateOnFrameRenderedListener();
maybeSetupTunnelingForFirstFrame();
haveReportedFirstFrameRenderedForCurrentSurface = false;
tunnelingOnFrameRenderedListener = null;
try {
Expand Down Expand Up @@ -851,7 +851,7 @@ private void setOutput(@Nullable Object output) throws ExoPlaybackException {
videoSinkProvider.clearOutputSurfaceInfo();
}
}
maybeUpdateOnFrameRenderedListener();
maybeSetupTunnelingForFirstFrame();
} else if (displaySurface != null && displaySurface != placeholderSurface) {
// The display surface is set and unchanged. If we know the video size and/or have already
// rendered to the display surface, report these again immediately.
Expand Down Expand Up @@ -1133,9 +1133,7 @@ protected void onCodecInitialized(
codecNeedsSetOutputSurfaceWorkaround = codecNeedsSetOutputSurfaceWorkaround(name);
codecHandlesHdr10PlusOutOfBandMetadata =
checkNotNull(getCodecInfo()).isHdr10PlusOutOfBandMetadataSupported();
if (Util.SDK_INT >= 23 && tunneling) {
tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(checkNotNull(getCodec()));
}
maybeSetupTunnelingForFirstFrame();
}

@Override
Expand Down Expand Up @@ -1467,7 +1465,7 @@ protected void onProcessedOutputBuffer(long presentationTimeUs) {
protected void onProcessedStreamChange() {
super.onProcessedStreamChange();
videoFrameReleaseControl.onProcessedStreamChange();
maybeUpdateOnFrameRenderedListener();
maybeSetupTunnelingForFirstFrame();
if (videoSinkProvider.isInitialized()) {
videoSinkProvider.setStreamOffsetUs(getOutputStreamOffsetUs());
}
Expand Down Expand Up @@ -1697,17 +1695,25 @@ private void releasePlaceholderSurface() {
}
}

private void maybeUpdateOnFrameRenderedListener() {
// The first frame notification is triggered by renderOutputBuffer or renderOutputBufferV21 for
// non-tunneled playback, onQueueInputBuffer for tunneled playback prior to API level 23, and
// OnFrameRenderedListenerV23.onFrameRenderedListener for tunneled playback on API level 23 and
// above.
if (Util.SDK_INT >= 23 && tunneling) {
@Nullable MediaCodecAdapter codec = getCodec();
// If codec is null then the listener will be instantiated in configureCodec.
if (codec != null) {
tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(codec);
}
private void maybeSetupTunnelingForFirstFrame() {
if (!tunneling || Util.SDK_INT < 23) {
// The first frame notification for tunneling is triggered by onQueueInputBuffer prior to API
// level 23 and no setup is needed here.
return;
}
@Nullable MediaCodecAdapter codec = getCodec();
if (codec == null) {
// If codec is null, then the setup will be triggered again in onCodecInitialized.
return;
}
tunnelingOnFrameRenderedListener = new OnFrameRenderedListenerV23(codec);
if (Util.SDK_INT >= 33) {
// This should be the default anyway according to the API contract, but some devices are known
// to not adhere to this contract and need to get the parameter explicitly. See
// https://github.com/androidx/media/issues/1169.
Bundle codecParameters = new Bundle();
codecParameters.putInt(MediaCodec.PARAMETER_KEY_TUNNEL_PEEK, 1);
codec.setParameters(codecParameters);
}
}

Expand Down

0 comments on commit f4ca703

Please sign in to comment.