package com.tencent.mm.plugin.a;

import android.annotation.TargetApi;
import android.util.Pair;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.pointers.PInt;
import com.tencent.mm.sdk.platformtools.ab;
import java.io.RandomAccessFile;
import java.util.List;

public final class f {
    private long duration;
    private long egJ;
    private String filePath;
    private long gki;
    private long[] gkl;
    public int gkm;
    private List<g> gkn;
    private List<Pair> gko;
    public int gkp = 0;

    public final int anZ() {
        int i;
        AppMethodBeat.i(117847);
        try {
            if (this.gko != null) {
                if (this.gkp == 0) {
                    this.gkp = (int) ((((Long) ((Pair) this.gko.get(this.gko.size() - 1)).second).longValue() / 1000) / 1000);
                }
                i = this.gkp;
            } else {
                i = 0;
            }
        } catch (Exception e) {
            ab.printErrStackTrace("MicroMsg.Mp4Parser", e, "get last key frame error.", new Object[0]);
            i = 0;
        }
        AppMethodBeat.o(117847);
        return i;
    }

    @TargetApi(5)
    public final boolean b(int i, PInt pInt, PInt pInt2) {
        boolean z;
        Throwable e;
        AppMethodBeat.i(117848);
        try {
            if (this.gko != null) {
                boolean z2;
                int size = this.gko.size();
                long j = 1000 * (((long) i) * 1000);
                pInt2.value = 0;
                pInt.value = 0;
                for (int i2 = 0; i2 < size; i2++) {
                    Pair pair = (Pair) this.gko.get(i2);
                    if (((Long) pair.second).longValue() > j) {
                        pInt2.value = (int) ((((Long) pair.second).longValue() / 1000) / 1000);
                        z2 = true;
                        break;
                    }
                    pInt.value = (int) ((((Long) pair.second).longValue() / 1000) / 1000);
                }
                z2 = false;
                if (z2) {
                    z = z2;
                } else {
                    try {
                        pInt.value = (int) ((((Long) ((Pair) this.gko.get(size - 1)).second).longValue() / 1000) / 1000);
                        pInt2.value = i;
                        z = true;
                    } catch (Exception e2) {
                        e = e2;
                        z = z2;
                        ab.printErrStackTrace("MicroMsg.Mp4Parser", e, "seekVFrame seekTime[%d]", new Object[]{Integer.valueOf(i)});
                        ab.i("MicroMsg.Mp4Parser", "seek key Frame seekTime[%d] pre[%d] next[%d]", new Object[]{Integer.valueOf(i), Integer.valueOf(pInt.value), Integer.valueOf(pInt2.value)});
                        AppMethodBeat.o(117848);
                        return z;
                    }
                }
                ab.i("MicroMsg.Mp4Parser", "seek key Frame seekTime[%d] pre[%d] next[%d]", new Object[]{Integer.valueOf(i), Integer.valueOf(pInt.value), Integer.valueOf(pInt2.value)});
                AppMethodBeat.o(117848);
                return z;
            }
            AppMethodBeat.o(117848);
            return false;
        } catch (Exception e3) {
            e = e3;
            z = false;
            ab.printErrStackTrace("MicroMsg.Mp4Parser", e, "seekVFrame seekTime[%d]", new Object[]{Integer.valueOf(i)});
            ab.i("MicroMsg.Mp4Parser", "seek key Frame seekTime[%d] pre[%d] next[%d]", new Object[]{Integer.valueOf(i), Integer.valueOf(pInt.value), Integer.valueOf(pInt2.value)});
            AppMethodBeat.o(117848);
            return z;
        }
    }

    public final boolean a(int i, int i2, PInt pInt, PInt pInt2) {
        if (this.gkl == null) {
            return false;
        }
        if (i < 0) {
            i = 0;
        }
        int length = this.gkl.length;
        if (i >= length || i2 >= length) {
            i = length - 2;
            i2 = length - 1;
        }
        long j = this.gkl[i];
        long j2 = this.gkl[i2];
        if (i == 0) {
            pInt.value = 0;
            pInt2.value = (int) j2;
        } else {
            pInt.value = (int) j;
            pInt2.value = ((int) j2) - ((int) j);
        }
        return true;
    }

