Commit 262bc04e authored by Vladimir Malenovsky's avatar Vladimir Malenovsky
Browse files

fix cases where st_ivas->ind_list_metadata is NULL

parent 69eac64a
Loading
Loading
Loading
Loading
Loading
+14 −7
Original line number Diff line number Diff line
@@ -375,7 +375,9 @@ ivas_error ivas_init_encoder(
    /* set the maximum allowed number of metadata indices in the list */
    st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate );

    /* allocate buffer of indices */
    /* allocate buffer of metadata indices */
    if ( st_ivas->ivas_max_num_indices_metadata > 0 )
    {
        if ( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
        {
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
@@ -386,6 +388,11 @@ ivas_error ivas_init_encoder(
        {
            st_ivas->ind_list_metadata[i].nb_bits = -1;
        }
    }
    else
    {
        st_ivas->ind_list_metadata = NULL;
    }
#endif

    /*-----------------------------------------------------------------*
+26 −10
Original line number Diff line number Diff line
@@ -1167,11 +1167,9 @@ ivas_error IVAS_ENC_EncodeFrameToSerial(
    {
        /* de-allocate old buffer of indices */
        free( st_ivas->ind_list );
        free( st_ivas->ind_list_metadata );

        /* set the maximum allowed number of indices in the list */
        st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );
        st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );

        /* allocate new buffer of indices */
        if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL )
@@ -1179,23 +1177,41 @@ ivas_error IVAS_ENC_EncodeFrameToSerial(
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) );
        }

        if ( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
        {
            return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
        }

        /* reset the list of indices */
        for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
        {
            st_ivas->ind_list[i].nb_bits = -1;
        }

        /* de-allocate old buffer of metadata indices */
        if ( st_ivas->ind_list_metadata != NULL )
        {
            free( st_ivas->ind_list_metadata );
        }

        /* set the maximum allowed number of metadata indices in the list */
        st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );

        if ( st_ivas->ivas_max_num_indices_metadata > 0 )
        {
            /* allocate new buffer of metadata indices */
            if ( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
            {
                return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
            }

            /* reset the list of metadata indices */
            for ( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ )
            {
                st_ivas->ind_list_metadata[i].nb_bits = -1;
            }
        }
        else
        {
            st_ivas->ind_list_metadata = NULL;
        }

        /* set pointers to the new buffer of indices in each element */
        /* set pointers to the new buffers of indices in each element */
        for ( n = 0; n < st_ivas->nSCE; n++ )
        {
            st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list;