Configure MediaCodecs for realtime priority

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180782164
This commit is contained in:
andrewlewis 2018-01-04 04:31:44 -08:00 committed by Oliver Woodman
parent 682953c411
commit c89cc81b71
3 changed files with 24 additions and 7 deletions

View File

@ -240,14 +240,15 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
MediaCrypto crypto) {
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
MediaFormat mediaFormat = getMediaFormatForPlayback(format);
if (passthroughEnabled) {
// 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);
codec.configure(passthroughMediaFormat, null, crypto, 0);
passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
} else {
codec.configure(format.getFrameworkMediaFormatV16(), null, crypto, 0);
codec.configure(mediaFormat, null, crypto, 0);
passthroughMediaFormat = null;
}
}

View File

@ -430,6 +430,21 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
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
protected void onEnabled(boolean joining) throws ExoPlaybackException {
decoderCounters = new DecoderCounters();
@ -1108,6 +1123,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
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.
* <p>

View File

@ -906,19 +906,15 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(Format format, CodecMaxValues codecMaxValues,
boolean deviceNeedsAutoFrcWorkaround, int tunnelingAudioSessionId) {
MediaFormat frameworkMediaFormat = format.getFrameworkMediaFormatV16();
// Set the maximum adaptive video dimensions.
MediaFormat frameworkMediaFormat = getMediaFormatForPlayback(format);
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_WIDTH, codecMaxValues.width);
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_HEIGHT, codecMaxValues.height);
// Set the maximum input size.
if (codecMaxValues.inputSize != Format.NO_VALUE) {
frameworkMediaFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, codecMaxValues.inputSize);
}
// Set FRC workaround.
if (deviceNeedsAutoFrcWorkaround) {
frameworkMediaFormat.setInteger("auto-frc", 0);
}
// Configure tunneling if enabled.
if (tunnelingAudioSessionId != C.AUDIO_SESSION_ID_UNSET) {
configureTunnelingV21(frameworkMediaFormat, tunnelingAudioSessionId);
}