Commit 900a498b authored by vaclav's avatar vaclav
Browse files

introduce IVAS_DEC_GetSamples_wrapper() and move IVAS_DEC_Setup() to decoder app.

parent f2ae2d87
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -3477,10 +3477,22 @@ static ivas_error decodeVoIP(

#ifdef SPLIT_REND_WITH_HEAD_ROT
#ifdef SUPPORT_JBM_TRACEFILE
#ifdef MEM_ALLOC_APP_DEC_JBM
        int16_t nSamplesRendered_pre = 0;

        if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered_pre, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK )
#else
        if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK )
#endif
#else
#ifdef MEM_ALLOC_APP_DEC_JBM
        int16_t nSamplesRendered_pre = 0;

        if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms, &nSamplesRendered_pre ) ) != IVAS_ERR_OK )
#else
        if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, (void *) pcmBuf, systemTime_ms ) ) != IVAS_ERR_OK )
#endif
#endif
#else
#ifdef SUPPORT_JBM_TRACEFILE
        if ( ( error = IVAS_DEC_VoIP_GetSamples( hIvasDec, nOutSamples, pcmBuf, systemTime_ms, writeJbmTraceFileFrameWrapper, jbmTraceWriter ) ) != IVAS_ERR_OK )
@@ -3493,6 +3505,24 @@ static ivas_error decodeVoIP(
            goto cleanup;
        }

#ifdef MEM_ALLOC_APP_DEC_JBM
        /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */
        uint16_t nSamplesRendered2 = 0;
        if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcmBuf + nSamplesRendered_pre * nOutChannels ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
            return error;
        }

        /* decode frame and get samples */
        if ( ( error = IVAS_DEC_GetSamples_wrapper( hIvasDec, nOutSamples, IVAS_DEC_PCM_INT16, pcmBuf, nSamplesRendered_pre ) ) != IVAS_ERR_OK )
        {
            fprintf( stderr, "\nError in IVAS_DEC_GetSamples_wrapper: %s\n", IVAS_DEC_GetErrorMessage( error ) );
            goto cleanup;
        }
#endif


        /* write JBM Offset file entry */
        if ( jbmOffsetWriter != NULL )
        {
+45 −20
Original line number Diff line number Diff line
@@ -1016,7 +1016,7 @@ ivas_error IVAS_DEC_GetSamples(
#ifdef MEM_ALLOC_APP_DEC_JBM
            if ( flag_decode == 0 )
            {
                *nOutSamples = -1; // TBD
                *nOutSamples = -1;

                return IVAS_ERR_OK;
            }
@@ -1401,6 +1401,14 @@ ivas_error IVAS_DEC_Setup(
        return IVAS_ERR_OK;
    }

#ifdef MEM_ALLOC_APP_DEC_JBM
    if ( !( hIvasDec->hasBeenFedFirstGoodFrame && ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) ) )
    {
        /* no frame was fed, do nothing */
        return IVAS_ERR_OK;
    }
#endif

    if ( hIvasDec->mode == IVAS_DEC_MODE_EVS )
    {
        /* EVS decoding, do nothing */
@@ -2808,6 +2816,10 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
    int16_t *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels  */
#endif
    const uint32_t systemTimestamp_ms /* i  : current system timestamp                    */
#ifdef MEM_ALLOC_APP_DEC_JBM
    ,
    int16_t *nSamplesRendered_pre
#endif
#ifdef SUPPORT_JBM_TRACEFILE
    ,
    JbmTraceFileWriterFn jbmWriterFn,
@@ -2988,6 +3000,8 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
#ifdef MEM_ALLOC_APP_DEC_JBM
            if ( nSamplesRendered_loop == -1 )
            {
                *nSamplesRendered_pre = nSamplesRendered;

                break;
            }
#endif
@@ -2997,39 +3011,50 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
        }
    }

    return IVAS_ERR_OK;
}

