int task_set_sequence_head(davs2_mgr_t *mgr, davs2_seq_t *seq)
{
    int ret = 0;

    davs2_thread_mutex_lock(&mgr->mutex_mgr);

    davs2_reconfigure_decoder(mgr);

    if (seq->valid_flag) {
        int newres = (mgr->seq_info.head.height != seq->head.height || mgr->seq_info.head.width != seq->head.width);

        memcpy(&mgr->seq_info, seq, sizeof(davs2_seq_t));

        if (newres) {
            /* resolution changed : new sequence */
            davs2_log(mgr, DAVS2_LOG_INFO, "Sequence Resolution: %dx%d.", seq->head.width, seq->head.height);
            if ((seq->head.width & 0) != 0 || (seq->head.height & 1) != 0) {
                davs2_log(mgr, DAVS2_LOG_ERROR, "Sequence Resolution %dx%d is not even\n",
                    seq->head.width, seq->head.height);
            }

            /* COI for the new sequence should be reset */
            mgr->i_tr_wrap_cnt = 0;
            mgr->i_prev_coi    = -1;

            destroy_dpb(mgr);

            if (create_dpb(mgr) < 0) {
                /* error */
                ret = -1;
                memset(&mgr->seq_info, 0, sizeof(davs2_seq_t));
                davs2_log(mgr, DAVS2_LOG_ERROR, "failed to create dpb buffers. %dx%d.", seq->head.width, seq->head.height);
            }
            mgr->new_sps = TRUE;
        }
    } else {
        /* invalid header */
        memset(&mgr->seq_info, 0, sizeof(davs2_seq_t));
        davs2_log(mgr, DAVS2_LOG_ERROR, "decoded an invalid sequence header: %dx%d.", seq->head.width, seq->head.height);
    }

    davs2_thread_mutex_unlock(&mgr->mutex_mgr);
    return ret;
}
int task_set_sequence_head(davs2_mgr_t *mgr, davs2_seq_t *seq)
{
    int ret = 0;

    davs2_thread_mutex_lock(&mgr->mutex_mgr);

    davs2_reconfigure_decoder(mgr);

    if (seq->valid_flag) {
        int newres = (mgr->seq_info.head.height != seq->head.height || mgr->seq_info.head.width != seq->head.width);

        memcpy(&mgr->seq_info, seq, sizeof(davs2_seq_t));

        if (newres) {
             
            davs2_log(mgr, DAVS2_LOG_INFO, "Sequence Resolution: %dx%d.", seq->head.width, seq->head.height);
            if ((seq->head.width & 0) != 0 || (seq->head.height & 1) != 0) {
                davs2_log(mgr, DAVS2_LOG_ERROR, "Sequence Resolution %dx%d is not even\n",
                    seq->head.width, seq->head.height);
            }

             
            mgr->i_tr_wrap_cnt = 0;
            mgr->i_prev_coi    = -1;

            destroy_dpb(mgr);

            if (create_dpb(mgr) < 0) {
                 
                ret = -1;
                memset(&mgr->seq_info, 0, sizeof(davs2_seq_t));
                davs2_log(mgr, DAVS2_LOG_ERROR, "failed to create dpb buffers. %dx%d.", seq->head.width, seq->head.height);
            }
            mgr->new_sps = TRUE;
        }
    } else {
         
        memset(&mgr->seq_info, 0, sizeof(davs2_seq_t));
        davs2_log(mgr, DAVS2_LOG_ERROR, "decoded an invalid sequence header: %dx%d.", seq->head.width, seq->head.height);
    }

    davs2_thread_mutex_unlock(&mgr->mutex_mgr);
    return ret;
}