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