QQ语音 7.8.2的语音红包触发run方法逻辑

package defpackage;

import android.os.Build;
import android.os.Build.VERSION;
import android.os.Process;
import android.os.SystemClock;
import com.tencent.mobileqq.ptt.processor.IPttProcessor;
import com.tencent.mobileqq.ptt.processor.IPttProcessor.ProcessData;
import com.tencent.mobileqq.ptt.processor.IPttProcessorListener;
import com.tencent.mobileqq.transfile.PttInfoCollector;
import com.tencent.mobileqq.utils.AudioHelper;
import com.tencent.mobileqq.utils.AudioUtil;
import com.tencent.mobileqq.utils.QQRecorder;
import com.tencent.mobileqq.utils.QQRecorder.RecordNoPermissonException;
import com.tencent.mobileqq.utils.WechatNsWrapper;
import com.tencent.qphone.base.util.QLog;
import java.util.HashMap;

/* compiled from: ProGuard */
public class ammg extends Thread implements IPttProcessorListener {
    int a = 0;
    long f0a = 0;
    final /* synthetic */ QQRecorder f1a;
    public String f2a;
    public volatile boolean f3a = true;
    public volatile boolean b = true;
    private boolean c;

    public ammg(QQRecorder qQRecorder) {
        this.f1a = qQRecorder;
    }

