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