Commit 8d19d964 authored by Stephane Ragot's avatar Stephane Ragot
Browse files

support of consistent RTP header across different encoder runs

parent 753f2543
Loading
Loading
Loading
Loading
Loading
+48 −17
Original line number Diff line number Diff line
@@ -178,8 +178,12 @@ static bool readBitrate( FILE *file, int32_t *bitrate );
static ivas_error readForcedMode( FILE *file, IVAS_ENC_FORCED_MODE *forcedMode, int32_t *forceFrameCounter );
static IVAS_ENC_FORCED_MODE parseForcedMode( char *forcedModeChar );
#endif
static int encoder_main( int argc, char *argv[] );
static void str2arg( char *str, int *argc_local, char *argv_local[] );
#ifdef IVAS_RTPDUMP
static int encoder_main( int argc, char *argv[], IVAS_RTP *ivasRtp, int init_RtpWriter );
#else
static int encoder_main( int argc, char *argv[] );
#endif


/*------------------------------------------------------------------------------------------*
@@ -198,7 +202,11 @@ int main(
    char line[256];
    int argc_local = 0;
    char *argv_local[MAX_ARGV] = { 0 };
    size_t length;
#ifdef IVAS_RTPDUMP
    IVAS_RTP ivasRtp = { 0 };
    char prev_outputBitstreamFilename[256] = { 0 };
    int rtp_term = 0;
#endif

    IVAS_ENC_PrintDisclaimer();

@@ -219,15 +227,33 @@ int main(
    while ( fgets( line, sizeof( line ), FmtSWFile ) )
    {
        /* remove trimming newline */
        length = strlen( line );
        if ( ( length > 0 ) && ( line[length - 1] == '\n' ) )
        {
            line[length - 1] = '\0';
        }
        line[strcspn( line, "\r\n" )] = 0; 
        printf( "Processing format switching commandline: %s\n", line );
        str2arg( line, &argc_local, argv_local );
#ifdef IVAS_RTPDUMP
        if ( strcmp( argv_local[argc_local - 1], (char *) prev_outputBitstreamFilename ) == 0 )
        {
            /* append to last Rtp file */
            encoder_main( argc_local, argv_local, &ivasRtp, 0 );
        }
        else
        {
            if ( rtp_term == 1 )
            {
                IVAS_RTP_Term( &ivasRtp );
            }
            /* write in separate Rtp file */
            encoder_main( argc_local, argv_local, &ivasRtp, 1 );
            rtp_term = 1;
        }
        strcpy( (char *) prev_outputBitstreamFilename, argv_local[argc_local - 1] );
#else
        encoder_main( argc_local, argv_local );
#endif
    }
#ifdef IVAS_RTPDUMP
    IVAS_RTP_Term( &ivasRtp );
#endif
    fclose( FmtSWFile );
    exit( 0 );
}
@@ -257,7 +283,13 @@ void str2arg(

int encoder_main(
    int argc,
#ifdef IVAS_RTPDUMP
    char *argv[],
    IVAS_RTP *ivasRtp,
    int init_RtpWriter )
#else
    char *argv[] )
