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

Commit cd50b1da authored by Kim Sungyeon's avatar Kim Sungyeon Committed by Lajos Molnar
Browse files

VT: Round off TMMBR / TMMBN value to fit in RTCP



When we express number like 2162000 (0x20FD50), mantissa is 0x20FD5.
It requires 18bits to express the mantissa.
But 17bits are the limit of space on RTCP's spec. (RFC5104 4.2.1.1)
This rounding off helps for describing these cases.

Bug: 175266635

Change-Id: I3df0b7c370eb7ff3134906ebe576a8a48fea3246
Signed-off-by: default avatarKim Sungyeon <sy85.kim@samsung.com>
parent ec895dd8
Loading
Loading
Loading
Loading
+15 −10
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>

#include <strings.h>

namespace android {

static uint32_t kSourceID = 0xdeadbeef;
@@ -380,21 +382,24 @@ void ARTPSource::addTMMBR(const sp<ABuffer> &buffer, int32_t targetBitrate) {
    data[14] = (mID >> 8) & 0xff;
    data[15] = mID & 0xff;

    int32_t exp, mantissa;
    // Find the first bit '1' from left & right side of the value.
    int32_t leftEnd = 31 - __builtin_clz(targetBitrate);
    int32_t rightEnd = ffs(targetBitrate) - 1;

    // Round off to the nearest 2^4th
    ALOGI("UE -> Op Req Rx bitrate : %d ", targetBitrate & 0xfffffff0);
    for (exp=4 ; exp < 32 ; exp++)
        if (((targetBitrate >> exp) & 0x01) != 0)
            break;
    mantissa = targetBitrate >> exp;
    // Mantissa have only 17bit space by RTCP specification.
    if ((leftEnd - rightEnd) > 16) {
        rightEnd = leftEnd - 16;
    }
    int32_t mantissa = targetBitrate >> rightEnd;

    data[16] = ((exp << 2) & 0xfc) | ((mantissa & 0x18000) >> 15);
    data[16] = ((rightEnd << 2) & 0xfc) | ((mantissa & 0x18000) >> 15);
    data[17] =                             (mantissa & 0x07f80) >> 7;
    data[18] =                             (mantissa & 0x0007f) << 1;
    data[19] = 40;              // 40 bytes overhead;

    buffer->setRange(buffer->offset(), buffer->size() + (data[3] + 1) * sizeof(int32_t));

    ALOGI("UE -> Op Req Rx bitrate : %d ", mantissa << rightEnd);
}

int ARTPSource::addNACK(const sp<ABuffer> &buffer) {
+16 −12
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@

#include "ARTPWriter.h"

#include <fcntl.h>

#include <media/stagefright/MediaSource.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
@@ -32,6 +30,9 @@
#include <media/stagefright/MetaData.h>
#include <utils/ByteOrder.h>

#include <fcntl.h>
#include <strings.h>

#define PT      97
#define PT_STR  "97"

@@ -746,21 +747,24 @@ void ARTPWriter::addTMMBN(const sp<ABuffer> &buffer) {
    data[14] = (mOpponentID >> 8) & 0xff;
    data[15] = mOpponentID & 0xff;

    int32_t exp, mantissa;
    // Find the first bit '1' from left & right side of the value.
    int32_t leftEnd = 31 - __builtin_clz(mBitrate);
    int32_t rightEnd = ffs(mBitrate) - 1;

    // Round off to the nearest 2^4th
    ALOGI("UE -> Op Noti Tx bitrate : %d ", mBitrate & 0xfffffff0);
    for (exp=4 ; exp < 32 ; exp++)
        if (((mBitrate >> exp) & 0x01) != 0)
            break;
    mantissa = mBitrate >> exp;
    // Mantissa have only 17bit space by RTCP specification.
    if ((leftEnd - rightEnd) > 16) {
        rightEnd = leftEnd - 16;
    }
    int32_t mantissa = mBitrate >> rightEnd;

    data[16] = ((exp << 2) & 0xfc) | ((mantissa & 0x18000) >> 15);
    data[16] = ((rightEnd << 2) & 0xfc) | ((mantissa & 0x18000) >> 15);
    data[17] =                             (mantissa & 0x07f80) >> 7;
    data[18] =                             (mantissa & 0x0007f) << 1;
    data[19] = 40;              // 40 bytes overhead;

    buffer->setRange(buffer->offset(), buffer->size() + 20);

    ALOGI("UE -> Op Noti Tx bitrate : %d ", mantissa << rightEnd);
}

// static