    public final int cK(int i, int i2) {
        int i3 = 0;
        if (this.gkl == null) {
            return 0;
        }
        int i4;
        long j = (long) (i + i2);
        int i5 = 0;
        while (true) {
            i4 = i3;
            if (i5 >= this.gkl.length) {
                break;
            } else if (this.gkl[i5] == j) {
                i4 = i5;
                break;
            } else {
                if (this.gkl[i5] >= j) {
                    if (this.gkl[i5] > j) {
                        break;
                    }
                    i3 = i4;
                } else {
                    i3 = i5;
                }
                i5++;
            }
        }
        return i4;
    }

    private static i a(RandomAccessFile randomAccessFile, byte[] bArr, long j) {
        AppMethodBeat.i(117850);
        ab.d("MicroMsg.Mp4Parser", "start to find trak atom.");
        if (c.a(randomAccessFile, j)) {
            i iVar = (i) c.a(randomAccessFile, bArr, a.aWk);
            AppMethodBeat.o(117850);
            return iVar;
        }
        AppMethodBeat.o(117850);
        return null;
    }

    /* JADX WARNING: Removed duplicated region for block: B:41:0x0155 A:{SYNTHETIC, Splitter:B:41:0x0155} */
    /* JADX WARNING: Removed duplicated region for block: B:49:0x0173 A:{SYNTHETIC, Splitter:B:49:0x0173} */
    public final boolean v(java.lang.String r11, long r12) {
        /*
        r10 = this;
        r0 = 117849; // 0x1cc59 float:1.65142E-40 double:5.8225E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r0);
        r0 = 0;
        r10.filePath = r0;
        r0 = 0;
        r10.gkl = r0;
        r0 = 0;
        r10.gkm = r0;
        r0 = 0;
        r10.duration = r0;
        r10.gki = r0;
        r10.egJ = r0;
        r0 = r10.gkn;
        if (r0 == 0) goto L_0x0020;
    L_0x001b:
        r0 = r10.gkn;
        r0.clear();
    L_0x0020:
        r0 = r10.gko;
        if (r0 == 0) goto L_0x0029;
    L_0x0024:
        r0 = r10.gko;
        r0.clear();
    L_0x0029:
        r0 = 0;
        r10.gkp = r0;
        r10.filePath = r11;
        r10.egJ = r12;
        r0 = new java.io.File;
        r1 = r10.filePath;
        r0.<init>(r1);
        r1 = r0.exists();
        if (r1 != 0) goto L_0x0045;
    L_0x003d:
        r0 = 0;
        r1 = 117849; // 0x1cc59 float:1.65142E-40 double:5.8225E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
    L_0x0044:
        return r0;
    L_0x0045:
        r2 = 0;
        r1 = 8;
        r3 = new byte[r1];	 Catch:{ Exception -> 0x012b, all -> 0x016f }
        r1 = new java.io.RandomAccessFile;	 Catch:{ Exception -> 0x012b, all -> 0x016f }
        r4 = "r";
        r1.<init>(r0, r4);	 Catch:{ Exception -> 0x012b, all -> 0x016f }
        r4 = r10.egJ;	 Catch:{ Exception -> 0x018d }
        r0 = a(r1, r3, r4);	 Catch:{ Exception -> 0x018d }
    L_0x0058:
        if (r0 == 0) goto L_0x0105;
    L_0x005a:
        r2 = "MicroMsg.Mp4Parser";
        r4 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x018d }
        r5 = "last trak atom file pos : ";
        r4.<init>(r5);	 Catch:{ Exception -> 0x018d }
        r6 = r0.gjN;	 Catch:{ Exception -> 0x018d }
        r4 = r4.append(r6);	 Catch:{ Exception -> 0x018d }
        r4 = r4.toString();	 Catch:{ Exception -> 0x018d }
        com.tencent.mm.sdk.platformtools.ab.d(r2, r4);	 Catch:{ Exception -> 0x018d }
        r4 = com.tencent.mm.plugin.a.i.b(r1, r3);	 Catch:{ Exception -> 0x018d }
        if (r4 == 0) goto L_0x0111;
    L_0x0078:
        r2 = r4.a(r1, r3);	 Catch:{ Exception -> 0x018d }
        if (r2 == 0) goto L_0x0111;
    L_0x007e:
        r6 = r4.gkj;	 Catch:{ Exception -> 0x018d }
        r2 = com.tencent.mm.plugin.a.e.gkf;	 Catch:{ Exception -> 0x018d }
        r8 = (long) r2;	 Catch:{ Exception -> 0x018d }
        r2 = (r6 > r8 ? 1 : (r6 == r8 ? 0 : -1));
        if (r2 != 0) goto L_0x00a9;
    L_0x0087:
        r2 = 1;
    L_0x0088:
        if (r2 != 0) goto L_0x00ab;
    L_0x008a:
        r4 = r0.getEndPos();	 Catch:{ Exception -> 0x018d }
        r6 = r1.getFilePointer();	 Catch:{ Exception -> 0x018d }
        r4 = r4 - r6;
        r0 = "MicroMsg.Mp4Parser";
        r2 = "this trak atom is not video trak skip: ";
        r6 = java.lang.String.valueOf(r4);	 Catch:{ Exception -> 0x018d }
        r2 = r2.concat(r6);	 Catch:{ Exception -> 0x018d }
        com.tencent.mm.sdk.platformtools.ab.d(r0, r2);	 Catch:{ Exception -> 0x018d }
        r0 = a(r1, r3, r4);	 Catch:{ Exception -> 0x018d }
        goto L_0x0058;
    L_0x00a9:
        r2 = 0;
        goto L_0x0088;
    L_0x00ab:
        r6 = r4.gki;	 Catch:{ Exception -> 0x018d }
        r10.gki = r6;	 Catch:{ Exception -> 0x018d }
        r6 = r4.duration;	 Catch:{ Exception -> 0x018d }
        r10.duration = r6;	 Catch:{ Exception -> 0x018d }
        r0 = "MicroMsg.Mp4Parser";
        r2 = new java.lang.StringBuilder;	 Catch:{ Exception -> 0x018d }
        r5 = "this trak atom is video trak. timeScale: ";
        r2.<init>(r5);	 Catch:{ Exception -> 0x018d }
        r6 = r10.gki;	 Catch:{ Exception -> 0x018d }
        r2 = r2.append(r6);	 Catch:{ Exception -> 0x018d }
        r5 = " duration: ";
        r2 = r2.append(r5);	 Catch:{ Exception -> 0x018d }
        r6 = r10.duration;	 Catch:{ Exception -> 0x018d }
        r2 = r2.append(r6);	 Catch:{ Exception -> 0x018d }
        r2 = r2.toString();	 Catch:{ Exception -> 0x018d }
        com.tencent.mm.sdk.platformtools.ab.d(r0, r2);	 Catch:{ Exception -> 0x018d }
        r4 = r4.gkk;	 Catch:{ Exception -> 0x018d }
        r1.seek(r4);	 Catch:{ Exception -> 0x018d }
        r0 = com.tencent.mm.plugin.a.a.aWn;	 Catch:{ Exception -> 0x018d }
        r0 = com.tencent.mm.plugin.a.c.a(r1, r3, r0);	 Catch:{ Exception -> 0x018d }
        r0 = (com.tencent.mm.plugin.a.h) r0;	 Catch:{ Exception -> 0x018d }
        if (r0 == 0) goto L_0x0105;
    L_0x00e7:
        r2 = r10.duration;	 Catch:{ Exception -> 0x018d }
        r0.duration = r2;	 Catch:{ Exception -> 0x018d }
        r2 = r10.gki;	 Catch:{ Exception -> 0x018d }
        r0.gki = r2;	 Catch:{ Exception -> 0x018d }
        r0.d(r1);	 Catch:{ Exception -> 0x018d }
        r2 = r0.gkl;	 Catch:{ Exception -> 0x018d }
        r10.gkl = r2;	 Catch:{ Exception -> 0x018d }
        r2 = r10.gkl;	 Catch:{ Exception -> 0x018d }
        r2 = r2.length;	 Catch:{ Exception -> 0x018d }
        r2 = r2 + -2;
        r10.gkm = r2;	 Catch:{ Exception -> 0x018d }
        r2 = r0.gkn;	 Catch:{ Exception -> 0x018d }
        r10.gkn = r2;	 Catch:{ Exception -> 0x018d }
        r0 = r0.gko;	 Catch:{ Exception -> 0x018d }
        r10.gko = r0;	 Catch:{ Exception -> 0x018d }
    L_0x0105:
        r1.close();	 Catch:{ IOException -> 0x011d }
    L_0x0108:
        r0 = 1;
        r1 = 117849; // 0x1cc59 float:1.65142E-40 double:5.8225E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0044;
    L_0x0111:
        r0 = "MicroMsg.Mp4Parser";
        r2 = "mdia atom parser fail.";
        com.tencent.mm.sdk.platformtools.ab.w(r0, r2);	 Catch:{ Exception -> 0x018d }
        r0 = 0;
        goto L_0x0058;
    L_0x011d:
        r0 = move-exception;
        r1 = "MicroMsg.Mp4Parser";
        r2 = "";
        r3 = 0;
        r3 = new java.lang.Object[r3];
        com.tencent.mm.sdk.platformtools.ab.printErrStackTrace(r1, r0, r2, r3);
        goto L_0x0108;
    L_0x012b:
        r0 = move-exception;
        r1 = r2;
    L_0x012d:
        r2 = "MicroMsg.Mp4Parser";
        r3 = "";
        r4 = 0;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x018b }
        com.tencent.mm.sdk.platformtools.ab.printErrStackTrace(r2, r0, r3, r4);	 Catch:{ all -> 0x018b }
        r2 = "MicroMsg.Mp4Parser";
        r3 = new java.lang.StringBuilder;	 Catch:{ all -> 0x018b }
        r4 = "parser mp4 error. e: ";
        r3.<init>(r4);	 Catch:{ all -> 0x018b }
        r0 = r0.toString();	 Catch:{ all -> 0x018b }
        r0 = r3.append(r0);	 Catch:{ all -> 0x018b }
        r0 = r0.toString();	 Catch:{ all -> 0x018b }
        com.tencent.mm.sdk.platformtools.ab.e(r2, r0);	 Catch:{ all -> 0x018b }
        if (r1 == 0) goto L_0x0158;
    L_0x0155:
        r1.close();	 Catch:{ IOException -> 0x0161 }
    L_0x0158:
        r0 = 0;
        r1 = 117849; // 0x1cc59 float:1.65142E-40 double:5.8225E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        goto L_0x0044;
    L_0x0161:
        r0 = move-exception;
        r1 = "MicroMsg.Mp4Parser";
        r2 = "";
        r3 = 0;
        r3 = new java.lang.Object[r3];
        com.tencent.mm.sdk.platformtools.ab.printErrStackTrace(r1, r0, r2, r3);
        goto L_0x0158;
    L_0x016f:
        r0 = move-exception;
        r1 = r2;
    L_0x0171:
        if (r1 == 0) goto L_0x0176;
    L_0x0173:
        r1.close();	 Catch:{ IOException -> 0x017d }
    L_0x0176:
        r1 = 117849; // 0x1cc59 float:1.65142E-40 double:5.8225E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r1);
        throw r0;
    L_0x017d:
        r1 = move-exception;
        r2 = "MicroMsg.Mp4Parser";
        r3 = "";
        r4 = 0;
        r4 = new java.lang.Object[r4];
        com.tencent.mm.sdk.platformtools.ab.printErrStackTrace(r2, r1, r3, r4);
        goto L_0x0176;
    L_0x018b:
        r0 = move-exception;
        goto L_0x0171;
    L_0x018d:
        r0 = move-exception;
        goto L_0x012d;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.a.f.v(java.lang.String, long):boolean");
    }
}
