Commit 8dc46d69 authored by vaclav's avatar vaclav
Browse files

Merge remote-tracking branch 'remotes/origin/main' into memory_alloc_from_api_3GPP

parents 23bb5e7a d804c8e9
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3129,7 +3129,7 @@ static ivas_error printBitstreamInfoVoip(
{
    bool previewFailed = true;
    ivas_error error = IVAS_ERR_OK;
    IVAS_RTP ivasRtp;
    IVAS_RTP ivasRtp = { 0 };
    uint8_t au[( IVAS_MAX_BITS_PER_FRAME + 7 ) >> 3];
    int16_t auSizeBits;
    uint8_t *auPtr = NULL;
+1 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@
/* #################### Start NON-BE switches ############################ */
/* any switch which is non-be wrt. TS 26.258 V3.0 */

#define USE_RTPDUMP                                     /* FhG: RTPDUMP format (rtptools standard) instead of custom format */
#define FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API            /* Expose Payload Type setting in RTP Header */
#define FIX_FLOAT_1569_REND_RENDER_CONFIG_CHECKS        /* Nokia: float issue 1569: fix render config checks in renderer */
#define FIX_1571_BFI_COPY_ARRAY_CORRECT_LEN             /* FhG: issue 1571: use correct channel signal length for copying signal to buffer */
+71 −1
Original line number Diff line number Diff line
@@ -36,12 +36,23 @@
#include <stdbool.h>  // bool type
#include "ivas_rtp_file.h"
#include "ivas_error_utils.h"
#ifdef USE_RTPDUMP
#include "rtpdump.h"

struct IVAS_RTP_FILE
{
    bool isFileWriter;
    RTPDUMP_HANDLE f_rtpstream;
    uint32_t offset_ms;
};

#else  // USE_RTPDUMP
struct IVAS_RTP_FILE
{
    bool isFileWriter;
    FILE *f_rtpstream;
};
#endif // USE_RTPDUMP

static ivas_error IvasRtpFile_Open(
    const char *filePath,           /* i : path to CA config file                */
@@ -49,6 +60,22 @@ static ivas_error IvasRtpFile_Open(
    IVAS_RTP_FILE_HANDLE *phRtpFile /* o : pointer to an IVAS file reader handle */
)
{
#ifdef USE_RTPDUMP
    RTPDUMP_HANDLE f_rtpstream;
    RTPDUMP_ERROR rderr;
    if ( isFileWriter )
    {
        rderr = RTPDUMP_OpenForWriting( &f_rtpstream, filePath );
    }
    else
    {
        rderr = RTPDUMP_OpenForReading( &f_rtpstream, filePath );
    }
    if ( rderr != RTPDUMP_NO_ERROR )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "rtpdump open error %d", rderr );
    }
#else // USE_RTPDUMP
    FILE *f_rtpstream;
    char *mode = isFileWriter ? "wb" : "rb";

@@ -58,6 +85,7 @@ static ivas_error IvasRtpFile_Open(
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "could not open: %s\n", filePath );
    }

#endif // USE_RTPDUMP
    *phRtpFile = calloc( 1, sizeof( struct IVAS_RTP_FILE ) );
    if ( *phRtpFile != NULL )
    {
@@ -76,7 +104,11 @@ static ivas_error IvasRtpFile_Close(
    {
        if ( ( *phReader )->f_rtpstream != NULL )
        {
#ifdef USE_RTPDUMP
            RTPDUMP_Close( &( *phReader )->f_rtpstream, 1 );
#else  // USE_RTPDUMP
            fclose( ( *phReader )->f_rtpstream );
#endif // USE_RTPDUMP
            ( *phReader )->f_rtpstream = NULL;
        }
        free( *phReader );
@@ -94,9 +126,20 @@ static ivas_error IvasRtpFile_Write(
    ivas_error error = IVAS_ERR_OK;
    if ( hRtpFile->isFileWriter )
    {
#ifdef USE_RTPDUMP
        RTPDUMP_RTPPACKET pkt;
        RTPDUMP_SetDefaultRtpPacketHeader( &pkt );
        numBytes = ( numBytes > sizeof( pkt.data ) ) ? sizeof( pkt.data ) : numBytes;
        memcpy( pkt.data, packet, numBytes );
        RTPDUMP_ParseRTPHeader( &pkt );
        pkt.payloadSize = (unsigned short) ( numBytes - pkt.headerSize );
        /* compute time offset in ms from RTP timestamp (16kHz clock) */
        error = ( RTPDUMP_WritePacket( hRtpFile->f_rtpstream, &pkt, pkt.timeStamp / 16 ) != RTPDUMP_NO_ERROR ) ? IVAS_ERR_FAILED_FILE_WRITE : IVAS_ERR_OK;
#else  // USE_RTPDUMP
        uint32_t length = (uint32_t) numBytes; /* Max packet length is < 32 bits*/
        fwrite( &length, sizeof( uint32_t ), 1, hRtpFile->f_rtpstream );
        fwrite( packet, sizeof( uint8_t ), numBytes, hRtpFile->f_rtpstream );
#endif // USE_RTPDUMP
    }
    else
    {
@@ -113,12 +156,35 @@ static ivas_error IvasRtpFile_Read(
)
{
    size_t nread = 0;
#ifndef USE_RTPDUMP
    uint32_t length = 0;
#endif // USE_RTPDUMP
    if ( hRtpFile->isFileWriter )
    {
        return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "File open for writing cannot be read" );
    }

#ifdef USE_RTPDUMP
    RTPDUMP_RTPPACKET pd;
    RTPDUMP_ERROR rderr = RTPDUMP_ReadPacket( hRtpFile->f_rtpstream, &pd, &hRtpFile->offset_ms );
    if ( rderr == RTPDUMP_READ_ENDOFFILE )
    {
        return IVAS_ERR_END_OF_FILE;
    }
    if ( rderr != RTPDUMP_NO_ERROR )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "rtpdump read error %d", rderr );
    }

    /* copy raw data to unpack buffer */
    nread = pd.headerSize + pd.payloadSize;
    if ( nread > capacity )
    {
        return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE;
    }
    memcpy( packet, pd.data, nread );
    *numBytes = nread;
#else // USE_RTPDUMP
    nread = fread( &length, sizeof( uint32_t ), 1, hRtpFile->f_rtpstream ); /* Read Packet Length */
    if ( nread == 0 )
    {
@@ -138,9 +204,11 @@ static ivas_error IvasRtpFile_Read(
        return IVAS_ERR_END_OF_FILE;
    }

#endif // USE_RTPDUMP
    return IVAS_ERR_OK;
}


static const char *const PiDataNames[IVAS_PI_MAX_ID] = {
    "SCENE_ORIENTATION", "DEVICE_ORIENTATION_COMPENSATED", "DEVICE_ORIENTATION_UNCOMPENSATED",
    "ACOUSTIC_ENVIRONMENT", "AUDIO_DESCRIPTION", "ISM_NUM", "ISM_ID", "ISM_GAIN", "ISM_ORIENTATION",
@@ -853,6 +921,7 @@ ivas_error IVAS_RTP_WRITER_Init(
            return error;
        }

        /* initialize RTP packer header sequence only in file-based mode */
#ifdef FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API
        error = IVAS_RTP_PACK_UpdateHeader( rtp->hPack, payloadType, seqNumInitVal, SSRC, 0, NULL, 0, 0, NULL );
#else
@@ -886,6 +955,7 @@ ivas_error IVAS_RTP_READER_Init(
    error = IVAS_RTP_UNPACK_Open( &rtp->hUnpack, &rtp->unpackCfg );
    if ( error == IVAS_ERR_OK )
    {
        /* Open the output file for RTPDump writing */
        error = IvasRtpFile_Open( inputBitstreamFilename, false, &rtp->hRtpFile );
        if ( error != IVAS_ERR_OK )
        {
+1 −1
Original line number Diff line number Diff line
@@ -322,7 +322,7 @@ static bool readLong(
{
    char buffer[4] = { 0 };

    if ( fread( buffer, 1, 4, file ) != 1U )
    if ( fread( buffer, 1, 4, file ) != 4U )
    {
        return false;
    }
+93 −3
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "options.h"
#include "rtpdump.h"

struct RTPDUMP
@@ -80,7 +81,7 @@ static unsigned char *parseByte( unsigned char *buffer, unsigned char *value )
static int readLong( FILE *file, unsigned int *value )
{
    char buffer[4] = { 0 };
    if ( fread( buffer, 1, 4, file ) != 1U )
    if ( fread( buffer, 1, 4, file ) != 4U )
    {
        return -1;
    }
@@ -96,7 +97,7 @@ static int readLong( FILE *file, unsigned int *value )
static int readShort( FILE *file, unsigned short *value )
{
    char buffer[2] = { 0 };
    if ( fread( buffer, 1, 2, file ) != 1U )
    if ( fread( buffer, 1, 2, file ) != 2U )
    {
        return -1;
    }
@@ -198,7 +199,22 @@ static int readHeader( struct RTPDUMP *hRTPDUMP )
static int writeHeader( struct RTPDUMP *hRTPDUMP )
{
    /* write rtpdump header */
    fprintf( hRTPDUMP->file, "#!rtpplay%s %s/%d\n", "1.0", "127.0.0.1", 5000 );
    /* Use defaults if not configured (for backward compatibility) */
    if ( hRTPDUMP->source == 0 && hRTPDUMP->port == 0 )
    {
        hRTPDUMP->source = 0x7F000001u; /* 127.0.0.1 */
        hRTPDUMP->port = 5000u;
    }

    /* Format IP address for text header */
    unsigned char ip[4];
    ip[0] = (unsigned char) ( ( hRTPDUMP->source >> 24 ) & 0xFF );
    ip[1] = (unsigned char) ( ( hRTPDUMP->source >> 16 ) & 0xFF );
    ip[2] = (unsigned char) ( ( hRTPDUMP->source >> 8 ) & 0xFF );
    ip[3] = (unsigned char) ( hRTPDUMP->source & 0xFF );

    fprintf( hRTPDUMP->file, "#!rtpplay%s %u.%u.%u.%u/%u\n", "1.0", ip[0], ip[1], ip[2], ip[3], hRTPDUMP->port );

    if ( !writeLong( hRTPDUMP->file, hRTPDUMP->startSeconds ) &&
         !writeLong( hRTPDUMP->file, hRTPDUMP->startMicroSeconds ) &&
         !writeLong( hRTPDUMP->file, hRTPDUMP->source ) &&
@@ -256,6 +272,7 @@ RTPDUMP_OpenForWriting( RTPDUMP_HANDLE *phRTPDUMP, const char *filename )
        return RTPDUMP_FILE_NOT_FOUND;
    }

    /* Write header immediately (can be updated later via RTPDUMP_SetHeaderInfo) */
    if ( writeHeader( *phRTPDUMP ) != 0 )
    {
        return RTPDUMP_INIT_ERROR;
@@ -264,6 +281,79 @@ RTPDUMP_OpenForWriting( RTPDUMP_HANDLE *phRTPDUMP, const char *filename )
    return RTPDUMP_NO_ERROR;
}

#ifdef USE_RTPDUMP
RTPDUMP_ERROR
RTPDUMP_SetHeaderInfo( RTPDUMP_HANDLE hRTPDUMP,
                       uint32_t source,
                       uint16_t port,
                       uint32_t startSeconds,
                       uint32_t startMicroSeconds )
{
    if ( !hRTPDUMP )
    {
        return RTPDUMP_NOT_INITIALIZED;
    }

    hRTPDUMP->source = source;
    hRTPDUMP->port = port;
    hRTPDUMP->startSeconds = startSeconds;
    hRTPDUMP->startMicroSeconds = startMicroSeconds;

    /* If file is open for writing, seek back and rewrite the header */
    if ( hRTPDUMP->file )
    {
        long currentPos = ftell( hRTPDUMP->file );
        if ( currentPos < 0 )
        {
            return RTPDUMP_WRITE_ERROR;
        }

        /* Seek to beginning and rewrite header */
        if ( fseek( hRTPDUMP->file, 0, SEEK_SET ) != 0 )
        {
            return RTPDUMP_WRITE_ERROR;
        }

        if ( writeHeader( hRTPDUMP ) != 0 )
        {
            return RTPDUMP_WRITE_ERROR;
        }

        /* Restore file position */
        if ( fseek( hRTPDUMP->file, currentPos, SEEK_SET ) != 0 )
        {
            return RTPDUMP_WRITE_ERROR;
        }
    }

    return RTPDUMP_NO_ERROR;
}

RTPDUMP_ERROR
RTPDUMP_GetHeaderInfo( RTPDUMP_HANDLE hRTPDUMP,
                       uint32_t *source,
                       uint16_t *port,
                       uint32_t *startSeconds,
                       uint32_t *startMicroSeconds )
{
    if ( !hRTPDUMP )
    {
        return RTPDUMP_NOT_INITIALIZED;
    }

    if ( source )
        *source = hRTPDUMP->source;
    if ( port )
        *port = hRTPDUMP->port;
    if ( startSeconds )
        *startSeconds = hRTPDUMP->startSeconds;
    if ( startMicroSeconds )
        *startMicroSeconds = hRTPDUMP->startMicroSeconds;

    return RTPDUMP_NO_ERROR;
}
#endif

RTPDUMP_ERROR
RTPDUMP_ReadPacket( RTPDUMP_HANDLE hRTPDUMP,
                    RTPDUMP_RTPPACKET *packet,
Loading