package okhttp3.n0.http2;

import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
import io.netty.handler.codec.rtsp.RtspHeaders;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketTimeoutException;
import java.util.ArrayDeque;
import java.util.Objects;
import kotlin.Metadata;
import kotlin.jvm.internal.o;
import okhttp3.Headers;
import okio.AsyncTimeout;
import okio.Buffer;
import okio.Sink;
import okio.Source;
import okio.Timeout;

/* JADX INFO: renamed from: y.n0.j.o, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000\u008a\u0001\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\t\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0010\u0002\n\u0002\b\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0006\u0018\u0000 _2\u00020\u0001:\u0004_`abB1\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0007\u0012\u0006\u0010\b\u001a\u00020\u0007\u0012\b\u0010\t\u001a\u0004\u0018\u00010\n¢\u0006\u0002\u0010\u000bJ\u000e\u0010@\u001a\u00020A2\u0006\u0010B\u001a\u00020#J\r\u0010C\u001a\u00020AH\u0000¢\u0006\u0002\bDJ\r\u0010E\u001a\u00020AH\u0000¢\u0006\u0002\bFJ\u0018\u0010G\u001a\u00020A2\u0006\u0010H\u001a\u00020\u000f2\b\u0010\u0014\u001a\u0004\u0018\u00010\u0015J\u001a\u0010I\u001a\u00020\u00072\u0006\u0010\u000e\u001a\u00020\u000f2\b\u0010\u0014\u001a\u0004\u0018\u00010\u0015H\u0002J\u000e\u0010J\u001a\u00020A2\u0006\u0010\u000e\u001a\u00020\u000fJ\u000e\u0010K\u001a\u00020A2\u0006\u0010L\u001a\u00020\nJ\u0006\u0010M\u001a\u00020NJ\u0006\u0010O\u001a\u00020PJ\u0006\u0010,\u001a\u00020QJ\u0016\u0010R\u001a\u00020A2\u0006\u00104\u001a\u00020S2\u0006\u0010T\u001a\u00020\u0003J\u0016\u0010U\u001a\u00020A2\u0006\u0010\t\u001a\u00020\n2\u0006\u0010\b\u001a\u00020\u0007J\u000e\u0010V\u001a\u00020A2\u0006\u0010\u000e\u001a\u00020\u000fJ\u0006\u0010W\u001a\u00020\nJ\u0006\u0010L\u001a\u00020\nJ\r\u0010X\u001a\u00020AH\u0000¢\u0006\u0002\bYJ$\u0010Z\u001a\u00020A2\f\u0010[\u001a\b\u0012\u0004\u0012\u00020]0\\2\u0006\u0010\u0006\u001a\u00020\u00072\u0006\u0010^\u001a\u00020\u0007J\u0006\u0010>\u001a\u00020QR\u0011\u0010\u0004\u001a\u00020\u0005¢\u0006\b\n\u0000\u001a\u0004\b\f\u0010\rR\u001e\u0010\u000e\u001a\u0004\u0018\u00010\u000f8@X\u0080\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0010\u0010\u0011\"\u0004\b\u0012\u0010\u0013R\u001c\u0010\u0014\u001a\u0004\u0018\u00010\u0015X\u0080\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0016\u0010\u0017\"\u0004\b\u0018\u0010\u0019R\u000e\u0010\u001a\u001a\u00020\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\u001b\u001a\b\u0012\u0004\u0012\u00020\n0\u001cX\u0082\u0004¢\u0006\u0002\n\u0000R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u001d\u0010\u001eR\u0011\u0010\u001f\u001a\u00020\u00078F¢\u0006\u0006\u001a\u0004\b\u001f\u0010 R\u0011\u0010!\u001a\u00020\u00078F¢\u0006\u0006\u001a\u0004\b!\u0010 R$\u0010$\u001a\u00020#2\u0006\u0010\"\u001a\u00020#@@X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b%\u0010&\"\u0004\b'\u0010(R$\u0010)\u001a\u00020#2\u0006\u0010\"\u001a\u00020#@@X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b*\u0010&\"\u0004\b+\u0010(R\u0018\u0010,\u001a\u00060-R\u00020\u0000X\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b.\u0010/R\u0018\u00100\u001a\u000601R\u00020\u0000X\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b2\u00103R\u0018\u00104\u001a\u000605R\u00020\u0000X\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b6\u00107R$\u00108\u001a\u00020#2\u0006\u0010\"\u001a\u00020#@@X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b9\u0010&\"\u0004\b:\u0010(R$\u0010;\u001a\u00020#2\u0006\u0010\"\u001a\u00020#@@X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b<\u0010&\"\u0004\b=\u0010(R\u0018\u0010>\u001a\u00060-R\u00020\u0000X\u0080\u0004¢\u0006\b\n\u0000\u001a\u0004\b?\u0010/¨\u0006c"}, d2 = {"Lokhttp3/internal/http2/Http2Stream;", "", "id", "", "connection", "Lokhttp3/internal/http2/Http2Connection;", "outFinished", "", "inFinished", "headers", "Lokhttp3/Headers;", "(ILokhttp3/internal/http2/Http2Connection;ZZLokhttp3/Headers;)V", "getConnection", "()Lokhttp3/internal/http2/Http2Connection;", "errorCode", "Lokhttp3/internal/http2/ErrorCode;", "getErrorCode$okhttp", "()Lokhttp3/internal/http2/ErrorCode;", "setErrorCode$okhttp", "(Lokhttp3/internal/http2/ErrorCode;)V", "errorException", "Ljava/io/IOException;", "getErrorException$okhttp", "()Ljava/io/IOException;", "setErrorException$okhttp", "(Ljava/io/IOException;)V", "hasResponseHeaders", "headersQueue", "Ljava/util/ArrayDeque;", "getId", "()I", "isLocallyInitiated", "()Z", "isOpen", "<set-?>", "", "readBytesAcknowledged", "getReadBytesAcknowledged", "()J", "setReadBytesAcknowledged$okhttp", "(J)V", "readBytesTotal", "getReadBytesTotal", "setReadBytesTotal$okhttp", "readTimeout", "Lokhttp3/internal/http2/Http2Stream$StreamTimeout;", "getReadTimeout$okhttp", "()Lokhttp3/internal/http2/Http2Stream$StreamTimeout;", "sink", "Lokhttp3/internal/http2/Http2Stream$FramingSink;", "getSink$okhttp", "()Lokhttp3/internal/http2/Http2Stream$FramingSink;", "source", "Lokhttp3/internal/http2/Http2Stream$FramingSource;", "getSource$okhttp", "()Lokhttp3/internal/http2/Http2Stream$FramingSource;", "writeBytesMaximum", "getWriteBytesMaximum", "setWriteBytesMaximum$okhttp", "writeBytesTotal", "getWriteBytesTotal", "setWriteBytesTotal$okhttp", "writeTimeout", "getWriteTimeout$okhttp", "addBytesToWriteWindow", "", "delta", "cancelStreamIfNecessary", "cancelStreamIfNecessary$okhttp", "checkOutNotClosed", "checkOutNotClosed$okhttp", "close", "rstStatusCode", "closeInternal", "closeLater", "enqueueTrailers", HttpHeaders.Values.TRAILERS, "getSink", "Lokio/Sink;", "getSource", "Lokio/Source;", "Lokio/Timeout;", "receiveData", "Lokio/BufferedSource;", "length", "receiveHeaders", "receiveRstStream", "takeHeaders", "waitForIo", "waitForIo$okhttp", "writeHeaders", "responseHeaders", "", "Lokhttp3/internal/http2/Header;", "flushHeaders", "Companion", "FramingSink", "FramingSource", "StreamTimeout", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class Http2Stream {
    public final int a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Http2Connection f9985b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public long f9986c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public long f9987d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public long f9988e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public long f9989f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ArrayDeque<Headers> f9990g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f9991h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final b f9992i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final a f9993j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final c f9994k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final c f9995l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public ErrorCode f9996m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public IOException f9997n;

    /* JADX INFO: renamed from: y.n0.j.o$a */
    @Metadata(d1 = {"\u00006\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\t\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\t\n\u0000\b\u0080\u0004\u0018\u00002\u00020\u0001B\u000f\u0012\b\b\u0002\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\b\u0010\u0014\u001a\u00020\u0015H\u0016J\u0010\u0010\u0016\u001a\u00020\u00152\u0006\u0010\u0017\u001a\u00020\u0003H\u0002J\b\u0010\u0018\u001a\u00020\u0015H\u0016J\b\u0010\u0019\u001a\u00020\u001aH\u0016J\u0018\u0010\u001b\u001a\u00020\u00152\u0006\u0010\u001c\u001a\u00020\r2\u0006\u0010\u001d\u001a\u00020\u001eH\u0016R\u001a\u0010\u0005\u001a\u00020\u0003X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0006\u0010\u0007\"\u0004\b\b\u0010\tR\u001a\u0010\u0002\u001a\u00020\u0003X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\n\u0010\u0007\"\u0004\b\u000b\u0010\tR\u000e\u0010\f\u001a\u00020\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u001c\u0010\u000e\u001a\u0004\u0018\u00010\u000fX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0010\u0010\u0011\"\u0004\b\u0012\u0010\u0013¨\u0006\u001f"}, d2 = {"Lokhttp3/internal/http2/Http2Stream$FramingSink;", "Lokio/Sink;", "finished", "", "(Lokhttp3/internal/http2/Http2Stream;Z)V", "closed", "getClosed", "()Z", "setClosed", "(Z)V", "getFinished", "setFinished", "sendBuffer", "Lokio/Buffer;", HttpHeaders.Values.TRAILERS, "Lokhttp3/Headers;", "getTrailers", "()Lokhttp3/Headers;", "setTrailers", "(Lokhttp3/Headers;)V", "close", "", "emitFrame", "outFinishedOnLastFrame", "flush", RtspHeaders.Values.TIMEOUT, "Lokio/Timeout;", "write", "source", "byteCount", "", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class a implements Sink {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public boolean f9998f;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public final Buffer f9999m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public boolean f10000n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public final /* synthetic */ Http2Stream f10001o;

        public a(Http2Stream http2Stream, boolean z2) {
            o.f(http2Stream, "this$0");
            this.f10001o = http2Stream;
            this.f9998f = z2;
            this.f9999m = new Buffer();
        }

        public final void a(boolean z2) throws SocketTimeoutException {
            long jMin;
            boolean z3;
            Http2Stream http2Stream = this.f10001o;
            synchronized (http2Stream) {
                http2Stream.f9995l.h();
                while (http2Stream.f9988e >= http2Stream.f9989f && !this.f9998f && !this.f10000n && http2Stream.f() == null) {
                    try {
                        http2Stream.l();
                    } finally {
                        http2Stream.f9995l.l();
                    }
                }
                http2Stream.f9995l.l();
                http2Stream.b();
                jMin = Math.min(http2Stream.f9989f - http2Stream.f9988e, this.f9999m.f10118m);
                http2Stream.f9988e += jMin;
                z3 = z2 && jMin == this.f9999m.f10118m;
            }
            this.f10001o.f9995l.h();
            try {
                Http2Stream http2Stream2 = this.f10001o;
                http2Stream2.f9985b.j(http2Stream2.a, z3, this.f9999m, jMin);
            } finally {
                http2Stream = this.f10001o;
            }
        }

        @Override // okio.Sink, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
        public void close() throws SocketTimeoutException {
            Http2Stream http2Stream = this.f10001o;
            byte[] bArr = okhttp3.n0.c.a;
            synchronized (http2Stream) {
                if (this.f10000n) {
                    return;
                }
                boolean z2 = http2Stream.f() == null;
                Http2Stream http2Stream2 = this.f10001o;
                if (!http2Stream2.f9993j.f9998f) {
                    if (this.f9999m.f10118m > 0) {
                        while (this.f9999m.f10118m > 0) {
                            a(true);
                        }
                    } else if (z2) {
                        http2Stream2.f9985b.j(http2Stream2.a, true, null, 0L);
                    }
                }
                synchronized (this.f10001o) {
                    this.f10000n = true;
                }
                this.f10001o.f9985b.M.flush();
                this.f10001o.a();
            }
        }

        @Override // okio.Sink, java.io.Flushable
        public void flush() throws SocketTimeoutException {
            Http2Stream http2Stream = this.f10001o;
            byte[] bArr = okhttp3.n0.c.a;
            synchronized (http2Stream) {
                http2Stream.b();
            }
            while (this.f9999m.f10118m > 0) {
                a(false);
                this.f10001o.f9985b.M.flush();
            }
        }

        @Override // okio.Sink
        /* JADX INFO: renamed from: timeout */
        public Timeout getF10143m() {
            return this.f10001o.f9995l;
        }

        @Override // okio.Sink
        public void write(Buffer buffer, long j2) throws SocketTimeoutException {
            o.f(buffer, "source");
            byte[] bArr = okhttp3.n0.c.a;
            this.f9999m.write(buffer, j2);
            while (this.f9999m.f10118m >= DefaultHttpDataFactory.MINSIZE) {
                a(false);
            }
        }
    }

    /* JADX INFO: renamed from: y.n0.j.o$b */
    @Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0010\u000b\n\u0002\b\t\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0004\u0018\u00002\u00020\u0001B\u0017\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\u001a\u001a\u00020\u001bH\u0016J\u0018\u0010\u001c\u001a\u00020\u00032\u0006\u0010\u001d\u001a\u00020\u000f2\u0006\u0010\u001e\u001a\u00020\u0003H\u0016J\u001d\u0010\u001f\u001a\u00020\u001b2\u0006\u0010 \u001a\u00020!2\u0006\u0010\u001e\u001a\u00020\u0003H\u0000¢\u0006\u0002\b\"J\b\u0010#\u001a\u00020$H\u0016J\u0010\u0010%\u001a\u00020\u001b2\u0006\u0010\u001c\u001a\u00020\u0003H\u0002R\u001a\u0010\u0007\u001a\u00020\u0005X\u0080\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\b\u0010\t\"\u0004\b\n\u0010\u000bR\u001a\u0010\u0004\u001a\u00020\u0005X\u0080\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\f\u0010\t\"\u0004\b\r\u0010\u000bR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u0011\u0010\u000e\u001a\u00020\u000f¢\u0006\b\n\u0000\u001a\u0004\b\u0010\u0010\u0011R\u0011\u0010\u0012\u001a\u00020\u000f¢\u0006\b\n\u0000\u001a\u0004\b\u0013\u0010\u0011R\u001c\u0010\u0014\u001a\u0004\u0018\u00010\u0015X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0016\u0010\u0017\"\u0004\b\u0018\u0010\u0019¨\u0006&"}, d2 = {"Lokhttp3/internal/http2/Http2Stream$FramingSource;", "Lokio/Source;", "maxByteCount", "", "finished", "", "(Lokhttp3/internal/http2/Http2Stream;JZ)V", "closed", "getClosed$okhttp", "()Z", "setClosed$okhttp", "(Z)V", "getFinished$okhttp", "setFinished$okhttp", "readBuffer", "Lokio/Buffer;", "getReadBuffer", "()Lokio/Buffer;", "receiveBuffer", "getReceiveBuffer", HttpHeaders.Values.TRAILERS, "Lokhttp3/Headers;", "getTrailers", "()Lokhttp3/Headers;", "setTrailers", "(Lokhttp3/Headers;)V", "close", "", "read", "sink", "byteCount", "receive", "source", "Lokio/BufferedSource;", "receive$okhttp", RtspHeaders.Values.TIMEOUT, "Lokio/Timeout;", "updateConnectionFlowControl", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class b implements Source {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final long f10002f;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public boolean f10003m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final Buffer f10004n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public final Buffer f10005o;

        /* JADX INFO: renamed from: p, reason: collision with root package name */
        public boolean f10006p;

        /* JADX INFO: renamed from: q, reason: collision with root package name */
        public final /* synthetic */ Http2Stream f10007q;

        public b(Http2Stream http2Stream, long j2, boolean z2) {
            o.f(http2Stream, "this$0");
            this.f10007q = http2Stream;
            this.f10002f = j2;
            this.f10003m = z2;
            this.f10004n = new Buffer();
            this.f10005o = new Buffer();
        }

        public final void a(long j2) {
            Http2Stream http2Stream = this.f10007q;
            byte[] bArr = okhttp3.n0.c.a;
            http2Stream.f9985b.h(j2);
        }

        @Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            long j2;
            Http2Stream http2Stream = this.f10007q;
            synchronized (http2Stream) {
                this.f10006p = true;
                Buffer buffer = this.f10005o;
                j2 = buffer.f10118m;
                buffer.skip(j2);
                http2Stream.notifyAll();
            }
            if (j2 > 0) {
                a(j2);
            }
            this.f10007q.a();
        }

        @Override // okio.Source
        public long r(Buffer buffer, long j2) throws Throwable {
            boolean z2;
            long jR;
            o.f(buffer, "sink");
            long j3 = 0;
            if (!(j2 >= 0)) {
                throw new IllegalArgumentException(o.l("byteCount < 0: ", Long.valueOf(j2)).toString());
            }
            while (true) {
                Throwable streamResetException = null;
                Http2Stream http2Stream = this.f10007q;
                synchronized (http2Stream) {
                    http2Stream.f9994k.h();
                    try {
                        if (http2Stream.f() != null && !this.f10003m && (streamResetException = http2Stream.f9997n) == null) {
                            ErrorCode errorCodeF = http2Stream.f();
                            o.c(errorCodeF);
                            streamResetException = new StreamResetException(errorCodeF);
                        }
                        if (this.f10006p) {
                            throw new IOException("stream closed");
                        }
                        Buffer buffer2 = this.f10005o;
                        long j4 = buffer2.f10118m;
                        if (j4 > j3) {
                            jR = buffer2.r(buffer, Math.min(j2, j4));
                            long j5 = http2Stream.f9986c + jR;
                            http2Stream.f9986c = j5;
                            long j6 = j5 - http2Stream.f9987d;
                            if (streamResetException == null && j6 >= http2Stream.f9985b.F.a() / 2) {
                                http2Stream.f9985b.o(http2Stream.a, j6);
                                http2Stream.f9987d = http2Stream.f9986c;
                            }
                            z2 = false;
                        } else {
                            if (this.f10003m || streamResetException != null) {
                                z2 = false;
                            } else {
                                http2Stream.l();
                                z2 = true;
                            }
                            jR = -1;
                        }
                    } finally {
                    }
                }
                if (!z2) {
                    if (jR != -1) {
                        a(jR);
                        return jR;
                    }
                    if (streamResetException == null) {
                        return -1L;
                    }
                    throw streamResetException;
                }
                j3 = 0;
            }
        }

        @Override // okio.Source
        /* JADX INFO: renamed from: timeout */
        public Timeout getF10138m() {
            return this.f10007q.f9994k;
        }
    }

    /* JADX INFO: renamed from: y.n0.j.o$c */
    @Metadata(d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0080\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0006\u0010\u0003\u001a\u00020\u0004J\u0012\u0010\u0005\u001a\u00020\u00062\b\u0010\u0007\u001a\u0004\u0018\u00010\u0006H\u0014J\b\u0010\b\u001a\u00020\u0004H\u0014¨\u0006\t"}, d2 = {"Lokhttp3/internal/http2/Http2Stream$StreamTimeout;", "Lokio/AsyncTimeout;", "(Lokhttp3/internal/http2/Http2Stream;)V", "exitAndThrowIfTimedOut", "", "newTimeoutException", "Ljava/io/IOException;", "cause", "timedOut", "okhttp"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class c extends AsyncTimeout {

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        public final /* synthetic */ Http2Stream f10008l;

        public c(Http2Stream http2Stream) {
            o.f(http2Stream, "this$0");
            this.f10008l = http2Stream;
        }

        @Override // okio.AsyncTimeout
        public IOException j(IOException iOException) {
            SocketTimeoutException socketTimeoutException = new SocketTimeoutException(RtspHeaders.Values.TIMEOUT);
            if (iOException != null) {
                socketTimeoutException.initCause(iOException);
            }
            return socketTimeoutException;
        }

        @Override // okio.AsyncTimeout
        public void k() {
            this.f10008l.e(ErrorCode.CANCEL);
            Http2Connection http2Connection = this.f10008l.f9985b;
            synchronized (http2Connection) {
                long j2 = http2Connection.C;
                long j3 = http2Connection.B;
                if (j2 < j3) {
                    return;
                }
                http2Connection.B = j3 + 1;
                http2Connection.E = System.nanoTime() + ((long) 1000000000);
                http2Connection.f9917v.c(new l(o.l(http2Connection.f9912q, " ping"), true, http2Connection), 0L);
            }
        }

        public final void l() throws SocketTimeoutException {
            if (i()) {
                throw new SocketTimeoutException(RtspHeaders.Values.TIMEOUT);
            }
        }
    }

    public Http2Stream(int i2, Http2Connection http2Connection, boolean z2, boolean z3, Headers headers) {
        o.f(http2Connection, "connection");
        this.a = i2;
        this.f9985b = http2Connection;
        this.f9989f = http2Connection.G.a();
        ArrayDeque<Headers> arrayDeque = new ArrayDeque<>();
        this.f9990g = arrayDeque;
        this.f9992i = new b(this, http2Connection.F.a(), z3);
        this.f9993j = new a(this, z2);
        this.f9994k = new c(this);
        this.f9995l = new c(this);
        if (headers == null) {
            if (!h()) {
                throw new IllegalStateException("remotely-initiated streams should have headers".toString());
            }
        } else {
            if (!(!h())) {
                throw new IllegalStateException("locally-initiated streams shouldn't have headers yet".toString());
            }
            arrayDeque.add(headers);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0019  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void a() {
        /*
            r2 = this;
            byte[] r0 = okhttp3.n0.c.a
            monitor-enter(r2)
            y.n0.j.o$b r0 = r2.f9992i     // Catch: java.lang.Throwable -> L32
            boolean r1 = r0.f10003m     // Catch: java.lang.Throwable -> L32
            if (r1 != 0) goto L19
            boolean r0 = r0.f10006p     // Catch: java.lang.Throwable -> L32
            if (r0 == 0) goto L19
            y.n0.j.o$a r0 = r2.f9993j     // Catch: java.lang.Throwable -> L32
            boolean r1 = r0.f9998f     // Catch: java.lang.Throwable -> L32
            if (r1 != 0) goto L17
            boolean r0 = r0.f10000n     // Catch: java.lang.Throwable -> L32
            if (r0 == 0) goto L19
        L17:
            r0 = 1
            goto L1a
        L19:
            r0 = 0
        L1a:
            boolean r1 = r2.i()     // Catch: java.lang.Throwable -> L32
            monitor-exit(r2)
            if (r0 == 0) goto L28
            y.n0.j.b r0 = okhttp3.n0.http2.ErrorCode.CANCEL
            r1 = 0
            r2.c(r0, r1)
            goto L31
        L28:
            if (r1 != 0) goto L31
            y.n0.j.f r0 = r2.f9985b
            int r1 = r2.a
            r0.e(r1)
        L31:
            return
        L32:
            r0 = move-exception
            monitor-exit(r2)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: okhttp3.n0.http2.Http2Stream.a():void");
    }

    public final void b() throws IOException {
        a aVar = this.f9993j;
        if (aVar.f10000n) {
            throw new IOException("stream closed");
        }
        if (aVar.f9998f) {
            throw new IOException("stream finished");
        }
        if (this.f9996m != null) {
            IOException iOException = this.f9997n;
            if (iOException != null) {
                throw iOException;
            }
            ErrorCode errorCode = this.f9996m;
            o.c(errorCode);
            throw new StreamResetException(errorCode);
        }
    }

    public final void c(ErrorCode errorCode, IOException iOException) {
        o.f(errorCode, "rstStatusCode");
        if (d(errorCode, iOException)) {
            Http2Connection http2Connection = this.f9985b;
            int i2 = this.a;
            Objects.requireNonNull(http2Connection);
            o.f(errorCode, "statusCode");
            http2Connection.M.j(i2, errorCode);
        }
    }

    public final boolean d(ErrorCode errorCode, IOException iOException) {
        byte[] bArr = okhttp3.n0.c.a;
        synchronized (this) {
            if (f() != null) {
                return false;
            }
            if (this.f9992i.f10003m && this.f9993j.f9998f) {
                return false;
            }
            this.f9996m = errorCode;
            this.f9997n = iOException;
            notifyAll();
            this.f9985b.e(this.a);
            return true;
        }
    }

    public final void e(ErrorCode errorCode) {
        o.f(errorCode, "errorCode");
        if (d(errorCode, null)) {
            this.f9985b.m(this.a, errorCode);
        }
    }

    public final synchronized ErrorCode f() {
        return this.f9996m;
    }

    public final Sink g() {
        synchronized (this) {
            if (!(this.f9991h || h())) {
                throw new IllegalStateException("reply before requesting the sink".toString());
            }
        }
        return this.f9993j;
    }

    public final boolean h() {
        return this.f9985b.f9909n == ((this.a & 1) == 1);
    }

    public final synchronized boolean i() {
        if (this.f9996m != null) {
            return false;
        }
        b bVar = this.f9992i;
        if (bVar.f10003m || bVar.f10006p) {
            a aVar = this.f9993j;
            if (aVar.f9998f || aVar.f10000n) {
                if (this.f9991h) {
                    return false;
                }
            }
        }
        return true;
    }

    public final void j(Headers headers, boolean z2) {
        boolean zI;
        o.f(headers, "headers");
        byte[] bArr = okhttp3.n0.c.a;
        synchronized (this) {
            if (this.f9991h && z2) {
                Objects.requireNonNull(this.f9992i);
            } else {
                this.f9991h = true;
                this.f9990g.add(headers);
            }
            if (z2) {
                this.f9992i.f10003m = true;
            }
            zI = i();
            notifyAll();
        }
        if (zI) {
            return;
        }
        this.f9985b.e(this.a);
    }

    public final synchronized void k(ErrorCode errorCode) {
        o.f(errorCode, "errorCode");
        if (this.f9996m == null) {
            this.f9996m = errorCode;
            notifyAll();
        }
    }

    public final void l() throws InterruptedIOException {
        try {
            wait();
        } catch (InterruptedException unused) {
            Thread.currentThread().interrupt();
            throw new InterruptedIOException();
        }
    }
}
