@@ -703,6 +703,7 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
mfxSyncPoint *sync;
mfxBitstream bs = { { { 0 } } };
int ret;
+ int max_count = 0;
if (avpkt->size) {
bs.Data = avpkt->data;
@@ -728,9 +729,18 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ? &bs : NULL,
insurf, &outsurf, sync);
- if (ret == MFX_WRN_DEVICE_BUSY)
+ if (ret == MFX_WRN_DEVICE_BUSY) {
+ /* Check the max wait time 500ms to avoid dead loop */
+ if (++max_count == 1000) {
+ av_log(avctx, AV_LOG_ERROR,
+ "MFX decoder returns device busy that reachs timeout 500ms \n");
+ av_freep(&sync);
+ return AVERROR(EBUSY);
+ }
av_usleep(500);
-
+ } else if (ret == MFX_ERR_MORE_SURFACE) {
+ max_count = 0;
+ }
} while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {