opentok / opentok-network-test

Sample app to test network connectivity and statistics (bps, packet-lost)
MIT License
112 stars 56 forks source link

mVideoBw is zero when publisher device is in low network #48

Open shahalRahman opened 4 years ago

shahalRahman commented 4 years ago

When the publisher device is moved to low network(2G), SubscriberVideoStats.videoBytesReceived is coming same for around 30 seconds. And during this time mVideoBw is calculated to 0.

private void checkSubscriberVideoStats(SubscriberKit.SubscriberVideoStats stats) {
    double videoTimestamp = stats.timeStamp / 1000;

    Log.d(TAG, "onVideoStats: stats considering same_timestamp:" + (s_prevVideoTimestamp==videoTimestamp)+" same_byte:"+(stats.videoBytesReceived == s_prevVideoBytes));
    //initialize values
    if (s_prevVideoTimestamp == 0) {
        s_prevVideoTimestamp = videoTimestamp;
        s_prevVideoBytes = stats.videoBytesReceived;
    }

    if (videoTimestamp - s_prevVideoTimestamp >= TIME_WINDOW) {
        //calculate video packets lost ratio
        if (s_prevVideoPacketsRcvd != 0) {
            long pl = stats.videoPacketsLost - s_prevVideoPacketsLost;
            long pr = stats.videoPacketsReceived - s_prevVideoPacketsRcvd;
            long pt = pl + pr;

            if (pt > 0) {
                s_videoPLRatio = (double) pl / (double) pt;
            }
        }
        s_prevVideoPacketsLost = stats.videoPacketsLost;
        s_prevVideoPacketsRcvd = stats.videoPacketsReceived;

        long mVideoBw = (long) ((8 * (stats.videoBytesReceived - s_prevVideoBytes)) / (videoTimestamp - s_prevVideoTimestamp));

        s_prevVideoTimestamp = videoTimestamp;
        s_prevVideoBytes = stats.videoBytesReceived;
        if (s_videoPLRatio > 0) {
            s_avgVideoPLRatio = (s_videoPLRatio + s_avgVideoPLRatio) / 2;
        } else {
            s_avgVideoPLRatio = s_videoPLRatio;
        }
        if (mVideoBw > 0) {
            s_avgVideoBw = (mVideoBw + s_avgVideoBw) / 2;
        } else {
            s_avgVideoBw = mVideoBw;
        }
        Log.d(TAG, "onVideoStats: stats considering avgVideoBw:" + s_avgVideoBw + " PLRatio:" + s_avgVideoPLRatio + " BytesReceived:" + stats.videoBytesReceived + " PacketsReceived:" + stats.videoPacketsReceived + " PacketsLost:" + stats.videoPacketsLost + " mVideoBw:" + mVideoBw);

    }

}

We're using v2.17.0