package r;

import a0.r;
import a0.x;
import a0.y;
import android.os.SystemClock;
import b0.AbstractC0399d;
import b0.D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.CancellationException;
import n.z;

/* JADX INFO: loaded from: classes.dex */
public final class n implements r.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final x f6349a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final m f6350b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final long f6351c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final b f6352d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private r f6353e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private y f6354f;

    private static class a implements y.a {
        private a() {
        }

        @Override // a0.y.a
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public Long a(String str, InputStream inputStream) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = bufferedReader.readLine();
            try {
                D.h(bufferedReader);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
                simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                return Long.valueOf(simpleDateFormat.parse(line).getTime());
            } catch (ParseException e2) {
                throw new z(e2);
            }
        }
    }

    public interface b {
        void a(m mVar, IOException iOException);

        void b(m mVar, long j2);
    }

    private static class c implements y.a {
        private c() {
        }

        @Override // a0.y.a
        /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
        public Long a(String str, InputStream inputStream) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = bufferedReader.readLine();
            AbstractC0399d.e(line != null);
            try {
                D.h(bufferedReader);
                return Long.valueOf(D.G(line));
            } catch (ParseException e2) {
                throw new z(e2);
            }
        }
    }

    private n(x xVar, m mVar, long j2, b bVar) {
        this.f6349a = xVar;
        this.f6350b = (m) AbstractC0399d.d(mVar);
        this.f6351c = j2;
        this.f6352d = (b) AbstractC0399d.d(bVar);
    }

    private void a() {
        this.f6353e.e();
    }

    private void b() {
        String str = this.f6350b.f6347a;
        if (D.a(str, "urn:mpeg:dash:utc:direct:2012") || D.a(str, "urn:mpeg:dash:utc:direct:2014")) {
            c();
            return;
        }
        if (D.a(str, "urn:mpeg:dash:utc:http-iso:2014")) {
            d(new a());
        } else if (D.a(str, "urn:mpeg:dash:utc:http-xsdate:2012") || D.a(str, "urn:mpeg:dash:utc:http-xsdate:2014")) {
            d(new c());
        } else {
            this.f6352d.a(this.f6350b, new IOException("Unsupported utc timing scheme"));
        }
    }

    private void c() {
        try {
            this.f6352d.b(this.f6350b, D.G(this.f6350b.f6348b) - this.f6351c);
        } catch (ParseException e2) {
            this.f6352d.a(this.f6350b, new z(e2));
        }
    }

    private void d(y.a aVar) {
        this.f6353e = new r("utctiming");
        y yVar = new y(this.f6350b.f6348b, this.f6349a, aVar);
        this.f6354f = yVar;
        this.f6353e.g(yVar, this);
    }

    public static void e(x xVar, m mVar, long j2, b bVar) {
        new n(xVar, mVar, j2, bVar).b();
    }

    @Override // a0.r.a
    public void l(r.c cVar) {
        a();
        this.f6352d.b(this.f6350b, ((Long) this.f6354f.a()).longValue() - SystemClock.elapsedRealtime());
    }

    @Override // a0.r.a
    public void n(r.c cVar, IOException iOException) {
        a();
        this.f6352d.a(this.f6350b, iOException);
    }

    @Override // a0.r.a
    public void v(r.c cVar) {
        n(cVar, new IOException("Load cancelled", new CancellationException()));
    }
}