    public void run() {
        while (this.b) {
            if (QLog.isColorLevel()) {
                QLog.d("QQRecorder", 2, "RecordThread : begin run");
            }
            this.f3a = true;
            this.c = false;
            a(this.f2a);
            if (this.b) {
                long uptimeMillis = SystemClock.uptimeMillis();
                synchronized (this.f1a) {
                    this.f1a.wait((long) QQRecorder.a);
                }
                if (SystemClock.uptimeMillis() - uptimeMillis < ((long) QQRecorder.a)) {
                    continue;
                } else {
                    if (QLog.isColorLevel()) {
                        QLog.d("QQRecorder", 2, "RecordThread more than maxtime release");
                    }
                    synchronized (this) {
                        this.b = false;
                    }
                    try {
                        a();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        a();
    }

    private void a(String str) {
        long j;
        int read;
        Throwable th;
        Object obj;
        HashMap hashMap;
        int i;
        StringBuilder stringBuilder;
        if (QLog.isColorLevel()) {
            QLog.d("QQRecorder", 2, "RecordThread doRecord: " + this);
        }
        long j2 = 0;
        long j3 = 0;
        int i2 = 0;
        double d = 0.0d;
        long currentTimeMillis = System.currentTimeMillis();
        long j4 = 0;
        long j5 = 0;
        int i3 = 0;
        long j6 = 0;
        int i4 = 250;
        Process.setThreadPriority(-19);
        AudioUtil.a(QQRecorder.a(this.f1a), true);
        HashMap hashMap2;
        int i5;
        StringBuilder stringBuilder2;
        try {
            int a;
            if (QQRecorder.a(this.f1a) != null) {
                QQRecorder.a(this.f1a).a(str, this.f1a.a);
            }
            byte[] bArr = new byte[QQRecorder.b(this.f1a)];
            QQRecorder.a(this.f1a);
            if (QQRecorder.a(this.f1a) != null) {
                i4 = QQRecorder.a(this.f1a).a();
                if (i4 <= 0) {
                    i4 = 250;
                }
                i4 = QQRecorder.a(i4);
            }
            if (QLog.isDevelopLevel()) {
                QLog.d("QQRecorder", 4, "PTT onRecordReady cost : " + (SystemClock.uptimeMillis() - PttInfoCollector.a));
            }
            QQRecorder.b(this.f1a);
            QQRecorder.a(this.f1a).a(this);
            Thread.sleep(200);
            int b = (QQRecorder.b(this.f1a.a.a) / 1000) * i4;
            int i6 = 0;
            while (i6 < b) {
                i4 = QQRecorder.b(this.f1a);
                if (QQRecorder.b(this.f1a) > b - i6) {
                    i4 = b - i6;
                }
                QQRecorder.a(this.f1a).read(bArr, 0, i4);
                i6 = i4 + i6;
            }
            if (QLog.isColorLevel()) {
                QLog.d("QQRecorder", 2, "MyThread abandonBuf,  abandonSize:" + i6 + " abandonBufLen:" + b);
            }
            if (QQRecorder.a(this.f1a) != null) {
                a = QQRecorder.a(this.f1a).a(this.f2a, this.f1a.a);
            } else {
                a = -1;
            }
            if (QLog.isDevelopLevel()) {
                QLog.d("QQRecorder", 4, "PTT onBeginReceiveData cost : " + (SystemClock.uptimeMillis() - PttInfoCollector.a));
            }
            long currentTimeMillis2 = System.currentTimeMillis();
            int i7 = 0;
            i6 = 0;
            long j7 = 0;
            Object obj2 = null;
            long j8 = 0;
            j2 = 0;
            double d2 = 0.0d;
            while (this.f3a && !this.c) {
                try {
                    if (System.currentTimeMillis() - currentTimeMillis2 > 1000 && r16 == null) {
                        obj2 = 1;
                        if (j7 == 0 || i3 == 0) {
                            if (QLog.isColorLevel()) {
                                QLog.d("QQRecorder", 2, "record abnormal: data size = " + j7 + ", max volume = " + i3);
                            }
                            throw new RecordNoPermissonException("no permission");
                        }
                    }
                    Object obj3 = obj2;
                    if (System.currentTimeMillis() - currentTimeMillis2 > 1000 && r4 == 0) {
                        if (QLog.isColorLevel()) {
                            QLog.d("QQRecorder", 2, "check 1000ms max volume, volume: " + this.a);
                        }
                        if (this.a <= 0 || this.a >= 500) {
                            i7 = 2;
                        } else {
                            i7 = 1;
                        }
                        if (QQRecorder.a(this.f1a) != null) {
                            QQRecorder.a(this.f1a).a(i7);
                        }
                    }
                    j = j8 + 1;
                    try {
                        read = QQRecorder.a(this.f1a).read(bArr, 0, QQRecorder.b(this.f1a));
                        if (read <= 0) {
                            try {
                                Thread.sleep(10);
                                obj2 = obj3;
                                i6 = read;
                                j8 = j;
                            } catch (Throwable th2) {
                                th = th2;
                                j3 = j7;
                                i2 = read;
                                d = d2;
                                obj = null;
                            }
                        } else {
                            j3 = 1 + j5;
                            long j9 = j7 + ((long) read);
                            try {
                                int a2 = (int) AudioHelper.a(QQRecorder.a(this.f1a), bArr, read, 1.0f);
                                int max = Math.max(i3, a2);
                                j7 = j6 + ((long) a2);
                                try {
                                    ProcessData a3 = QQRecorder.a(this.f1a).a(bArr, 0, read);
                                    PttInfoCollector.b();
                                    d2 += QQRecorder.a((long) read, this.f1a.a.a);
                                    if (!(QQRecorder.a(this.f1a) == null || a3 == null)) {
                                        QQRecorder.a(this.f1a).a(str, a3.a, a3.a, QQRecorder.c(this.f1a), d2, this.f1a.a);
                                    }
                                    if (a3 != null) {
                                        j6 = ((long) a3.a) + j2;
                                    } else {
                                        j6 = j2;
                                    }
                                    if (i7 == 1) {
                                        try {
                                            if (this.a > 500) {
                                                i7 = 2;
                                                if (QQRecorder.a(this.f1a) != null) {
                                                    QQRecorder.a(this.f1a).a(2);
                                                }
                                                if (QLog.isColorLevel()) {
                                                    QLog.d("QQRecorder", 2, "volume state changed, normal volume: " + this.a);
                                                }
                                            }
                                        } catch (Throwable th3) {
                                            th = th3;
                                            i3 = max;
                                            j5 = j3;
                                            j2 = j6;
                                            j6 = j7;
                                            d = d2;
                                            j3 = j9;
                                            i2 = i6;
                                            obj = null;
                                        }
                                    }
                                    if (a != -1 && d2 >= ((double) a)) {
                                        this.c = true;
                                    }
                                    i3 = max;
                                    j5 = j3;
                                    j2 = j6;
                                    j6 = j7;
                                    obj2 = obj3;
                                    j8 = j;
                                    j7 = j9;
                                } catch (Throwable th4) {
                                    th = th4;
                                    j6 = j7;
                                    i3 = max;
                                    j5 = j3;
                                    d = d2;
                                    i2 = i6;
                                    j3 = j9;
                                    obj = null;
                                }
                            } catch (Throwable th5) {
                                th = th5;
                                j5 = j3;
                                d = d2;
                                i2 = i6;
                                obj = null;
                                j3 = j9;
                            }
                        }
                    } catch (Throwable th6) {
                        th = th6;
                        d = d2;
                        j3 = j7;
                        i2 = i6;
                        obj = null;
                    }
                } catch (Throwable th7) {
                    th = th7;
                    j3 = j7;
                    j = j8;
                    i2 = i6;
                    d = d2;
                    obj = null;
                }
            }
            if (QQRecorder.a(this.f1a) != null) {
                QQRecorder.a(this.f1a).a(str, this.f1a.a, d2);
                if (!(this.f1a.a == null || QQRecorder.d(this.f1a) == -1)) {
                    this.f1a.a.setMode(0);
                }
            }
            if (QQRecorder.a(this.f1a) != null && QQRecorder.a(this.f1a).getState() == 1) {
                QQRecorder.a(this.f1a).stop();
            }
            try {
                QQRecorder.c(this.f1a);
            } catch (Throwable th8) {
                th8.printStackTrace();
            }
            if (QLog.isColorLevel()) {
                QLog.d("QQRecorder", 2, "MyThread end: " + this);
                QLog.d("QQRecorder", 2, "read times = " + j8 + " orginal data size = " + j7 + "arm data size = " + j2 + "  error code = " + i6);
            }
            AudioUtil.a(QQRecorder.a(this.f1a), false);
            if ((j2 < 512 || d2 < 1000.0d) && System.currentTimeMillis() - currentTimeMillis > 1000) {//如果arm大小小于512 ,或者读取时间小于1000但是总时长间隔超过了1000.那么就研究你触摸了多久。
                try {
                    hashMap2 = new HashMap();
                    hashMap2.put("exceptionType", "1");
                    hashMap2.put("osVersion", VERSION.SDK_INT + "");
                    hashMap2.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
                    hashMap2.put("dataSize", j7 + "");
                    hashMap2.put("maxVolume", i3 + "");
                    hashMap2.put("readTime", d2 + "");
                    hashMap2.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
                    QQRecorder.a("actPttRecordException", false, hashMap2);
                    if (QLog.isColorLevel()) {
                        QLog.d("QQRecorder", 2, "report exception(short record) | exception type = 1 | dataSize = " + j7 + " | amrSize = " + j2 + " | readTime = " + d2 + " | toucTime = " + (System.currentTimeMillis() - currentTimeMillis));
                    }
                } catch (Throwable th82) {
                    if (QLog.isColorLevel()) {
                        QLog.d("QQRecorder", 2, "Report exception error.", th82);
                    }
                }
            }
            try {
                hashMap2 = new HashMap();
                hashMap2.put("osVersion", VERSION.SDK_INT + "");
                hashMap2.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
                hashMap2.put("dataSize", j7 + "");
                hashMap2.put("pttDuration", d2 + "");
                hashMap2.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
                hashMap2.put("maxVolume", i3 + "");
                hashMap2.put("amrMaxVolume", this.a + "");
                read = (int) (j5 == 0 ? -1 : j6 / j5);
                if (j5 == 0) {
                    j6 = -1;
                } else {
                    j6 = this.f0a / j5;
                }
                i5 = (int) j6;
                hashMap2.put("averageVolume", read + "");
                hashMap2.put("amrAverageVolume", i5 + "");
                QQRecorder.a("actPttRecordVolume", true, hashMap2);
                if (QLog.isColorLevel()) {
                    stringBuilder2 = new StringBuilder();
                    stringBuilder2.append("report record detail | maxVolume = ").append(i3);
                    stringBuilder2.append(" | averageVolume = ").append(read);
                    stringBuilder2.append(" | amrMaxVolume = ").append(i5);
                    stringBuilder2.append(" | amrAverage = ").append(i5);
                    stringBuilder2.append(" | dataSize = ").append(j7);
                    stringBuilder2.append(" | amrSize = ").append(j2);
                    stringBuilder2.append(" | pttDuration = ").append(d2);
                    stringBuilder2.append(" | touchTime = ").append(System.currentTimeMillis() - currentTimeMillis);
                    QLog.d("QQRecorder", 2, stringBuilder2.toString());
                }
            } catch (Throwable th822) {
                if (QLog.isColorLevel()) {
                    QLog.d("QQRecorder", 2, "Report record error.", th822);
                }
            }
        } catch (Throwable th9) {
            th822 = th9;
            j = 0;
            j2 = 0;
            obj = null;
            if (QQRecorder.a(this.f1a) != null && QQRecorder.a(this.f1a).getState() == 1) {
                QQRecorder.a(this.f1a).stop();
            }
            QQRecorder.c(this.f1a);
            if (QLog.isColorLevel()) {
                QLog.d("QQRecorder", 2, "MyThread end: " + this);
                QLog.d("QQRecorder", 2, "read times = " + j + " orginal data size = " + j3 + "arm data size = " + j2 + "  error code = " + i2);
            }
            AudioUtil.a(QQRecorder.a(this.f1a), false);
            if ((j2 < 512 || d < 1000.0d) && r10 == null && System.currentTimeMillis() - currentTimeMillis > 1000) {
                hashMap = new HashMap();
                hashMap.put("exceptionType", "1");
                hashMap.put("osVersion", VERSION.SDK_INT + "");
                hashMap.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
                hashMap.put("dataSize", j3 + "");
                hashMap.put("maxVolume", i3 + "");
                hashMap.put("readTime", d + "");
                hashMap.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
                QQRecorder.a("actPttRecordException", false, hashMap);
                if (QLog.isColorLevel()) {
                    QLog.d("QQRecorder", 2, "report exception(short record) | exception type = 1 | dataSize = " + j3 + " | amrSize = " + j2 + " | readTime = " + d + " | toucTime = " + (System.currentTimeMillis() - currentTimeMillis));
                }
            }
            hashMap = new HashMap();
            hashMap.put("osVersion", VERSION.SDK_INT + "");
            hashMap.put("deviceName", Build.MANUFACTURER + "_" + Build.MODEL);
            hashMap.put("dataSize", j3 + "");
            hashMap.put("pttDuration", d + "");
            hashMap.put("touchTime", (System.currentTimeMillis() - currentTimeMillis) + "");
            hashMap.put("maxVolume", i3 + "");
            hashMap.put("amrMaxVolume", this.a + "");
            if (j5 != 0) {
            }
            i = (int) (j5 != 0 ? j6 / j5 : -1);
            if (j5 != 0) {
                j6 = -1;
            } else {
                j6 = this.f0a / j5;
            }
            i5 = (int) j6;
            hashMap.put("averageVolume", i + "");
            hashMap.put("amrAverageVolume", i5 + "");
            QQRecorder.a("actPttRecordVolume", true, hashMap);
            if (QLog.isColorLevel()) {
                stringBuilder = new StringBuilder();
                stringBuilder.append("report record detail | maxVolume = ").append(i3);
                stringBuilder.append(" | averageVolume = ").append(i);
                stringBuilder.append(" | amrMaxVolume = ").append(i5);
                stringBuilder.append(" | amrAverage = ").append(i5);
                stringBuilder.append(" | dataSize = ").append(j3);
                stringBuilder.append(" | amrSize = ").append(j2);
                stringBuilder.append(" | pttDuration = ").append(d);
                stringBuilder.append(" | touchTime = ").append(System.currentTimeMillis() - currentTimeMillis);
                QLog.d("QQRecorder", 2, stringBuilder.toString());
            }
            throw th822;
        }
    }

    public void a(IPttProcessor iPttProcessor, ProcessData processData) {
        if ((iPttProcessor instanceof WechatNsWrapper) && QQRecorder.a(this.f1a) != null) {
            QQRecorder.a(this.f1a).b(iPttProcessor, processData);
        }
    }

    public void b(IPttProcessor iPttProcessor, ProcessData processData) {
        if (iPttProcessor instanceof WechatNsWrapper) {
            QQRecorder.b(this.f1a, (int) AudioHelper.a(QQRecorder.a(this.f1a), processData.a, processData.a, 1.0f));
            this.a = Math.max(this.a, QQRecorder.c(this.f1a));
            this.f0a += (long) QQRecorder.c(this.f1a);
            if (QQRecorder.a(this.f1a) != null) {
                QQRecorder.a(this.f1a).a(iPttProcessor, processData);
            }
        }
    }

    public boolean m0a() {
        return this.b || QQRecorder.a(this.f1a) != null;
    }

    public void a() {
        if (QQRecorder.a(this.f1a) != null) {
            if (QLog.isColorLevel()) {
                QLog.d("QQRecorder", 2, "releaseRecorder");
            }
            QQRecorder.a(this.f1a).release();
            QQRecorder.a(this.f1a, null);
        }
    }
}

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,948评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,371评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,490评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,521评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,627评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,842评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,997评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,741评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,203评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,534评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,673评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,339评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,955评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,770评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,000评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,394评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,562评论 2 349

推荐阅读更多精彩内容