Commit dd710487 authored by Stefan Doehla's avatar Stefan Doehla
Browse files

payload implementation of PI latency

parent 4ddd4422
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@
#define RTP_S4_251135_CR26253_0016_REV1                /* RTP Pack/Unpack API corresponding to CR 26253 */
#define IVAS_RTPDUMP                                   /* RTPDUMP writing and reading for IVAS payloads */
#define FIXED_RTP_SEQUENCE_NUM                         /* Remove random sequence number initialization */
#define PI_LATENCY                                     /* Pi latency PI frame */

/* ################### Start BE switches ################################# */
/* only BE switches wrt selection floating point code */
+79 −2
Original line number Diff line number Diff line
@@ -630,6 +630,73 @@ static ivas_error unpackAudioFocusCommon( const uint8_t *buffer, uint32_t numDat
    return IVAS_ERR_OK;
}

#ifdef PI_LATENCY
static ivas_error packPiLatency( const IVAS_PIDATA_GENERIC *piData, uint8_t *buffer, uint32_t maxDataBytes, uint32_t *nBytesWritten )
{
    uint32_t typeBits;
    uint32_t latencyBits;
    uint32_t word;
    uint32_t nBytes = 0;
    const IVAS_PIDATA_REVERSE_PI_LATENCY *p = (const IVAS_PIDATA_REVERSE_PI_LATENCY *) piData;

    *nBytesWritten = 0;
    if ( piData->size != sizeof( IVAS_PIDATA_REVERSE_PI_LATENCY ) )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect size for PI_LATENCY data" );
    }
    if ( piData->piDataType != IVAS_PI_PI_LATENCY )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "Incorrect PI ID for PI_LATENCY data" );
    }
    if ( maxDataBytes < 2 + 4 )
    {
        return IVAS_ERROR( IVAS_ERR_RTP_INSUFFICIENT_OUTPUT_SIZE, "Insufficient space to pack PI_LATENCY data" );
    }

    buffer[nBytes++] = ( p->piDataType & MASK_5BIT );
    buffer[nBytes++] = 4;

    typeBits = (uint32_t)( p->type & MASK_5BIT );
    latencyBits = (uint32_t)( p->latency & 0x07FFFFFF );
    word = ( typeBits << 27 ) | latencyBits;

    buffer[nBytes++] = (uint8_t)( word >> 24 );
    buffer[nBytes++] = (uint8_t)( word >> 16 );
    buffer[nBytes++] = (uint8_t)( word >> 8 );
    buffer[nBytes++] = (uint8_t)( word );
    *nBytesWritten = nBytes;

    return IVAS_ERR_OK;
}

static ivas_error unpackPiLatency( const uint8_t *buffer, uint32_t numDataBytes, IVAS_PIDATA_GENERIC *piData )
{
    uint32_t word;
    uint32_t lat;
    IVAS_PIDATA_REVERSE_PI_LATENCY *p = (IVAS_PIDATA_REVERSE_PI_LATENCY *) piData;

    if ( numDataBytes != 4 )
    {
        return IVAS_ERROR( IVAS_ERR_RTP_UNPACK_PI_DATA, "Incorrect size to unpack PI_LATENCY data" );
    }

    p->size = sizeof( IVAS_PIDATA_REVERSE_PI_LATENCY );
    p->piDataType = IVAS_PI_PI_LATENCY;

    word = ((uint32_t)buffer[0] << 24) | ((uint32_t)buffer[1] << 16) |
                    ((uint32_t)buffer[2] << 8) | (uint32_t)buffer[3];
    p->type = (IVAS_PI_TYPE)( ( word >> 27 ) & MASK_5BIT );
    lat = word & 0x07FFFFFF;

    /* Sign-extend 27-bit value */
    if ( lat & ( 1u << 26 ) )
        p->latency = (int32_t)( lat | ~0x07FFFFFF );
    else
        p->latency = (int32_t) lat;

    return IVAS_ERR_OK;
}
#endif

#endif /* RTP_S4_251135_CR26253_0016_REV1 */

