]> git.sesse.net Git - vlc/blob - modules/video_filter/dynamicoverlay/dynamicoverlay_queue.c
Refactor dynamic overlays from Google Summer of Code project.
[vlc] / modules / video_filter / dynamicoverlay / dynamicoverlay_queue.c
1 /*****************************************************************************
2  * dynamicoverlay_commands.c : dynamic overlay plugin commands
3  *****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id$
6  *
7  * Author: Søren Bøg <avacore@videolan.org>
8  *         Jean-Paul Saman <jpsaman@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
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 General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc/vlc.h>
30
31 #include "dynamicoverlay.h"
32
33 /*****************************************************************************
34  * queue_t: Command queue
35  *****************************************************************************/
36
37 int QueueInit( queue_t *p_queue )
38 {
39     memset( p_queue, 0, sizeof( queue_t ) );
40     p_queue->p_head = NULL;
41     p_queue->p_tail = NULL;
42
43     return VLC_SUCCESS;
44 }
45
46 int QueueDestroy( queue_t *p_queue )
47 {
48     command_t *p_cur = p_queue->p_head, *p_temp;
49     while( p_cur != NULL )
50     {
51         p_temp = p_cur;
52         p_cur = p_cur->p_next;
53         free( p_temp );
54     }
55     p_queue->p_head = NULL;
56     p_queue->p_tail = NULL;
57
58     return VLC_SUCCESS;
59 }
60
61 int QueueEnqueue( queue_t *p_queue, command_t *p_cmd )
62 {
63     if( p_queue->p_tail != NULL )
64     {
65         p_queue->p_tail->p_next = p_cmd;
66     }
67     if( p_queue->p_head == NULL )
68     {
69         p_queue->p_head = p_cmd;
70     }
71     p_queue->p_tail = p_cmd;
72     p_cmd->p_next = NULL;
73
74     return VLC_SUCCESS;
75 }
76
77 command_t *QueueDequeue( queue_t *p_queue )
78 {
79     if( p_queue->p_head == NULL )
80     {
81         return NULL;
82     }
83     else
84     {
85         command_t *p_ret = p_queue->p_head;
86         if( p_queue->p_head == p_queue->p_tail )
87         {
88             p_queue->p_head = p_queue->p_tail = NULL;
89         }
90         else
91         {
92             p_queue->p_head = p_queue->p_head->p_next;
93         }
94         return p_ret;
95     }
96 }
97
98 int QueueTransfer( queue_t *p_sink, queue_t *p_source )
99 {
100     if( p_source->p_head == NULL ) {
101         return VLC_SUCCESS;
102     }
103
104     if( p_sink->p_head == NULL ) {
105         p_sink->p_head = p_source->p_head;
106         p_sink->p_tail = p_source->p_tail;
107     } else {
108         p_sink->p_tail->p_next = p_source->p_head;
109         p_sink->p_tail = p_source->p_tail;
110     }
111     p_source->p_head = p_source->p_tail = NULL;
112
113     return VLC_SUCCESS;
114 }