int task_decoder_update(davs2_t *h)
{
    davs2_mgr_t *mgr  = h->task_info.taskmgr;
    davs2_seq_t *seq  = &mgr->seq_info;

    if (seq->valid_flag == 0) {
        davs2_log(h, DAVS2_LOG_ERROR, "failed to update decoder (invalid sequence header).");
        return -1;
    }

    if (h->b_sao != seq->enable_sao || h->b_alf != seq->enable_alf ||
        h->i_chroma_format != (int)seq->head.chroma_format || h->i_lcu_level != seq->log2_lcu_size ||
        h->i_image_width != (int)seq->head.width || h->i_image_height != (int)seq->head.height ||
        h->p_integral == NULL) {
        /* resolution changed */
        decoder_free_extra_buffer(h);

        /* key properties of the video sequence: size and color format */
        h->i_lcu_level      = seq->log2_lcu_size;
        h->i_lcu_size       = 1 << h->i_lcu_level;
        h->i_lcu_size_sub1  = (1 << h->i_lcu_level) - 1;
        h->i_chroma_format  = seq->head.chroma_format;
        h->i_image_width    = seq->head.width;
        h->i_image_height   = seq->head.height;
        h->i_width          = seq->i_enc_width;
        h->i_height         = seq->i_enc_height;

        h->i_width_in_scu   = h->i_width  >> MIN_CU_SIZE_IN_BIT;
        h->i_height_in_scu  = h->i_height >> MIN_CU_SIZE_IN_BIT;
        h->i_size_in_scu    = h->i_width_in_scu * h->i_height_in_scu;
        h->i_width_in_spu   = h->i_width  >> MIN_PU_SIZE_IN_BIT;
        h->i_height_in_spu  = h->i_height >> MIN_PU_SIZE_IN_BIT;
        h->i_width_in_lcu   = (h->i_width + h->i_lcu_size_sub1) >> h->i_lcu_level;
        h->i_height_in_lcu  = (h->i_height + h->i_lcu_size_sub1) >> h->i_lcu_level;

        /* encoding tools configuration */
        h->b_sao            = seq->enable_sao;
        h->b_alf            = seq->enable_alf;

        if (decoder_alloc_extra_buffer(h) < 0) {
            h->i_lcu_level     = 0;
            h->i_chroma_format = 0;
            h->i_image_width   = 0;
            h->i_image_height  = 0;

            davs2_log(h, DAVS2_LOG_ERROR, "failed to update the decoder(failed to alloc space).");

            return -1;
        }
    }

    /* update sequence header */
    h->i_chroma_format  = seq->head.chroma_format;
    h->i_lcu_level      = seq->log2_lcu_size;
    h->b_bkgnd_picture  = seq->enable_background_picture;

    // h->b_dmh            = 1;
    h->output_bit_depth = 8;
    h->sample_bit_depth = 8;

    h->p_tab_DL_avail   = tab_DL_Avails[h->i_lcu_level];
    h->p_tab_TR_avail   = tab_TR_Avails[h->i_lcu_level];

    if (seq->head.profile_id == MAIN10_PROFILE) {
        h->output_bit_depth = 6 + (seq->sample_precision << 1);
        h->sample_bit_depth = 6 + (seq->encoding_precision << 1);
    }

#if HIGH_BIT_DEPTH
    g_bit_depth   = h->sample_bit_depth;
    max_pel_value = (1 << g_bit_depth) - 1;
    g_dc_value    = 1 << (g_bit_depth - 1);
#else
    if (g_bit_depth != h->sample_bit_depth) {
        davs2_log(h, DAVS2_LOG_ERROR, "Un-supported bit-depth %d in this version.\n", h->sample_bit_depth);
        return -1;
    }
#endif

    memcpy(h->wq.seq_wq_matrix, seq->seq_wq_matrix, 2 * 64 * sizeof(int16_t)); /* weighting quantization matrix */
    memcpy(&h->seq_info, seq, sizeof(davs2_seq_t));

    return 0;
}
int task_decoder_update(davs2_t *h)
{
    davs2_mgr_t *mgr  = h->task_info.taskmgr;
    davs2_seq_t *seq  = &mgr->seq_info;

    if (seq->valid_flag == 0) {
        davs2_log(h, DAVS2_LOG_ERROR, "failed to update decoder (invalid sequence header).");
        return -1;
    }

    if (h->b_sao != seq->enable_sao || h->b_alf != seq->enable_alf ||
        h->i_chroma_format != (int)seq->head.chroma_format || h->i_lcu_level != seq->log2_lcu_size ||
        h->i_image_width != (int)seq->head.width || h->i_image_height != (int)seq->head.height ||
        h->p_integral == NULL) {
         
        decoder_free_extra_buffer(h);

         
        h->i_lcu_level      = seq->log2_lcu_size;
        h->i_lcu_size       = 1 << h->i_lcu_level;
        h->i_lcu_size_sub1  = (1 << h->i_lcu_level) - 1;
        h->i_chroma_format  = seq->head.chroma_format;
        h->i_image_width    = seq->head.width;
        h->i_image_height   = seq->head.height;
        h->i_width          = seq->i_enc_width;
        h->i_height         = seq->i_enc_height;

        h->i_width_in_scu   = h->i_width  >> MIN_CU_SIZE_IN_BIT;
        h->i_height_in_scu  = h->i_height >> MIN_CU_SIZE_IN_BIT;
        h->i_size_in_scu    = h->i_width_in_scu * h->i_height_in_scu;
        h->i_width_in_spu   = h->i_width  >> MIN_PU_SIZE_IN_BIT;
        h->i_height_in_spu  = h->i_height >> MIN_PU_SIZE_IN_BIT;
        h->i_width_in_lcu   = (h->i_width + h->i_lcu_size_sub1) >> h->i_lcu_level;
        h->i_height_in_lcu  = (h->i_height + h->i_lcu_size_sub1) >> h->i_lcu_level;

         
        h->b_sao            = seq->enable_sao;
        h->b_alf            = seq->enable_alf;

        if (decoder_alloc_extra_buffer(h) < 0) {
            h->i_lcu_level     = 0;
            h->i_chroma_format = 0;
            h->i_image_width   = 0;
            h->i_image_height  = 0;

            davs2_log(h, DAVS2_LOG_ERROR, "failed to update the decoder(failed to alloc space).");

            return -1;
        }
    }

     
    h->i_chroma_format  = seq->head.chroma_format;
    h->i_lcu_level      = seq->log2_lcu_size;
    h->b_bkgnd_picture  = seq->enable_background_picture;

     
    h->output_bit_depth = 8;
    h->sample_bit_depth = 8;

    h->p_tab_DL_avail   = tab_DL_Avails[h->i_lcu_level];
    h->p_tab_TR_avail   = tab_TR_Avails[h->i_lcu_level];

    if (seq->head.profile_id == MAIN10_PROFILE) {
        h->output_bit_depth = 6 + (seq->sample_precision << 1);
        h->sample_bit_depth = 6 + (seq->encoding_precision << 1);
    }

#if HIGH_BIT_DEPTH
    g_bit_depth   = h->sample_bit_depth;
    max_pel_value = (1 << g_bit_depth) - 1;
    g_dc_value    = 1 << (g_bit_depth - 1);
#else
    if (g_bit_depth != h->sample_bit_depth) {
        davs2_log(h, DAVS2_LOG_ERROR, "Un-supported bit-depth %d in this version.\n", h->sample_bit_depth);
        return -1;
    }
#endif

    memcpy(h->wq.seq_wq_matrix, seq->seq_wq_matrix, 2 * 64 * sizeof(int16_t));  
    memcpy(&h->seq_info, seq, sizeof(davs2_seq_t));

    return 0;
}