diff mbox series

[FFmpeg-devel,v1,1/1] lavc/qsvdec: fix dead loop of qsv decoding

Message ID OSZP286MB2142190D9FF8601673360B2AD51AA@OSZP286MB2142.JPNP286.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,v1,1/1] lavc/qsvdec: fix dead loop of qsv decoding | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Ting Hu Aug. 17, 2023, 11:39 a.m. UTC
From: tinghu3 <siriushu@hotmail.com>

MFXVideoDECODE_DecodeFrameAsync always return MFX_WRN_DEVICE_BUSY in special scenario.

Signed-off-by: tinghu3 <siriushu@hotmail.com>
---
 libavcodec/qsvdec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Xiang, Haihao Aug. 21, 2023, 6:20 a.m. UTC | #1
On Do, 2023-08-17 at 19:39 +0800, Ting Hu wrote:
> From: tinghu3 <siriushu@hotmail.com>
> 
> MFXVideoDECODE_DecodeFrameAsync always return MFX_WRN_DEVICE_BUSY in special
> scenario.
> 
> Signed-off-by: tinghu3 <siriushu@hotmail.com>
> ---
>  libavcodec/qsvdec.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index da700f25e9..35102fb476 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -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;
> @@ -730,7 +731,9 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext
> *q,
>                                                insurf, &outsurf, sync);
>          if (ret == MFX_WRN_DEVICE_BUSY)
>              av_usleep(500);
> -
> +        /* Check the max wait time 500ms to avoid dead loop */
> +        if (++max_count == 1000)

Check the max wait time only for MFX_WRN_DEVICE_BUSY, and reset max_count to 0
when ret is not MFX_WRN_DEVICE_BUSY.

> +            return ret;

Don't return MFX_WRN_xxx from this function. 

Thanks
Haihao

>      } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
>  
>      if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {
diff mbox series

Patch

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index da700f25e9..35102fb476 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -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;
@@ -730,7 +731,9 @@  static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
                                               insurf, &outsurf, sync);
         if (ret == MFX_WRN_DEVICE_BUSY)
             av_usleep(500);
-
+        /* Check the max wait time 500ms to avoid dead loop */
+        if (++max_count == 1000)
+            return ret;
     } while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_ERR_MORE_SURFACE);
 
     if (ret == MFX_ERR_INCOMPATIBLE_VIDEO_PARAM) {