Search in sources :

Example 1 with VideoSize

use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.

the class MediaMetricsListener method onVideoSizeChanged.

@Override
public void onVideoSizeChanged(EventTime eventTime, VideoSize videoSize) {
    @Nullable PendingFormatUpdate pendingVideoFormat = this.pendingVideoFormat;
    if (pendingVideoFormat != null && pendingVideoFormat.format.height == Format.NO_VALUE) {
        Format formatWithHeightAndWidth = pendingVideoFormat.format.buildUpon().setWidth(videoSize.width).setHeight(videoSize.height).build();
        this.pendingVideoFormat = new PendingFormatUpdate(formatWithHeightAndWidth, pendingVideoFormat.selectionReason, pendingVideoFormat.sessionId);
    }
}
Also used : Format(com.google.android.exoplayer2.Format) Nullable(androidx.annotation.Nullable)

Example 2 with VideoSize

use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.

the class StyledPlayerView method updateAspectRatio.

private void updateAspectRatio() {
    VideoSize videoSize = player != null ? player.getVideoSize() : VideoSize.UNKNOWN;
    int width = videoSize.width;
    int height = videoSize.height;
    int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
    float videoAspectRatio = (height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
    if (surfaceView instanceof TextureView) {
        // Try to apply rotation transformation when our surface is a TextureView.
        if (videoAspectRatio > 0 && (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270)) {
            // We will apply a rotation 90/270 degree to the output texture of the TextureView.
            // In this case, the output video's width and height will be swapped.
            videoAspectRatio = 1 / videoAspectRatio;
        }
        if (textureViewRotation != 0) {
            surfaceView.removeOnLayoutChangeListener(componentListener);
        }
        textureViewRotation = unappliedRotationDegrees;
        if (textureViewRotation != 0) {
            // The texture view's dimensions might be changed after layout step.
            // So add an OnLayoutChangeListener to apply rotation after layout step.
            surfaceView.addOnLayoutChangeListener(componentListener);
        }
        applyTextureViewRotation((TextureView) surfaceView, textureViewRotation);
    }
    onContentAspectRatioChanged(contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio);
}
Also used : VideoSize(com.google.android.exoplayer2.video.VideoSize) TextureView(android.view.TextureView) SuppressLint(android.annotation.SuppressLint)

Example 3 with VideoSize

use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.

the class PlayerView method updateAspectRatio.

private void updateAspectRatio() {
    VideoSize videoSize = player != null ? player.getVideoSize() : VideoSize.UNKNOWN;
    int width = videoSize.width;
    int height = videoSize.height;
    int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
    float videoAspectRatio = (height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
    if (surfaceView instanceof TextureView) {
        // Try to apply rotation transformation when our surface is a TextureView.
        if (videoAspectRatio > 0 && (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270)) {
            // We will apply a rotation 90/270 degree to the output texture of the TextureView.
            // In this case, the output video's width and height will be swapped.
            videoAspectRatio = 1 / videoAspectRatio;
        }
        if (textureViewRotation != 0) {
            surfaceView.removeOnLayoutChangeListener(componentListener);
        }
        textureViewRotation = unappliedRotationDegrees;
        if (textureViewRotation != 0) {
            // The texture view's dimensions might be changed after layout step.
            // So add an OnLayoutChangeListener to apply rotation after layout step.
            surfaceView.addOnLayoutChangeListener(componentListener);
        }
        applyTextureViewRotation((TextureView) surfaceView, textureViewRotation);
    }
    onContentAspectRatioChanged(contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio);
}
Also used : VideoSize(com.google.android.exoplayer2.video.VideoSize) TextureView(android.view.TextureView) SuppressLint(android.annotation.SuppressLint)

Example 4 with VideoSize

use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.

the class MediaCodecVideoRendererTest method render_sendsVideoSizeChangeWithCurrentFormatValues.

@Test
public void render_sendsVideoSizeChangeWithCurrentFormatValues() throws Exception {
    FakeSampleStream fakeSampleStream = new FakeSampleStream(new DefaultAllocator(/* trimOnReset= */
    true, /* individualAllocationSize= */
    1024), /* mediaSourceEventDispatcher= */
    null, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), /* initialFormat= */
    VIDEO_H264, ImmutableList.of(oneByteSample(/* timeUs= */
    0, C.BUFFER_FLAG_KEY_FRAME), END_OF_STREAM_ITEM));
    fakeSampleStream.writeData(/* startPositionUs= */
    0);
    mediaCodecVideoRenderer.enable(RendererConfiguration.DEFAULT, new Format[] { VIDEO_H264 }, fakeSampleStream, /* positionUs= */
    0, /* joining= */
    false, /* mayRenderStartOfStream= */
    true, /* startPositionUs= */
    0, /* offsetUs */
    0);
    mediaCodecVideoRenderer.setCurrentStreamFinal();
    mediaCodecVideoRenderer.start();
    int positionUs = 0;
    do {
        mediaCodecVideoRenderer.render(positionUs, SystemClock.elapsedRealtime() * 1000);
        positionUs += 10;
    } while (!mediaCodecVideoRenderer.isEnded());
    shadowOf(testMainLooper).idle();
    verify(eventListener).onVideoSizeChanged(new VideoSize(VIDEO_H264.width, VIDEO_H264.height, VIDEO_H264.rotationDegrees, VIDEO_H264.pixelWidthHeightRatio));
}
Also used : FakeSampleStream(com.google.android.exoplayer2.testutil.FakeSampleStream) DefaultAllocator(com.google.android.exoplayer2.upstream.DefaultAllocator) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Test(org.junit.Test)

Example 5 with VideoSize

use of com.google.android.exoplayer2.video.VideoSize in project ExoPlayer by google.

the class FakeVideoRenderer method shouldProcessBuffer.

@Override
protected boolean shouldProcessBuffer(long bufferTimeUs, long playbackPositionUs) {
    boolean shouldProcess = super.shouldProcessBuffer(bufferTimeUs, playbackPositionUs);
    boolean shouldRenderFirstFrame = output != null && (!renderedFirstFrameAfterEnable ? (getState() == Renderer.STATE_STARTED || mayRenderFirstFrameAfterEnableIfNotStarted) : !renderedFirstFrameAfterReset);
    shouldProcess |= shouldRenderFirstFrame && playbackPositionUs >= streamOffsetUs;
    @Nullable Object output = this.output;
    if (shouldProcess && !renderedFirstFrameAfterReset && output != null) {
        @MonotonicNonNull Format format = Assertions.checkNotNull(this.format);
        eventDispatcher.videoSizeChanged(new VideoSize(format.width, format.height, format.rotationDegrees, format.pixelWidthHeightRatio));
        eventDispatcher.renderedFirstFrame(output);
        renderedFirstFrameAfterReset = true;
        renderedFirstFrameAfterEnable = true;
    }
    return shouldProcess;
}
Also used : Format(com.google.android.exoplayer2.Format) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) VideoSize(com.google.android.exoplayer2.video.VideoSize) Nullable(androidx.annotation.Nullable)

Aggregations

VideoSize (com.google.android.exoplayer2.video.VideoSize)4 Nullable (androidx.annotation.Nullable)3 Format (com.google.android.exoplayer2.Format)3 Test (org.junit.Test)3 SuppressLint (android.annotation.SuppressLint)2 TextureView (android.view.TextureView)2 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 FakeSampleStream (com.google.android.exoplayer2.testutil.FakeSampleStream)2 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)2 SurfaceTexture (android.graphics.SurfaceTexture)1 CodecCapabilities (android.media.MediaCodecInfo.CodecCapabilities)1 CodecProfileLevel (android.media.MediaCodecInfo.CodecProfileLevel)1 MediaFormat (android.media.MediaFormat)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 SystemClock (android.os.SystemClock)1 Surface (android.view.Surface)1 SurfaceView (android.view.SurfaceView)1 ApplicationProvider (androidx.test.core.app.ApplicationProvider)1