Commit 71fd335b by olly Committed by kim-vde

Simplify output format propagation

PiperOrigin-RevId: 324805335
parent 4d03d308
...@@ -2188,11 +2188,9 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -2188,11 +2188,9 @@ public class SimpleExoPlayer extends BasePlayer
} }
@Override @Override
public void onVideoFrameProcessingOffset( public void onVideoFrameProcessingOffset(long totalProcessingOffsetUs, int frameCount) {
long totalProcessingOffsetUs, int frameCount, Format format) {
for (VideoRendererEventListener videoDebugListener : videoDebugListeners) { for (VideoRendererEventListener videoDebugListener : videoDebugListeners) {
videoDebugListener.onVideoFrameProcessingOffset( videoDebugListener.onVideoFrameProcessingOffset(totalProcessingOffsetUs, frameCount);
totalProcessingOffsetUs, frameCount, format);
} }
} }
......
...@@ -319,11 +319,10 @@ public class AnalyticsCollector ...@@ -319,11 +319,10 @@ public class AnalyticsCollector
} }
@Override @Override
public final void onVideoFrameProcessingOffset( public final void onVideoFrameProcessingOffset(long totalProcessingOffsetUs, int frameCount) {
long totalProcessingOffsetUs, int frameCount, Format format) {
EventTime eventTime = generatePlayingMediaPeriodEventTime(); EventTime eventTime = generatePlayingMediaPeriodEventTime();
for (AnalyticsListener listener : listeners) { for (AnalyticsListener listener : listeners) {
listener.onVideoFrameProcessingOffset(eventTime, totalProcessingOffsetUs, frameCount, format); listener.onVideoFrameProcessingOffset(eventTime, totalProcessingOffsetUs, frameCount);
} }
} }
......
...@@ -591,10 +591,9 @@ public interface AnalyticsListener { ...@@ -591,10 +591,9 @@ public interface AnalyticsListener {
* @param totalProcessingOffsetUs The sum of the video frame processing offsets for frames * @param totalProcessingOffsetUs The sum of the video frame processing offsets for frames
* rendered since the last call to this method. * rendered since the last call to this method.
* @param frameCount The number to samples included in {@code totalProcessingOffsetUs}. * @param frameCount The number to samples included in {@code totalProcessingOffsetUs}.
* @param format The video {@link Format} being rendered.
*/ */
default void onVideoFrameProcessingOffset( default void onVideoFrameProcessingOffset(
EventTime eventTime, long totalProcessingOffsetUs, int frameCount, Format format) {} EventTime eventTime, long totalProcessingOffsetUs, int frameCount) {}
/** /**
* Called when a frame is rendered for the first time since setting the surface, or since the * Called when a frame is rendered for the first time since setting the surface, or since the
......
...@@ -91,7 +91,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -91,7 +91,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
private boolean codecNeedsDiscardChannelsWorkaround; private boolean codecNeedsDiscardChannelsWorkaround;
private boolean codecNeedsEosBufferTimestampWorkaround; private boolean codecNeedsEosBufferTimestampWorkaround;
@Nullable private Format codecPassthroughFormat; @Nullable private Format codecPassthroughFormat;
@Nullable private Format inputFormat;
private long currentPositionUs; private long currentPositionUs;
private boolean allowFirstBufferPositionDiscontinuity; private boolean allowFirstBufferPositionDiscontinuity;
private boolean allowPositionDiscontinuity; private boolean allowPositionDiscontinuity;
...@@ -379,29 +378,23 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -379,29 +378,23 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override @Override
protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException { protected void onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException {
super.onInputFormatChanged(formatHolder); super.onInputFormatChanged(formatHolder);
inputFormat = formatHolder.format; eventDispatcher.inputFormatChanged(formatHolder.format);
eventDispatcher.inputFormatChanged(inputFormat);
} }
@Override @Override
protected void onOutputFormatChanged(Format outputFormat) throws ExoPlaybackException { protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat)
configureOutput(outputFormat); throws ExoPlaybackException {
}
@Override
protected void configureOutput(Format outputFormat) throws ExoPlaybackException {
Format audioSinkInputFormat; Format audioSinkInputFormat;
@Nullable int[] channelMap = null; @Nullable int[] channelMap = null;
if (codecPassthroughFormat != null) { // Raw codec passthrough if (codecPassthroughFormat != null) { // Raw codec passthrough
audioSinkInputFormat = codecPassthroughFormat; audioSinkInputFormat = codecPassthroughFormat;
} else if (getCodec() == null) { // Codec bypass passthrough } else if (getCodec() == null) { // Codec bypass passthrough
audioSinkInputFormat = outputFormat; audioSinkInputFormat = format;
} else { } else {
MediaFormat mediaFormat = getCodec().getOutputFormat();
@C.PcmEncoding int pcmEncoding; @C.PcmEncoding int pcmEncoding;
if (MimeTypes.AUDIO_RAW.equals(outputFormat.sampleMimeType)) { if (MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)) {
// For PCM streams, the encoder passes through int samples despite set to float mode. // For PCM streams, the encoder passes through int samples despite set to float mode.
pcmEncoding = outputFormat.pcmEncoding; pcmEncoding = format.pcmEncoding;
} else if (Util.SDK_INT >= 24 && mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)) { } else if (Util.SDK_INT >= 24 && mediaFormat.containsKey(MediaFormat.KEY_PCM_ENCODING)) {
pcmEncoding = mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING); pcmEncoding = mediaFormat.getInteger(MediaFormat.KEY_PCM_ENCODING);
} else if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) { } else if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) {
...@@ -409,22 +402,25 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -409,22 +402,25 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
} else { } else {
// If the format is anything other than PCM then we assume that the audio decoder will // If the format is anything other than PCM then we assume that the audio decoder will
// output 16-bit PCM. // output 16-bit PCM.
pcmEncoding = C.ENCODING_PCM_16BIT; pcmEncoding =
MimeTypes.AUDIO_RAW.equals(format.sampleMimeType)
? format.pcmEncoding
: C.ENCODING_PCM_16BIT;
} }
audioSinkInputFormat = audioSinkInputFormat =
new Format.Builder() new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_RAW) .setSampleMimeType(MimeTypes.AUDIO_RAW)
.setPcmEncoding(pcmEncoding) .setPcmEncoding(pcmEncoding)
.setEncoderDelay(outputFormat.encoderDelay) .setEncoderDelay(format.encoderDelay)
.setEncoderPadding(outputFormat.encoderPadding) .setEncoderPadding(format.encoderPadding)
.setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)) .setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT))
.setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)) .setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE))
.build(); .build();
if (codecNeedsDiscardChannelsWorkaround if (codecNeedsDiscardChannelsWorkaround
&& audioSinkInputFormat.channelCount == 6 && audioSinkInputFormat.channelCount == 6
&& outputFormat.channelCount < 6) { && format.channelCount < 6) {
channelMap = new int[outputFormat.channelCount]; channelMap = new int[format.channelCount];
for (int i = 0; i < outputFormat.channelCount; i++) { for (int i = 0; i < format.channelCount; i++) {
channelMap[i] = i; channelMap[i] = i;
} }
} }
...@@ -432,7 +428,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -432,7 +428,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
try { try {
audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap); audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
} catch (AudioSink.ConfigurationException e) { } catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, outputFormat); throw createRendererException(e, format);
} }
} }
...@@ -621,8 +617,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -621,8 +617,8 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
try { try {
audioSink.playToEndOfStream(); audioSink.playToEndOfStream();
} catch (AudioSink.WriteException e) { } catch (AudioSink.WriteException e) {
Format outputFormat = getCurrentOutputFormat(); @Nullable Format outputFormat = getOutputFormat();
throw createRendererException(e, outputFormat != null ? outputFormat : inputFormat); throw createRendererException(e, outputFormat != null ? outputFormat : getInputFormat());
} }
} }
......
...@@ -153,9 +153,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -153,9 +153,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
private long totalVideoFrameProcessingOffsetUs; private long totalVideoFrameProcessingOffsetUs;
private int videoFrameProcessingOffsetCount; private int videoFrameProcessingOffsetCount;
@Nullable private MediaFormat currentMediaFormat;
private int mediaFormatWidth;
private int mediaFormatHeight;
private int currentWidth; private int currentWidth;
private int currentHeight; private int currentHeight;
private int currentUnappliedRotationDegrees; private int currentUnappliedRotationDegrees;
...@@ -262,8 +259,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -262,8 +259,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
currentHeight = Format.NO_VALUE; currentHeight = Format.NO_VALUE;
currentPixelWidthHeightRatio = Format.NO_VALUE; currentPixelWidthHeightRatio = Format.NO_VALUE;
scalingMode = VIDEO_SCALING_MODE_DEFAULT; scalingMode = VIDEO_SCALING_MODE_DEFAULT;
mediaFormatWidth = Format.NO_VALUE;
mediaFormatHeight = Format.NO_VALUE;
clearReportedVideoSize(); clearReportedVideoSize();
} }
...@@ -449,7 +444,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -449,7 +444,6 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
@Override @Override
protected void onDisabled() { protected void onDisabled() {
currentMediaFormat = null;
clearReportedVideoSize(); clearReportedVideoSize();
clearRenderedFirstFrame(); clearRenderedFirstFrame();
frameReleaseTimeHelper.disable(); frameReleaseTimeHelper.disable();
...@@ -668,51 +662,37 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -668,51 +662,37 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
@Override @Override
protected void onOutputMediaFormatChanged(MediaCodec codec, MediaFormat outputMediaFormat) { protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat) {
currentMediaFormat = outputMediaFormat; @Nullable MediaCodec codec = getCodec();
boolean hasCrop = if (codec != null) {
outputMediaFormat.containsKey(KEY_CROP_RIGHT) // Must be applied each time the output format changes.
&& outputMediaFormat.containsKey(KEY_CROP_LEFT) codec.setVideoScalingMode(scalingMode);
&& outputMediaFormat.containsKey(KEY_CROP_BOTTOM) }
&& outputMediaFormat.containsKey(KEY_CROP_TOP);
mediaFormatWidth =
hasCrop
? outputMediaFormat.getInteger(KEY_CROP_RIGHT)
- outputMediaFormat.getInteger(KEY_CROP_LEFT)
+ 1
: outputMediaFormat.getInteger(MediaFormat.KEY_WIDTH);
mediaFormatHeight =
hasCrop
? outputMediaFormat.getInteger(KEY_CROP_BOTTOM)
- outputMediaFormat.getInteger(KEY_CROP_TOP)
+ 1
: outputMediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
// Must be applied each time the output MediaFormat changes.
codec.setVideoScalingMode(scalingMode);
maybeNotifyVideoFrameProcessingOffset();
}
@Override
protected void onOutputFormatChanged(Format outputFormat) {
configureOutput(outputFormat);
}
@Override
protected void configureOutput(Format outputFormat) {
if (tunneling) { if (tunneling) {
currentWidth = outputFormat.width; currentWidth = format.width;
currentHeight = outputFormat.height; currentHeight = format.height;
} else { } else {
currentWidth = mediaFormatWidth; Assertions.checkNotNull(mediaFormat);
currentHeight = mediaFormatHeight; boolean hasCrop =
} mediaFormat.containsKey(KEY_CROP_RIGHT)
currentPixelWidthHeightRatio = outputFormat.pixelWidthHeightRatio; && mediaFormat.containsKey(KEY_CROP_LEFT)
&& mediaFormat.containsKey(KEY_CROP_BOTTOM)
&& mediaFormat.containsKey(KEY_CROP_TOP);
currentWidth =
hasCrop
? mediaFormat.getInteger(KEY_CROP_RIGHT) - mediaFormat.getInteger(KEY_CROP_LEFT) + 1
: mediaFormat.getInteger(MediaFormat.KEY_WIDTH);
currentHeight =
hasCrop
? mediaFormat.getInteger(KEY_CROP_BOTTOM) - mediaFormat.getInteger(KEY_CROP_TOP) + 1
: mediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
}
currentPixelWidthHeightRatio = format.pixelWidthHeightRatio;
if (Util.SDK_INT >= 21) { if (Util.SDK_INT >= 21) {
// On API level 21 and above the decoder applies the rotation when rendering to the surface. // On API level 21 and above the decoder applies the rotation when rendering to the surface.
// Hence currentUnappliedRotation should always be 0. For 90 and 270 degree rotations, we need // Hence currentUnappliedRotation should always be 0. For 90 and 270 degree rotations, we need
// to flip the width, height and pixel aspect ratio to reflect the rotation that was applied. // to flip the width, height and pixel aspect ratio to reflect the rotation that was applied.
if (outputFormat.rotationDegrees == 90 || outputFormat.rotationDegrees == 270) { if (format.rotationDegrees == 90 || format.rotationDegrees == 270) {
int rotatedHeight = currentWidth; int rotatedHeight = currentWidth;
currentWidth = currentHeight; currentWidth = currentHeight;
currentHeight = rotatedHeight; currentHeight = rotatedHeight;
...@@ -720,9 +700,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -720,9 +700,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
} else { } else {
// On API level 20 and below the decoder does not apply the rotation. // On API level 20 and below the decoder does not apply the rotation.
currentUnappliedRotationDegrees = outputFormat.rotationDegrees; currentUnappliedRotationDegrees = format.rotationDegrees;
} }
currentFrameRate = outputFormat.frameRate; currentFrameRate = format.frameRate;
updateSurfaceFrameRate(/* isNewSurface= */ false); updateSurfaceFrameRate(/* isNewSurface= */ false);
} }
...@@ -811,7 +791,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -811,7 +791,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|| (isStarted && shouldForceRenderOutputBuffer(earlyUs, elapsedSinceLastRenderUs))); || (isStarted && shouldForceRenderOutputBuffer(earlyUs, elapsedSinceLastRenderUs)));
if (forceRenderOutputBuffer) { if (forceRenderOutputBuffer) {
long releaseTimeNs = System.nanoTime(); long releaseTimeNs = System.nanoTime();
notifyFrameMetadataListener(presentationTimeUs, releaseTimeNs, format, currentMediaFormat); notifyFrameMetadataListener(presentationTimeUs, releaseTimeNs, format);
if (Util.SDK_INT >= 21) { if (Util.SDK_INT >= 21) {
renderOutputBufferV21(codec, bufferIndex, presentationTimeUs, releaseTimeNs); renderOutputBufferV21(codec, bufferIndex, presentationTimeUs, releaseTimeNs);
} else { } else {
...@@ -857,8 +837,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -857,8 +837,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
if (Util.SDK_INT >= 21) { if (Util.SDK_INT >= 21) {
// Let the underlying framework time the release. // Let the underlying framework time the release.
if (earlyUs < 50000) { if (earlyUs < 50000) {
notifyFrameMetadataListener( notifyFrameMetadataListener(presentationTimeUs, adjustedReleaseTimeNs, format);
presentationTimeUs, adjustedReleaseTimeNs, format, currentMediaFormat);
renderOutputBufferV21(codec, bufferIndex, presentationTimeUs, adjustedReleaseTimeNs); renderOutputBufferV21(codec, bufferIndex, presentationTimeUs, adjustedReleaseTimeNs);
updateVideoFrameProcessingOffsetCounters(earlyUs); updateVideoFrameProcessingOffsetCounters(earlyUs);
return true; return true;
...@@ -877,8 +856,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -877,8 +856,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
return false; return false;
} }
} }
notifyFrameMetadataListener( notifyFrameMetadataListener(presentationTimeUs, adjustedReleaseTimeNs, format);
presentationTimeUs, adjustedReleaseTimeNs, format, currentMediaFormat);
renderOutputBuffer(codec, bufferIndex, presentationTimeUs); renderOutputBuffer(codec, bufferIndex, presentationTimeUs);
updateVideoFrameProcessingOffsetCounters(earlyUs); updateVideoFrameProcessingOffsetCounters(earlyUs);
return true; return true;
...@@ -890,10 +868,10 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -890,10 +868,10 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
private void notifyFrameMetadataListener( private void notifyFrameMetadataListener(
long presentationTimeUs, long releaseTimeNs, Format format, MediaFormat mediaFormat) { long presentationTimeUs, long releaseTimeNs, Format format) {
if (frameMetadataListener != null) { if (frameMetadataListener != null) {
frameMetadataListener.onVideoFrameAboutToBeRendered( frameMetadataListener.onVideoFrameAboutToBeRendered(
presentationTimeUs, releaseTimeNs, format, mediaFormat); presentationTimeUs, releaseTimeNs, format, getCodecOutputMediaFormat());
} }
} }
...@@ -1230,10 +1208,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1230,10 +1208,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
private void maybeNotifyVideoFrameProcessingOffset() { private void maybeNotifyVideoFrameProcessingOffset() {
@Nullable Format outputFormat = getCurrentOutputFormat(); if (videoFrameProcessingOffsetCount != 0) {
if (outputFormat != null && videoFrameProcessingOffsetCount != 0) {
eventDispatcher.reportVideoFrameProcessingOffset( eventDispatcher.reportVideoFrameProcessingOffset(
totalVideoFrameProcessingOffsetUs, videoFrameProcessingOffsetCount, outputFormat); totalVideoFrameProcessingOffsetUs, videoFrameProcessingOffsetCount);
totalVideoFrameProcessingOffsetUs = 0; totalVideoFrameProcessingOffsetUs = 0;
videoFrameProcessingOffsetCount = 0; videoFrameProcessingOffsetCount = 0;
} }
......
...@@ -88,10 +88,8 @@ public interface VideoRendererEventListener { ...@@ -88,10 +88,8 @@ public interface VideoRendererEventListener {
* @param totalProcessingOffsetUs The sum of all video frame processing offset samples for the * @param totalProcessingOffsetUs The sum of all video frame processing offset samples for the
* video frames processed by the renderer in microseconds. * video frames processed by the renderer in microseconds.
* @param frameCount The number of samples included in the {@code totalProcessingOffsetUs}. * @param frameCount The number of samples included in the {@code totalProcessingOffsetUs}.
* @param format The {@link Format} that is currently output.
*/ */
default void onVideoFrameProcessingOffset( default void onVideoFrameProcessingOffset(long totalProcessingOffsetUs, int frameCount) {}
long totalProcessingOffsetUs, int frameCount, Format format) {}
/** /**
* Called before a frame is rendered for the first time since setting the surface, and each time * Called before a frame is rendered for the first time since setting the surface, and each time
...@@ -182,13 +180,12 @@ public interface VideoRendererEventListener { ...@@ -182,13 +180,12 @@ public interface VideoRendererEventListener {
} }
/** Invokes {@link VideoRendererEventListener#onVideoFrameProcessingOffset}. */ /** Invokes {@link VideoRendererEventListener#onVideoFrameProcessingOffset}. */
public void reportVideoFrameProcessingOffset( public void reportVideoFrameProcessingOffset(long totalProcessingOffsetUs, int frameCount) {
long totalProcessingOffsetUs, int frameCount, Format format) {
if (handler != null) { if (handler != null) {
handler.post( handler.post(
() -> () ->
castNonNull(listener) castNonNull(listener)
.onVideoFrameProcessingOffset(totalProcessingOffsetUs, frameCount, format)); .onVideoFrameProcessingOffset(totalProcessingOffsetUs, frameCount));
} }
} }
......
...@@ -1955,7 +1955,7 @@ public final class AnalyticsCollectorTest { ...@@ -1955,7 +1955,7 @@ public final class AnalyticsCollectorTest {
@Override @Override
public void onVideoFrameProcessingOffset( public void onVideoFrameProcessingOffset(
EventTime eventTime, long totalProcessingOffsetUs, int frameCount, Format format) { EventTime eventTime, long totalProcessingOffsetUs, int frameCount) {
reportedEvents.add(new ReportedEvent(EVENT_VIDEO_FRAME_PROCESSING_OFFSET, eventTime)); reportedEvents.add(new ReportedEvent(EVENT_VIDEO_FRAME_PROCESSING_OFFSET, eventTime));
} }
......
...@@ -25,7 +25,9 @@ import static org.mockito.ArgumentMatchers.anyLong; ...@@ -25,7 +25,9 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.media.MediaFormat;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.annotation.Nullable;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -216,15 +218,16 @@ public class MediaCodecAudioRendererTest { ...@@ -216,15 +218,16 @@ public class MediaCodecAudioRendererTest {
/* eventHandler= */ null, /* eventHandler= */ null,
/* eventListener= */ null) { /* eventListener= */ null) {
@Override @Override
protected void onOutputFormatChanged(Format outputFormat) throws ExoPlaybackException { protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat)
super.onOutputFormatChanged(outputFormat); throws ExoPlaybackException {
if (!outputFormat.equals(AUDIO_AAC)) { super.onOutputFormatChanged(format, mediaFormat);
if (!format.equals(AUDIO_AAC)) {
setPendingPlaybackException( setPendingPlaybackException(
ExoPlaybackException.createForRenderer( ExoPlaybackException.createForRenderer(
new AudioSink.ConfigurationException("Test"), new AudioSink.ConfigurationException("Test"),
"rendererName", "rendererName",
/* rendererIndex= */ 0, /* rendererIndex= */ 0,
outputFormat, format,
FORMAT_HANDLED)); FORMAT_HANDLED));
} }
} }
...@@ -254,8 +257,11 @@ public class MediaCodecAudioRendererTest { ...@@ -254,8 +257,11 @@ public class MediaCodecAudioRendererTest {
exceptionThrowingRenderer.render(/* positionUs= */ 0, SystemClock.elapsedRealtime() * 1000); exceptionThrowingRenderer.render(/* positionUs= */ 0, SystemClock.elapsedRealtime() * 1000);
exceptionThrowingRenderer.render(/* positionUs= */ 250, SystemClock.elapsedRealtime() * 1000); exceptionThrowingRenderer.render(/* positionUs= */ 250, SystemClock.elapsedRealtime() * 1000);
MediaFormat mediaFormat = new MediaFormat();
mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 2);
mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, 32_000);
// Simulating the exception being thrown when not traceable back to render. // Simulating the exception being thrown when not traceable back to render.
exceptionThrowingRenderer.onOutputFormatChanged(changedFormat); exceptionThrowingRenderer.onOutputFormatChanged(changedFormat, mediaFormat);
assertThrows( assertThrows(
ExoPlaybackException.class, ExoPlaybackException.class,
......
...@@ -29,6 +29,7 @@ import static org.mockito.Mockito.verify; ...@@ -29,6 +29,7 @@ import static org.mockito.Mockito.verify;
import static org.robolectric.Shadows.shadowOf; import static org.robolectric.Shadows.shadowOf;
import android.graphics.SurfaceTexture; import android.graphics.SurfaceTexture;
import android.media.MediaFormat;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.SystemClock; import android.os.SystemClock;
...@@ -37,7 +38,6 @@ import androidx.annotation.Nullable; ...@@ -37,7 +38,6 @@ import androidx.annotation.Nullable;
import androidx.test.core.app.ApplicationProvider; import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Renderer; import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
...@@ -113,9 +113,9 @@ public class MediaCodecVideoRendererTest { ...@@ -113,9 +113,9 @@ public class MediaCodecVideoRendererTest {
} }
@Override @Override
protected void onOutputFormatChanged(Format outputFormat) { protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat) {
super.onOutputFormatChanged(outputFormat); super.onOutputFormatChanged(format, mediaFormat);
currentOutputFormat = outputFormat; currentOutputFormat = format;
} }
}; };
...@@ -458,59 +458,4 @@ public class MediaCodecVideoRendererTest { ...@@ -458,59 +458,4 @@ public class MediaCodecVideoRendererTest {
shadowLooper.idle(); shadowLooper.idle();
verify(eventListener, times(2)).onRenderedFirstFrame(any()); verify(eventListener, times(2)).onRenderedFirstFrame(any());
} }
@Test
public void onVideoFrameProcessingOffset_isCalledAfterOutputFormatChanges()
throws ExoPlaybackException {
Format mp4Uhd = VIDEO_H264.buildUpon().setWidth(3840).setHeight(2160).build();
FakeSampleStream fakeSampleStream =
new FakeSampleStream(
/* mediaSourceEventDispatcher= */ null,
DrmSessionManager.DUMMY,
new DrmSessionEventListener.EventDispatcher(),
/* initialFormat= */ mp4Uhd,
ImmutableList.of(
oneByteSample(/* timeUs= */ 0, C.BUFFER_FLAG_KEY_FRAME),
format(VIDEO_H264),
oneByteSample(/* timeUs= */ 50, C.BUFFER_FLAG_KEY_FRAME),
oneByteSample(/* timeUs= */ 100),
format(mp4Uhd),
oneByteSample(/* timeUs= */ 150, C.BUFFER_FLAG_KEY_FRAME),
oneByteSample(/* timeUs= */ 200),
oneByteSample(/* timeUs= */ 250),
format(VIDEO_H264),
oneByteSample(/* timeUs= */ 300, C.BUFFER_FLAG_KEY_FRAME),
FakeSampleStreamItem.END_OF_STREAM_ITEM));
mediaCodecVideoRenderer.enable(
RendererConfiguration.DEFAULT,
new Format[] {mp4Uhd},
fakeSampleStream,
/* positionUs= */ 0,
/* joining= */ false,
/* mayRenderStartOfStream= */ true,
/* offsetUs */ 0);
mediaCodecVideoRenderer.setCurrentStreamFinal();
mediaCodecVideoRenderer.start();
int positionUs = 10;
do {
mediaCodecVideoRenderer.render(positionUs, SystemClock.elapsedRealtime() * 1000);
positionUs += 10;
} while (!mediaCodecVideoRenderer.isEnded());
mediaCodecVideoRenderer.stop();
shadowOf(testMainLooper).idle();
InOrder orderVerifier = inOrder(eventListener);
orderVerifier.verify(eventListener).onVideoFrameProcessingOffset(anyLong(), eq(1), eq(mp4Uhd));
orderVerifier
.verify(eventListener)
.onVideoFrameProcessingOffset(anyLong(), eq(2), eq(VIDEO_H264));
orderVerifier.verify(eventListener).onVideoFrameProcessingOffset(anyLong(), eq(3), eq(mp4Uhd));
orderVerifier
.verify(eventListener)
.onVideoFrameProcessingOffset(anyLong(), eq(1), eq(VIDEO_H264));
orderVerifier.verifyNoMoreInteractions();
}
} }
...@@ -67,9 +67,7 @@ public class FakeVideoRenderer extends FakeRenderer { ...@@ -67,9 +67,7 @@ public class FakeVideoRenderer extends FakeRenderer {
super.onStopped(); super.onStopped();
eventDispatcher.droppedFrames(/* droppedFrameCount= */ 0, /* elapsedMs= */ 0); eventDispatcher.droppedFrames(/* droppedFrameCount= */ 0, /* elapsedMs= */ 0);
eventDispatcher.reportVideoFrameProcessingOffset( eventDispatcher.reportVideoFrameProcessingOffset(
/* totalProcessingOffsetUs= */ 400000, /* totalProcessingOffsetUs= */ 400000, /* frameCount= */ 10);
/* frameCount= */ 10,
Assertions.checkNotNull(format));
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment