]> git.sesse.net Git - vlc/blob - src/video_output/event.h
Privatize aout_request_vout_t
[vlc] / src / video_output / event.h
1 /*****************************************************************************
2  * event.h: vout event
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 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
26 #endif
27
28 #include <vlc_common.h>
29 #include <vlc_playlist.h>
30 #include <math.h>
31
32 #include "vout_control.h"
33
34 /* TODO/FIXME
35  *
36  * It should be converted to something like input_thread_t:
37  * one intf-event can be grabbed by a callback, all others
38  * variable only var_Change
39  *
40  * Maybe a intf-mouse can be used too (don't like it).
41  *
42  * (Some case may infinite loop otherwise here)
43  */
44
45 static inline void vout_SendEventClose(vout_thread_t *vout)
46 {
47         /* Ask to stop
48          * FIXME works only for input handled by the playlist
49          */
50         playlist_t *playlist = pl_Hold(vout);
51         if (playlist) {
52                 playlist_Stop(playlist);
53                 pl_Release(vout);
54         }
55 }
56 static inline void vout_SendEventKey(vout_thread_t *vout, int key)
57 {
58         var_SetInteger(vout->p_libvlc, "key-pressed", key);
59 }
60 static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
61 {
62         var_SetInteger(vout, "mouse-x", x);
63         var_SetInteger(vout, "mouse-y", y);
64         var_SetBool(vout, "mouse-moved", true);
65 }
66 static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
67 {
68         int current = var_GetInteger(vout, "mouse-button-down");
69         current |= 1 << button;
70         var_SetInteger(vout, "mouse-button-down", current);
71
72         switch (button)
73         {
74         case MOUSE_BUTTON_LEFT:
75         var_SetBool(vout, "mouse-clicked", true);
76                 var_SetBool(vout->p_libvlc, "intf-popupmenu", false);
77                 break;
78         case MOUSE_BUTTON_CENTER:
79                 var_SetBool(vout->p_libvlc, "intf-show",
80                                          !var_GetBool(vout->p_libvlc, "intf-show"));
81                 break;
82         case MOUSE_BUTTON_RIGHT:
83                 var_SetBool(vout->p_libvlc, "intf-popupmenu", true);
84                 break;
85         }
86 }
87 static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
88 {
89         int current = var_GetInteger(vout, "mouse-button-down");
90         current &= ~(1 << button);
91         var_SetInteger(vout, "mouse-button-down", current);
92 }
93 static inline void vout_SendEventMouseDoubleClick(vout_thread_t *vout)
94 {
95     //vout_ControlSetFullscreen(vout, !var_GetBool(vout, "fullscreen"));
96     var_ToggleBool(vout, "fullscreen");
97 }
98 static inline void vout_SendEventMouseVisible(vout_thread_t *vout)
99 {
100     /* TODO */
101     VLC_UNUSED(vout);
102 }
103 static inline void vout_SendEventMouseHidden(vout_thread_t *vout)
104 {
105     /* TODO */
106     VLC_UNUSED(vout);
107 }
108
109 static inline void vout_SendEventFullscreen(vout_thread_t *vout, bool is_fullscreen)
110 {
111     if (!var_GetBool(vout, "fullscreen") != !is_fullscreen)
112         var_SetBool(vout, "fullscreen", is_fullscreen);
113 }
114
115 static inline void vout_SendEventDisplayFilled(vout_thread_t *vout, bool is_display_filled)
116 {
117     if (!var_GetBool(vout, "autoscale") != !is_display_filled)
118         var_SetBool(vout, "autoscale", is_display_filled);
119 }
120
121 static inline void vout_SendEventZoom(vout_thread_t *vout, int num, int den)
122 {
123     VLC_UNUSED(vout);
124     VLC_UNUSED(num);
125     VLC_UNUSED(den);
126     /* FIXME deadlock problems with current vout */
127 #if 0
128     const float zoom = (float)num / (float)den;
129
130     /* XXX 0.1% is arbitrary */
131     if (fabs(zoom - var_GetFloat(vout, "scale")) > 0.001)
132         var_SetFloat(vout, "scale", zoom);
133 #endif
134 }
135
136 static inline void vout_SendEventOnTop(vout_thread_t *vout, bool is_on_top)
137 {
138     VLC_UNUSED(vout);
139     VLC_UNUSED(is_on_top);
140     /* FIXME deadlock problems with current vout */
141 #if 0
142
143     if (!var_GetBool(vout, "video-on-top") != !is_on_top)
144         var_SetBool(vout, "video-on-top", is_on_top);
145 #endif
146 }
147
148 /**
149  * It must be called on source aspect ratio changes, with the new DAR (Display
150  * Aspect Ratio) value.
151  */
152 static inline void vout_SendEventSourceAspect(vout_thread_t *vout,
153                                               unsigned num, unsigned den)
154 {
155     VLC_UNUSED(vout);
156     VLC_UNUSED(num);
157     VLC_UNUSED(den);
158     /* FIXME the value stored in "aspect-ratio" are not reduced
159      * creating a lot of problems here */
160 #if 0
161     char *ar;
162     if (num > 0 && den > 0) {
163         if (asprintf(&ar, "%u:%u", num, den) < 0)
164             return;
165     } else {
166         ar = strdup("");
167     }
168
169     char *current = var_GetString(vout, "aspect-ratio");
170     msg_Err(vout, "vout_SendEventSourceAspect %s -> %s", current, ar);
171     if (ar && current && strcmp(ar, current))
172         var_SetString(vout, "aspect-ratio", ar);
173
174     free(current);
175     free(ar);
176 #endif
177 }
178 static inline void vout_SendEventSourceCrop(vout_thread_t *vout,
179                                             unsigned num, unsigned den,
180                                             unsigned left, unsigned top,
181                                             unsigned right, unsigned bottom)
182 {
183     VLC_UNUSED(num);
184     VLC_UNUSED(den);
185
186     vlc_value_t val;
187
188     /* I cannot use var_Set here, infinite loop otherwise */
189
190     /* */
191     val.i_int = left;
192     var_Change(vout, "crop-left",   VLC_VAR_SETVALUE, &val, NULL);
193     val.i_int = top;
194     var_Change(vout, "crop-top",    VLC_VAR_SETVALUE, &val, NULL);
195     val.i_int = right;
196     var_Change(vout, "crop-right",  VLC_VAR_SETVALUE, &val, NULL);
197     val.i_int = bottom;
198     var_Change(vout, "crop-bottom", VLC_VAR_SETVALUE, &val, NULL);
199
200     /* FIXME the value stored in "crop" are not reduced
201      * creating a lot of problems here */
202 #if 0
203     char *crop;
204     if (num > 0 && den > 0) {
205         if (asprintf(&crop, "%u:%u", num, den) < 0)
206             crop = NULL;
207     } else if (left > 0 || top > 0 || right > 0 || bottom > 0) {
208         if (asprintf(&crop, "%u+%u+%u+%u", left, top, right, bottom) < 0)
209             crop = NULL;
210     } else {
211         crop = strdup("");
212     }
213     if (crop) {
214         val.psz_string = crop;
215         var_Change(vout, "crop", VLC_VAR_SETVALUE, &val, NULL);
216         free(crop);
217     }
218 #endif
219 }
220 #if 0
221 static inline void vout_SendEventSnapshot(vout_thread_t *vout, const char *filename)
222 {
223     /* signal creation of a new snapshot file */
224     var_SetString(vout->p_libvlc, "snapshot-file", filename);
225 }
226
227 #warning "FIXME clean up postproc event"
228
229 extern void vout_InstallDeprecatedPostProcessing(vout_thread_t *);
230 extern void vout_UninstallDeprecatedPostProcessing(vout_thread_t *);
231
232 static inline void vout_SendEventPostProcessing(vout_thread_t *vout, bool is_available)
233 {
234     if (is_available)
235         vout_InstallDeprecatedPostProcessing(vout);
236     else
237         vout_UninstallDeprecatedPostProcessing(vout);
238 }
239
240 static inline void vout_SendEventFilters(vout_thread_t *vout)
241 {
242     vout_filter_t **filter;
243     int           filter_count;
244
245     vout_ControlGetFilters(vout, &filter, &filter_count);
246
247     char *list = strdup("");
248     for (int i = 0; i < filter_count; i++) {
249         char *psz;
250
251         if (asprintf(&psz, "%s%s%s",
252                      list, i > 0 ? ":" : "", filter[i]->name) < 0) {
253             free(list);
254             list = NULL;
255             break;
256         }
257         free(list);
258         list = psz;
259     }
260
261     if (list) {
262         vlc_value_t val;
263         val.psz_string = list;
264         var_Change(vout, "video-filter", VLC_VAR_SETVALUE, &val, NULL);
265         free(list);
266     }
267
268     for (int i = 0; i < filter_count; i++)
269         vout_filter_Delete(filter[i]);
270     free(filter);
271 }
272 #endif