Commit 237a788b authored by Laurent Aimar's avatar Laurent Aimar

Cosmetics (K&R of picture_fifo).

parent 2deed367
......@@ -73,16 +73,16 @@ VLC_EXPORT( void, picture_fifo_Push, ( picture_fifo_t *, picture_t * ) );
/**
* It release all picture inside the fifo that have a lower or equal date
* if b_below or higher or equal to not b_below than the given one.
* if flush_before or higher or equal to if not flush_before than the given one.
*
* All pictures inside the fifo will be released by picture_Release.
*/
VLC_EXPORT( void, picture_fifo_Flush, ( picture_fifo_t *, mtime_t i_date, bool b_below ) );
VLC_EXPORT( void, picture_fifo_Flush, ( picture_fifo_t *, mtime_t date, bool flush_before ) );
/**
* It applies a delta on all the picture timestamp.
*/
VLC_EXPORT( void, picture_fifo_OffsetDate, ( picture_fifo_t *, mtime_t i_delta ) );
VLC_EXPORT( void, picture_fifo_OffsetDate, ( picture_fifo_t *, mtime_t delta ) );
#endif /* VLC_PICTURE_FIFO_H */
......
......@@ -37,119 +37,114 @@
/*****************************************************************************
*
*****************************************************************************/
struct picture_fifo_t
{
struct picture_fifo_t {
vlc_mutex_t lock;
picture_t *p_first;
picture_t **pp_last;
picture_t *first;
picture_t **last_ptr;
};
static void PictureFifoReset( picture_fifo_t *p_fifo )
static void PictureFifoReset(picture_fifo_t *fifo)
{
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
fifo->first = NULL;
fifo->last_ptr = &fifo->first;
}
static void PictureFifoPush( picture_fifo_t *p_fifo, picture_t *p_picture )
static void PictureFifoPush(picture_fifo_t *fifo, picture_t *picture)
{
assert( !p_picture->p_next );
*p_fifo->pp_last = p_picture;
p_fifo->pp_last = &p_picture->p_next;
assert(!picture->p_next);
*fifo->last_ptr = picture;
fifo->last_ptr = &picture->p_next;
}
static picture_t *PictureFifoPop( picture_fifo_t *p_fifo )
static picture_t *PictureFifoPop(picture_fifo_t *fifo)
{
picture_t *p_picture = p_fifo->p_first;
picture_t *picture = fifo->first;
if( p_picture )
{
p_fifo->p_first = p_picture->p_next;
if( !p_fifo->p_first )
p_fifo->pp_last = &p_fifo->p_first;
if (picture) {
fifo->first = picture->p_next;
if (!fifo->first)
fifo->last_ptr = &fifo->first;
}
return p_picture;
return picture;
}
picture_fifo_t *picture_fifo_New(void)
{
picture_fifo_t *p_fifo = malloc( sizeof(*p_fifo) );
if( !p_fifo )
picture_fifo_t *fifo = malloc(sizeof(*fifo));
if (!fifo)
return NULL;
vlc_mutex_init( &p_fifo->lock );
PictureFifoReset( p_fifo );
return p_fifo;
vlc_mutex_init(&fifo->lock);
PictureFifoReset(fifo);
return fifo;
}
void picture_fifo_Push( picture_fifo_t *p_fifo, picture_t *p_picture )
void picture_fifo_Push(picture_fifo_t *fifo, picture_t *picture)
{
vlc_mutex_lock( &p_fifo->lock );
PictureFifoPush( p_fifo, p_picture );
vlc_mutex_unlock( &p_fifo->lock );
vlc_mutex_lock(&fifo->lock);
PictureFifoPush(fifo, picture);
vlc_mutex_unlock(&fifo->lock);
}
picture_t *picture_fifo_Pop( picture_fifo_t *p_fifo )
picture_t *picture_fifo_Pop(picture_fifo_t *fifo)
{
vlc_mutex_lock( &p_fifo->lock );
picture_t *p_picture = PictureFifoPop( p_fifo );
vlc_mutex_unlock( &p_fifo->lock );
vlc_mutex_lock(&fifo->lock);
picture_t *picture = PictureFifoPop(fifo);
vlc_mutex_unlock(&fifo->lock);
return p_picture;
return picture;
}
picture_t *picture_fifo_Peek( picture_fifo_t *p_fifo )
picture_t *picture_fifo_Peek(picture_fifo_t *fifo)
{
vlc_mutex_lock( &p_fifo->lock );
picture_t *p_picture = p_fifo->p_first;
if( p_picture )
picture_Hold( p_picture );
vlc_mutex_unlock( &p_fifo->lock );
vlc_mutex_lock(&fifo->lock);
picture_t *picture = fifo->first;
if (picture)
picture_Hold(picture);
vlc_mutex_unlock(&fifo->lock);
return p_picture;
return picture;
}
void picture_fifo_Flush( picture_fifo_t *p_fifo, mtime_t i_date, bool b_below )
void picture_fifo_Flush(picture_fifo_t *fifo, mtime_t date, bool flush_before)
{
picture_t *p_picture;
picture_t *picture;
vlc_mutex_lock( &p_fifo->lock );
vlc_mutex_lock(&fifo->lock);
p_picture = p_fifo->p_first;
PictureFifoReset( p_fifo );
picture = fifo->first;
PictureFifoReset(fifo);
picture_fifo_t tmp;
PictureFifoReset( &tmp );
PictureFifoReset(&tmp);
while( p_picture )
{
picture_t *p_next = p_picture->p_next;
while (picture) {
picture_t *next = picture->p_next;
p_picture->p_next = NULL;
if( ( b_below && p_picture->date <= i_date ) ||
( !b_below && p_picture->date >= i_date ) )
PictureFifoPush( &tmp, p_picture );
picture->p_next = NULL;
if (( flush_before && picture->date <= date) ||
(!flush_before && picture->date >= date))
PictureFifoPush(&tmp, picture);
else
PictureFifoPush( p_fifo, p_picture );
p_picture = p_next;
PictureFifoPush(fifo, picture);
picture = next;
}
vlc_mutex_unlock( &p_fifo->lock );
vlc_mutex_unlock(&fifo->lock);
for( ;; )
{
picture_t *p_picture = PictureFifoPop( &tmp );
if( !p_picture )
for (;;) {
picture_t *picture = PictureFifoPop(&tmp);
if (!picture)
break;
picture_Release( p_picture );
picture_Release(picture);
}
}
void picture_fifo_OffsetDate( picture_fifo_t *p_fifo, mtime_t i_delta )
void picture_fifo_OffsetDate(picture_fifo_t *fifo, mtime_t delta)
{
vlc_mutex_lock( &p_fifo->lock );
for( picture_t *p_picture = p_fifo->p_first; p_picture != NULL; )
{
p_picture->date += i_delta;
p_picture = p_picture->p_next;
vlc_mutex_lock(&fifo->lock);
for (picture_t *picture = fifo->first; picture != NULL;) {
picture->date += delta;
picture = picture->p_next;
}
vlc_mutex_unlock( &p_fifo->lock );
vlc_mutex_unlock(&fifo->lock);
}
void picture_fifo_Delete( picture_fifo_t *p_fifo )
void picture_fifo_Delete(picture_fifo_t *fifo)
{
picture_fifo_Flush( p_fifo, INT64_MAX, true );
vlc_mutex_destroy( &p_fifo->lock );
picture_fifo_Flush(fifo, INT64_MAX, true);
vlc_mutex_destroy(&fifo->lock);
}
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