Commit 07e428de authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

picture_pool: split picture_pool_NonEmpty and picture_pool_Reset

parent 3ca607e8
......@@ -93,18 +93,25 @@ VLC_API void picture_pool_Delete( picture_pool_t * );
*/
VLC_API picture_t * picture_pool_Get( picture_pool_t * ) VLC_USED;
/**
* Forcefully return all pictures in the pool to free/unallocated state.
*
* @warning This can only be called when it is known that all pending
* references to the picture pool are stale, e.g. a decoder failed to
* release pictures properly when it terminated.
*/
void picture_pool_Reset( picture_pool_t * );
/**
* It forces the next picture_pool_Get to return a picture even if no
* pictures are free.
*
* If b_reset is true, all pictures will be marked as free.
*
* It does it by releasing itself the oldest used picture if none is
* available.
* XXX it should be used with great care, the only reason you may need
* it is to workaround a bug.
*/
VLC_API void picture_pool_NonEmpty( picture_pool_t *, bool reset );
VLC_API void picture_pool_NonEmpty( picture_pool_t * );
/**
* It reserves picture_count pictures from the given pool and returns
......
......@@ -289,31 +289,43 @@ picture_t *picture_pool_Get(picture_pool_t *pool)
return NULL;
}
void picture_pool_NonEmpty(picture_pool_t *pool, bool reset)
void picture_pool_Reset(picture_pool_t *pool)
{
picture_t *old = NULL;
for (int i = 0; i < pool->picture_count; i++) {
if (pool->picture_reserved[i])
continue;
picture_t *picture = pool->picture[i];
if (reset) {
if (atomic_load(&picture->gc.refcount) > 0)
Unlock(picture);
atomic_store(&picture->gc.refcount, 0);
} else if (atomic_load(&picture->gc.refcount) == 0) {
return;
} else if (!old || picture->gc.p_sys->tick < old->gc.p_sys->tick) {
old = picture;
}
if (atomic_load(&picture->gc.refcount) > 0)
Unlock(picture);
atomic_store(&picture->gc.refcount, 0);
}
if (!reset && old) {
if (atomic_load(&old->gc.refcount) > 0)
Unlock(old);
atomic_store(&old->gc.refcount, 0);
}
void picture_pool_NonEmpty(picture_pool_t *pool)
{
picture_t *oldest = NULL;
for (int i = 0; i < pool->picture_count; i++) {
if (pool->picture_reserved[i])
continue;
picture_t *picture = pool->picture[i];
if (atomic_load(&picture->gc.refcount) == 0)
return; /* Nothing to do */
if (oldest == NULL || picture->gc.p_sys->tick < oldest->gc.p_sys->tick)
oldest = picture;
}
if (oldest == NULL)
return; /* Cannot fix! */
if (atomic_load(&oldest->gc.refcount) > 0)
Unlock(oldest);
atomic_store(&oldest->gc.refcount, 0);
}
int picture_pool_GetSize(picture_pool_t *pool)
{
return pool->picture_count;
......
......@@ -363,7 +363,7 @@ void vout_FixLeaks( vout_thread_t *vout )
msg_Err(vout, "pictures leaked, trying to workaround");
/* */
picture_pool_NonEmpty(vout->p->decoder_pool, false);
picture_pool_NonEmpty(vout->p->decoder_pool);
vlc_mutex_unlock(&vout->p->picture_lock);
}
......@@ -1232,7 +1232,7 @@ static void ThreadReset(vout_thread_t *vout)
{
ThreadFlush(vout, true, INT64_MAX);
if (vout->p->decoder_pool)
picture_pool_NonEmpty(vout->p->decoder_pool, true);
picture_pool_Reset(vout->p->decoder_pool);
vout->p->pause.is_on = false;
vout->p->pause.date = mdate();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment