void destroy_dpb(davs2_mgr_t *mgr)
{
    davs2_frame_t *frame = NULL;
    int i;

    for (i = 0; i < mgr->dpbsize; i++) {
        frame = mgr->dpb[i];
        assert(frame);

        mgr->dpb[i] = NULL;

        davs2_thread_mutex_lock(&frame->mutex_frm);

        if (frame->i_ref_count == 0) {
            davs2_thread_mutex_unlock(&frame->mutex_frm);
            davs2_frame_destroy(frame);
        } else {
            frame->i_disposable = 2; /* free when not referenced */
            davs2_thread_mutex_unlock(&frame->mutex_frm);
        }
    }

    davs2_free(mgr->dpb);
    mgr->dpb = NULL;
}
void destroy_dpb(davs2_mgr_t *mgr)
{
    davs2_frame_t *frame = NULL;
    int i;

    for (i = 0; i < mgr->dpbsize; i++) {
        frame = mgr->dpb[i];
        assert(frame);

        mgr->dpb[i] = NULL;

        davs2_thread_mutex_lock(&frame->mutex_frm);

        if (frame->i_ref_count == 0) {
            davs2_thread_mutex_unlock(&frame->mutex_frm);
            davs2_frame_destroy(frame);
        } else {
            frame->i_disposable = 2;  
            davs2_thread_mutex_unlock(&frame->mutex_frm);
        }
    }

    davs2_free(mgr->dpb);
    mgr->dpb = NULL;
}