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

Commit 5095374c authored by Byeongjo Park's avatar Byeongjo Park
Browse files

VT: process packets right after jbtime expired



[Problem] Video frame cycle of RTP is unstable.
[Cause] Some of packets stil wait even it's
  jitter buffer time expired.
  Because jitter buffer will be checked only if
  there is new packet coming regardless jitter
  buffer expiration time.
[Solution] Create a timer to request jitter buffer
  check at jitter buffer expiration time.

Bug: 183578712

Signed-off-by: default avatarByeongjo Park <bjo.park@samsung.com>
Change-Id: I819eb270206788bd97b864a2c7444de80ec53bad
parent 4d5fc223
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -195,6 +195,10 @@ ARTPAssembler::AssemblyStatus AAVCAssembler::addNALUnit(

    if (!isExpired) {
        ALOGV("buffering in jitter buffer.");
        // set an alarm for jitter buffer time expiration.
        // adding 1ms because jitter buffer time is keep changing.
        int64_t expTimeUs = (RtpToMs(std::abs(diffTimeRtp), clockRate) + 1) * 1000;
        source->setJbAlarmTime(nowTimeUs, expTimeUs);
        return NOT_ENOUGH_DATA;
    }

+4 −0
Original line number Diff line number Diff line
@@ -205,6 +205,10 @@ ARTPAssembler::AssemblyStatus AHEVCAssembler::addNALUnit(

    if (!isExpired) {
        ALOGV("buffering in jitter buffer.");
        // set an alarm for jitter buffer time expiration.
        // adding 1ms because jitter buffer time is keep changing.
        int64_t expTimeUs = (RtpToMs(std::abs(diffTimeRtp), clockRate) + 1) * 1000;
        source->setJbAlarmTime(nowTimeUs, expTimeUs);
        return NOT_ENOUGH_DATA;
    }

+15 −2
Original line number Diff line number Diff line
@@ -18,9 +18,7 @@
#define LOG_TAG "ARTPConnection"
#include <utils/Log.h>

#include "ARTPAssembler.h"
#include "ARTPConnection.h"

#include "ARTPSource.h"
#include "ASessionDescription.h"

@@ -306,6 +304,12 @@ void ARTPConnection::onMessageReceived(const sp<AMessage> &msg) {
            break;
        }

        case kWhatAlarmStream:
        {
            onAlarmStream(msg);
            break;
        }

        case kWhatInjectPacket:
        {
            onInjectPacket(msg);
@@ -571,6 +575,13 @@ void ARTPConnection::onPollStreams() {
    }
}

void ARTPConnection::onAlarmStream(const sp<AMessage> msg) {
    sp<ARTPSource> source = nullptr;
    if (msg->findObject("source", (sp<android::RefBase>*)&source)) {
        source->processRTPPacket();
    }
}

status_t ARTPConnection::receive(StreamInfo *s, bool receiveRTP) {
    ALOGV("receiving %s", receiveRTP ? "RTP" : "RTCP");

@@ -1099,6 +1110,8 @@ sp<ARTPSource> ARTPConnection::findSource(StreamInfo *info, uint32_t srcId) {

        source->setSelfID(mSelfID);
        source->setStaticJitterTimeMs(mStaticJitterTimeMs);
        sp<AMessage> timer = new AMessage(kWhatAlarmStream, this);
        source->setJbTimer(timer);
        info->mSources.add(srcId, source);
    } else {
        source = info->mSources.valueAt(index);
+2 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ private:
        kWhatRemoveStream,
        kWhatPollStreams,
        kWhatInjectPacket,
        kWhatAlarmStream,
    };

    static const int64_t kSelectTimeoutUs;
@@ -98,6 +99,7 @@ private:
    void onSeekStream(const sp<AMessage> &msg);
    void onRemoveStream(const sp<AMessage> &msg);
    void onPollStreams();
    void onAlarmStream(const sp<AMessage> msg);
    void onInjectPacket(const sp<AMessage> &msg);
    void onSendReceiverReports();
    void checkRxBitrate(int64_t nowUs);
+36 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ ARTPSource::ARTPSource(
    int32_t clockRate, numChannels;
    ASessionDescription::ParseFormatDesc(desc.c_str(), &clockRate, &numChannels);
    mClockRate = clockRate;
    mLastJbAlarmTimeUs = 0;
    mJitterCalc = new JitterCalc(mClockRate);
}

@@ -122,6 +123,12 @@ void ARTPSource::processRTPPacket(const sp<ABuffer> &buffer) {
    }
}

void ARTPSource::processRTPPacket() {
    if (mAssembler != NULL && !mQueue.empty()) {
        mAssembler->onPacketReceived(this);
    }
}

void ARTPSource::timeUpdate(uint32_t rtpTime, uint64_t ntpTime) {
    mLastSrRtpTime = rtpTime;
    mLastSrNtpTime = ntpTime;
@@ -613,6 +620,35 @@ void ARTPSource::putInterArrivalJitterData(uint32_t timeStamp, int64_t arrivalTi
    mJitterCalc->putInterArrivalData(timeStamp, arrivalTime);
}

void ARTPSource::setJbTimer(const sp<AMessage> timer) {
    mJbTimer = timer;
}

void ARTPSource::setJbAlarmTime(int64_t nowTimeUs, int64_t alarmAfterUs) {
    if (mJbTimer == NULL) {
        return;
    }
    int64_t alarmTimeUs = nowTimeUs + alarmAfterUs;
    bool alarm = false;
    if (mLastJbAlarmTimeUs <= nowTimeUs) {
        // no more alarm in pending.
        mLastJbAlarmTimeUs = nowTimeUs + alarmAfterUs;
        alarm = true;
    } else if (mLastJbAlarmTimeUs > alarmTimeUs + 5000L) {
        // bring an alarm forward more than 5ms.
        mLastJbAlarmTimeUs = alarmTimeUs;
        alarm = true;
    } else {
        // would not set alarm if it is close with before one.
    }

    if (alarm) {
        sp<AMessage> notify = mJbTimer->dup();
        notify->setObject("source", this);
        notify->post(alarmAfterUs);
    }
}

bool ARTPSource::isNeedToEarlyNotify() {
    uint32_t expected = mHighestSeqNumber - mBaseSeqNumber + 1;
    int32_t intervalExpectedInNow = expected - mPrevExpected;
Loading