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