Search in sources :

Example 1 with ScalingType

use of org.webrtc.RendererCommon.ScalingType in project matrix-android-sdk by matrix-org.

the class MXWebRtcView method onLayout.

/**
 * {@inheritDoc}
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int height = b - t;
    int width = r - l;
    if (height == 0 || width == 0) {
        l = t = r = b = 0;
    } else {
        int frameHeight;
        int frameRotation;
        int frameWidth;
        ScalingType scalingType;
        synchronized (layoutSyncRoot) {
            frameHeight = this.frameHeight;
            frameRotation = this.frameRotation;
            frameWidth = this.frameWidth;
            scalingType = this.scalingType;
        }
        SurfaceViewRenderer surfaceViewRenderer = getSurfaceViewRenderer();
        switch(scalingType) {
            case SCALE_ASPECT_FILL:
                // Fill this ViewGroup with surfaceViewRenderer and the latter
                // will take care of filling itself with the video similarly to
                // the cover value the CSS property object-fit.
                r = width;
                l = 0;
                b = height;
                t = 0;
                break;
            case SCALE_ASPECT_FIT:
            default:
                // (which will not matter, eventually).
                if (frameHeight == 0 || frameWidth == 0) {
                    l = t = r = b = 0;
                } else {
                    float frameAspectRatio = (frameRotation % 180 == 0) ? frameWidth / (float) frameHeight : frameHeight / (float) frameWidth;
                    Point frameDisplaySize = RendererCommon.getDisplaySize(scalingType, frameAspectRatio, width, height);
                    l = (width - frameDisplaySize.x) / 2;
                    t = (height - frameDisplaySize.y) / 2;
                    r = l + frameDisplaySize.x;
                    b = t + frameDisplaySize.y;
                }
                break;
        }
    }
    surfaceViewRenderer.layout(l, t, r, b);
}
Also used : ScalingType(org.webrtc.RendererCommon.ScalingType) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) Point(android.graphics.Point) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Point (android.graphics.Point)1 ScalingType (org.webrtc.RendererCommon.ScalingType)1 SurfaceViewRenderer (org.webrtc.SurfaceViewRenderer)1