Simplify setting of codec operating rate
Issue: #2826 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=218540967
This commit is contained in:
parent
706ce49bd3
commit
1b6801c091
@ -388,7 +388,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getCodecOperatingRate(
|
protected float getCodecOperatingRateV23(
|
||||||
float operatingRate, Format format, Format[] streamFormats) {
|
float operatingRate, Format format, Format[] streamFormats) {
|
||||||
// Use the highest known stream sample-rate up front, to avoid having to reconfigure the codec
|
// Use the highest known stream sample-rate up front, to avoid having to reconfigure the codec
|
||||||
// should an adaptive switch to that stream occur.
|
// should an adaptive switch to that stream occur.
|
||||||
|
@ -298,7 +298,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
private MediaCodec codec;
|
private MediaCodec codec;
|
||||||
private float rendererOperatingRate;
|
private float rendererOperatingRate;
|
||||||
private float codecOperatingRate;
|
private float codecOperatingRate;
|
||||||
private boolean codecConfiguredWithOperatingRate;
|
|
||||||
@Nullable private ArrayDeque<MediaCodecInfo> availableCodecInfos;
|
@Nullable private ArrayDeque<MediaCodecInfo> availableCodecInfos;
|
||||||
@Nullable private DecoderInitializationException preferredDecoderInitializationException;
|
@Nullable private DecoderInitializationException preferredDecoderInitializationException;
|
||||||
@Nullable private MediaCodecInfo codecInfo;
|
@Nullable private MediaCodecInfo codecInfo;
|
||||||
@ -783,20 +782,20 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
MediaCodec codec = null;
|
MediaCodec codec = null;
|
||||||
String codecName = codecInfo.name;
|
String codecName = codecInfo.name;
|
||||||
|
|
||||||
updateCodecOperatingRate();
|
float codecOperatingRate =
|
||||||
boolean configureWithOperatingRate = codecOperatingRate > assumedMinimumCodecOperatingRate;
|
Util.SDK_INT < 23
|
||||||
|
? CODEC_OPERATING_RATE_UNSET
|
||||||
|
: getCodecOperatingRateV23(rendererOperatingRate, format, getStreamFormats());
|
||||||
|
if (codecOperatingRate <= assumedMinimumCodecOperatingRate) {
|
||||||
|
codecOperatingRate = CODEC_OPERATING_RATE_UNSET;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
codecInitializingTimestamp = SystemClock.elapsedRealtime();
|
codecInitializingTimestamp = SystemClock.elapsedRealtime();
|
||||||
TraceUtil.beginSection("createCodec:" + codecName);
|
TraceUtil.beginSection("createCodec:" + codecName);
|
||||||
codec = MediaCodec.createByCodecName(codecName);
|
codec = MediaCodec.createByCodecName(codecName);
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
TraceUtil.beginSection("configureCodec");
|
TraceUtil.beginSection("configureCodec");
|
||||||
configureCodec(
|
configureCodec(codecInfo, codec, format, crypto, codecOperatingRate);
|
||||||
codecInfo,
|
|
||||||
codec,
|
|
||||||
format,
|
|
||||||
crypto,
|
|
||||||
configureWithOperatingRate ? codecOperatingRate : CODEC_OPERATING_RATE_UNSET);
|
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
TraceUtil.beginSection("startCodec");
|
TraceUtil.beginSection("startCodec");
|
||||||
codec.start();
|
codec.start();
|
||||||
@ -813,7 +812,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
|
|
||||||
this.codec = codec;
|
this.codec = codec;
|
||||||
this.codecInfo = codecInfo;
|
this.codecInfo = codecInfo;
|
||||||
codecConfiguredWithOperatingRate = configureWithOperatingRate;
|
this.codecOperatingRate = codecOperatingRate;
|
||||||
codecAdaptationWorkaroundMode = codecAdaptationWorkaroundMode(codecName);
|
codecAdaptationWorkaroundMode = codecAdaptationWorkaroundMode(codecName);
|
||||||
codecNeedsReconfigureWorkaround = codecNeedsReconfigureWorkaround(codecName);
|
codecNeedsReconfigureWorkaround = codecNeedsReconfigureWorkaround(codecName);
|
||||||
codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
|
codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
|
||||||
@ -1227,7 +1226,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
* @return The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if no codec operating
|
* @return The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if no codec operating
|
||||||
* rate should be set.
|
* rate should be set.
|
||||||
*/
|
*/
|
||||||
protected float getCodecOperatingRate(
|
protected float getCodecOperatingRateV23(
|
||||||
float operatingRate, Format format, Format[] streamFormats) {
|
float operatingRate, Format format, Format[] streamFormats) {
|
||||||
return CODEC_OPERATING_RATE_UNSET;
|
return CODEC_OPERATING_RATE_UNSET;
|
||||||
}
|
}
|
||||||
@ -1238,33 +1237,26 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
* @throws ExoPlaybackException If an error occurs releasing or initializing a codec.
|
* @throws ExoPlaybackException If an error occurs releasing or initializing a codec.
|
||||||
*/
|
*/
|
||||||
private void updateCodecOperatingRate() throws ExoPlaybackException {
|
private void updateCodecOperatingRate() throws ExoPlaybackException {
|
||||||
if (format == null || Util.SDK_INT < 23) {
|
if (Util.SDK_INT < 23 || codec == null || codecDrainAction == DRAIN_ACTION_REINITIALIZE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float codecOperatingRate =
|
float newCodecOperatingRate =
|
||||||
getCodecOperatingRate(rendererOperatingRate, format, getStreamFormats());
|
getCodecOperatingRateV23(rendererOperatingRate, format, getStreamFormats());
|
||||||
if (this.codecOperatingRate == codecOperatingRate) {
|
if (codecOperatingRate == newCodecOperatingRate) {
|
||||||
return;
|
// No change.
|
||||||
}
|
} else if (newCodecOperatingRate == CODEC_OPERATING_RATE_UNSET) {
|
||||||
|
// The only way to clear the operating rate is to instantiate a new codec instance. See
|
||||||
this.codecOperatingRate = codecOperatingRate;
|
// [Internal ref: b/71987865].
|
||||||
if (codec == null || codecDrainAction == DRAIN_ACTION_REINITIALIZE) {
|
|
||||||
// Either no codec, or it's about to be released due to re-initialization anyway.
|
|
||||||
} else if (codecOperatingRate == CODEC_OPERATING_RATE_UNSET
|
|
||||||
&& codecConfiguredWithOperatingRate) {
|
|
||||||
// We need to clear the operating rate. The only way to do so is to instantiate a new codec
|
|
||||||
// instance. See [Internal ref: b/71987865].
|
|
||||||
drainAndReinitializeCodec();
|
drainAndReinitializeCodec();
|
||||||
} else if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET
|
} else if (codecOperatingRate != CODEC_OPERATING_RATE_UNSET
|
||||||
&& (codecConfiguredWithOperatingRate
|
|| newCodecOperatingRate > assumedMinimumCodecOperatingRate) {
|
||||||
|| codecOperatingRate > assumedMinimumCodecOperatingRate)) {
|
|
||||||
// We need to set the operating rate, either because we've set it previously or because it's
|
// We need to set the operating rate, either because we've set it previously or because it's
|
||||||
// above the assumed minimum rate.
|
// above the assumed minimum rate.
|
||||||
Bundle codecParameters = new Bundle();
|
Bundle codecParameters = new Bundle();
|
||||||
codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate);
|
codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, newCodecOperatingRate);
|
||||||
codec.setParameters(codecParameters);
|
codec.setParameters(codecParameters);
|
||||||
codecConfiguredWithOperatingRate = true;
|
codecOperatingRate = newCodecOperatingRate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getCodecOperatingRate(
|
protected float getCodecOperatingRateV23(
|
||||||
float operatingRate, Format format, Format[] streamFormats) {
|
float operatingRate, Format format, Format[] streamFormats) {
|
||||||
// Use the highest known stream frame-rate up front, to avoid having to reconfigure the codec
|
// Use the highest known stream frame-rate up front, to avoid having to reconfigure the codec
|
||||||
// should an adaptive switch to that stream occur.
|
// should an adaptive switch to that stream occur.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user