Configure MediaCodecs for realtime priority
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=180782164
This commit is contained in:
parent
682953c411
commit
c89cc81b71
@ -240,14 +240,15 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
|||||||
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
||||||
MediaCrypto crypto) {
|
MediaCrypto crypto) {
|
||||||
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
|
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
|
||||||
|
MediaFormat mediaFormat = getMediaFormatForPlayback(format);
|
||||||
if (passthroughEnabled) {
|
if (passthroughEnabled) {
|
||||||
// Override the MIME type used to configure the codec if we are using a passthrough decoder.
|
// Override the MIME type used to configure the codec if we are using a passthrough decoder.
|
||||||
passthroughMediaFormat = format.getFrameworkMediaFormatV16();
|
passthroughMediaFormat = mediaFormat;
|
||||||
passthroughMediaFormat.setString(MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW);
|
passthroughMediaFormat.setString(MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW);
|
||||||
codec.configure(passthroughMediaFormat, null, crypto, 0);
|
codec.configure(passthroughMediaFormat, null, crypto, 0);
|
||||||
passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
|
passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
|
||||||
} else {
|
} else {
|
||||||
codec.configure(format.getFrameworkMediaFormatV16(), null, crypto, 0);
|
codec.configure(mediaFormat, null, crypto, 0);
|
||||||
passthroughMediaFormat = null;
|
passthroughMediaFormat = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -430,6 +430,21 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
return codecInfo;
|
return codecInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
|
||||||
|
* for decoding the given {@link Format} for playback.
|
||||||
|
*
|
||||||
|
* @param format The format of the media.
|
||||||
|
* @return The framework media format.
|
||||||
|
*/
|
||||||
|
protected final MediaFormat getMediaFormatForPlayback(Format format) {
|
||||||
|
MediaFormat mediaFormat = format.getFrameworkMediaFormatV16();
|
||||||
|
if (Util.SDK_INT >= 23) {
|
||||||
|
configureMediaFormatForPlaybackV23(mediaFormat);
|
||||||
|
}
|
||||||
|
return mediaFormat;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEnabled(boolean joining) throws ExoPlaybackException {
|
protected void onEnabled(boolean joining) throws ExoPlaybackException {
|
||||||
decoderCounters = new DecoderCounters();
|
decoderCounters = new DecoderCounters();
|
||||||
@ -1108,6 +1123,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(23)
|
||||||
|
private static void configureMediaFormatForPlaybackV23(MediaFormat mediaFormat) {
|
||||||
|
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the decoder is known to fail when flushed.
|
* Returns whether the decoder is known to fail when flushed.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -906,19 +906,15 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
protected MediaFormat getMediaFormat(Format format, CodecMaxValues codecMaxValues,
|
protected MediaFormat getMediaFormat(Format format, CodecMaxValues codecMaxValues,
|
||||||
boolean deviceNeedsAutoFrcWorkaround, int tunnelingAudioSessionId) {
|
boolean deviceNeedsAutoFrcWorkaround, int tunnelingAudioSessionId) {
|
||||||
MediaFormat frameworkMediaFormat = format.getFrameworkMediaFormatV16();
|
MediaFormat frameworkMediaFormat = getMediaFormatForPlayback(format);
|
||||||
// Set the maximum adaptive video dimensions.
|
|
||||||
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
|
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
|
||||||
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
|
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
|
||||||
// Set the maximum input size.
|
|
||||||
if (codecMaxValues.inputSize != Format.NO_VALUE) {
|
if (codecMaxValues.inputSize != Format.NO_VALUE) {
|
||||||
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
|
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
|
||||||
}
|
}
|
||||||
// Set FRC workaround.
|
|
||||||
if (deviceNeedsAutoFrcWorkaround) {
|
if (deviceNeedsAutoFrcWorkaround) {
|
||||||
frameworkMediaFormat.setInteger("auto-frc", 0);
|
frameworkMediaFormat.setInteger("auto-frc", 0);
|
||||||
}
|
}
|
||||||
// Configure tunneling if enabled.
|
|
||||||
if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
|
if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
|
||||||
configureTunnelingV21(frameworkMediaFormat, tunnelingAudioSessionId);
|
configureTunnelingV21(frameworkMediaFormat, tunnelingAudioSessionId);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user