diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c b/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c index 6ba5834631..da520c48cc 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_dpb.c @@ -238,6 +238,14 @@ gst_vaapi_dpb_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) return klass->add(dpb, picture); } +guint +gst_vaapi_dpb_size(GstVaapiDpb *dpb) +{ + g_return_val_if_fail(GST_VAAPI_IS_DPB(dpb), 0); + + return dpb->num_pictures; +} + /* ------------------------------------------------------------------------- */ /* --- MPEG-2 Decoded Picture Buffer --- */ /* ------------------------------------------------------------------------- */ diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_dpb.h b/gst-libs/gst/vaapi/gstvaapidecoder_dpb.h index 198ad19521..1a199b8949 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_dpb.h +++ b/gst-libs/gst/vaapi/gstvaapidecoder_dpb.h @@ -103,6 +103,10 @@ gboolean gst_vaapi_dpb_add(GstVaapiDpb *dpb, GstVaapiPicture *picture) attribute_hidden; +guint +gst_vaapi_dpb_size(GstVaapiDpb *dpb) + attribute_hidden; + static inline gpointer gst_vaapi_dpb_ref(gpointer ptr) { diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c index 0e97d2e13d..3477573134 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c @@ -700,6 +700,39 @@ decode_picture_ext(GstVaapiDecoderMpeg2 *decoder, guchar *buf, guint buf_size) picture->structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME; break; } + + /* Allocate dummy picture for first field based I-frame */ + if (picture->type == GST_VAAPI_PICTURE_TYPE_I && + !GST_VAAPI_PICTURE_IS_FRAME(picture) && + gst_vaapi_dpb_size(priv->dpb) == 0) { + GstVaapiPicture *dummy_picture; + gboolean success; + + dummy_picture = GST_VAAPI_PICTURE_NEW(MPEG2, decoder); + if (!dummy_picture) { + GST_ERROR("failed to allocate dummy picture"); + return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED; + } + + dummy_picture->type = GST_VAAPI_PICTURE_TYPE_I; + dummy_picture->pts = GST_CLOCK_TIME_NONE; + dummy_picture->poc = -1; + dummy_picture->structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME; + + GST_VAAPI_PICTURE_FLAG_SET( + dummy_picture, + (GST_VAAPI_PICTURE_FLAG_SKIPPED | + GST_VAAPI_PICTURE_FLAG_REFERENCE) + ); + + success = gst_vaapi_dpb_add(priv->dpb, dummy_picture); + gst_vaapi_picture_unref(dummy_picture); + if (!success) { + GST_ERROR("failed to add dummy picture into DPB"); + return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN; + } + GST_INFO("allocated dummy picture for first field based I-frame"); + } return GST_VAAPI_DECODER_STATUS_SUCCESS; }