]> git.sesse.net Git - vlc/blob - src/video_output/vout_wrapper.c
4ed32559c6030252a64cae33fcecfea564e5c747
[vlc] / src / video_output / vout_wrapper.c
1 /*****************************************************************************
2  * vout_display.c: "vout display" -> "video output" wrapper
3  *****************************************************************************
4  * Copyright (C) 2009 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
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"
38
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
46
47 /*****************************************************************************
48  *
49  *****************************************************************************/
50 int vout_OpenWrapper(vout_thread_t *vout,
51                      const char *splitter_name, const vout_display_state_t *state)
52 {
53     vout_thread_sys_t *sys = vout->p;
54     msg_Dbg(vout, "Opening vout display wrapper");
55
56     /* */
57     sys->display.title = var_CreateGetNonEmptyString(vout, "video-title");
58
59     /* */
60     const mtime_t double_click_timeout = 300000;
61     const mtime_t hide_timeout = var_CreateGetInteger(vout, "mouse-hide-timeout") * 1000;
62
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);
69     }
70     if (!sys->display.vd) {
71         free(sys->display.title);
72         return VLC_EGENERIC;
73     }
74
75     /* */
76 #ifdef WIN32
77     var_Create(vout, "direct3d-desktop", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
78     var_AddCallback(vout, "direct3d-desktop", Forward, NULL);
79     var_Create(vout, "video-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT);
80     var_AddCallback(vout, "video-wallpaper", Forward, NULL);
81 #endif
82
83     /* */
84     sys->decoder_pool = NULL;
85
86     return VLC_SUCCESS;
87 }
88
89 /*****************************************************************************
90  *
91  *****************************************************************************/
92 void vout_CloseWrapper(vout_thread_t *vout, vout_display_state_t *state)
93 {
94     vout_thread_sys_t *sys = vout->p;
95
96 #ifdef WIN32
97     var_DelCallback(vout, "direct3d-desktop", Forward, NULL);
98     var_DelCallback(vout, "video-wallpaper", Forward, NULL);
99 #endif
100     sys->decoder_pool = NULL; /* FIXME remove */
101
102     vout_DeleteDisplay(sys->display.vd, state);
103     free(sys->display.title);
104 }
105
106 /*****************************************************************************
107  *
108  *****************************************************************************/
109 /* Minimum number of display picture */
110 #define DISPLAY_PICTURE_COUNT (1)
111
112 static void NoDrInit(vout_thread_t *vout)
113 {
114     vout_thread_sys_t *sys = vout->p;
115
116     if (sys->display.use_dr)
117         sys->display_pool = vout_display_Pool(sys->display.vd, 3);
118     else
119         //sys->display_pool = picture_pool_Reserve(sys->decoder_pool, DISPLAY_PICTURE_COUNT);
120         sys->display_pool = picture_pool_NewFromFormat(&sys->display.vd->source, DISPLAY_PICTURE_COUNT);
121 }
122 static void NoDrClean(vout_thread_t *vout)
123 {
124     vout_thread_sys_t *sys = vout->p;
125
126     if (!sys->display.use_dr)
127         picture_pool_Delete(sys->display_pool);
128 }
129 int vout_InitWrapper(vout_thread_t *vout)
130 {
131     vout_thread_sys_t *sys = vout->p;
132     vout_display_t *vd = sys->display.vd;
133     video_format_t source = vd->source;
134
135     sys->display.use_dr = !vout_IsDisplayFiltered(vd);
136     const bool allow_dr = !vd->info.has_pictures_invalid && sys->display.use_dr;
137     const unsigned private_picture  = 3; /* XXX 2 for filter, 1 for SPU */
138     const unsigned decoder_picture  = 1 + sys->dpb_size;
139     const unsigned kept_picture     = 1; /* last displayed picture */
140     const unsigned reserved_picture = DISPLAY_PICTURE_COUNT +
141                                       private_picture +
142                                       kept_picture;
143     picture_pool_t *display_pool =
144         vout_display_Pool(vd, allow_dr ? __MAX(VOUT_MAX_PICTURES,
145                                                reserved_picture + decoder_picture) : 3);
146     if (allow_dr &&
147         picture_pool_GetSize(display_pool) >= reserved_picture + decoder_picture) {
148         sys->dpb_size     = picture_pool_GetSize(display_pool) - reserved_picture;
149         sys->decoder_pool = display_pool;
150         sys->display_pool = display_pool;
151         sys->is_decoder_pool_slow = vd->info.is_slow;
152     } else if (!sys->decoder_pool) {
153         sys->decoder_pool =
154             picture_pool_NewFromFormat(&source,
155                                        __MAX(VOUT_MAX_PICTURES,
156                                              reserved_picture + decoder_picture - DISPLAY_PICTURE_COUNT));
157         if (allow_dr) {
158             msg_Warn(vout, "Not enough direct buffers, using system memory");
159             sys->dpb_size = 0;
160         } else {
161             sys->dpb_size = picture_pool_GetSize(sys->decoder_pool) - reserved_picture;
162         }
163         NoDrInit(vout);
164         sys->is_decoder_pool_slow = false;
165     }
166     sys->private_pool = picture_pool_Reserve(sys->decoder_pool, private_picture);
167     sys->display.filtered = NULL;
168     return VLC_SUCCESS;
169 }
170
171 /*****************************************************************************
172  *
173  *****************************************************************************/
174 void vout_EndWrapper(vout_thread_t *vout)
175 {
176     vout_thread_sys_t *sys = vout->p;
177
178     assert(!sys->display.filtered);
179     if (sys->private_pool)
180         picture_pool_Delete(sys->private_pool);
181
182     if (sys->decoder_pool != sys->display_pool) {
183         NoDrClean(vout);
184         picture_pool_Delete(sys->decoder_pool);
185     }
186 }
187
188 /*****************************************************************************
189  *
190  *****************************************************************************/
191 void vout_ManageWrapper(vout_thread_t *vout)
192 {
193     vout_thread_sys_t *sys = vout->p;
194     vout_display_t *vd = sys->display.vd;
195
196     bool reset_display_pool = sys->display.use_dr && vout_AreDisplayPicturesInvalid(vd);
197     vout_ManageDisplay(vd, !sys->display.use_dr || reset_display_pool);
198
199     if (reset_display_pool) {
200         NoDrClean(vout);
201
202         sys->display.use_dr = !vout_IsDisplayFiltered(vd);
203         NoDrInit(vout);
204     }
205 }
206
207 /*****************************************************************************
208  * Render
209  *****************************************************************************/
210 void vout_RenderWrapper(vout_thread_t *vout,
211                         picture_t *picture, subpicture_t *subpicture)
212 {
213     vout_thread_sys_t *sys = vout->p;
214     vout_display_t *vd = sys->display.vd;
215
216     assert(vout_IsDisplayFiltered(vd) == !sys->display.use_dr);
217
218     vout_UpdateDisplaySourceProperties(vd, &picture->format);
219     if (sys->display.use_dr) {
220         vout_display_Prepare(vd, picture, subpicture);
221     } else {
222         sys->display.filtered = vout_FilterDisplay(vd, picture);
223         if (sys->display.filtered)
224             vout_display_Prepare(vd, sys->display.filtered, subpicture);
225     }
226 }
227
228 /*****************************************************************************
229  *
230  *****************************************************************************/
231 void vout_DisplayWrapper(vout_thread_t *vout,
232                          picture_t *picture, subpicture_t *subpicture)
233 {
234     vout_thread_sys_t *sys = vout->p;
235     vout_display_t *vd = sys->display.vd;
236
237     vout_display_Display(vd,
238                          sys->display.filtered ? sys->display.filtered
239                                                 : picture,
240                          subpicture);
241     sys->display.filtered = NULL;
242 }
243
244 #ifdef WIN32
245 static int Forward(vlc_object_t *object, char const *var,
246                    vlc_value_t oldval, vlc_value_t newval, void *data)
247 {
248     vout_thread_t *vout = (vout_thread_t*)object;
249
250     VLC_UNUSED(oldval);
251     VLC_UNUSED(data);
252     return var_Set(vout->p->display.vd, var, newval);
253 }
254 #endif
255