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

complete RTPDUMP (as defined by rtptools) implementation; add tests and a few fixes

parent e12d941d
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -168,6 +168,8 @@
/* #################### Start NON-BE switches ############################ */
/* any switch which is non-be wrt. TS 26.258 V3.0 */

#define USE_RTPDUMP 1                           /* FhG: RTPDUMP format (rtptools standard) instead of custom format */


/* ##################### End NON-BE switches ########################### */

+26 −10
Original line number Diff line number Diff line
@@ -869,13 +869,24 @@ void IVAS_RTP_Term(
    }
}

#ifdef FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API
ivas_error IVAS_RTP_WRITER_Init(
    IVAS_RTP *rtp,                       /* i/o : IVAS RTP File writer handle      */
    const char *outputBitstreamFilename, /* i   : RTP Dump filename                */
    uint32_t numFramesPerPacket,         /* i   : No. of frames per packet desired */
    uint8_t payloadType,                 /* i   : Payload Type negotiated via sdp  */
    uint32_t SSRC,                       /* i   : SSRC for RTP Header              */
    uint16_t seqNumInitVal               /* i   : Initial seq number in rtp header */
)
#else
ivas_error IVAS_RTP_WRITER_Init(
    IVAS_RTP *rtp,                       /* i/o : IVAS RTP File writer handle      */
    const char *outputBitstreamFilename, /* i   : RTP Dump filename                */
    uint32_t numFramesPerPacket,         /* i   : No. of frames per packet desired */
    uint32_t SSRC,                       /* i   : SSRC for RTP Header              */
    uint16_t seqNumInitVal               /* i   : Initial seq number in rtp header */
)
#endif
{
    ivas_error error = IVAS_ERR_OK;

@@ -896,8 +907,14 @@ ivas_error IVAS_RTP_WRITER_Init(
            {
                return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "rtpdump open error %d", rderr );
            }
            /* start sequence numbering at zero */
            rtp->nextSeq = 0;
            /* initialize sequence number and RTP header fields */
            rtp->nextSeq = seqNumInitVal;
            rtp->ssrc = SSRC;
#ifdef FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API
            rtp->pt = payloadType;
#else
            rtp->pt = 96; /* hard-coded for now */
#endif
        }
#else
        error = IvasRtpFile_Open( outputBitstreamFilename, true, &rtp->hRtpFile );
@@ -905,23 +922,19 @@ ivas_error IVAS_RTP_WRITER_Init(
        {
            return error;
        }
#endif

        /* initialize RTP packer header sequence only in file-based mode */
#ifndef USE_RTPDUMP
#ifdef FIXED_RTP_SEQUENCE_NUM
#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
        error = IVAS_RTP_PACK_UpdateHeader( rtp->hPack, seqNumInitVal, SSRC, 0, NULL, 0, 0, NULL );
#endif
        if ( error != IVAS_ERR_OK )
        {
            fprintf( stderr, "error in IVAS_RTP_PACK_UpdateHeader(): %d\n", error );
        }
#endif
#else
        rtp->ssrc = SSRC;
        rtp->pt = 96; /* hard-coded for now */
#ifdef FIXED_RTP_SEQUENCE_NUM
        rtp->nextSeq = seqNumInitVal;
#endif
#endif
    }

@@ -1062,6 +1075,9 @@ ivas_error IVAS_RTP_WriteNextFrame(
            /* set proper header and payload sizes */
            pkt.headerSize = 12;
            pkt.payloadSize = (unsigned short) ( len - pkt.headerSize );
            /* override header fields to match configured values */
            pkt.ssrc = rtp->ssrc;
            pkt.payloadTypeId = rtp->pt;
            /* override sequence number to enforce 1-step increments */
            pkt.sequenceNumber = rtp->nextSeq++;
            /* compute time offset in ms from RTP timestamp (16kHz clock) */
+5 −2
Original line number Diff line number Diff line
@@ -33,8 +33,7 @@
#ifndef IVAS_RTP_FILE_H
#define IVAS_RTP_FILE_H

#define USE_RTPDUMP 1

#include "options.h"
#include "common_api_types.h"
#include "ivas_rtp_api.h"
#include "ivas_rtp_pi_data.h"
@@ -78,7 +77,11 @@ typedef struct
    IVAS_RTP_SR_INFO srInfo;
} IVAS_RTP;

