VLC  4.0.0-dev
vlc_picture_pool.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_picture_pool.h: picture pool definitions
3  *****************************************************************************
4  * Copyright (C) 2009 VLC authors and VideoLAN
5  *
6  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22 
23 #ifndef VLC_PICTURE_POOL_H
24 #define VLC_PICTURE_POOL_H 1
25 
26 /**
27  * \file
28  * This file defines picture pool structures and functions in vlc
29  */
30 
31 #include <vlc_picture.h>
32 
33 /**
34  * Picture pool handle
35  */
36 typedef struct picture_pool_t picture_pool_t;
37 
38 /**
39  * Picture pool configuration
40  */
41 typedef struct {
42  unsigned picture_count;
43  picture_t *const *picture;
44 
45  int (*lock)(picture_t *);
46  void (*unlock)(picture_t *);
48 
49 /**
50  * Creates a pool of preallocated pictures. Free pictures can be allocated from
51  * the pool, and are returned to the pool when they are no longer referenced.
52  *
53  * This avoids allocating and deallocationg pictures repeatedly, and ensures
54  * that memory consumption remains within limits.
55  *
56  * To obtain a picture from the pool, use picture_pool_Get(). To increase and
57  * decrease the reference count, use picture_Hold() and picture_Release()
58  * respectively.
59  *
60  * If defined, picture_pool_configuration_t::lock will be called before
61  * a picture is used, and picture_pool_configuration_t::unlock will be called
62  * as soon as a picture is returned to the pool.
63  * Those callbacks can modify picture_t::p and access picture_t::p_sys.
64  *
65  * @return A pointer to the new pool on success, or NULL on error
66  * (pictures are <b>not</b> released on error).
67  */
69 
70 /**
71  * Creates a picture pool with pictures in a given array.
72  * This is a convenience wrapper for picture_pool_NewExtended() without the
73  * lock and unlock callbacks.
74  *
75  * @param count number of pictures in the array
76  * @param tab array of pictures
77  *
78  * @return a pointer to the new pool on success, or NULL on error
79  * (pictures are <b>not</b> released on error)
80  */
82  picture_t *const *tab) VLC_USED;
83 
84 /**
85  * Allocates pictures from the heap and creates a picture pool with them.
86  * This is a convenience wrapper for picture_NewFromFormat() and
87  * picture_pool_New().
88  *
89  * @param fmt video format of pictures to allocate from the heap
90  * @param count number of pictures to allocate
91  *
92  * @return a pointer to the new pool on success, NULL on error
93  */
95  unsigned count) VLC_USED;
96 
97 /**
98  * Releases a pool created by picture_pool_NewExtended(), picture_pool_New()
99  * or picture_pool_NewFromFormat().
100  *
101  * @note If there are no pending references to the pooled pictures, and the
102  * picture_resource_t.pf_destroy callback was not NULL, it will be invoked.
103  * Otherwise the default callback will be used.
104  *
105  * @warning If there are pending references (a.k.a. late pictures), the
106  * pictures will remain valid until the all pending references are dropped by
107  * picture_Release().
108  */
110 
111 /**
112  * Obtains a picture from a pool if any is immediately available.
113  *
114  * The picture must be released with picture_Release().
115  *
116  * @return a picture, or NULL if all pictures in the pool are allocated
117  *
118  * @note This function is thread-safe.
119  */
121 
122 /**
123  * Obtains a picture from a pool.
124  *
125  * The picture must be released with picture_Release().
126  *
127  * @return a picture or NULL on memory error
128  *
129  * @note This function is thread-safe.
130  */
132 
133 /**
134  * Cancel the picture pool.
135  *
136  * It won't return any pictures via picture_pool_Get or picture_pool_Wait if
137  * canceled is true. This function will also unblock picture_pool_Wait.
138  * picture_pool_Reset will also reset the cancel state to false.
139  */
141 
142 /**
143  * Test if a picture belongs to the picture pool
144  *
145  * FIXME: remove this function when the vout_PutPicture() hack is fixed.
146  */
148 
149 /**
150  * Reserves pictures from a pool and creates a new pool with those.
151  *
152  * When the new pool is released, pictures are returned to the master pool.
153  * If the master pool was already released, pictures will be destroyed.
154  *
155  * @param count number of picture to reserve
156  *
157  * @return the new pool, or NULL if there were not enough pictures available
158  * or on error
159  *
160  * @note This function is thread-safe (but it might return NULL if other
161  * threads have already allocated too many pictures).
162  */
164 VLC_USED;
165 
166 /**
167  * @return the total number of pictures in the given pool
168  * @note This function is thread-safe.
169  */
171 
172 
173 #endif /* VLC_PICTURE_POOL_H */
174 
vlc_mutex_t lock
Definition: picture_pool.c:44
picture_pool_t * picture_pool_NewExtended(const picture_pool_configuration_t *)
Creates a pool of preallocated pictures.
Definition: picture_pool.c:117
This file defines picture structures and functions in vlc.
void picture_pool_Cancel(picture_pool_t *, bool canceled)
Cancel the picture pool.
Definition: picture_pool.c:279
Video picture.
Definition: vlc_picture.h:126
Picture pool configuration.
Definition: vlc_picture_pool.h:42
picture_t * picture_pool_Wait(picture_pool_t *)
Obtains a picture from a pool.
Definition: picture_pool.c:242
unsigned short picture_count
Definition: picture_pool.c:50
picture_pool_t * picture_pool_Reserve(picture_pool_t *, unsigned count)
Reserves pictures from a pool and creates a new pool with those.
Definition: picture_pool.c:180
unsigned picture_pool_GetSize(const picture_pool_t *)
Definition: picture_pool.c:316
picture_t * picture[]
Definition: picture_pool.c:51
size_t count
Definition: core.c:402
video format description
Definition: vlc_es.h:349
bool canceled
Definition: picture_pool.c:47
void picture_pool_Release(picture_pool_t *)
Releases a pool created by picture_pool_NewExtended(), picture_pool_New() or picture_pool_NewFromForm...
Definition: picture_pool.c:65
Definition: picture_pool.c:41
bool picture_pool_OwnsPic(picture_pool_t *, picture_t *)
Test if a picture belongs to the picture pool.
Definition: picture_pool.c:290
#define VLC_API
Definition: fourcc_gen.c:31
picture_pool_t * picture_pool_New(unsigned count, picture_t *const *tab)
Creates a picture pool with pictures in a given array.
Definition: picture_pool.c:146
picture_t * picture_pool_Get(picture_pool_t *)
Obtains a picture from a pool if any is immediately available.
Definition: picture_pool.c:203
picture_pool_t * picture_pool_NewFromFormat(const video_format_t *fmt, unsigned count)
Allocates pictures from the heap and creates a picture pool with them.
Definition: picture_pool.c:156
#define VLC_USED
Definition: fourcc_gen.c:32