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

Commit 3107a0bb authored by Lajos Molnar's avatar Lajos Molnar Committed by Gerrit Code Review
Browse files

Merge changes I4a6854ee,I12af66ef,I5b41cbe2

* changes:
  VT: ubsan: Prevent assertion by overflowing rtp-time
  VT: Increase TMMBR reaction speed
  VT: fixed "Uninitialized scalar field" reported by static analysis
parents 7a9b5d11 e27532aa
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -2858,23 +2858,24 @@ void NuPlayer::sendIMSRxNotice(const sp<AMessage> &msg) {
    in.writeInt32(payloadType);

    switch (payloadType) {
        case NuPlayer::RTPSource::RTCP_TSFB:   // RTCP TSFB
        case NuPlayer::RTPSource::RTCP_PSFB:   // RTCP PSFB
        case NuPlayer::RTPSource::RTP_AUTODOWN:
        case ARTPSource::RTCP_TSFB:   // RTCP TSFB
        case ARTPSource::RTCP_PSFB:   // RTCP PSFB
        case ARTPSource::RTP_AUTODOWN:
        {
            int32_t feedbackType, id;
            CHECK(msg->findInt32("feedback-type", &feedbackType));
            CHECK(msg->findInt32("sender", &id));
            in.writeInt32(feedbackType);
            in.writeInt32(id);
            if (payloadType == NuPlayer::RTPSource::RTCP_TSFB) {
            if (payloadType == ARTPSource::RTCP_TSFB) {
                int32_t bitrate;
                CHECK(msg->findInt32("bit-rate", &bitrate));
                in.writeInt32(bitrate);
            }
            break;
        }
        case NuPlayer::RTPSource::RTP_QUALITY:
        case ARTPSource::RTP_QUALITY:
        case ARTPSource::RTP_QUALITY_EMC:
        {
            int32_t feedbackType, bitrate;
            int32_t highestSeqNum, baseSeqNum, prevExpected;
@@ -2895,7 +2896,7 @@ void NuPlayer::sendIMSRxNotice(const sp<AMessage> &msg) {
            in.writeInt32(prevNumBufRecv);
            break;
        }
        case NuPlayer::RTPSource::RTP_CVO:
        case ARTPSource::RTP_CVO:
        {
            int32_t cvo;
            CHECK(msg->findInt32("cvo", &cvo));
+13 −3
Original line number Diff line number Diff line
@@ -45,7 +45,17 @@ NuPlayer::RTPSource::RTPSource(
      mRTPConn(new ARTPConnection(ARTPConnection::kViLTEConnection)),
      mEOSTimeoutAudio(0),
      mEOSTimeoutVideo(0),
      mLastCVOUpdated(-1) {
      mFirstAccessUnit(true),
      mAllTracksHaveTime(false),
      mNTPAnchorUs(-1),
      mMediaAnchorUs(-1),
      mLastMediaTimeUs(-1),
      mNumAccessUnitsReceived(0),
      mLastCVOUpdated(-1),
      mReceivedFirstRTCPPacket(false),
      mReceivedFirstRTPPacket(false),
      mPausing(false),
      mPauseGeneration(0) {
    ALOGD("RTPSource initialized with rtpParams=%s", rtpParams.string());
}

@@ -289,7 +299,7 @@ status_t NuPlayer::RTPSource::dequeueAccessUnit(
    if ((*accessUnit) != NULL && (*accessUnit)->meta()->findInt32("cvo", &cvo) &&
            cvo != mLastCVOUpdated) {
        sp<AMessage> msg = new AMessage();
        msg->setInt32("payload-type", NuPlayer::RTPSource::RTP_CVO);
        msg->setInt32("payload-type", ARTPSource::RTP_CVO);
        msg->setInt32("cvo", cvo);

        sp<AMessage> notify = dupNotify();
+1 −10
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "AnotherPacketSource.h"
#include "APacketSource.h"
#include "ARTPConnection.h"
#include "ARTPSource.h"
#include "ASessionDescription.h"
#include "NuPlayerSource.h"

@@ -51,16 +52,6 @@ struct NuPlayer::RTPSource : public NuPlayer::Source {
            const sp<AMessage> &notify,
            const String8& rtpParams);

    enum {
        RTP_FIRST_PACKET = 100,
        RTCP_FIRST_PACKET = 101,
        RTP_QUALITY = 102,
        RTCP_TSFB = 205,
        RTCP_PSFB = 206,
        RTP_CVO = 300,
        RTP_AUTODOWN = 400,
    };

    virtual status_t getBufferingSettings(
            BufferingSettings* buffering /* nonnull */) override;
    virtual status_t setBufferingSettings(const BufferingSettings& buffering) override;
+27 −15
Original line number Diff line number Diff line
@@ -112,24 +112,25 @@ int32_t AAVCAssembler::addNack(
ARTPAssembler::AssemblyStatus AAVCAssembler::addNALUnit(
        const sp<ARTPSource> &source) {
    List<sp<ABuffer> > *queue = source->queue();
    const uint32_t firstRTPTime = source->mFirstRtpTime;

    if (queue->empty()) {
        return NOT_ENOUGH_DATA;
    }

    sp<ABuffer> buffer = *queue->begin();
    uint32_t rtpTime;
    CHECK(buffer->meta()->findInt32("rtp-time", (int32_t *)&rtpTime));
    buffer->meta()->setObject("source", source);

    int64_t rtpTime = findRTPTime(firstRTPTime, buffer);

    int64_t startTime = source->mFirstSysTime / 1000;
    int64_t nowTime = ALooper::GetNowUs() / 1000;
    int64_t playedTime = nowTime - startTime;
    int64_t playedTimeRtp =
        source->mFirstRtpTime + (((uint32_t)playedTime) * (source->mClockRate / 1000));
    const uint32_t jitterTime =
        (uint32_t)(source->mClockRate / ((float)1000 / (source->mJbTimeMs)));
    uint32_t expiredTimeInJb = rtpTime + jitterTime;

    int64_t playedTimeRtp = source->mFirstRtpTime + playedTime * (int64_t)source->mClockRate / 1000;
    const int64_t jitterTime = source->mJbTimeMs * (int64_t)source->mClockRate / 1000;

    int64_t expiredTimeInJb = rtpTime + jitterTime;
    bool isExpired = expiredTimeInJb <= (playedTimeRtp);
    bool isTooLate200 = expiredTimeInJb < (playedTimeRtp - jitterTime);
    bool isTooLate300 = expiredTimeInJb < (playedTimeRtp - (jitterTime * 3 / 2));
@@ -154,11 +155,11 @@ ARTPAssembler::AssemblyStatus AAVCAssembler::addNALUnit(

    if (isTooLate300) {
        ALOGW("buffer arrived after 300ms ... \t Diff in Jb=%lld \t Seq# %d",
              ((long long)playedTimeRtp) - expiredTimeInJb, buffer->int32Data());
                (long long)(playedTimeRtp - expiredTimeInJb), buffer->int32Data());
        printNowTimeUs(startTime, nowTime, playedTime);
        printRTPTime(rtpTime, playedTimeRtp, expiredTimeInJb, isExpired);

        mNextExpectedSeqNo = pickProperSeq(queue, jitterTime, playedTimeRtp);
        mNextExpectedSeqNo = pickProperSeq(queue, firstRTPTime, playedTimeRtp, jitterTime);
    }

    if (mNextExpectedSeqNoValid) {
@@ -564,14 +565,25 @@ void AAVCAssembler::submitAccessUnit() {
    msg->post();
}

int32_t AAVCAssembler::pickProperSeq(const Queue *queue, uint32_t jit, int64_t play) {
inline int64_t AAVCAssembler::findRTPTime(
        const uint32_t& firstRTPTime, const sp<ABuffer>& buffer) {
    /* If you want to +, -, * rtpTime, recommend to declare rtpTime as int64_t.
       Because rtpTime can be near UINT32_MAX. Beware the overflow. */
    int64_t rtpTime = 0;
    CHECK(buffer->meta()->findInt32("rtp-time", (int32_t *)&rtpTime));
    // If the first overs 2^31 and rtp unders 2^31, the rtp value is overflowed one.
    int64_t overflowMask = (firstRTPTime & 0x80000000 & ~rtpTime) << 1;
    return rtpTime | overflowMask;
}

int32_t AAVCAssembler::pickProperSeq(const Queue *queue,
        uint32_t first, int64_t play, int64_t jit) {
    sp<ABuffer> buffer = *(queue->begin());
    uint32_t rtpTime;
    int32_t nextSeqNo = buffer->int32Data();

    Queue::const_iterator it = queue->begin();
    while (it != queue->end()) {
        CHECK((*it)->meta()->findInt32("rtp-time", (int32_t *)&rtpTime));
        int64_t rtpTime = findRTPTime(first, *it);
        // if pkt in time exists, that should be the next pivot
        if (rtpTime + jit >= play) {
            nextSeqNo = (*it)->int32Data();
@@ -613,9 +625,9 @@ inline void AAVCAssembler::printNowTimeUs(int64_t start, int64_t now, int64_t pl
            (long long)start, (long long)now, (long long)play);
}

inline void AAVCAssembler::printRTPTime(uint32_t rtp, int64_t play, uint32_t exp, bool isExp) {
    ALOGD("rtp-time(JB)=%u, played-rtp-time(JB)=%lld, expired-rtp-time(JB)=%u isExpired=%d",
            rtp, (long long)play, exp, isExp);
inline void AAVCAssembler::printRTPTime(int64_t rtp, int64_t play, int64_t exp, bool isExp) {
    ALOGD("rtp-time(JB)=%lld, played-rtp-time(JB)=%lld, expired-rtp-time(JB)=%lld expired=%d",
            (long long)rtp, (long long)play, (long long)exp, isExp);
}

ARTPAssembler::AssemblyStatus AAVCAssembler::assembleMore(
+3 −2
Original line number Diff line number Diff line
@@ -63,12 +63,13 @@ private:

    void submitAccessUnit();

    int32_t pickProperSeq(const Queue *q, uint32_t jit, int64_t play);
    inline int64_t findRTPTime(const uint32_t& firstRTPTime, const sp<ABuffer>& buffer);
    int32_t pickProperSeq(const Queue *q, uint32_t first, int64_t play, int64_t jit);
    bool recycleUnit(uint32_t start, uint32_t end, uint32_t connected,
            size_t avail, float goodRatio);
    int32_t deleteUnitUnderSeq(Queue *q, uint32_t seq);
    void printNowTimeUs(int64_t start, int64_t now, int64_t play);
    void printRTPTime(uint32_t rtp, int64_t play, uint32_t exp, bool isExp);
    void printRTPTime(int64_t rtp, int64_t play, int64_t exp, bool isExp);

    DISALLOW_EVIL_CONSTRUCTORS(AAVCAssembler);
};
Loading