#ifdef FIX_1540_EXPOSE_PT_IN_RTP_HEADER_API
ivas_error IVAS_RTP_WRITER_Init( IVAS_RTP *rtp, const char *outputBitstreamFilename, uint32_t numFramesPerPacket, uint8_t payloadType, uint32_t SSRC, uint16_t seqNumInitVal );
#else
ivas_error IVAS_RTP_WRITER_Init( IVAS_RTP *rtp, const char *outputBitstreamFilename, uint32_t numFramesPerPacket, uint32_t SSRC, uint16_t seqNumInitVal );
#endif
ivas_error IVAS_RTP_READER_Init( IVAS_RTP *rtp, const char *inputBitstreamFilename, const char *piOutputFilename, bool isExtOutput, const char *outputWavFilename );
void IVAS_RTP_Term( IVAS_RTP *rtp );
ivas_error IVAS_RTP_WriteNextFrame( IVAS_RTP *rtp, uint8_t *au, const IVAS_RTP_SR_INFO *srInfo, int16_t auSizeBits, bool isMono, bool forcePacket );
+95 −9
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
@@ -198,10 +199,22 @@ static int readHeader( struct RTPDUMP *hRTPDUMP )
static int writeHeader( struct RTPDUMP *hRTPDUMP )
{
    /* write rtpdump header */
    /* 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;
        fprintf( hRTPDUMP->file, "#!rtpplay%s %s/%d\n", "1.0", "127.0.0.1", hRTPDUMP->port );
    }

    /* 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 %03u.%03u.%03u.%03u/%05u\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 ) &&
@@ -210,7 +223,6 @@ static int writeHeader( struct RTPDUMP *hRTPDUMP )
    {
        return 0;
    }
    }
    return -1;
}

@@ -260,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;
@@ -268,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,
+19 −1
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ extern "C"
{
#endif

#define RTPDUMP_MAX_PACKET_SIZE 12300 /* Maximum size of an RTP packet, 12300 to cover IVAS jumbo packets, 1458 for MTU size 1500 */

    typedef enum _RTPDUMP_ERROR
    {
        RTPDUMP_NO_ERROR = 0x0000,
@@ -68,7 +70,7 @@ extern "C"
        unsigned short sequenceNumber;
        unsigned int timeStamp;
        unsigned int ssrc;
        char data[1500 + 12]; /* raw RTP packet */
        char data[RTPDUMP_MAX_PACKET_SIZE]; /* raw RTP packet */
        unsigned short headerSize;
        unsigned short payloadSize;
    } RTPDUMP_RTPPACKET;
@@ -83,6 +85,22 @@ extern "C"
    RTPDUMP_ERROR
    RTPDUMP_OpenForWriting( RTPDUMP_HANDLE *phRTPDUMP, const char *filename );

#ifdef USE_RTPDUMP
    RTPDUMP_ERROR
    RTPDUMP_SetHeaderInfo( RTPDUMP_HANDLE hRTPDUMP,
                           uint32_t source,
                           uint16_t port,
                           uint32_t startSeconds,
                           uint32_t startMicroSeconds );

    RTPDUMP_ERROR
    RTPDUMP_GetHeaderInfo( RTPDUMP_HANDLE hRTPDUMP,
                           uint32_t *source,
                           uint16_t *port,
                           uint32_t *startSeconds,
                           uint32_t *startMicroSeconds );
#endif

    RTPDUMP_ERROR
    RTPDUMP_ReadPacket( RTPDUMP_HANDLE hRTPDUMP,
                        RTPDUMP_RTPPACKET *packet,
Loading