- used = 0;
- for (i = 0; i < pic->nb_refs; i++) {
- if (pic->refs[i] == st)
- used = 1;
- }
- if (!used) {
- // Usually each picture always uses all of the others in the
- // DPB as references. The one case we have to treat here is
- // a non-IDR IRAP picture, which may need to hold unused
- // references across itself to be used for the decoding of
- // following RASL pictures. This looks for such an RASL
- // picture, and keeps the reference if there is one.
- VAAPIEncodePicture *rp;
- for (rp = ctx->pic_start; rp; rp = rp->next) {
- if (rp->encode_order < pic->encode_order)
- continue;
- if (rp->type != PICTURE_TYPE_B)
- continue;
- if (rp->refs[0] == st && rp->refs[1] == pic)
- break;
- }
- if (!rp)
- continue;
- }
- // This only works for one instance of each (delta_poc_sN_minus1
- // is relative to the previous frame in the list, not relative to
- // the current frame directly).
- if (st->display_order < pic->display_order) {
- rps->delta_poc_s0_minus1[rps->num_negative_pics] =
- pic->display_order - st->display_order - 1;
- rps->used_by_curr_pic_s0_flag[rps->num_negative_pics] = used;
- ++rps->num_negative_pics;
- } else {
- rps->delta_poc_s1_minus1[rps->num_positive_pics] =
- st->display_order - pic->display_order - 1;
- rps->used_by_curr_pic_s1_flag[rps->num_positive_pics] = used;
- ++rps->num_positive_pics;
+ if (j < pic->nb_refs)
+ continue;
+ strp = pic->dpb[i]->priv_data;
+ rps_poc[rps_pics] = strp->pic_order_cnt;
+ rps_used[rps_pics] = 0;
+ ++rps_pics;
+ }
+
+ for (i = 1; i < rps_pics; i++) {
+ for (j = i; j > 0; j--) {
+ if (rps_poc[j] > rps_poc[j - 1])
+ break;
+ av_assert0(rps_poc[j] != rps_poc[j - 1]);
+ FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
+ FFSWAP(int, rps_used[j], rps_used[j - 1]);