package com.google.android.exoplayer2.extractor.mkv;

import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.util.ParsableByteArray;
import java.io.IOException;

final class Sniffer {
    private static final int ID_EBML = 440786851;
    private static final int SEARCH_LENGTH = 1024;
    private int peekLength;
    private final ParsableByteArray scratch = new ParsableByteArray(8);

    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0075, code lost:
        r0 = readUint(r14);
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean sniff(com.google.android.exoplayer2.extractor.ExtractorInput r14) throws java.io.IOException, java.lang.InterruptedException {
        /*
            r13 = this;
            long r0 = r14.getLength()
            r2 = -1
            int r2 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            r3 = 1024(0x400, double:5.06E-321)
            if (r2 == 0) goto L_0x0012
            int r5 = (r0 > r3 ? 1 : (r0 == r3 ? 0 : -1))
            if (r5 <= 0) goto L_0x0011
            goto L_0x0012
        L_0x0011:
            r3 = r0
        L_0x0012:
            int r3 = (int) r3
            com.google.android.exoplayer2.util.ParsableByteArray r4 = r13.scratch
            byte[] r4 = r4.data
            r5 = 4
            r6 = 0
            r14.peekFully(r4, r6, r5)
            com.google.android.exoplayer2.util.ParsableByteArray r4 = r13.scratch
            long r7 = r4.readUnsignedInt()
            r13.peekLength = r5
        L_0x0024:
            r4 = 440786851(0x1a45dfa3, double:2.1777764E-315)
            int r4 = (r7 > r4 ? 1 : (r7 == r4 ? 0 : -1))
            r5 = 1
            if (r4 == 0) goto L_0x004d
            int r4 = r13.peekLength
            int r4 = r4 + r5
            r13.peekLength = r4
            if (r4 != r3) goto L_0x0034
            return r6
        L_0x0034:
            com.google.android.exoplayer2.util.ParsableByteArray r4 = r13.scratch
            byte[] r4 = r4.data
            r14.peekFully(r4, r6, r5)
            r4 = 8
            long r4 = r7 << r4
            r7 = -256(0xffffffffffffff00, double:NaN)
            long r4 = r4 & r7
            com.google.android.exoplayer2.util.ParsableByteArray r7 = r13.scratch
            byte[] r7 = r7.data
            byte r7 = r7[r6]
            r7 = r7 & 255(0xff, float:3.57E-43)
            long r7 = (long) r7
            long r7 = r7 | r4
            goto L_0x0024
        L_0x004d:
            long r3 = r13.readUint(r14)
            int r7 = r13.peekLength
            long r7 = (long) r7
            r9 = -9223372036854775808
            int r11 = (r3 > r9 ? 1 : (r3 == r9 ? 0 : -1))
            if (r11 == 0) goto L_0x009c
            if (r2 == 0) goto L_0x0063
            long r11 = r7 + r3
            int r0 = (r11 > r0 ? 1 : (r11 == r0 ? 0 : -1))
            if (r0 < 0) goto L_0x0063
            goto L_0x009c
        L_0x0063:
            int r0 = r13.peekLength
            long r1 = (long) r0
            long r11 = r7 + r3
            int r1 = (r1 > r11 ? 1 : (r1 == r11 ? 0 : -1))
            if (r1 >= 0) goto L_0x0096
            long r0 = r13.readUint(r14)
            int r0 = (r0 > r9 ? 1 : (r0 == r9 ? 0 : -1))
            if (r0 != 0) goto L_0x0075
            return r6
        L_0x0075:
            long r0 = r13.readUint(r14)
            r11 = 0
            int r2 = (r0 > r11 ? 1 : (r0 == r11 ? 0 : -1))
            if (r2 < 0) goto L_0x0095
            r11 = 2147483647(0x7fffffff, double:1.060997895E-314)
            int r11 = (r0 > r11 ? 1 : (r0 == r11 ? 0 : -1))
            if (r11 <= 0) goto L_0x0087
            goto L_0x0095
        L_0x0087:
            if (r2 == 0) goto L_0x0063
            int r2 = (int) r0
            r14.advancePeekPosition(r2)
            int r2 = r13.peekLength
            long r11 = (long) r2
            long r11 = r11 + r0
            int r0 = (int) r11
            r13.peekLength = r0
            goto L_0x0063
        L_0x0095:
            return r6
        L_0x0096:
            long r0 = (long) r0
            int r14 = (r0 > r11 ? 1 : (r0 == r11 ? 0 : -1))
            if (r14 != 0) goto L_0x009c
            r6 = r5
        L_0x009c:
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.exoplayer2.extractor.mkv.Sniffer.sniff(com.google.android.exoplayer2.extractor.ExtractorInput):boolean");
    }

    private long readUint(ExtractorInput extractorInput) throws IOException, InterruptedException {
        int i = 0;
        extractorInput.peekFully(this.scratch.data, 0, 1);
        byte b = this.scratch.data[0] & 255;
        if (b == 0) {
            return Long.MIN_VALUE;
        }
        int i2 = 128;
        int i3 = 0;
        while ((b & i2) == 0) {
            i2 >>= 1;
            i3++;
        }
        int i4 = b & (~i2);
        extractorInput.peekFully(this.scratch.data, 1, i3);
        while (i < i3) {
            i++;
            i4 = (this.scratch.data[i] & 255) + (i4 << 8);
        }
        this.peekLength += i3 + 1;
        return (long) i4;
    }
}
