Commit 60945d28 authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

refactor to avoid sub-function call

parent 851fd41d
Loading
Loading
Loading
Loading
Loading
+26 −32
Original line number Diff line number Diff line
@@ -2274,6 +2274,22 @@ static ivas_error ivas_dec_flush_split_binaural_internal(
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits, may be NULL to discard       */
    int16_t *nOutSamples                      /* o  : number of samples per channel flushed                     */
)
{
}


/*---------------------------------------------------------------------*
 * IVAS_DEC_FlushSplitBinaural( )
 *
 * Flush split-rendering audio and metadata/bitstream.
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_FlushSplitBinaural(
    IVAS_DEC_HANDLE hIvasDec,                 /* i/o: IVAS decoder handle                                       */
    void *pcmBuf,                             /* o  : output synthesis signal for BINAURAL_SPLIT_PCM            */
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits                               */
    int16_t *nSamplesFlushed                  /* o  : number of samples per channel written to output buffer    */
)
{
    Decoder_Struct *st_ivas;
    ivas_error error;
@@ -2283,7 +2299,7 @@ static ivas_error ivas_dec_flush_split_binaural_internal(
    bool needNewFrame;
    int16_t i;

    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || nOutSamples == NULL )
    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || splitRendBits == NULL || nSamplesFlushed == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }
@@ -2300,7 +2316,7 @@ static ivas_error ivas_dec_flush_split_binaural_internal(

    if ( st_ivas->ivas_format == MONO_FORMAT || hIvasDec->nSamplesAvailableNext == 0 )
    {
        *nOutSamples = 0;
        *nSamplesFlushed = 0;
        return IVAS_ERR_OK;
    }

@@ -2312,12 +2328,12 @@ static ivas_error ivas_dec_flush_split_binaural_internal(
        p_head_pose_buf[i] = head_pose_buf[i];
    }

    if ( ( error = isar_render_poses( hIvasDec, isar_get_frame_size( st_ivas ), nOutSamples, &needNewFrame ) ) != IVAS_ERR_OK )
    if ( ( error = isar_render_poses( hIvasDec, isar_get_frame_size( st_ivas ), nSamplesFlushed, &needNewFrame ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    if ( !hIvasDec->hasBeenFedFirstGoodFrame || *nOutSamples <= 0 )
    if ( !hIvasDec->hasBeenFedFirstGoodFrame || *nSamplesFlushed <= 0 )
    {
        return IVAS_ERR_OK;
    }
@@ -2327,51 +2343,29 @@ static ivas_error ivas_dec_flush_split_binaural_internal(
       LCLD encoder assumptions and lead to a crash. Therefore, we skip
       such cases. */
    if ( st_ivas->hDecoderConfig->output_config != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM &&
         *nOutSamples < isar_get_frame_size( st_ivas ) )
         *nSamplesFlushed < isar_get_frame_size( st_ivas ) )
    {
        *nOutSamples = 0;
        *nSamplesFlushed = 0;
        splitRendBits->bits_read = 0;
        splitRendBits->bits_written = 0;
        return IVAS_ERR_OK;
    }

    if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nOutSamples, splitRendBits ) ) != IVAS_ERR_OK )
    if ( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesFlushed, splitRendBits ) ) != IVAS_ERR_OK )
    {
        return error;
    }

    if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && pcmBuf_out != NULL )
    if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM && pcmBuf != NULL )
    {
#ifndef DISABLE_LIMITER
        ivas_limiter_dec( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nOutSamples, st_ivas->BER_detect );
        ivas_limiter_dec( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesFlushed, st_ivas->BER_detect );
#endif
        ivas_syn_output( p_head_pose_buf, *nOutSamples, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf_out );
        ivas_syn_output( p_head_pose_buf, *nSamplesFlushed, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf );
    }

    return IVAS_ERR_OK;
}


/*---------------------------------------------------------------------*
 * IVAS_DEC_FlushSplitBinaural( )
 *
 * Flush split-rendering audio and metadata/bitstream.
 *---------------------------------------------------------------------*/

ivas_error IVAS_DEC_FlushSplitBinaural(
    IVAS_DEC_HANDLE hIvasDec,                 /* i/o: IVAS decoder handle                                       */
    void *pcmBuf,                             /* o  : output synthesis signal for BINAURAL_SPLIT_PCM            */
    ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits                               */
    int16_t *nSamplesFlushed                  /* o  : number of samples per channel written to output buffer    */
)
{
    if ( hIvasDec == NULL || splitRendBits == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

    return ivas_dec_flush_split_binaural_internal( hIvasDec, pcmBuf, splitRendBits, nSamplesFlushed );
}
#endif

/*---------------------------------------------------------------------*