Skip to content

Commit

Permalink
Configure MediaCodecs for realtime priority
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=180782164
  • Loading branch information
andrewlewis authored and ojw28 committed Jan 4, 2018
1 parent 682953c commit c89cc81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,15 @@ protected boolean allowPassthrough(String mimeType) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ protected final MediaCodecInfo getCodecInfo() {
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();
Expand Down Expand Up @@ -1108,6 +1123,11 @@ private boolean shouldSkipOutputBuffer(long presentationTimeUs) {
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,19 +906,15 @@ protected CodecMaxValues getCodecMaxValues(MediaCodecInfo codecInfo, Format form
@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);
}
Expand Down

0 comments on commit c89cc81

Please sign in to comment.