diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c b/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c index 4bdd7eb232..6ba5834631 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c @@ -70,7 +70,7 @@ dpb_get_oldest(GstVaapiDpb *dpb, gboolean output) GstVaapiPicture * const picture = dpb->pictures[i]; if ((GST_VAAPI_PICTURE_IS_OUTPUT(picture) ^ output) != 0) continue; - if (picture->pts < dpb->pictures[lowest_pts_index]->pts) + if (picture->poc < dpb->pictures[lowest_pts_index]->poc) lowest_pts_index = i; } return lowest_pts_index; @@ -164,7 +164,7 @@ gst_vaapi_dpb_base_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) while (dpb->num_pictures == dpb->max_pictures) { for (i = 0; i < dpb->num_pictures; i++) { if (!GST_VAAPI_PICTURE_IS_OUTPUT(picture) && - dpb->pictures[i]->pts < picture->pts) + dpb->pictures[i]->poc < picture->poc) break; } if (i == dpb->num_pictures) @@ -261,7 +261,7 @@ gst_vaapi_dpb_mpeg2_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) * - the oldest reference picture is replaced with the new reference picture */ if (G_LIKELY(dpb->num_pictures == 2)) { - index = (dpb->pictures[0]->pts > dpb->pictures[1]->pts); + index = (dpb->pictures[0]->poc > dpb->pictures[1]->poc); ref_picture = dpb->pictures[index]; if (!GST_VAAPI_PICTURE_IS_OUTPUT(ref_picture)) { if (!dpb_output(dpb, ref_picture)) @@ -315,9 +315,9 @@ gst_vaapi_dpb_mpeg2_get_references( ref_pictures[1] = NULL; for (i = 0; i < dpb->num_pictures; i++) { ref_picture = dpb->pictures[i]; - index = ref_picture->pts > picture->pts; + index = ref_picture->poc > picture->poc; picture_ptr = &ref_pictures[index]; - if (!*picture_ptr || ((*picture_ptr)->pts > ref_picture->pts) == index) + if (!*picture_ptr || ((*picture_ptr)->poc > ref_picture->poc) == index) *picture_ptr = ref_picture; } diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c index e4e0e957c7..815d058f13 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c @@ -94,6 +94,12 @@ pts_get_duration(PTSGenerator *tsg, guint num_frames) GST_SECOND * tsg->fps_d, tsg->fps_n); } +static inline guint +pts_get_poc(PTSGenerator *tsg) +{ + return tsg->gop_tsn + tsg->ovl_tsn * 1024 + tsg->lst_tsn; +} + static void pts_set_framerate(PTSGenerator *tsg, guint fps_n, guint fps_d) { @@ -647,6 +653,7 @@ decode_picture(GstVaapiDecoderMpeg2 *decoder, guchar *buf, guint buf_size) /* Update presentation time */ pts = gst_adapter_prev_timestamp(priv->adapter, NULL); picture->pts = pts_eval(&priv->tsg, pts, pic_hdr->tsn); + picture->poc = pts_get_poc(&priv->tsg); return status; } diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c index ce0de82272..4725fac853 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c @@ -106,6 +106,7 @@ gst_vaapi_picture_create( picture->surface = gst_vaapi_surface_proxy_get_surface(picture->proxy); picture->type = parent_picture->type; picture->pts = parent_picture->pts; + picture->poc = parent_picture->poc; // Copy all picture flags but "output" GST_VAAPI_PICTURE_FLAG_SET( @@ -180,6 +181,7 @@ gst_vaapi_picture_init(GstVaapiPicture *picture) picture->iq_matrix = NULL; picture->bitplane = NULL; picture->pts = GST_CLOCK_TIME_NONE; + picture->poc = 0; } GstVaapiPicture * diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.h b/gst-libs/gst/vaapi/gstvaapidecoder_objects.h index fe8d62c420..93d8ce27e4 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.h +++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.h @@ -148,6 +148,7 @@ struct _GstVaapiPicture { GstVaapiIqMatrix *iq_matrix; GstVaapiBitPlane *bitplane; GstClockTime pts; + gint32 poc; guint structure; };