@@ -668,14 +735,19 @@ static const PACK_PI_FN packPiDataFuntions[IVAS_PI_MAX_ID] = {
    packListenerPosition,   /* LISTENER_POSITION                */
    packDynamicSuppression, /* DYNAMIC_AUDIO_SUPPRESSION        */
    packAudioFocusCommon,   /* AUDIO_FOCUS_REQUEST              */
#ifdef PI_LATENCY
    packPiLatency,          /* PI_LATENCY                       */
#else
    packUnsupportedData,    /* PI_LATENCY                       */
#endif
#else
    packUnsupportedData,   /* PLAYBACK_DEVICE_ORIENTATION      */
    packUnsupportedData,   /* HEAD_ORIENTATION                 */
    packUnsupportedData,   /* LISTENER_POSITION                */
    packUnsupportedData,   /* DYNAMIC_AUDIO_SUPPRESSION        */
    packUnsupportedData,   /* AUDIO_FOCUS_DIRECTION            */
#endif
    packUnsupportedData,   /* PI_LATENCY                       */
#endif
    packUnsupportedData, /* R_ISM_ID                         */
    packUnsupportedData, /* R_ISM_GAIN                       */
#ifdef RTP_S4_251135_CR26253_0016_REV1
@@ -727,14 +799,19 @@ static const UNPACK_PI_FN unpackPiDataFuntions[IVAS_PI_MAX_ID] = {
    unpackListenerPosition,   /* LISTENER_POSITION                */
    unpackDynamicSuppression, /* DYNAMIC_AUDIO_SUPPRESSION        */
    unpackAudioFocusCommon,   /* AUDIO_FOCUS_REQUEST              */
#ifdef PI_LATENCY
    unpackPiLatency,          /* PI_LATENCY                       */
#else
    unpackUnsupportedData, /* PI_LATENCY                       */
#endif
#else
    unpackUnsupportedData, /* PLAYBACK_DEVICE_ORIENTATION      */
    unpackUnsupportedData, /* HEAD_ORIENTATION                 */
    unpackUnsupportedData, /* LISTENER_POSITION                */
    unpackUnsupportedData, /* DYNAMIC_AUDIO_SUPPRESSION        */
    unpackUnsupportedData, /* AUDIO_FOCUS_DIRECTION            */
#endif
    unpackUnsupportedData, /* PI_LATENCY                       */
#endif
    unpackUnsupportedData, /* R_ISM_ID                         */
    unpackUnsupportedData, /* R_ISM_GAIN                       */
#ifdef RTP_S4_251135_CR26253_0016_REV1
+24 −2
Original line number Diff line number Diff line
@@ -394,6 +394,11 @@ class AUDIO_FOCUS:
    direction: Optional[ORIENTATION] = None
    level: Optional[AUDIO_FOCUS_LEVEL] = None

@dataclass
class PI_LATENCY:
    reverseType: PIDATAS
    latency: int


@dataclass
class PIDATA:
@@ -923,6 +928,23 @@ def packAudioFocus(bitstrm: BitStream, data: any):
        bitstrm.append(f"uint:4={level}")
        bitstrm.append(f"uint:4=0")

def unpackPiLatency(bitstrm: ConstBitStream, piSize: int) -> PI_LATENCY:
    assert piSize == 4, "PI_LATENCY must be 4 bytes"
    word = bitstrm.read(32).uint
    typeBits = (word >> 27) & 0x1F
    reverseType = PiTypeNames[typeBits]
    raw = word & 0x07FFFFFF
    # Sign-extend 27-bit
    if raw & (1 << 26):
        raw = raw | ~0x07FFFFFF
    return PI_LATENCY(reverseType, int(raw))

def packPiLatency(bitstrm: BitStream, data: any) -> None:
    assert type(data) == PI_LATENCY, "PI_LATENCY pack expects PI_LATENCY data"
    idx = PiTypeNames.index(data.reverseType)
    latency = data.latency & 0x07FFFFFF
    word = (idx << 27) | latency
    bitstrm.append(f"uint:32={word}")

PIDataUnpacker = [
    unpackOrientation,  # SCENE_ORIENTATION,
@@ -946,7 +968,7 @@ PIDataUnpacker = [
    unpackPosition,  # LISTENER_POSITION
    unpackDAS,  # DYNAMIC_AUDIO_SUPPRESSION_REQUEST
    unpackAudioFocus,  # AUDIO_FOCUS_REQUEST
    unpackUnsupported,  # PI_LATENCY
    unpackPiLatency,    # PI_LATENCY
    unpackUnsupported,  # R_ISM_ID
    unpackUnsupported,  # R_ISM_GAIN
    unpackOrientation,  # R_ISM_ORIENTATION
@@ -981,7 +1003,7 @@ PIDataPacker = [
    packPosition,  # LISTENER_POSITION
    packDAS,  # DYNAMIC_AUDIO_SUPPRESSION_REQUEST
    packAudioFocus,  # AUDIO_FOCUS_DIRECTION
    packUnsupported,  # PI_LATENCY
    packPiLatency,    # PI_LATENCY
    packUnsupported,  # R_ISM_ID
    packUnsupported,  # R_ISM_GAIN
    packOrientation,  # R_ISM_ORIENTATION
+17 −1
Original line number Diff line number Diff line
@@ -228,6 +228,17 @@ def generatePiData(startTs: int, endTs: int) -> dict:
    someAuFocusLvl = lambda: AUDIO_FOCUS(level=AUDIO_FOCUS_LEVEL(random.randint(0, 15)))
    someAuFocusList = [someAuFocusDirLvl, someAuFocusDir, someAuFocusLvl]
    
    someLatency = lambda: PI_LATENCY(
        reverseType=random.choice([
            "PLAYBACK_DEVICE_ORIENTATION",
            "HEAD_ORIENTATION",
            "LISTENER_POSITION",
            "DYNAMIC_AUDIO_SUPPRESSION_REQUEST",
            "AUDIO_FOCUS_REQUEST"
        ]),
        latency=random.randint(- (1 << 26), (1 << 26) - 1)
    )
    
    for ts in range(startTs, endTs, 320):
        pidata = dict()
        pidata["SCENE_ORIENTATION"] = someOrientation()
@@ -243,6 +254,7 @@ def generatePiData(startTs: int, endTs: int) -> dict:
        pidata["ACOUSTIC_ENVIRONMENT"] = ACOUSTIC_ENVIRONMENT(
            aeid=random.randint(0, 127)
        )
        pidata["PI_LATENCY"] = someLatency()
        data[str(ts)] = pidata
    return data

@@ -637,6 +649,10 @@ def run_rtp_bitstream_tests(
                            generatedPIData[ts][pitype], decodedPiData[ts][pitype]
                        ):
                            isEqualAD(AUDIO_DESCRIPTION(**d), r)
                    elif type(generatedPIData[ts][pitype]) == PI_LATENCY:
                        # Decoded JSON stores latency as integer
                        assert int(decodedPiData[ts][pitype]) == data.latency, \
                            f"PI_LATENCY mismatch: {decodedPiData[ts][pitype]} != {data.latency}"
                    else:
                        assert False, "Unsupported PI data found"