playlist/item: playlist_Add: fix documentation
[vlc.git] / src / misc / picture_fifo.c
blob5e999926ec8cf309ed201373dd1338285a8cfc6a
1 /*****************************************************************************
2 * picture_fifo.c : picture fifo functions
3 *****************************************************************************
4 * Copyright (C) 2009 VLC authors and VideoLAN
5 * Copyright (C) 2009 Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
6 * $Id$
8 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * Preamble
27 *****************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32 #include <assert.h>
34 #include <vlc_common.h>
35 #include <vlc_picture_fifo.h>
37 /*****************************************************************************
39 *****************************************************************************/
40 struct picture_fifo_t {
41 vlc_mutex_t lock;
42 picture_t *first;
43 picture_t **last_ptr;
46 static void PictureFifoReset(picture_fifo_t *fifo)
48 fifo->first = NULL;
49 fifo->last_ptr = &fifo->first;
51 static void PictureFifoPush(picture_fifo_t *fifo, picture_t *picture)
53 assert(!picture->p_next);
54 *fifo->last_ptr = picture;
55 fifo->last_ptr = &picture->p_next;
57 static picture_t *PictureFifoPop(picture_fifo_t *fifo)
59 picture_t *picture = fifo->first;
61 if (picture) {
62 fifo->first = picture->p_next;
63 if (!fifo->first)
64 fifo->last_ptr = &fifo->first;
65 picture->p_next = NULL;
67 return picture;
70 picture_fifo_t *picture_fifo_New(void)
72 picture_fifo_t *fifo = malloc(sizeof(*fifo));
73 if (!fifo)
74 return NULL;
76 vlc_mutex_init(&fifo->lock);
77 PictureFifoReset(fifo);
78 return fifo;
81 void picture_fifo_Push(picture_fifo_t *fifo, picture_t *picture)
83 vlc_mutex_lock(&fifo->lock);
84 PictureFifoPush(fifo, picture);
85 vlc_mutex_unlock(&fifo->lock);
87 picture_t *picture_fifo_Pop(picture_fifo_t *fifo)
89 vlc_mutex_lock(&fifo->lock);
90 picture_t *picture = PictureFifoPop(fifo);
91 vlc_mutex_unlock(&fifo->lock);
93 return picture;
95 picture_t *picture_fifo_Peek(picture_fifo_t *fifo)
97 vlc_mutex_lock(&fifo->lock);
98 picture_t *picture = fifo->first;
99 if (picture)
100 picture_Hold(picture);
101 vlc_mutex_unlock(&fifo->lock);
103 return picture;
105 void picture_fifo_Flush(picture_fifo_t *fifo, mtime_t date, bool flush_before)
107 picture_t *picture;
109 vlc_mutex_lock(&fifo->lock);
111 picture = fifo->first;
112 PictureFifoReset(fifo);
114 picture_fifo_t tmp;
115 PictureFifoReset(&tmp);
117 while (picture) {
118 picture_t *next = picture->p_next;
120 picture->p_next = NULL;
121 if (( flush_before && picture->date <= date) ||
122 (!flush_before && picture->date >= date))
123 PictureFifoPush(&tmp, picture);
124 else
125 PictureFifoPush(fifo, picture);
126 picture = next;
128 vlc_mutex_unlock(&fifo->lock);
130 while ((picture = PictureFifoPop(&tmp)) != NULL)
131 picture_Release(picture);
133 void picture_fifo_OffsetDate(picture_fifo_t *fifo, mtime_t delta)
135 vlc_mutex_lock(&fifo->lock);
136 for (picture_t *picture = fifo->first; picture != NULL;) {
137 picture->date += delta;
138 picture = picture->p_next;
140 vlc_mutex_unlock(&fifo->lock);
142 void picture_fifo_Delete(picture_fifo_t *fifo)
144 picture_fifo_Flush(fifo, INT64_MAX, true);
145 vlc_mutex_destroy(&fifo->lock);
146 free(fifo);