mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Use fast surface switching on API level 23+ when possible
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=150185483
This commit is contained in:
parent
7c5f0b7d3b
commit
a9617af29c
@ -298,15 +298,20 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setSurface(Surface surface) throws ExoPlaybackException {
|
private void setSurface(Surface surface) throws ExoPlaybackException {
|
||||||
// We only need to release and reinitialize the codec if the surface has changed.
|
// We only need to update the codec if the surface has changed.
|
||||||
if (this.surface != surface) {
|
if (this.surface != surface) {
|
||||||
this.surface = surface;
|
this.surface = surface;
|
||||||
int state = getState();
|
int state = getState();
|
||||||
if (state == STATE_ENABLED || state == STATE_STARTED) {
|
if (state == STATE_ENABLED || state == STATE_STARTED) {
|
||||||
|
MediaCodec codec = getCodec();
|
||||||
|
if (Util.SDK_INT >= 23 && codec != null && surface != null) {
|
||||||
|
setOutputSurfaceV23(codec, surface);
|
||||||
|
} else {
|
||||||
releaseCodec();
|
releaseCodec();
|
||||||
maybeInitCodec();
|
maybeInitCodec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Clear state so that we always call the event listener with the video size and when a frame
|
// Clear state so that we always call the event listener with the video size and when a frame
|
||||||
// is rendered, even if the surface hasn't changed.
|
// is rendered, even if the surface hasn't changed.
|
||||||
clearRenderedFirstFrame();
|
clearRenderedFirstFrame();
|
||||||
@ -589,6 +594,11 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
return frameworkMediaFormat;
|
return frameworkMediaFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(23)
|
||||||
|
private static void setOutputSurfaceV23(MediaCodec codec, Surface surface) {
|
||||||
|
codec.setOutputSurface(surface);
|
||||||
|
}
|
||||||
|
|
||||||
@TargetApi(21)
|
@TargetApi(21)
|
||||||
private static void configureTunnelingV21(MediaFormat mediaFormat, int tunnelingAudioSessionId) {
|
private static void configureTunnelingV21(MediaFormat mediaFormat, int tunnelingAudioSessionId) {
|
||||||
mediaFormat.setFeatureEnabled(CodecCapabilities.FEATURE_TunneledPlayback, true);
|
mediaFormat.setFeatureEnabled(CodecCapabilities.FEATURE_TunneledPlayback, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user