package tv.danmaku.ijk.media.player.ui;

import android.view.View;
import java.lang.ref.WeakReference;

/* JADX INFO: loaded from: classes3.dex */
public final class MeasureHelper {
    private int mCurrentAspectRatio = 0;
    private int mMeasuredHeight;
    private int mMeasuredWidth;
    private int mVideoHeight;
    private int mVideoRotationDegree;
    private int mVideoSarDen;
    private int mVideoSarNum;
    private int mVideoWidth;
    private final WeakReference<View> mWeakView;

    public MeasureHelper(View view) {
        this.mWeakView = new WeakReference<>(view);
    }

    /* JADX WARN: Code restructure failed: missing block: B:45:0x00a3, code lost:
    
        if (r2 != false) goto L46;
     */
    /* JADX WARN: Code restructure failed: missing block: B:48:0x00a9, code lost:
    
        r2 = (int) (r5 / r8);
     */
    /* JADX WARN: Code restructure failed: missing block: B:49:0x00ad, code lost:
    
        if (r2 != false) goto L48;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void doMeasure(int i10, int i11) {
        int size;
        int size2;
        int i12;
        int i13;
        int i14;
        float f10;
        int i15;
        float f11;
        float f12;
        float f13;
        int i16 = this.mVideoRotationDegree;
        if (i16 == 90 || i16 == 270) {
            size = i10;
            size2 = i11;
        } else {
            size2 = i10;
            size = i11;
        }
        int defaultSize = View.getDefaultSize(this.mVideoWidth, size2);
        int defaultSize2 = View.getDefaultSize(this.mVideoHeight, size);
        if (this.mCurrentAspectRatio != 3) {
            if (this.mVideoWidth <= 0 || this.mVideoHeight <= 0) {
                size2 = defaultSize;
                size = defaultSize2;
            } else {
                int mode = View.MeasureSpec.getMode(size2);
                size2 = View.MeasureSpec.getSize(size2);
                int mode2 = View.MeasureSpec.getMode(size);
                size = View.MeasureSpec.getSize(size);
                float f14 = 0.75f;
                if (mode == Integer.MIN_VALUE && mode2 == Integer.MIN_VALUE) {
                    float f15 = size2;
                    f10 = size;
                    float f16 = f15 / f10;
                    int i17 = this.mCurrentAspectRatio;
                    if (i17 == 1) {
                        int i18 = this.mVideoRotationDegree;
                        f13 = (i18 == 90 || i18 == 270) ? 0.5625f : 1.7777778f;
                    } else if (i17 != 2) {
                        f13 = this.mVideoWidth / this.mVideoHeight;
                    } else {
                        int i19 = this.mVideoRotationDegree;
                        f13 = (i19 == 90 || i19 == 270) ? 0.75f : 1.3333334f;
                    }
                    boolean z10 = f13 > f16;
                    if (i17 != 0 && i17 != 1 && i17 != 2) {
                        if (i17 != 4) {
                            if (z10) {
                                size2 = Math.min(this.mVideoWidth, size2);
                                i14 = (int) (size2 / f13);
                                size = i14;
                            } else {
                                int iMin = Math.min(this.mVideoHeight, size);
                                i13 = (int) (iMin * f13);
                                size = iMin;
                                size2 = i13;
                            }
                        }
                    }
                } else if (mode == 1073741824 && mode2 == 1073741824) {
                    float f17 = size2;
                    f10 = size;
                    float f18 = f17 / f10;
                    int i20 = this.mCurrentAspectRatio;
                    if (i20 == 6) {
                        int i21 = this.mVideoWidth;
                        int i22 = i21 * size;
                        int i23 = this.mVideoHeight;
                        if (i22 > size2 * i23) {
                            i13 = (i21 * size) / i23;
                            size2 = i13;
                        } else if (i21 * size < size2 * i23) {
                            i15 = (i23 * size2) / i21;
                            size = i15;
                        }
                    } else {
                        if (i20 == 1) {
                            int i24 = this.mVideoRotationDegree;
                            f13 = (i24 == 90 || i24 == 270) ? 0.5625f : 1.7777778f;
                            if (f13 > f18) {
                                f12 = f17 / f13;
                            }
                            f11 = f10 * f13;
                            size2 = (int) f11;
                        } else if (i20 == 2) {
                            int i25 = this.mVideoRotationDegree;
                            if (i25 != 90 && i25 != 270) {
                                f14 = 1.3333334f;
                            }
                            if (f14 > f18) {
                                f12 = f17 / f14;
                            } else {
                                f11 = f10 * f14;
                                size2 = (int) f11;
                            }
                        } else if (i20 != 4) {
                            int i26 = this.mVideoWidth;
                            int i27 = i26 * size;
                            int i28 = this.mVideoHeight;
                            if (i27 < size2 * i28) {
                                i13 = (i26 * size) / i28;
                                size2 = i13;
                            } else if (i26 * size > size2 * i28) {
                                i15 = (i28 * size2) / i26;
                                size = i15;
                            }
                        }
                        size = (int) f12;
                    }
                } else if (mode == 1073741824) {
                    i14 = (this.mVideoHeight * size2) / this.mVideoWidth;
                    if (mode2 != Integer.MIN_VALUE || i14 <= size) {
                        size = i14;
                    }
                } else if (mode2 == 1073741824) {
                    i13 = (this.mVideoWidth * size) / this.mVideoHeight;
                    if (mode != Integer.MIN_VALUE || i13 <= size2) {
                        size2 = i13;
                    }
                } else {
                    int i29 = this.mVideoWidth;
                    int i30 = this.mVideoHeight;
                    if (mode2 != Integer.MIN_VALUE || i30 <= size) {
                        i12 = i29;
                        size = i30;
                    } else {
                        i12 = (size * i29) / i30;
                    }
                    if (mode != Integer.MIN_VALUE || i12 <= size2) {
                        size2 = i12;
                    } else {
                        size = (i30 * size2) / i29;
                    }
                }
            }
        }
        this.mMeasuredWidth = size2;
        this.mMeasuredHeight = size;
    }

    public int getMeasuredHeight() {
        return this.mMeasuredHeight;
    }

    public int getMeasuredWidth() {
        return this.mMeasuredWidth;
    }

    public View getView() {
        return this.mWeakView.get();
    }

    public void setAspectRatio(int i10) {
        this.mCurrentAspectRatio = i10;
    }

    public void setVideoRotation(int i10) {
        this.mVideoRotationDegree = i10;
    }

    public void setVideoSampleAspectRatio(int i10, int i11) {
        this.mVideoSarNum = i10;
        this.mVideoSarDen = i11;
    }

    public void setVideoSize(int i10, int i11) {
        this.mVideoWidth = i10;
        this.mVideoHeight = i11;
    }
}