#endif
{
    bool mainFailed = true; /* Assume main failed until cleanup is reached without errors */
    EncArguments arg;
@@ -300,7 +332,7 @@ int encoder_main(

#ifdef IVAS_RTPDUMP
    uint8_t au[IVAS_MAX_BITS_PER_FRAME / 8];
    IVAS_RTP ivasRtp = { 0 };
    /* IVAS_RTP ivasRtp = { 0 }; */
#endif

    /*------------------------------------------------------------------------------------------*
@@ -327,7 +359,6 @@ int encoder_main(
    /*------------------------------------------------------------------------------------------*
     * Open output bitstream file
     *------------------------------------------------------------------------------------------*/
    printf( "bst = %s\n", arg.outputBitstreamFilename );
    const BS_WRITER_FORMAT bsWriterFormat = arg.mimeOutput ? BS_WRITER_FORMAT_MIME : BS_WRITER_FORMAT_G192;

#ifdef IVAS_RTPDUMP
@@ -697,9 +728,9 @@ int encoder_main(
     * RTPDump
     *------------------------------------------------------------------------------------------*/

    if ( arg.rtpdumpOutput )
    if ( arg.rtpdumpOutput && init_RtpWriter )
    {
        if ( ( error = IVAS_RTP_WRITER_Init( &ivasRtp, arg.outputBitstreamFilename, arg.numFramesPerPacket ) ) != IVAS_ERR_OK )
        if ( ( error = IVAS_RTP_WRITER_Init( ivasRtp, arg.outputBitstreamFilename, arg.numFramesPerPacket ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError: Can't open output bitstream file for RTP output %s \n\n", arg.outputBitstreamFilename );
            goto cleanup;
@@ -898,17 +929,17 @@ int encoder_main(

        /* *** Encode one frame *** */
#ifdef IVAS_RTPDUMP
        if ( ivasRtp.hPack )
        if ( ivasRtp->hPack )
        {
            bool isMono = ( arg.inputFormat == IVAS_ENC_INPUT_MONO );
            bool forcePacket = ( numSamplesRead < pcmBufSize ); /* If EoF force Packet generation */

            ivasRtp.nWrittenPiData = 0;
            ivasRtp->nWrittenPiData = 0;

            /* scene orientation */
            if ( sceneOrientationFileReader )
            {
                PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++];
                PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++];
                IVAS_PIDATA_ORIENTATION *scene = &piDataTs->data.scene;

                memset( piDataTs, 0, sizeof( PIDATA_TS ) );
@@ -925,7 +956,7 @@ int encoder_main(
            /* device orientation */
            if ( deviceOrientationFileReader )
            {
                PIDATA_TS *piDataTs = &ivasRtp.piData[ivasRtp.nWrittenPiData++];
                PIDATA_TS *piDataTs = &ivasRtp->piData[ivasRtp->nWrittenPiData++];
                IVAS_PIDATA_ORIENTATION *device = &piDataTs->data.deviceUnCompensated;

                memset( piDataTs, 0, sizeof( PIDATA_TS ) );
@@ -945,7 +976,7 @@ int encoder_main(
                goto cleanup;
            }

            if ( ( error = IVAS_RTP_WriteNextFrame( &ivasRtp, au, numBits, isMono, forcePacket ) ) != IVAS_ERR_OK )
            if ( ( error = IVAS_RTP_WriteNextFrame( ivasRtp, au, numBits, isMono, forcePacket ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nError %s while pushing audio frame to RTP pack\n", IVAS_ENC_GetErrorMessage( error ) );
                goto cleanup;
@@ -1057,7 +1088,7 @@ cleanup:
        RotationFileReader_close( &deviceOrientationFileReader );
    }

    IVAS_RTP_Term( &ivasRtp );
    /* IVAS_RTP_Term( &ivasRtp ); */
#endif

    IVAS_ENC_Close( &hIvasEnc );
+2 −17
Original line number Diff line number Diff line
@@ -43,12 +43,6 @@ struct IVAS_RTP_FILE
    FILE *f_rtpstream;
};

static bool file_exists( const char *filename )
{
    struct stat buffer;
    return ( stat( filename, &buffer ) == 0 );
}

static ivas_error IvasRtpFile_Open(
    const char *filePath,           /* i : path to CA config file                */
    bool isFileWriter,              /* i : instance is a file writer else reader */
@@ -56,18 +50,9 @@ static ivas_error IvasRtpFile_Open(
)
{
    FILE *f_rtpstream;

    if ( file_exists( filePath ) )
    {
        char *mode = isFileWriter ? "ab" : "rb";
        fprintf( stderr, "Warning: Rtp file %s already exists, opening in append mode\n", filePath );
        f_rtpstream = fopen( filePath, mode );
    }
    else
    {
    char *mode = isFileWriter ? "wb" : "rb";

    f_rtpstream = fopen( filePath, mode );
    }
    if ( f_rtpstream == NULL )
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_FILE_OPEN, "could not open: %s\n", filePath );