vout_wrapper: remove local variable
[vlc.git] / src / video_output / vout_wrapper.c
blobb02a59891ad64c0a924fd3737ed769a504f6a5a2
1 /*****************************************************************************
2 * vout_wrapper.c: "vout display" -> "video output" wrapper
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * $Id$
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout_wrapper.h>
34 #include <vlc_vout.h>
35 #include <assert.h>
36 #include "vout_internal.h"
37 #include "display.h"
39 /*****************************************************************************
40 * Local prototypes
41 *****************************************************************************/
42 #ifdef _WIN32
43 static int Forward(vlc_object_t *, char const *,
44 vlc_value_t, vlc_value_t, void *);
45 #endif
47 /*****************************************************************************
49 *****************************************************************************/
50 int vout_OpenWrapper(vout_thread_t *vout,
51 const char *splitter_name, const vout_display_state_t *state)
53 vout_thread_sys_t *sys = vout->p;
54 msg_Dbg(vout, "Opening vout display wrapper");
56 /* */
57 sys->display.title = var_InheritString(vout, "video-title");
59 /* */
60 const mtime_t double_click_timeout = 300000;
61 const mtime_t hide_timeout = var_CreateGetInteger(vout, "mouse-hide-timeout") * 1000;
63 if (splitter_name) {
64 sys->display.vd = vout_NewSplitter(vout, &vout->p->original, state, "$vout", splitter_name,
65 double_click_timeout, hide_timeout);
66 } else {
67 sys->display.vd = vout_NewDisplay(vout, &vout->p->original, state, "$vout",
68 double_click_timeout, hide_timeout);
70 if (!sys->display.vd) {
71 free(sys->display.title);
72 return VLC_EGENERIC;
75 /* */
76 #ifdef _WIN32
77 var_Create(vout, "video-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
78 var_AddCallback(vout, "video-wallpaper", Forward, NULL);
79 #endif
81 /* */
82 sys->decoder_pool = NULL;
84 return VLC_SUCCESS;
87 /*****************************************************************************
89 *****************************************************************************/
90 void vout_CloseWrapper(vout_thread_t *vout, vout_display_state_t *state)
92 vout_thread_sys_t *sys = vout->p;
94 #ifdef _WIN32
95 var_DelCallback(vout, "video-wallpaper", Forward, NULL);
96 #endif
97 sys->decoder_pool = NULL; /* FIXME remove */
99 vout_DeleteDisplay(sys->display.vd, state);
100 free(sys->display.title);
103 /*****************************************************************************
105 *****************************************************************************/
106 /* Minimum number of display picture */
107 #define DISPLAY_PICTURE_COUNT (1)
109 static void NoDrInit(vout_thread_t *vout)
111 vout_thread_sys_t *sys = vout->p;
113 if (sys->display.use_dr)
114 sys->display_pool = vout_display_Pool(sys->display.vd, 3);
115 else
116 sys->display_pool = NULL;
119 int vout_InitWrapper(vout_thread_t *vout)
121 vout_thread_sys_t *sys = vout->p;
122 vout_display_t *vd = sys->display.vd;
124 sys->display.use_dr = !vout_IsDisplayFiltered(vd);
125 const bool allow_dr = !vd->info.has_pictures_invalid && !vd->info.is_slow && sys->display.use_dr;
126 const unsigned private_picture = 4; /* XXX 3 for filter, 1 for SPU */
127 const unsigned decoder_picture = 1 + sys->dpb_size;
128 const unsigned kept_picture = 1; /* last displayed picture */
129 const unsigned reserved_picture = DISPLAY_PICTURE_COUNT +
130 private_picture +
131 kept_picture;
132 const unsigned display_pool_size = allow_dr ? __MAX(VOUT_MAX_PICTURES,
133 reserved_picture + decoder_picture) : 3;
134 picture_pool_t *display_pool = vout_display_Pool(vd, display_pool_size);
135 if (display_pool == NULL)
136 return VLC_EGENERIC;
138 #ifndef NDEBUG
139 if ( picture_pool_GetSize(display_pool) < display_pool_size )
140 msg_Warn(vout, "Not enough display buffers in the pool, requested %d got %d",
141 display_pool_size, picture_pool_GetSize(display_pool));
142 #endif
144 if (allow_dr &&
145 picture_pool_GetSize(display_pool) >= reserved_picture + decoder_picture) {
146 sys->dpb_size = picture_pool_GetSize(display_pool) - reserved_picture;
147 sys->decoder_pool = display_pool;
148 sys->display_pool = display_pool;
149 } else if (!sys->decoder_pool) {
150 sys->decoder_pool =
151 picture_pool_NewFromFormat(&vd->source,
152 __MAX(VOUT_MAX_PICTURES,
153 reserved_picture + decoder_picture - DISPLAY_PICTURE_COUNT));
154 if (!sys->decoder_pool)
155 return VLC_EGENERIC;
156 if (allow_dr) {
157 msg_Warn(vout, "Not enough direct buffers, using system memory");
158 sys->dpb_size = 0;
159 } else {
160 sys->dpb_size = picture_pool_GetSize(sys->decoder_pool) - reserved_picture;
162 NoDrInit(vout);
164 sys->private_pool = picture_pool_Reserve(sys->decoder_pool, private_picture);
165 if (!sys->private_pool)
167 if (sys->decoder_pool != sys->display_pool)
168 picture_pool_Release(sys->decoder_pool);
169 sys->display_pool = sys->decoder_pool = NULL;
170 return VLC_EGENERIC;
172 return VLC_SUCCESS;
175 /*****************************************************************************
177 *****************************************************************************/
178 void vout_EndWrapper(vout_thread_t *vout)
180 vout_thread_sys_t *sys = vout->p;
182 assert(vout->p->decoder_pool && vout->p->private_pool);
184 picture_pool_Release(sys->private_pool);
186 if (sys->decoder_pool != sys->display_pool)
187 picture_pool_Release(sys->decoder_pool);
190 /*****************************************************************************
192 *****************************************************************************/
193 void vout_ManageWrapper(vout_thread_t *vout)
195 vout_thread_sys_t *sys = vout->p;
196 vout_display_t *vd = sys->display.vd;
198 bool reset_display_pool = vout_AreDisplayPicturesInvalid(vd);
199 reset_display_pool |= vout_ManageDisplay(vd, !sys->display.use_dr || reset_display_pool);
201 if (reset_display_pool) {
202 sys->display.use_dr = !vout_IsDisplayFiltered(vd);
203 NoDrInit(vout);
207 #ifdef _WIN32
208 static int Forward(vlc_object_t *object, char const *var,
209 vlc_value_t oldval, vlc_value_t newval, void *data)
211 vout_thread_t *vout = (vout_thread_t*)object;
213 VLC_UNUSED(oldval);
214 VLC_UNUSED(data);
215 return var_Set(vout->p->display.vd, var, newval);
217 #endif