129 lines
5.6 KiB
Java
129 lines
5.6 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.dynamite.DynamiteModule;
|
|
import com.google.android.gms.internal.firebase_ml.zzmd;
|
|
import com.google.android.gms.vision.label.ImageLabel;
|
|
import com.google.android.gms.vision.label.ImageLabeler;
|
|
import com.google.firebase.FirebaseApp;
|
|
import com.google.firebase.ml.common.FirebaseMLException;
|
|
import com.google.firebase.ml.vision.label.FirebaseVisionImageLabel;
|
|
import com.google.firebase.ml.vision.label.FirebaseVisionOnDeviceImageLabelerOptions;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class zzqe implements zznm<List<FirebaseVisionImageLabel>, zzpz>, zznw {
|
|
private static boolean zzata = true;
|
|
private static volatile Boolean zzaza;
|
|
private final Context zzad;
|
|
private final zznu zzaqs;
|
|
private final FirebaseVisionOnDeviceImageLabelerOptions zzazb;
|
|
private ImageLabeler zzazc;
|
|
|
|
public zzqe(FirebaseApp firebaseApp, FirebaseVisionOnDeviceImageLabelerOptions firebaseVisionOnDeviceImageLabelerOptions) {
|
|
Preconditions.checkNotNull(firebaseApp, "Context can not be null");
|
|
Preconditions.checkNotNull(firebaseVisionOnDeviceImageLabelerOptions, "FirebaseVisionOnDeviceImageLabelerOptions can not be null");
|
|
this.zzad = firebaseApp.getApplicationContext();
|
|
this.zzazb = firebaseVisionOnDeviceImageLabelerOptions;
|
|
this.zzaqs = zznu.zza(firebaseApp, 1);
|
|
}
|
|
|
|
@Override // com.google.android.gms.internal.firebase_ml.zznm
|
|
public final zznw zzlm() {
|
|
return this;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
@Override // com.google.android.gms.internal.firebase_ml.zznm
|
|
public final List<FirebaseVisionImageLabel> zza(zzpz zzpzVar) throws FirebaseMLException {
|
|
ArrayList arrayList;
|
|
boolean z;
|
|
synchronized (this) {
|
|
if (zzaza == null) {
|
|
Context context = this.zzad;
|
|
if (DynamiteModule.getLocalVersion(context, "com.google.android.gms.vision.dynamite.ica") <= 0 && DynamiteModule.getLocalVersion(context, "com.google.android.gms.vision.dynamite.imagelabel") <= 0) {
|
|
z = true;
|
|
zzaza = Boolean.valueOf(z);
|
|
}
|
|
z = false;
|
|
zzaza = Boolean.valueOf(z);
|
|
}
|
|
if (zzaza.booleanValue()) {
|
|
throw new FirebaseMLException("No model is bundled. Please check your app setup to includefirebase-ml-vision-image-label-model dependency.", 14);
|
|
}
|
|
long elapsedRealtime = SystemClock.elapsedRealtime();
|
|
ImageLabeler imageLabeler = this.zzazc;
|
|
if (imageLabeler == null) {
|
|
zza(zzmk.UNKNOWN_ERROR, elapsedRealtime, zzpzVar);
|
|
throw new FirebaseMLException("Model source is unavailable. Please load the model resource first.", 13);
|
|
}
|
|
if (!imageLabeler.isOperational()) {
|
|
zza(zzmk.MODEL_NOT_DOWNLOADED, elapsedRealtime, zzpzVar);
|
|
throw new FirebaseMLException("Waiting for the label detection model to be downloaded. Please wait.", 14);
|
|
}
|
|
SparseArray<ImageLabel> detect = this.zzazc.detect(zzpzVar.zzaxe);
|
|
arrayList = new ArrayList();
|
|
if (detect != null) {
|
|
for (int i = 0; i < detect.size(); i++) {
|
|
arrayList.add(new FirebaseVisionImageLabel(detect.get(detect.keyAt(i))));
|
|
}
|
|
}
|
|
zza(zzmk.NO_ERROR, elapsedRealtime, zzpzVar);
|
|
zzata = false;
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
@Override // com.google.android.gms.internal.firebase_ml.zznw
|
|
public final void zzlp() {
|
|
synchronized (this) {
|
|
if (this.zzazc == null) {
|
|
this.zzazc = new ImageLabeler.Builder(this.zzad).setScoreThreshold(this.zzazb.getConfidenceThreshold()).build();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.google.android.gms.internal.firebase_ml.zznw
|
|
public final void release() {
|
|
synchronized (this) {
|
|
ImageLabeler imageLabeler = this.zzazc;
|
|
if (imageLabeler != null) {
|
|
imageLabeler.release();
|
|
this.zzazc = null;
|
|
}
|
|
zzata = true;
|
|
}
|
|
}
|
|
|
|
private final void zza(final zzmk zzmkVar, final long j, final zzpz zzpzVar) {
|
|
this.zzaqs.zza(new zznv(this, j, zzmkVar, zzpzVar) { // from class: com.google.android.gms.internal.firebase_ml.zzqf
|
|
private final long zzatf;
|
|
private final zzmk zzawe;
|
|
private final zzpz zzawf;
|
|
private final zzqe zzazd;
|
|
|
|
@Override // com.google.android.gms.internal.firebase_ml.zznv
|
|
public final zzmd.zzq.zza zzm() {
|
|
return this.zzazd.zza(this.zzatf, this.zzawe, this.zzawf);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
{
|
|
this.zzazd = this;
|
|
this.zzatf = j;
|
|
this.zzawe = zzmkVar;
|
|
this.zzawf = zzpzVar;
|
|
}
|
|
}, zzmn.ON_DEVICE_IMAGE_LABEL_DETECT);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public final /* synthetic */ zzmd.zzq.zza zza(long j, zzmk zzmkVar, zzpz zzpzVar) {
|
|
return zzmd.zzq.zzjx().zzb(zzmd.zzx.zzkm().zze(zzmd.zzs.zzkb().zzn(SystemClock.elapsedRealtime() - j).zzc(zzmkVar).zzz(zzata).zzaa(true).zzab(true)).zzb(this.zzazb.zzno()).zzd(zzpv.zzc(zzpzVar)));
|
|
}
|
|
}
|