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 * ) ); ...@@ -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 * 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. * 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. * 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 */ #endif /* VLC_PICTURE_FIFO_H */
......
...@@ -37,119 +37,114 @@ ...@@ -37,119 +37,114 @@
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
struct picture_fifo_t struct picture_fifo_t {
{
vlc_mutex_t lock; vlc_mutex_t lock;
picture_t *p_first; picture_t *first;
picture_t **pp_last; picture_t **last_ptr;
}; };
static void PictureFifoReset( picture_fifo_t *p_fifo ) static void PictureFifoReset(picture_fifo_t *fifo)
{ {
p_fifo->p_first = NULL; fifo->first = NULL;
p_fifo->pp_last = &p_fifo->p_first; 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 ); assert(!picture->p_next);
*p_fifo->pp_last = p_picture; *fifo->last_ptr = picture;
p_fifo->pp_last = &p_picture->p_next; 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 ) if (picture) {
{ fifo->first = picture->p_next;
p_fifo->p_first = p_picture->p_next; if (!fifo->first)
if( !p_fifo->p_first ) fifo->last_ptr = &fifo->first;
p_fifo->pp_last = &p_fifo->p_first;
} }
return p_picture; return picture;
} }
picture_fifo_t *picture_fifo_New(void) picture_fifo_t *picture_fifo_New(void)
{ {
picture_fifo_t *p_fifo = malloc( sizeof(*p_fifo) ); picture_fifo_t *fifo = malloc(sizeof(*fifo));
if( !p_fifo ) if (!fifo)
return NULL; return NULL;
vlc_mutex_init( &p_fifo->lock ); vlc_mutex_init(&fifo->lock);
PictureFifoReset( p_fifo ); PictureFifoReset(fifo);
return p_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 ); vlc_mutex_lock(&fifo->lock);
PictureFifoPush( p_fifo, p_picture ); PictureFifoPush(fifo, picture);
vlc_mutex_unlock( &p_fifo->lock ); 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 ); vlc_mutex_lock(&fifo->lock);
picture_t *p_picture = PictureFifoPop( p_fifo ); picture_t *picture = PictureFifoPop(fifo);
vlc_mutex_unlock( &p_fifo->lock ); 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 ); vlc_mutex_lock(&fifo->lock);
picture_t *p_picture = p_fifo->p_first; picture_t *picture = fifo->first;
if( p_picture ) if (picture)
picture_Hold( p_picture ); picture_Hold(picture);
vlc_mutex_unlock( &p_fifo->lock ); 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; picture = fifo->first;
PictureFifoReset( p_fifo ); PictureFifoReset(fifo);
picture_fifo_t tmp; picture_fifo_t tmp;
PictureFifoReset( &tmp ); PictureFifoReset(&tmp);
while( p_picture ) while (picture) {
{ picture_t *next = picture->p_next;
picture_t *p_next = p_picture->p_next;
p_picture->p_next = NULL; picture->p_next = NULL;
if( ( b_below && p_picture->date <= i_date ) || if (( flush_before && picture->date <= date) ||
( !b_below && p_picture->date >= i_date ) ) (!flush_before && picture->date >= date))
PictureFifoPush( &tmp, p_picture ); PictureFifoPush(&tmp, picture);
else else
PictureFifoPush( p_fifo, p_picture ); PictureFifoPush(fifo, picture);
p_picture = p_next; picture = next;
} }
vlc_mutex_unlock( &p_fifo->lock ); vlc_mutex_unlock(&fifo->lock);
for( ;; ) for (;;) {
{ picture_t *picture = PictureFifoPop(&tmp);
picture_t *p_picture = PictureFifoPop( &tmp ); if (!picture)
if( !p_picture )
break; 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 ); vlc_mutex_lock(&fifo->lock);
for( picture_t *p_picture = p_fifo->p_first; p_picture != NULL; ) for (picture_t *picture = fifo->first; picture != NULL;) {
{ picture->date += delta;
p_picture->date += i_delta; picture = picture->p_next;
p_picture = p_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 ); picture_fifo_Flush(fifo, INT64_MAX, true);
vlc_mutex_destroy( &p_fifo->lock ); 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