*** Original commit ***

Rollback of 2a6f893fba

*** Original commit ***

Set video size to 0/0 when video render is disabled

In terms of MCVR wi...

***

PiperOrigin-RevId: 540525069
This commit is contained in:
bachinger 2023-06-15 11:10:06 +01:00 committed by Marc Baechinger
parent 51fb72b00d
commit bd97dd8519
10 changed files with 238 additions and 49 deletions

View File

@ -492,7 +492,7 @@
]
},
{
"name": "Audio -> Video -> Audio",
"name": "Audio -> Video (MKV) -> Video (MKV) -> Audio -> Video (MKV) -> Video (DASH) -> Audio",
"playlist": [
{
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/audio-141.mp4"
@ -500,6 +500,18 @@
{
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv"
},
{
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv"
},
{
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/audio-141.mp4"
},
{
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv"
},
{
"uri": "https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd"
},
{
"uri": "https://storage.googleapis.com/exoplayer-test-media-1/gen-3/screens/dash-vod-single-segment/audio-141.mp4"
}

View File

@ -1079,7 +1079,7 @@ public interface Player {
default void onDeviceVolumeChanged(int volume, boolean muted) {}
/**
* Called each time there's a change in the size of the video being rendered.
* Called each time when {@link Player#getVideoSize()} changes.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
@ -3187,8 +3187,8 @@ public interface Player {
/**
* Gets the size of the video.
*
* <p>The video's width and height are {@code 0} if there is no video or its size has not been
* determined yet.
* <p>The video's width and height are {@code 0} if there is {@linkplain
* Tracks#isTypeSupported(int) no supported video track} or its size has not been determined yet.
*
* @see Listener#onVideoSizeChanged(VideoSize)
*/

View File

@ -684,6 +684,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
super.onDisabled();
} finally {
eventDispatcher.disabled(decoderCounters);
eventDispatcher.videoSizeChanged(VideoSize.UNKNOWN);
}
}

View File

@ -121,6 +121,7 @@ import androidx.media3.common.Timeline;
import androidx.media3.common.Timeline.Window;
import androidx.media3.common.TrackGroup;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Clock;
import androidx.media3.common.util.HandlerWrapper;
@ -357,6 +358,76 @@ public final class ExoPlayerTest {
player.release();
}
@Test
public void play_audioVideoAudioVideoTransition_videoSizeChangedCalledCorrectly()
throws Exception {
Timeline timeline = new FakeTimeline(/* windowCount= */ 1);
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.setVideoSurface(new Surface(new SurfaceTexture(/* texName= */ 0)));
Player.Listener mockPlayerListener = mock(Player.Listener.class);
player.addListener(mockPlayerListener);
AnalyticsListener mockAnalyticsListener = mock(AnalyticsListener.class);
player.addAnalyticsListener(mockAnalyticsListener);
player.setMediaSources(
ImmutableList.of(
new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT),
new FakeMediaSource(
timeline, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT),
new FakeMediaSource(timeline, ExoPlayerTestRunner.AUDIO_FORMAT),
new FakeMediaSource(
timeline, ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT)));
player.prepare();
List<VideoSize> videoSizesFromGetter = new ArrayList<>();
player.addListener(
new Listener() {
@Override
public void onVideoSizeChanged(VideoSize videoSize) {
videoSizesFromGetter.add(player.getVideoSize());
}
});
player.play();
runUntilPlaybackState(player, Player.STATE_READY);
// Get the video size right after the first audio item was prepared.
videoSizesFromGetter.add(player.getVideoSize());
runUntilPlaybackState(player, Player.STATE_ENDED);
videoSizesFromGetter.add(player.getVideoSize());
player.release();
ShadowLooper.runMainLooperToNextTask();
InOrder playerListenerOrder = inOrder(mockPlayerListener);
playerListenerOrder.verify(mockPlayerListener).onVideoSizeChanged(new VideoSize(1280, 720));
playerListenerOrder.verify(mockPlayerListener).onVideoSizeChanged(VideoSize.UNKNOWN);
playerListenerOrder.verify(mockPlayerListener).onVideoSizeChanged(new VideoSize(1280, 720));
playerListenerOrder.verify(mockPlayerListener).onPlaybackStateChanged(STATE_ENDED);
verify(mockPlayerListener, times(3)).onVideoSizeChanged(any());
// Verify calls to analytics listener.
verify(mockAnalyticsListener, times(2)).onVideoEnabled(any(), any());
verify(mockAnalyticsListener, times(2)).onVideoDisabled(any(), any());
verify(mockAnalyticsListener).onAudioEnabled(any(), any());
verify(mockAnalyticsListener).onAudioDisabled(any(), any());
InOrder inOrder = Mockito.inOrder(mockAnalyticsListener);
inOrder.verify(mockAnalyticsListener).onAudioEnabled(any(), any());
inOrder.verify(mockAnalyticsListener).onVideoEnabled(any(), any());
inOrder.verify(mockAnalyticsListener).onVideoSizeChanged(any(), eq(new VideoSize(1280, 720)));
inOrder.verify(mockAnalyticsListener).onVideoDisabled(any(), any());
inOrder.verify(mockAnalyticsListener).onVideoSizeChanged(any(), eq(VideoSize.UNKNOWN));
inOrder.verify(mockAnalyticsListener).onVideoEnabled(any(), any());
inOrder.verify(mockAnalyticsListener).onVideoSizeChanged(any(), eq(new VideoSize(1280, 720)));
inOrder.verify(mockAnalyticsListener).onVideoDisabled(any(), any());
inOrder.verify(mockAnalyticsListener).onAudioDisabled(any(), any());
verify(mockAnalyticsListener, times(3)).onVideoSizeChanged(any(), any());
// Verify video sizes from getter.
assertThat(videoSizesFromGetter)
.containsExactly(
VideoSize.UNKNOWN, // When first item starts playing
new VideoSize(1280, 720), // When onVideoSizeChanged() called
VideoSize.UNKNOWN, // When onVideoSizeChanged() called
new VideoSize(1280, 720), // When onVideoSizeChanged() called
new VideoSize(1280, 720)) // In STATE_ENDED
.inOrder();
}
/** Tests playback of periods with very short duration. */
@Test
public void playShortDurationPeriods() throws Exception {

View File

@ -356,9 +356,7 @@ public final class DefaultAnalyticsCollectorTest {
.containsExactly(period0, period1)
.inOrder();
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period1);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(period0, period1)
.inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(period0, period1)
.inOrder();
@ -425,7 +423,11 @@ public final class DefaultAnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(
period0, // First frame rendered of first video item
period1) // width=0, height=0 for audio only media source
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET)).containsExactly(period0);
listener.assertNoMoreEvents();
@ -506,7 +508,11 @@ public final class DefaultAnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_VIDEO_DECODER_INITIALIZED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_INPUT_FORMAT_CHANGED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(period0);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(
period0, // First frame rendered of first video item
period1) // width=0, height=0 for audio only media source
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(period0);
listener.assertNoMoreEvents();
}
@ -604,7 +610,10 @@ public final class DefaultAnalyticsCollectorTest {
.containsExactly(period0, period1Seq2)
.inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(period0, period1Seq1, period0, period1Seq2)
.containsExactly(
period0, // First frame rendered
period1Seq1, // Renderer disabled after seek
period0) // First frame rendered after seek
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(period0, period1Seq1, period0, period1Seq2)
@ -697,7 +706,10 @@ public final class DefaultAnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq1);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(period0Seq0, period0Seq1)
.containsExactly(
period0Seq0, // First frame rendered
period0Seq0, // Renderer disabled after timeline changed
period0Seq1) // First frame rendered of new source
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(period0Seq0, period0Seq1)
@ -780,7 +792,7 @@ public final class DefaultAnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq0);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(period0Seq0, period0Seq0);
.containsExactly(period0Seq0, period0Seq0, period0Seq0);
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(period0Seq0, period0Seq0);
assertThat(listener.getEvents(EVENT_VIDEO_FRAME_PROCESSING_OFFSET))
@ -857,7 +869,9 @@ public final class DefaultAnalyticsCollectorTest {
.containsExactly(window0Period1Seq0, period1Seq0)
.inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(window0Period1Seq0, window1Period0Seq1)
.containsExactly(
window0Period1Seq0, // First frame rendered
window0Period1Seq0) // Renderer disabled after timeline update
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(window0Period1Seq0, window1Period0Seq1)
@ -945,7 +959,10 @@ public final class DefaultAnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(period0Seq0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(period0Seq1);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(period0Seq0, period1Seq1, period0Seq1)
.containsExactly(
period0Seq0, // First frame rendered
period0Seq1, // Renderer disabled after media item removal
period0Seq1) // First frame rendered after removal
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(period0Seq0, period1Seq1, period0Seq1);
@ -1172,13 +1189,7 @@ public final class DefaultAnalyticsCollectorTest {
.containsExactly(contentAfterPreroll, contentAfterMidroll, contentAfterPostroll)
.inOrder();
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(
prerollAd,
contentAfterPreroll,
midrollAd,
contentAfterMidroll,
postrollAd,
contentAfterPostroll)
.containsExactly(prerollAd) // First frame rendered
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(
@ -1318,7 +1329,10 @@ public final class DefaultAnalyticsCollectorTest {
assertThat(listener.getEvents(EVENT_VIDEO_DISABLED)).containsExactly(contentBeforeMidroll);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(contentAfterMidroll);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
.containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll)
.containsExactly(
contentBeforeMidroll, // First frame rendered
midrollAd, // Renderer disabled for seek
midrollAd) // First frame rendered after seek
.inOrder();
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(contentBeforeMidroll, midrollAd, contentAfterMidroll)

View File

@ -24,6 +24,9 @@ public class MediaSessionConstants {
public static final String TEST_CONTROLLER_LISTENER_SESSION_REJECTS = "connection_sessionRejects";
public static final String TEST_IS_SESSION_COMMAND_AVAILABLE = "testIsSessionCommandAvailable";
public static final String TEST_COMMAND_GET_TRACKS = "testCommandGetTracksUnavailable";
public static final String TEST_ON_VIDEO_SIZE_CHANGED = "onVideoSizeChanged";
public static final String TEST_ON_TRACKS_CHANGED_VIDEO_TO_AUDIO_TRANSITION =
"onTracksChanged_videoToAudioTransition";
// Bundle keys
public static final String KEY_AVAILABLE_SESSION_COMMANDS = "availableSessionCommands";

View File

@ -25,6 +25,7 @@ import static androidx.media3.test.session.common.MediaSessionConstants.KEY_COMM
import static androidx.media3.test.session.common.MediaSessionConstants.KEY_CONTROLLER;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_COMMAND_GET_TRACKS;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_CONTROLLER_LISTENER_SESSION_REJECTS;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_ON_VIDEO_SIZE_CHANGED;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_WITH_CUSTOM_COMMANDS;
import static androidx.media3.test.session.common.TestUtils.LONG_TIMEOUT_MS;
import static androidx.media3.test.session.common.TestUtils.NO_RESPONSE_TIMEOUT_MS;
@ -2545,40 +2546,53 @@ public class MediaControllerListenerTest {
@Test
public void onVideoSizeChanged() throws Exception {
VideoSize testVideoSize =
new VideoSize(
/* width= */ 100,
/* height= */ 42,
/* unappliedRotationDegrees= */ 90,
/* pixelWidthHeightRatio= */ 1.2f);
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
CountDownLatch latch = new CountDownLatch(2);
AtomicReference<VideoSize> videoSizeFromParamRef = new AtomicReference<>();
AtomicReference<VideoSize> videoSizeFromGetterRef = new AtomicReference<>();
AtomicReference<Player.Events> eventsRef = new AtomicReference<>();
VideoSize defaultVideoSize = MediaTestUtils.createDefaultVideoSize();
RemoteMediaSession session = createRemoteMediaSession(TEST_ON_VIDEO_SIZE_CHANGED);
MediaController controller = controllerTestRule.createController(session.getToken());
List<VideoSize> videoSizeFromGetterList = new ArrayList<>();
List<VideoSize> videoSizeFromParamList = new ArrayList<>();
List<Player.Events> eventsList = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(6);
Player.Listener listener =
new Player.Listener() {
@Override
public void onVideoSizeChanged(VideoSize videoSize) {
videoSizeFromParamRef.set(videoSize);
videoSizeFromGetterRef.set(controller.getVideoSize());
videoSizeFromParamList.add(videoSize);
videoSizeFromGetterList.add(controller.getVideoSize());
latch.countDown();
}
@Override
public void onEvents(Player player, Player.Events events) {
eventsRef.set(events);
eventsList.add(events);
latch.countDown();
}
};
threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
threadTestRule
.getHandler()
.postAndSync(
() -> {
controller.addListener(listener);
// Verify initial controller state.
assertThat(controller.getVideoSize()).isEqualTo(defaultVideoSize);
});
remoteSession.getMockPlayer().notifyVideoSizeChanged(testVideoSize);
session.getMockPlayer().notifyVideoSizeChanged(VideoSize.UNKNOWN);
session.getMockPlayer().notifyVideoSizeChanged(defaultVideoSize);
session.getMockPlayer().notifyVideoSizeChanged(defaultVideoSize);
session.getMockPlayer().notifyVideoSizeChanged(VideoSize.UNKNOWN);
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
assertThat(videoSizeFromParamRef.get()).isEqualTo(testVideoSize);
assertThat(videoSizeFromGetterRef.get()).isEqualTo(testVideoSize);
assertThat(getEventsAsList(eventsRef.get())).containsExactly(Player.EVENT_VIDEO_SIZE_CHANGED);
assertThat(videoSizeFromParamList)
.containsExactly(VideoSize.UNKNOWN, defaultVideoSize, VideoSize.UNKNOWN)
.inOrder();
assertThat(videoSizeFromGetterList)
.containsExactly(VideoSize.UNKNOWN, defaultVideoSize, VideoSize.UNKNOWN)
.inOrder();
assertThat(eventsList).hasSize(3);
assertThat(getEventsAsList(eventsList.get(0))).containsExactly(Player.EVENT_VIDEO_SIZE_CHANGED);
assertThat(getEventsAsList(eventsList.get(1))).containsExactly(Player.EVENT_VIDEO_SIZE_CHANGED);
assertThat(getEventsAsList(eventsList.get(2))).containsExactly(Player.EVENT_VIDEO_SIZE_CHANGED);
}
@Test

View File

@ -62,6 +62,8 @@ import static androidx.media3.test.session.common.MediaSessionConstants.TEST_COM
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_CONTROLLER_LISTENER_SESSION_REJECTS;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_GET_SESSION_ACTIVITY;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_IS_SESSION_COMMAND_AVAILABLE;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_ON_TRACKS_CHANGED_VIDEO_TO_AUDIO_TRANSITION;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_ON_VIDEO_SIZE_CHANGED;
import static androidx.media3.test.session.common.MediaSessionConstants.TEST_WITH_CUSTOM_COMMANDS;
import android.app.PendingIntent;
@ -257,6 +259,13 @@ public class MediaSessionProviderService extends Service {
});
break;
}
case TEST_ON_TRACKS_CHANGED_VIDEO_TO_AUDIO_TRANSITION:
case TEST_ON_VIDEO_SIZE_CHANGED:
{
mockPlayer.videoSize = MediaTestUtils.createDefaultVideoSize();
mockPlayer.currentTracks = MediaTestUtils.createDefaultVideoTracks();
break;
}
default: // fall out
}

View File

@ -31,14 +31,21 @@ import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.session.MediaSessionCompat;
import androidx.annotation.Nullable;
import androidx.media.MediaBrowserServiceCompat.BrowserRoot;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.MediaMetadata;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.Timeline;
import androidx.media3.common.TrackGroup;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
import androidx.media3.common.util.Log;
import androidx.media3.session.MediaLibraryService.LibraryParams;
import androidx.media3.session.MediaSession.ControllerInfo;
import androidx.media3.test.session.common.TestUtils;
import androidx.test.core.app.ApplicationProvider;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -50,6 +57,50 @@ public final class MediaTestUtils {
private static final String TEST_IMAGE_PATH = "media/png/non-motion-photo-shortened.png";
private static final VideoSize DEFAULT_VIDEO_SIZE = new VideoSize(640, 480);
private static final Format VIDEO_FORMAT =
new Format.Builder()
.setSampleMimeType(MimeTypes.VIDEO_H264)
.setAverageBitrate(2_400_000)
.setWidth(DEFAULT_VIDEO_SIZE.width)
.setHeight(DEFAULT_VIDEO_SIZE.height)
.build();
private static final Format AUDIO_FORMAT =
new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_AAC)
.setAverageBitrate(320_000)
.setChannelCount(2)
.setSampleRate(44100)
.build();
/**
* Tracks with {@linkplain C#TRACK_TYPE_VIDEO a single video} track and {@linkplain
* C#TRACK_TYPE_AUDIO a single audio} track for testing purpose.
*/
public static Tracks createDefaultVideoTracks() {
return new Tracks(
ImmutableList.of(
new Tracks.Group(
new TrackGroup(VIDEO_FORMAT),
/* adaptiveSupported= */ false,
new int[] {C.FORMAT_HANDLED},
/* trackSelected= */ new boolean[] {true}),
new Tracks.Group(
new TrackGroup(AUDIO_FORMAT),
/* adaptiveSupported= */ false,
new int[] {C.FORMAT_HANDLED},
/* trackSelected= */ new boolean[] {true})));
}
/** Returns a new {@link VideoSize} instance for testing purpose. */
public static VideoSize createDefaultVideoSize() {
return new VideoSize(
DEFAULT_VIDEO_SIZE.width,
DEFAULT_VIDEO_SIZE.height,
DEFAULT_VIDEO_SIZE.unappliedRotationDegrees,
DEFAULT_VIDEO_SIZE.pixelWidthHeightRatio);
}
/** Create a media item with the mediaId for testing purpose. */
public static MediaItem createMediaItem(String mediaId) {
MediaMetadata mediaMetadata =

View File

@ -28,6 +28,8 @@ import androidx.media3.exoplayer.DecoderCounters;
import androidx.media3.exoplayer.ExoPlaybackException;
import androidx.media3.exoplayer.Renderer;
import androidx.media3.exoplayer.video.VideoRendererEventListener;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** A {@link FakeRenderer} that supports {@link C#TRACK_TYPE_VIDEO}. */
@ -37,6 +39,7 @@ public class FakeVideoRenderer extends FakeRenderer {
private final HandlerWrapper handler;
private final VideoRendererEventListener eventListener;
private final DecoderCounters decoderCounters;
private final AtomicReference<VideoSize> videoSizeRef = new AtomicReference<>();
private @MonotonicNonNull Format format;
@Nullable private Object output;
private long streamOffsetUs;
@ -49,6 +52,7 @@ public class FakeVideoRenderer extends FakeRenderer {
this.handler = handler;
this.eventListener = eventListener;
decoderCounters = new DecoderCounters();
videoSizeRef.set(VideoSize.UNKNOWN);
}
@Override
@ -81,7 +85,12 @@ public class FakeVideoRenderer extends FakeRenderer {
@Override
protected void onDisabled() {
super.onDisabled();
handler.post(() -> eventListener.onVideoDisabled(decoderCounters));
videoSizeRef.set(VideoSize.UNKNOWN);
handler.post(
() -> {
eventListener.onVideoDisabled(decoderCounters);
eventListener.onVideoSizeChanged(VideoSize.UNKNOWN);
});
}
@Override
@ -141,13 +150,18 @@ public class FakeVideoRenderer extends FakeRenderer {
if (shouldProcess && !renderedFirstFrameAfterReset && output != null) {
@MonotonicNonNull Format format = Assertions.checkNotNull(this.format);
handler.post(
() ->
eventListener.onVideoSizeChanged(
new VideoSize(
format.width,
format.height,
format.rotationDegrees,
format.pixelWidthHeightRatio)));
() -> {
VideoSize videoSize =
new VideoSize(
format.width,
format.height,
format.rotationDegrees,
format.pixelWidthHeightRatio);
if (!Objects.equals(videoSize, videoSizeRef.get())) {
eventListener.onVideoSizeChanged(videoSize);
videoSizeRef.set(videoSize);
}
});
handler.post(
() ->
eventListener.onRenderedFirstFrame(