#ifdef MEM_ALLOC_APP_DEC_JBM
    if ( hIvasDec->hasBeenFedFirstGoodFrame )
    {
        if ( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
        {
            uint16_t nSamplesRendered2 = 0; // VE: todo - verify use for EVS

            /* Reconfigure IVAS decoder handles and reallocate the memory if IVAS total bitrate has changed */
            if ( ( error = IVAS_DEC_Setup( hIvasDec, &nSamplesRendered2, IVAS_DEC_PCM_INT16, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ) ) ) != IVAS_ERR_OK )
            {
                fprintf( stderr, "\nIVAS_DEC_Setup failed: %s\n\n", IVAS_DEC_GetErrorMessage( error ) );
                return error;
            }
        }
/*---------------------------------------------------------------------*
 * IVAS_DEC_GetSamples_wrapper( )
 *
 * Main function to decode one frame in VoIP
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_GetSamples_wrapper(
    IVAS_DEC_HANDLE hIvasDec,          /* i/o: IVAS decoder handle                      */
    const int16_t nSamplesAsked,       /* i  : number of samples wanted by the caller   */
    const IVAS_DEC_PCM_TYPE pcmType,   /* i  : type for the decoded PCM resolution      */
    void *pcmBuf,                      /* o  : output synthesis signal                  */
    const int16_t nSamplesRendered_pre /* i  : number of samples already rendered       */
)
{
    ivas_error error;
    int16_t nOutChannels;
    int16_t nSamplesToRender, nSamplesRendered_loop;
    bool tmp;
        nSamplesToRender = nSamplesPerChannel - nSamplesRendered;

    nOutChannels = hIvasDec->st_ivas->hDecoderConfig->nchan_out;
    nSamplesToRender = nSamplesAsked - nSamplesRendered_pre;

    if ( hIvasDec->hasBeenFedFirstGoodFrame )
    {
        /* render IVAS frames directly to the output buffer */
        if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered * nOutChannels ), &nSamplesRendered_loop, &tmp, 1 ) ) != IVAS_ERR_OK )
        if ( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmType, pcm_buffer_offset( pcmBuf, pcmType, nSamplesRendered_pre * nOutChannels ), &nSamplesRendered_loop, &tmp, 1 ) ) != IVAS_ERR_OK )
        {
            return error;
        }

        nSamplesRendered += nSamplesRendered_loop;
        //nSamplesRendered_pre += nSamplesRendered_loop;
        update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop );
    }
#endif

    return IVAS_ERR_OK;
}

#endif

/*---------------------------------------------------------------------*
 * update_voip_rendered20ms( )
 *
+14 −0
Original line number Diff line number Diff line
@@ -310,12 +310,26 @@ ivas_error IVAS_DEC_VoIP_GetSamples(
    int16_t *pcmBuf,                            /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels  */
#endif
    const uint32_t systemTimestamp_ms           /* i  : current system timestamp                                                */
#ifdef MEM_ALLOC_APP_DEC_JBM
    ,
    int16_t *nSamplesRendered_pre
#endif
#ifdef SUPPORT_JBM_TRACEFILE
    , JbmTraceFileWriterFn jbmWriterFn,
    void* jbmWriter
#endif
);

#ifdef MEM_ALLOC_APP_DEC_JBM
ivas_error IVAS_DEC_GetSamples_wrapper(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    const int16_t nSamplesAsked,                /* i  : number of samples wanted by the caller                                  */
    const IVAS_DEC_PCM_TYPE pcmType,            /* i  : type for the decoded PCM resolution                                     */
    void *pcmBuf,                               /* o  : output synthesis signal                                                 */
    const int16_t nSamplesRendered_pre          /* i  : number of samples already rendered                                      */
);

#endif
ivas_error IVAS_DEC_Flush(
    IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle                                                     */
    const int16_t nSamplesPerChannel,           /* i  : number of samples per channel requested to be written to output buffer  */