[vlc-devel] [PATCH 2/2] avcodec: va: wait indefinitely until a surface is available

Steve Lhomme robux4 at ycbcr.xyz
Thu Jul 9 11:56:30 CEST 2020


If there's no surface available the decoder should wait for one to be available,
not get an error and not try to decode anymore. When pictures (and thus
surfaces) were coming from the display a picture_pool_Wait() was used, so in
the normal case we should do something similar.

The infinite looping shouldn't be an issue as on Flush or Close the decoder
will release all the past pictures/surfaces. So there will be new surfaces
available for past calls.

We could improve the code by using a conditional variable or semaphore to
unlock the pending requests rather than using vlc_tick_sleep().
---
 modules/codec/avcodec/va_surface.c | 5 -----
 modules/hw/vdpau/avcodec.c         | 3 ---
 2 files changed, 8 deletions(-)

diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 9c97a709854..9045273fa3f 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -38,8 +38,6 @@
 
 #include "avcodec.h"
 
-#define MAX_GET_RETRIES  ((VLC_TICK_FROM_SEC(1) + VOUT_OUTMEM_SLEEP) / VOUT_OUTMEM_SLEEP)
-
 struct vlc_va_surface_t {
     size_t               index;
     atomic_uintptr_t     refcount; // 1 ref for the surface existance, 1 per surface/clone in-flight
@@ -136,7 +134,6 @@ static vlc_va_surface_t *GetSurface(va_pool_t *va_pool)
 
 vlc_va_surface_t *va_pool_Get(va_pool_t *va_pool)
 {
-    unsigned tries = MAX_GET_RETRIES;
     vlc_va_surface_t *surface;
 
     if (va_pool->surface_count == 0)
@@ -144,8 +141,6 @@ vlc_va_surface_t *va_pool_Get(va_pool_t *va_pool)
 
     while ((surface = GetSurface(va_pool)) == NULL)
     {
-        if (--tries == 0)
-            return NULL;
         /* Pool empty. Wait for some time as in src/input/decoder.c.
          * XXX: Both this and the core should use a semaphore or a CV. */
         vlc_tick_sleep(VOUT_OUTMEM_SLEEP);
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index f83100bd851..c4120039454 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -98,12 +98,9 @@ static vlc_vdp_video_field_t *GetSurface(vlc_va_sys_t *sys)
 static vlc_vdp_video_field_t *Get(vlc_va_sys_t *sys)
 {
     vlc_vdp_video_field_t *field;
-    unsigned tries = (VLC_TICK_FROM_SEC(1) + VOUT_OUTMEM_SLEEP) / VOUT_OUTMEM_SLEEP;
 
     while ((field = GetSurface(sys)) == NULL)
     {
-        if (--tries == 0)
-            return NULL;
         /* Pool empty. Wait for some time as in src/input/decoder.c.
          * XXX: Both this and the core should use a semaphore or a CV. */
         vlc_tick_sleep(VOUT_OUTMEM_SLEEP);
-- 
2.26.2



More information about the vlc-devel mailing list