]> git.sesse.net Git - vlc/blob - modules/video_filter/dynamicoverlay/dynamicoverlay_list.c
e3c5acc43c9f25e501367144533e07f9233ef833
[vlc] / modules / video_filter / dynamicoverlay / dynamicoverlay_list.c
1 /*****************************************************************************
2  * dynamicoverlay_list.h : dynamic overlay list
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_common.h>
30 #include <vlc_osd.h>
31
32 #include <fcntl.h>
33 #include "dynamicoverlay.h"
34
35 /*****************************************************************************
36  * list_t: Command queue
37  *****************************************************************************/
38
39 int ListInit( list_t *p_list )
40 {
41     p_list->pp_head = malloc( 16 * sizeof( overlay_t * ) );
42     if( p_list->pp_head == NULL )
43         return VLC_ENOMEM;
44
45     p_list->pp_tail = p_list->pp_head + 16;
46     memset( p_list->pp_head, 0, 16 * sizeof( overlay_t * ) );
47
48     return VLC_SUCCESS;
49 }
50
51 int ListDestroy( list_t *p_list )
52 {
53     for( overlay_t **pp_cur = p_list->pp_head;
54          pp_cur < p_list->pp_tail;
55          ++pp_cur )
56     {
57         if( *pp_cur != NULL )
58         {
59             OverlayDestroy( *pp_cur );
60             free( *pp_cur );
61         }
62     }
63     free( p_list->pp_head );
64
65     return VLC_SUCCESS;
66 }
67
68 ssize_t ListAdd( list_t *p_list, overlay_t *p_new )
69 {
70     /* Find an available slot */
71     for( overlay_t **pp_cur = p_list->pp_head;
72          pp_cur < p_list->pp_tail;
73          ++pp_cur )
74     {
75         if( *pp_cur == NULL )
76         {
77             *pp_cur = p_new;
78             return pp_cur - p_list->pp_head;
79         }
80     }
81
82     /* Have to expand */
83     size_t i_size = p_list->pp_tail - p_list->pp_head;
84     size_t i_newsize = i_size * 2;
85     p_list->pp_head = realloc( p_list->pp_head,
86                                i_newsize * sizeof( overlay_t * ) );
87     if( p_list->pp_head == NULL )
88         return VLC_ENOMEM;
89
90     p_list->pp_tail = p_list->pp_head + i_newsize;
91     memset( p_list->pp_head + i_size, 0, i_size * sizeof( overlay_t * ) );
92     p_list->pp_head[i_size] = p_new;
93     return i_size;
94 }
95
96 int ListRemove( list_t *p_list, size_t i_idx )
97 {
98     int ret;
99
100     if( ( i_idx >= (size_t)( p_list->pp_tail - p_list->pp_head ) ) ||
101         ( p_list->pp_head[i_idx] == NULL ) )
102     {
103         return VLC_EGENERIC;
104     }
105
106     ret = OverlayDestroy( p_list->pp_head[i_idx] );
107     free( p_list->pp_head[i_idx] );
108     p_list->pp_head[i_idx] = NULL;
109
110     return ret;
111 }
112
113 overlay_t *ListGet( list_t *p_list, size_t i_idx )
114 {
115     if( ( i_idx >= (size_t)( p_list->pp_tail - p_list->pp_head ) ) ||
116         ( p_list->pp_head[i_idx] == NULL ) )
117     {
118         return NULL;
119     }
120     return p_list->pp_head[i_idx];
121 }
122
123 overlay_t *ListWalk( list_t *p_list )
124 {
125     static overlay_t **pp_cur = NULL;
126
127     if( pp_cur == NULL )
128         pp_cur = p_list->pp_head;
129     else
130         pp_cur = pp_cur + 1;
131
132     for( ; pp_cur < p_list->pp_tail; ++pp_cur )
133     {
134         if( ( *pp_cur != NULL ) &&
135             ( (*pp_cur)->b_active == true )&&
136             ( (*pp_cur)->format.i_chroma != VLC_FOURCC( '\0','\0','\0','\0') ) )
137         {
138             return *pp_cur;
139         }
140     }
141     pp_cur = NULL;
142     return NULL;
143 }