package z1;

import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.XmlPullParserUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.m0;
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

/* JADX INFO: loaded from: classes.dex */
public abstract class g {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final String[] f37027a = {"Camera:MotionPhoto", "GCamera:MotionPhoto", "Camera:MicroVideo", "GCamera:MicroVideo"};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final String[] f37028b = {"Camera:MotionPhotoPresentationTimestampUs", "GCamera:MotionPhotoPresentationTimestampUs", "Camera:MicroVideoPresentationTimestampUs", "GCamera:MicroVideoPresentationTimestampUs"};

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final String[] f37029c = {"Camera:MicroVideoOffset", "GCamera:MicroVideoOffset"};

    public static ImmutableList a(XmlPullParser xmlPullParser, String str, String str2) throws XmlPullParserException, IOException {
        m0 m0VarM = ImmutableList.m();
        String strConcat = str.concat(":Item");
        String strConcat2 = str.concat(":Directory");
        do {
            xmlPullParser.next();
            if (XmlPullParserUtil.isStartTag(xmlPullParser, strConcat)) {
                String strConcat3 = str2.concat(":Mime");
                String strConcat4 = str2.concat(":Semantic");
                String strConcat5 = str2.concat(":Length");
                String strConcat6 = str2.concat(":Padding");
                String attributeValue = XmlPullParserUtil.getAttributeValue(xmlPullParser, strConcat3);
                String attributeValue2 = XmlPullParserUtil.getAttributeValue(xmlPullParser, strConcat4);
                String attributeValue3 = XmlPullParserUtil.getAttributeValue(xmlPullParser, strConcat5);
                String attributeValue4 = XmlPullParserUtil.getAttributeValue(xmlPullParser, strConcat6);
                if (attributeValue == null || attributeValue2 == null) {
                    return ImmutableList.t();
                }
                m0VarM.c(new b(attributeValue, attributeValue3 != null ? Long.parseLong(attributeValue3) : 0L, attributeValue4 != null ? Long.parseLong(attributeValue4) : 0L));
            }
        } while (!XmlPullParserUtil.isEndTag(xmlPullParser, strConcat2));
        return m0VarM.i();
    }

    @Nullable
    public static c parse(String str) throws IOException {
        try {
            return parseInternal(str);
        } catch (ParserException | NumberFormatException | XmlPullParserException unused) {
            Log.w("MotionPhotoXmpParser", "Ignoring unexpected XMP metadata");
            return null;
        }
    }

    @Nullable
    private static c parseInternal(String str) throws XmlPullParserException, IOException {
        long j10;
        XmlPullParser xmlPullParserNewPullParser = XmlPullParserFactory.newInstance().newPullParser();
        xmlPullParserNewPullParser.setInput(new StringReader(str));
        xmlPullParserNewPullParser.next();
        if (!XmlPullParserUtil.isStartTag(xmlPullParserNewPullParser, "x:xmpmeta")) {
            throw ParserException.createForMalformedContainer("Couldn't find xmp metadata", null);
        }
        ImmutableList immutableListT = ImmutableList.t();
        long j11 = -9223372036854775807L;
        loop0: do {
            xmlPullParserNewPullParser.next();
            if (XmlPullParserUtil.isStartTag(xmlPullParserNewPullParser, "rdf:Description")) {
                String[] strArr = f37027a;
                int i10 = 0;
                int i11 = 0;
                while (true) {
                    if (i11 >= 4) {
                        break loop0;
                    }
                    String attributeValue = XmlPullParserUtil.getAttributeValue(xmlPullParserNewPullParser, strArr[i11]);
                    if (attributeValue == null) {
                        i11++;
                    } else if (Integer.parseInt(attributeValue) == 1) {
                        String[] strArr2 = f37028b;
                        int i12 = 0;
                        while (true) {
                            if (i12 >= 4) {
                                break;
                            }
                            String attributeValue2 = XmlPullParserUtil.getAttributeValue(xmlPullParserNewPullParser, strArr2[i12]);
                            if (attributeValue2 != null) {
                                j10 = Long.parseLong(attributeValue2);
                                if (j10 == -1) {
                                    break;
                                }
                            } else {
                                i12++;
                            }
                        }
                        j10 = -9223372036854775807L;
                        String[] strArr3 = f37029c;
                        while (true) {
                            if (i10 >= 2) {
                                immutableListT = ImmutableList.t();
                                break;
                            }
                            String attributeValue3 = XmlPullParserUtil.getAttributeValue(xmlPullParserNewPullParser, strArr3[i10]);
                            if (attributeValue3 != null) {
                                immutableListT = ImmutableList.x(new b(MimeTypes.IMAGE_JPEG, 0L, 0L), new b(MimeTypes.VIDEO_MP4, Long.parseLong(attributeValue3), 0L));
                                break;
                            }
                            i10++;
                        }
                        j11 = j10;
                    }
                }
                return null;
            }
            if (XmlPullParserUtil.isStartTag(xmlPullParserNewPullParser, "Container:Directory")) {
                immutableListT = a(xmlPullParserNewPullParser, "Container", "Item");
            } else if (XmlPullParserUtil.isStartTag(xmlPullParserNewPullParser, "GContainer:Directory")) {
                immutableListT = a(xmlPullParserNewPullParser, "GContainer", "GContainerItem");
            }
        } while (!XmlPullParserUtil.isEndTag(xmlPullParserNewPullParser, "x:xmpmeta"));
        if (immutableListT.isEmpty()) {
            return null;
        }
        return new c(j11, immutableListT);
    }
}
