Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 126568c7 authored by Andreas Huber's avatar Andreas Huber
Browse files

Attempt to recover from network stalls by dropping frames on the source side.

Change-Id: I5f9eb4f5acb624a9e5bc0087801fb5a4a9ade35c
parent c148e7a6
Loading
Loading
Loading
Loading
+22 −4
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ private:

    AString mInBuffer;

    int64_t mLastStallReportUs;

    void notifyError(bool send, status_t err, const char *detail);
    void notify(NotificationReason reason);

@@ -137,7 +139,8 @@ ANetworkSession::Session::Session(
      mSocket(s),
      mNotify(notify),
      mSawReceiveFailure(false),
      mSawSendFailure(false) {
      mSawSendFailure(false),
      mLastStallReportUs(-1ll) {
    if (mState == CONNECTED) {
        struct sockaddr_in localAddr;
        socklen_t localAddrLen = sizeof(localAddr);
@@ -508,11 +511,26 @@ status_t ANetworkSession::Session::writeMore() {
        mSawSendFailure = true;
    }

#if 0
#if 1
    int numBytesQueued;
    int res = ioctl(mSocket, SIOCOUTQ, &numBytesQueued);
    if (res == 0 && numBytesQueued > 102400) {
        ALOGI("numBytesQueued = %d", numBytesQueued);
    if (res == 0 && numBytesQueued > 50 * 1024) {
        if (numBytesQueued > 409600) {
            ALOGW("!!! numBytesQueued = %d", numBytesQueued);
        }

        int64_t nowUs = ALooper::GetNowUs();

        if (mLastStallReportUs < 0ll
                || nowUs > mLastStallReportUs + 500000ll) {
            sp<AMessage> msg = mNotify->dup();
            msg->setInt32("sessionID", mSessionID);
            msg->setInt32("reason", kWhatNetworkStall);
            msg->setSize("numBytesQueued", numBytesQueued);
            msg->post();

            mLastStallReportUs = nowUs;
        }
    }
#endif

+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ struct ANetworkSession : public RefBase {
        kWhatData,
        kWhatDatagram,
        kWhatBinaryData,
        kWhatNetworkStall,
    };

protected:
+16 −0
Original line number Diff line number Diff line
@@ -325,6 +325,15 @@ void MediaSender::onSenderNotify(const sp<AMessage> &msg) {
            break;
        }

        case kWhatNetworkStall:
        {
            size_t numBytesQueued;
            CHECK(msg->findSize("numBytesQueued", &numBytesQueued));

            notifyNetworkStall(numBytesQueued);
            break;
        }

        default:
            TRESPASS();
    }
@@ -344,6 +353,13 @@ void MediaSender::notifyError(status_t err) {
    notify->post();
}

void MediaSender::notifyNetworkStall(size_t numBytesQueued) {
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatNetworkStall);
    notify->setSize("numBytesQueued", numBytesQueued);
    notify->post();
}

status_t MediaSender::packetizeAccessUnit(
        size_t trackIndex,
        sp<ABuffer> accessUnit,
+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ struct MediaSender : public AHandler {
    enum {
        kWhatInitDone,
        kWhatError,
        kWhatNetworkStall,
    };

    MediaSender(
@@ -113,6 +114,7 @@ private:

    void notifyInitDone(status_t err);
    void notifyError(status_t err);
    void notifyNetworkStall(size_t numBytesQueued);

    status_t packetizeAccessUnit(
            size_t trackIndex,
+19 −0
Original line number Diff line number Diff line
@@ -530,6 +530,18 @@ void RTPSender::onNetNotify(bool isRTP, const sp<AMessage> &msg) {
            }
            break;
        }

        case ANetworkSession::kWhatNetworkStall:
        {
            size_t numBytesQueued;
            CHECK(msg->findSize("numBytesQueued", &numBytesQueued));

            notifyNetworkStall(numBytesQueued);
            break;
        }

        default:
            TRESPASS();
    }
}

@@ -699,5 +711,12 @@ void RTPSender::notifyError(status_t err) {
    notify->post();
}

void RTPSender::notifyNetworkStall(size_t numBytesQueued) {
    sp<AMessage> notify = mNotify->dup();
    notify->setInt32("what", kWhatNetworkStall);
    notify->setSize("numBytesQueued", numBytesQueued);
    notify->post();
}

}  // namespace android
Loading