Simplify codec configuration.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=114427767
This commit is contained in:
parent
335bb0aff2
commit
ebf87a3619
@ -25,6 +25,7 @@ import com.google.android.exoplayer.util.Util;
|
||||
import android.annotation.TargetApi;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaCrypto;
|
||||
import android.media.PlaybackParams;
|
||||
import android.media.audiofx.Virtualizer;
|
||||
import android.os.Handler;
|
||||
@ -237,17 +238,15 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCodec(MediaCodec codec, boolean codecIsAdaptive,
|
||||
android.media.MediaFormat format, android.media.MediaCrypto crypto) {
|
||||
String mimeType = format.getString(android.media.MediaFormat.KEY_MIME);
|
||||
protected void configureCodec(MediaCodec codec, MediaFormat format, MediaCrypto crypto) {
|
||||
if (passthroughEnabled) {
|
||||
// Override the MIME type used to configure the codec if we are using a passthrough decoder.
|
||||
format.setString(android.media.MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW);
|
||||
codec.configure(format, null, crypto, 0);
|
||||
format.setString(android.media.MediaFormat.KEY_MIME, mimeType);
|
||||
passthroughMediaFormat = format;
|
||||
passthroughMediaFormat = format.getFrameworkMediaFormatV16();
|
||||
passthroughMediaFormat.setString(android.media.MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW);
|
||||
codec.configure(passthroughMediaFormat, null, crypto, 0);
|
||||
passthroughMediaFormat.setString(android.media.MediaFormat.KEY_MIME, format.mimeType);
|
||||
} else {
|
||||
codec.configure(format, null, crypto, 0);
|
||||
codec.configure(format.getFrameworkMediaFormatV16(), null, crypto, 0);
|
||||
passthroughMediaFormat = null;
|
||||
}
|
||||
}
|
||||
|
@ -318,14 +318,10 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||
* wish to configure the codec with a non-null surface.
|
||||
*
|
||||
* @param codec The {@link MediaCodec} to configure.
|
||||
* @param codecIsAdaptive Whether the codec is adaptive.
|
||||
* @param format The format for which the codec is being configured.
|
||||
* @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption.
|
||||
*/
|
||||
protected void configureCodec(MediaCodec codec, boolean codecIsAdaptive,
|
||||
android.media.MediaFormat format, MediaCrypto crypto) {
|
||||
codec.configure(format, null, crypto, 0);
|
||||
}
|
||||
protected abstract void configureCodec(MediaCodec codec, MediaFormat format, MediaCrypto crypto);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected final void maybeInitCodec() throws ExoPlaybackException {
|
||||
@ -381,7 +377,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
|
||||
codec = MediaCodec.createByCodecName(codecName);
|
||||
TraceUtil.endSection();
|
||||
TraceUtil.beginSection("configureCodec");
|
||||
configureCodec(codec, decoderInfo.adaptive, format.getFrameworkMediaFormatV16(), mediaCrypto);
|
||||
configureCodec(codec, format, mediaCrypto);
|
||||
TraceUtil.endSection();
|
||||
TraceUtil.beginSection("codec.start()");
|
||||
codec.start();
|
||||
|
@ -345,10 +345,8 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
|
||||
|
||||
// Override configureCodec to provide the surface.
|
||||
@Override
|
||||
protected void configureCodec(MediaCodec codec, boolean codecIsAdaptive,
|
||||
android.media.MediaFormat format, MediaCrypto crypto) {
|
||||
maybeSetMaxInputSize(format, codecIsAdaptive);
|
||||
codec.configure(format, surface, crypto, 0);
|
||||
protected void configureCodec(MediaCodec codec, MediaFormat format, MediaCrypto crypto) {
|
||||
codec.configure(getFrameworkMediaFormat(format), surface, crypto, 0);
|
||||
codec.setVideoScalingMode(videoScalingMode);
|
||||
}
|
||||
|
||||
@ -519,27 +517,24 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
private void maybeSetMaxInputSize(android.media.MediaFormat format, boolean codecIsAdaptive) {
|
||||
if (format.containsKey(android.media.MediaFormat.KEY_MAX_INPUT_SIZE)) {
|
||||
// Already set. The source of the format may know better, so do nothing.
|
||||
return;
|
||||
}
|
||||
int maxHeight = format.getInteger(android.media.MediaFormat.KEY_HEIGHT);
|
||||
if (codecIsAdaptive && format.containsKey(android.media.MediaFormat.KEY_MAX_HEIGHT)) {
|
||||
maxHeight = Math.max(maxHeight, format.getInteger(android.media.MediaFormat.KEY_MAX_HEIGHT));
|
||||
}
|
||||
int maxWidth = format.getInteger(android.media.MediaFormat.KEY_WIDTH);
|
||||
if (codecIsAdaptive && format.containsKey(android.media.MediaFormat.KEY_MAX_WIDTH)) {
|
||||
maxWidth = Math.max(maxHeight, format.getInteger(android.media.MediaFormat.KEY_MAX_WIDTH));
|
||||
private android.media.MediaFormat getFrameworkMediaFormat(MediaFormat format) {
|
||||
android.media.MediaFormat frameworkMediaFormat = format.getFrameworkMediaFormatV16();
|
||||
if (format.maxInputSize > 0) {
|
||||
// The format already has a maximum input size.
|
||||
return frameworkMediaFormat;
|
||||
}
|
||||
|
||||
// If the format doesn't define a maximum input size, determine one ourselves.
|
||||
int maxHeight = Math.max(format.maxHeight, format.height);
|
||||
int maxWidth = Math.max(format.maxWidth, format.maxWidth);
|
||||
int maxPixels;
|
||||
int minCompressionRatio;
|
||||
switch (format.getString(android.media.MediaFormat.KEY_MIME)) {
|
||||
switch (format.mimeType) {
|
||||
case MimeTypes.VIDEO_H264:
|
||||
if ("BRAVIA 4K 2015".equals(Util.MODEL)) {
|
||||
// The Sony BRAVIA 4k TV has input buffers that are too small for the calculated 4k video
|
||||
// maximum input size, so use the default value.
|
||||
return;
|
||||
return frameworkMediaFormat;
|
||||
}
|
||||
// Round up width/height to an integer number of macroblocks.
|
||||
maxPixels = ((maxWidth + 15) / 16) * ((maxHeight + 15) / 16) * 16 * 16;
|
||||
@ -556,11 +551,12 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
|
||||
break;
|
||||
default:
|
||||
// Leave the default max input size.
|
||||
return;
|
||||
return frameworkMediaFormat;
|
||||
}
|
||||
// Estimate the maximum input size assuming three channel 4:2:0 subsampled input frames.
|
||||
int maxInputSize = (maxPixels * 3) / (2 * minCompressionRatio);
|
||||
format.setInteger(android.media.MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
|
||||
frameworkMediaFormat.setInteger(android.media.MediaFormat.KEY_MAX_INPUT_SIZE, maxInputSize);
|
||||
return frameworkMediaFormat;
|
||||
}
|
||||
|
||||
private void maybeNotifyVideoSizeChanged() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user