1 /*****************************************************************************
2 * vout_display.c: "vout display" -> "video output" wrapper
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <vlc_common.h>
32 #include <vlc_plugin.h>
33 #include <vlc_vout_wrapper.h>
36 #include "vout_internal.h"
39 /* Minimum number of direct pictures the video output will accept without
40 * creating additional pictures in system memory */
41 #ifdef OPTIMIZE_MEMORY
42 # define VOUT_MIN_DIRECT_PICTURES (VOUT_MAX_PICTURES/2)
44 # define VOUT_MIN_DIRECT_PICTURES (3*VOUT_MAX_PICTURES/4)
47 /*****************************************************************************
49 *****************************************************************************/
50 static void VoutGetDisplayCfg(vout_thread_t *,
51 vout_display_cfg_t *, const char *title);
53 static int Forward(vlc_object_t *, char const *,
54 vlc_value_t, vlc_value_t, void *);
57 /*****************************************************************************
59 *****************************************************************************/
60 int vout_OpenWrapper(vout_thread_t *vout, const char *name)
62 vout_thread_sys_t *sys = vout->p;
63 msg_Dbg(vout, "Opening vout display wrapper");
66 sys->display.title = var_CreateGetNonEmptyString(vout, "video-title");
69 video_format_t source = vout->p->original;
70 source.i_visible_width = source.i_width;
71 source.i_visible_height = source.i_height;
72 source.i_x_offset = 0;
73 source.i_y_offset = 0;
75 vout_display_state_t state;
76 VoutGetDisplayCfg(vout, &state.cfg, sys->display.title);
77 state.is_on_top = var_CreateGetBool(vout, "video-on-top");
81 const mtime_t double_click_timeout = 300000;
82 const mtime_t hide_timeout = var_CreateGetInteger(vout, "mouse-hide-timeout") * 1000;
84 sys->display.vd = vout_NewDisplay(vout, &source, &state, name ? name : "$vout",
85 double_click_timeout, hide_timeout);
86 /* If we need to video filter and it fails, then try a splitter
87 * XXX it is a hack for now FIXME */
88 if (name && !sys->display.vd)
89 sys->display.vd = vout_NewSplitter(vout, &source, &state, "$vout", name,
90 double_click_timeout, hide_timeout);
91 if (!sys->display.vd) {
92 free(sys->display.title);
98 var_Create(vout, "direct3d-desktop", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
99 var_AddCallback(vout, "direct3d-desktop", Forward, NULL);
100 var_Create(vout, "video-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
101 var_AddCallback(vout, "video-wallpaper", Forward, NULL);
105 sys->decoder_pool = NULL;
110 /*****************************************************************************
112 *****************************************************************************/
113 void vout_CloseWrapper(vout_thread_t *vout)
115 vout_thread_sys_t *sys = vout->p;
118 var_DelCallback(vout, "direct3d-desktop", Forward, NULL);
119 var_DelCallback(vout, "video-wallpaper", Forward, NULL);
121 sys->decoder_pool = NULL; /* FIXME remove */
123 vout_DeleteDisplay(sys->display.vd, NULL);
124 free(sys->display.title);
127 /*****************************************************************************
129 *****************************************************************************/
130 int vout_InitWrapper(vout_thread_t *vout)
132 vout_thread_sys_t *sys = vout->p;
133 vout_display_t *vd = sys->display.vd;
134 video_format_t source = vd->source;
136 /* XXX For non dr case, the current vout implementation force us to
137 * create at most 1 direct picture (otherwise the buffers will be kept
138 * referenced even through the Init/End.
140 sys->display.use_dr = !vout_IsDisplayFiltered(vd);
141 const bool allow_dr = !vd->info.has_pictures_invalid && sys->display.use_dr;
143 picture_pool_t *display_pool = vout_display_Pool(vd, allow_dr ? VOUT_MAX_PICTURES : 3);
144 if (allow_dr && picture_pool_GetSize(display_pool) >= VOUT_MIN_DIRECT_PICTURES) {
145 sys->decoder_pool = display_pool;
146 sys->display_pool = display_pool;
147 sys->is_decoder_pool_slow = vd->info.is_slow;
148 } else if (!sys->decoder_pool) {
149 sys->decoder_pool = picture_pool_NewFromFormat(&source, VOUT_MAX_PICTURES);
150 if (sys->display.use_dr)
151 sys->display_pool = display_pool;
153 sys->display_pool = picture_pool_Reserve(sys->decoder_pool, 1);;
154 sys->is_decoder_pool_slow = false;
156 sys->private_pool = picture_pool_Reserve(sys->decoder_pool, 3); /* XXX 2 for filter, 1 for SPU */
157 sys->display.filtered = NULL;
161 /*****************************************************************************
163 *****************************************************************************/
164 void vout_EndWrapper(vout_thread_t *vout)
166 vout_thread_sys_t *sys = vout->p;
168 assert(!sys->display.filtered);
169 if (sys->private_pool)
170 picture_pool_Delete(sys->private_pool);
172 if (sys->decoder_pool != sys->display_pool) {
173 if (!sys->display.use_dr)
174 picture_pool_Delete(sys->display_pool);
175 picture_pool_Delete(sys->decoder_pool);
179 /*****************************************************************************
181 *****************************************************************************/
182 int vout_ManageWrapper(vout_thread_t *vout)
184 vout_thread_sys_t *sys = vout->p;
185 vout_display_t *vd = sys->display.vd;
187 bool reset_display_pool = sys->display.use_dr && vout_AreDisplayPicturesInvalid(vd);
188 vout_ManageDisplay(vd, !sys->display.use_dr || reset_display_pool);
190 if (reset_display_pool)
191 sys->display_pool = vout_display_Pool(vd, 3);
196 /*****************************************************************************
198 *****************************************************************************/
199 void vout_RenderWrapper(vout_thread_t *vout, picture_t *picture)
201 vout_thread_sys_t *sys = vout->p;
202 vout_display_t *vd = sys->display.vd;
204 assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
206 if (sys->display.use_dr) {
207 vout_display_Prepare(vd, picture);
209 sys->display.filtered = vout_FilterDisplay(vd, picture);
210 if (sys->display.filtered)
211 vout_display_Prepare(vd, sys->display.filtered);
215 /*****************************************************************************
217 *****************************************************************************/
218 void vout_DisplayWrapper(vout_thread_t *vout, picture_t *picture)
220 vout_thread_sys_t *sys = vout->p;
221 vout_display_t *vd = sys->display.vd;
223 vout_display_Display(vd, sys->display.filtered ? sys->display.filtered : picture);
224 sys->display.filtered = NULL;
227 static void VoutGetDisplayCfg(vout_thread_t *vout, vout_display_cfg_t *cfg, const char *title)
229 /* Load configuration */
230 cfg->is_fullscreen = var_CreateGetBool(vout, "fullscreen");
231 cfg->display.title = title;
232 const int display_width = var_CreateGetInteger(vout, "width");
233 const int display_height = var_CreateGetInteger(vout, "height");
234 cfg->display.width = display_width > 0 ? display_width : 0;
235 cfg->display.height = display_height > 0 ? display_height : 0;
236 cfg->is_display_filled = var_CreateGetBool(vout, "autoscale");
237 cfg->display.sar.num = 1; /* TODO monitor AR */
238 cfg->display.sar.den = 1;
239 unsigned zoom_den = 1000;
240 unsigned zoom_num = zoom_den * var_CreateGetFloat(vout, "scale");
241 vlc_ureduce(&zoom_num, &zoom_den, zoom_num, zoom_den, 0);
242 cfg->zoom.num = zoom_num;
243 cfg->zoom.den = zoom_den;
244 cfg->align.vertical = VOUT_DISPLAY_ALIGN_CENTER;
245 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_CENTER;
246 const int align_mask = var_CreateGetInteger(vout, "align");
247 if (align_mask & 0x1)
248 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_LEFT;
249 else if (align_mask & 0x2)
250 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_RIGHT;
251 if (align_mask & 0x4)
252 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_TOP;
253 else if (align_mask & 0x8)
254 cfg->align.horizontal = VOUT_DISPLAY_ALIGN_BOTTOM;
258 static int Forward(vlc_object_t *object, char const *var,
259 vlc_value_t oldval, vlc_value_t newval, void *data)
261 vout_thread_t *vout = (vout_thread_t*)object;
265 return var_Set(vout->p->display.vd, var, newval);