mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Address comments.
This commit is contained in:
parent
db53606c1d
commit
5cdb886db1
5 changed files with 29 additions and 39 deletions
|
|
@ -137,7 +137,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOperatingRate(float operatingRate) {
|
public final void setOperatingRate(float operatingRate) {
|
||||||
onOperatingRateChanged(operatingRate);
|
onOperatingRateChanged(operatingRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import android.media.MediaCodec;
|
||||||
import android.media.MediaCrypto;
|
import android.media.MediaCrypto;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.media.audiofx.Virtualizer;
|
import android.media.audiofx.Virtualizer;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
|
@ -318,12 +317,12 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
||||||
MediaCrypto crypto) {
|
MediaCrypto crypto, float codecOperatingRate) {
|
||||||
codecMaxInputSize = getCodecMaxInputSize(codecInfo, format, getStreamFormats());
|
codecMaxInputSize = getCodecMaxInputSize(codecInfo, format, getStreamFormats());
|
||||||
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
|
codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name);
|
||||||
passthroughEnabled = codecInfo.passthrough;
|
passthroughEnabled = codecInfo.passthrough;
|
||||||
String codecMimeType = codecInfo.mimeType == null ? MimeTypes.AUDIO_RAW : codecInfo.mimeType;
|
String codecMimeType = codecInfo.mimeType == null ? MimeTypes.AUDIO_RAW : codecInfo.mimeType;
|
||||||
MediaFormat mediaFormat = getMediaFormat(format, codecMimeType, codecMaxInputSize);
|
MediaFormat mediaFormat = getMediaFormat(format, codecMimeType, codecMaxInputSize, codecOperatingRate);
|
||||||
codec.configure(mediaFormat, /* surface= */ null, crypto, /* flags= */ 0);
|
codec.configure(mediaFormat, /* surface= */ null, crypto, /* flags= */ 0);
|
||||||
if (passthroughEnabled) {
|
if (passthroughEnabled) {
|
||||||
// Store the input MIME type if we're using the passthrough codec.
|
// Store the input MIME type if we're using the passthrough codec.
|
||||||
|
|
@ -351,19 +350,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(23)
|
|
||||||
@Override
|
|
||||||
protected void updateCodecOperatingRate(Format format) {
|
|
||||||
if (format.sampleRate == Format.NO_VALUE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
MediaCodec codec = getCodec();
|
|
||||||
float codecOperatingRate = getCodecOperatingRate();
|
|
||||||
Bundle codecParameters = new Bundle();
|
|
||||||
codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, format.sampleRate * codecOperatingRate);
|
|
||||||
codec.setParameters(codecParameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCodecInitialized(String name, long initializedTimestampMs,
|
protected void onCodecInitialized(String name, long initializedTimestampMs,
|
||||||
long initializationDurationMs) {
|
long initializationDurationMs) {
|
||||||
|
|
@ -647,10 +633,12 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
||||||
* @param format The format of the media.
|
* @param format The format of the media.
|
||||||
* @param codecMimeType The MIME type handled by the codec.
|
* @param codecMimeType The MIME type handled by the codec.
|
||||||
* @param codecMaxInputSize The maximum input size supported by the codec.
|
* @param codecMaxInputSize The maximum input size supported by the codec.
|
||||||
|
* @param codecOperatingRate
|
||||||
* @return The framework media format.
|
* @return The framework media format.
|
||||||
*/
|
*/
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
protected MediaFormat getMediaFormat(Format format, String codecMimeType, int codecMaxInputSize) {
|
protected MediaFormat getMediaFormat(Format format, String codecMimeType, int codecMaxInputSize,
|
||||||
|
float codecOperatingRate) {
|
||||||
MediaFormat mediaFormat = new MediaFormat();
|
MediaFormat mediaFormat = new MediaFormat();
|
||||||
// Set format parameters that should always be set.
|
// Set format parameters that should always be set.
|
||||||
mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
|
mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType);
|
||||||
|
|
@ -663,7 +651,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
|
||||||
if (Util.SDK_INT >= 23) {
|
if (Util.SDK_INT >= 23) {
|
||||||
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
|
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
|
||||||
if (format.sampleRate != Format.NO_VALUE) {
|
if (format.sampleRate != Format.NO_VALUE) {
|
||||||
float codecOperatingRate = getCodecOperatingRate();
|
|
||||||
mediaFormat.setFloat(
|
mediaFormat.setFloat(
|
||||||
MediaFormat.KEY_OPERATING_RATE, codecOperatingRate * format.sampleRate);
|
MediaFormat.KEY_OPERATING_RATE, codecOperatingRate * format.sampleRate);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
private DrmSession<FrameworkMediaCrypto> drmSession;
|
private DrmSession<FrameworkMediaCrypto> drmSession;
|
||||||
private DrmSession<FrameworkMediaCrypto> pendingDrmSession;
|
private DrmSession<FrameworkMediaCrypto> pendingDrmSession;
|
||||||
private MediaCodec codec;
|
private MediaCodec codec;
|
||||||
private float codecOperatingRate = 1;
|
private float codecOperatingRate = 1.0f;
|
||||||
private @Nullable ArrayDeque<MediaCodecInfo> availableCodecInfos;
|
private @Nullable ArrayDeque<MediaCodecInfo> availableCodecInfos;
|
||||||
private @Nullable DecoderInitializationException preferredDecoderInitializationException;
|
private @Nullable DecoderInitializationException preferredDecoderInitializationException;
|
||||||
private @Nullable MediaCodecInfo codecInfo;
|
private @Nullable MediaCodecInfo codecInfo;
|
||||||
|
|
@ -386,10 +386,13 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
* @param codec The {@link MediaCodec} to configure.
|
* @param codec The {@link MediaCodec} to configure.
|
||||||
* @param format The format for which the codec is being configured.
|
* @param format The format for which the codec is being configured.
|
||||||
* @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption.
|
* @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption.
|
||||||
|
* @param codecOperatingRate The {@link MediaFormat#KEY_OPERATING_RATE} to use for configuration.
|
||||||
* @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
|
* @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
|
||||||
*/
|
*/
|
||||||
protected abstract void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
protected abstract void configureCodec(MediaCodecInfo codecInfo,
|
||||||
MediaCrypto crypto) throws DecoderQueryException;
|
MediaCodec codec, Format format,
|
||||||
|
MediaCrypto crypto,
|
||||||
|
float codecOperatingRate) throws DecoderQueryException;
|
||||||
|
|
||||||
protected final void maybeInitCodec() throws ExoPlaybackException {
|
protected final void maybeInitCodec() throws ExoPlaybackException {
|
||||||
if (codec != null || format == null) {
|
if (codec != null || format == null) {
|
||||||
|
|
@ -466,8 +469,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
return codecInfo;
|
return codecInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final float getCodecOperatingRate() { return codecOperatingRate; }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEnabled(boolean joining) throws ExoPlaybackException {
|
protected void onEnabled(boolean joining) throws ExoPlaybackException {
|
||||||
decoderCounters = new DecoderCounters();
|
decoderCounters = new DecoderCounters();
|
||||||
|
|
@ -485,8 +486,8 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
@Override
|
@Override
|
||||||
protected void onOperatingRateChanged(float operatingRate) {
|
protected void onOperatingRateChanged(float operatingRate) {
|
||||||
codecOperatingRate = operatingRate;
|
codecOperatingRate = operatingRate;
|
||||||
if (codec != null && format != null) {
|
if (format != null) {
|
||||||
updateCodecOperatingRate(format);
|
updateCodecOperatingRate(codec, format, operatingRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -734,7 +735,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
codec = MediaCodec.createByCodecName(name);
|
codec = MediaCodec.createByCodecName(name);
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
TraceUtil.beginSection("configureCodec");
|
TraceUtil.beginSection("configureCodec");
|
||||||
configureCodec(codecInfo, codec, format, crypto);
|
configureCodec(codecInfo, codec, format, crypto, codecOperatingRate);
|
||||||
TraceUtil.endSection();
|
TraceUtil.endSection();
|
||||||
TraceUtil.beginSection("startCodec");
|
TraceUtil.beginSection("startCodec");
|
||||||
codec.start();
|
codec.start();
|
||||||
|
|
@ -1038,7 +1039,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Util.SDK_INT >= 23) {
|
if (Util.SDK_INT >= 23) {
|
||||||
updateCodecOperatingRate(format);
|
updateCodecOperatingRate(codec, format, codecOperatingRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1048,7 +1049,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
* <p>
|
* <p>
|
||||||
* The default implementation is a no-op.
|
* The default implementation is a no-op.
|
||||||
*/
|
*/
|
||||||
protected void updateCodecOperatingRate(Format format) {
|
protected void updateCodecOperatingRate(MediaCodec codec, Format format, float codecOperatingRate) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -443,11 +443,14 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
protected void configureCodec(MediaCodecInfo codecInfo,
|
||||||
MediaCrypto crypto) throws DecoderQueryException {
|
MediaCodec codec,
|
||||||
|
Format format,
|
||||||
|
MediaCrypto crypto,
|
||||||
|
float codecOperatingRate) throws DecoderQueryException {
|
||||||
codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
|
codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
|
||||||
MediaFormat mediaFormat = getMediaFormat(format, codecMaxValues, deviceNeedsAutoFrcWorkaround,
|
MediaFormat mediaFormat = getMediaFormat(format, codecMaxValues, deviceNeedsAutoFrcWorkaround,
|
||||||
tunnelingAudioSessionId);
|
tunnelingAudioSessionId, codecOperatingRate);
|
||||||
if (surface == null) {
|
if (surface == null) {
|
||||||
Assertions.checkState(shouldUseDummySurface(codecInfo));
|
Assertions.checkState(shouldUseDummySurface(codecInfo));
|
||||||
if (dummySurface == null) {
|
if (dummySurface == null) {
|
||||||
|
|
@ -501,12 +504,10 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
||||||
|
|
||||||
@TargetApi(23)
|
@TargetApi(23)
|
||||||
@Override
|
@Override
|
||||||
protected void updateCodecOperatingRate(Format format) {
|
protected void updateCodecOperatingRate(MediaCodec codec, Format format, float codecOperatingRate) {
|
||||||
if (format.frameRate == Format.NO_VALUE) {
|
if (format.frameRate == Format.NO_VALUE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
MediaCodec codec = getCodec();
|
|
||||||
float codecOperatingRate = getCodecOperatingRate();
|
|
||||||
Bundle codecParameters = new Bundle();
|
Bundle codecParameters = new Bundle();
|
||||||
codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, format.frameRate * codecOperatingRate);
|
codecParameters.putFloat(MediaFormat.KEY_OPERATING_RATE, format.frameRate * codecOperatingRate);
|
||||||
codec.setParameters(codecParameters);
|
codec.setParameters(codecParameters);
|
||||||
|
|
@ -951,6 +952,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
||||||
* logic that negatively impacts ExoPlayer.
|
* logic that negatively impacts ExoPlayer.
|
||||||
* @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
|
* @param tunnelingAudioSessionId The audio session id to use for tunneling, or {@link
|
||||||
* C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
|
* C#AUDIO_SESSION_ID_UNSET} if tunneling should not be enabled.
|
||||||
|
* @param codecOperatingRate
|
||||||
* @return The framework {@link MediaFormat} that should be used to configure the decoder.
|
* @return The framework {@link MediaFormat} that should be used to configure the decoder.
|
||||||
*/
|
*/
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
|
|
@ -958,7 +960,8 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
||||||
Format format,
|
Format format,
|
||||||
CodecMaxValues codecMaxValues,
|
CodecMaxValues codecMaxValues,
|
||||||
boolean deviceNeedsAutoFrcWorkaround,
|
boolean deviceNeedsAutoFrcWorkaround,
|
||||||
int tunnelingAudioSessionId) {
|
int tunnelingAudioSessionId,
|
||||||
|
float codecOperatingRate) {
|
||||||
MediaFormat mediaFormat = new MediaFormat();
|
MediaFormat mediaFormat = new MediaFormat();
|
||||||
// Set format parameters that should always be set.
|
// Set format parameters that should always be set.
|
||||||
mediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
|
mediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType);
|
||||||
|
|
@ -978,7 +981,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
||||||
if (Util.SDK_INT >= 23) {
|
if (Util.SDK_INT >= 23) {
|
||||||
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
|
mediaFormat.setInteger(MediaFormat.KEY_PRIORITY, 0 /* realtime priority */);
|
||||||
if (format.frameRate != Format.NO_VALUE) {
|
if (format.frameRate != Format.NO_VALUE) {
|
||||||
float codecOperatingRate = getCodecOperatingRate();
|
|
||||||
mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate * format.frameRate);
|
mediaFormat.setFloat(MediaFormat.KEY_OPERATING_RATE, codecOperatingRate * format.frameRate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,14 +82,14 @@ public class DebugRenderersFactory extends DefaultRenderersFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format format,
|
||||||
MediaCrypto crypto) throws DecoderQueryException {
|
MediaCrypto crypto, float codecOperatingRate) throws DecoderQueryException {
|
||||||
// If the codec is being initialized whilst the renderer is started, default behavior is to
|
// If the codec is being initialized whilst the renderer is started, default behavior is to
|
||||||
// render the first frame (i.e. the keyframe before the current position), then drop frames up
|
// render the first frame (i.e. the keyframe before the current position), then drop frames up
|
||||||
// to the current playback position. For test runs that place a maximum limit on the number of
|
// to the current playback position. For test runs that place a maximum limit on the number of
|
||||||
// dropped frames allowed, this is not desired behavior. Hence we skip (rather than drop)
|
// dropped frames allowed, this is not desired behavior. Hence we skip (rather than drop)
|
||||||
// frames up to the current playback position [Internal: b/66494991].
|
// frames up to the current playback position [Internal: b/66494991].
|
||||||
skipToPositionBeforeRenderingFirstFrame = getState() == Renderer.STATE_STARTED;
|
skipToPositionBeforeRenderingFirstFrame = getState() == Renderer.STATE_STARTED;
|
||||||
super.configureCodec(codecInfo, codec, format, crypto);
|
super.configureCodec(codecInfo, codec, format, crypto, codecOperatingRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue