103 lines
4.0 KiB
Java
103 lines
4.0 KiB
Java
|
package com.google.android.gms.internal.firebase_ml;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.os.SystemClock;
|
||
|
import android.util.SparseArray;
|
||
|
import com.google.android.gms.common.internal.Preconditions;
|
||
|
import com.google.android.gms.internal.firebase_ml.zzmd;
|
||
|
import com.google.android.gms.vision.text.TextBlock;
|
||
|
import com.google.android.gms.vision.text.TextRecognizer;
|
||
|
import com.google.firebase.FirebaseApp;
|
||
|
import com.google.firebase.ml.common.FirebaseMLException;
|
||
|
import com.google.firebase.ml.vision.text.FirebaseVisionText;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class zzqj implements zznm<FirebaseVisionText, zzpz>, zznw {
|
||
|
static boolean zzata = true;
|
||
|
private final Context zzad;
|
||
|
private final zznu zzaqs;
|
||
|
private zzpu zzawc = new zzpu();
|
||
|
private TextRecognizer zzazt;
|
||
|
|
||
|
public zzqj(FirebaseApp firebaseApp) {
|
||
|
Preconditions.checkNotNull(firebaseApp, "Firebase App can not be null");
|
||
|
this.zzad = firebaseApp.getApplicationContext();
|
||
|
this.zzaqs = zznu.zza(firebaseApp, 1);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.internal.firebase_ml.zznm
|
||
|
public final zznw zzlm() {
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.internal.firebase_ml.zznw
|
||
|
public final void zzlp() {
|
||
|
synchronized (this) {
|
||
|
if (this.zzazt == null) {
|
||
|
this.zzazt = new TextRecognizer.Builder(this.zzad).build();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.internal.firebase_ml.zznw
|
||
|
public final void release() {
|
||
|
synchronized (this) {
|
||
|
TextRecognizer textRecognizer = this.zzazt;
|
||
|
if (textRecognizer != null) {
|
||
|
textRecognizer.release();
|
||
|
this.zzazt = null;
|
||
|
}
|
||
|
zzata = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
@Override // com.google.android.gms.internal.firebase_ml.zznm
|
||
|
/* renamed from: zzd, reason: merged with bridge method [inline-methods] */
|
||
|
public final FirebaseVisionText zza(zzpz zzpzVar) throws FirebaseMLException {
|
||
|
synchronized (this) {
|
||
|
long elapsedRealtime = SystemClock.elapsedRealtime();
|
||
|
TextRecognizer textRecognizer = this.zzazt;
|
||
|
if (textRecognizer == null) {
|
||
|
zza(zzmk.UNKNOWN_ERROR, elapsedRealtime, zzpzVar);
|
||
|
throw new FirebaseMLException("Model source is unavailable. Please load the model resource first.", 13);
|
||
|
}
|
||
|
if (!textRecognizer.isOperational()) {
|
||
|
zza(zzmk.MODEL_NOT_DOWNLOADED, elapsedRealtime, zzpzVar);
|
||
|
throw new FirebaseMLException("Waiting for the text recognition model to be downloaded. Please wait.", 14);
|
||
|
}
|
||
|
this.zzawc.zzb(zzpzVar);
|
||
|
SparseArray<TextBlock> detect = this.zzazt.detect(zzpzVar.zzaxe);
|
||
|
zza(zzmk.NO_ERROR, elapsedRealtime, zzpzVar);
|
||
|
zzata = false;
|
||
|
if (detect == null) {
|
||
|
return null;
|
||
|
}
|
||
|
return new FirebaseVisionText(detect);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private final void zza(final zzmk zzmkVar, final long j, final zzpz zzpzVar) {
|
||
|
this.zzaqs.zza(new zznv(j, zzmkVar, zzpzVar) { // from class: com.google.android.gms.internal.firebase_ml.zzqk
|
||
|
private final long zzaue;
|
||
|
private final zzmk zzazu;
|
||
|
private final zzpz zzazv;
|
||
|
|
||
|
@Override // com.google.android.gms.internal.firebase_ml.zznv
|
||
|
public final zzmd.zzq.zza zzm() {
|
||
|
long j2 = this.zzaue;
|
||
|
zzmk zzmkVar2 = this.zzazu;
|
||
|
zzpz zzpzVar2 = this.zzazv;
|
||
|
return zzmd.zzq.zzjx().zzb(zzmd.zzab.zzle().zzh(zzmd.zzs.zzkb().zzn(SystemClock.elapsedRealtime() - j2).zzc(zzmkVar2).zzz(zzqj.zzata).zzaa(true).zzab(true)).zze(zzpv.zzc(zzpzVar2)));
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
{
|
||
|
this.zzaue = j;
|
||
|
this.zzazu = zzmkVar;
|
||
|
this.zzazv = zzpzVar;
|
||
|
}
|
||
|
}, zzmn.ON_DEVICE_TEXT_DETECT);
|
||
|
}
|
||
|
}
|