1 /*****************************************************************************
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 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
28 #include <vlc_common.h>
29 #include <vlc_playlist.h>
32 #include "vout_control.h"
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
40 * Maybe a intf-mouse can be used too (don't like it).
42 * (Some case may infinite loop otherwise here)
45 static inline void vout_SendEventClose(vout_thread_t *vout)
48 * FIXME works only for input handled by the playlist
50 playlist_t *playlist = pl_Hold(vout);
52 playlist_Stop(playlist);
56 static inline void vout_SendEventKey(vout_thread_t *vout, int key)
58 var_SetInteger(vout->p_libvlc, "key-pressed", key);
60 static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
62 var_SetInteger(vout, "mouse-x", x);
63 var_SetInteger(vout, "mouse-y", y);
64 var_SetBool(vout, "mouse-moved", true);
66 static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
68 int current = var_GetInteger(vout, "mouse-button-down");
69 current |= 1 << button;
70 var_SetInteger(vout, "mouse-button-down", current);
74 case MOUSE_BUTTON_LEFT:
75 var_SetBool(vout, "mouse-clicked", true);
76 var_SetBool(vout->p_libvlc, "intf-popupmenu", false);
78 case MOUSE_BUTTON_CENTER:
79 var_SetBool(vout->p_libvlc, "intf-show",
80 !var_GetBool(vout->p_libvlc, "intf-show"));
82 case MOUSE_BUTTON_RIGHT:
83 var_SetBool(vout->p_libvlc, "intf-popupmenu", true);
87 static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
89 int current = var_GetInteger(vout, "mouse-button-down");
90 current &= ~(1 << button);
91 var_SetInteger(vout, "mouse-button-down", current);
93 static inline void vout_SendEventMouseDoubleClick(vout_thread_t *vout)
95 //vout_ControlSetFullscreen(vout, !var_GetBool(vout, "fullscreen"));
96 var_ToggleBool(vout, "fullscreen");
98 static inline void vout_SendEventMouseVisible(vout_thread_t *vout)
103 static inline void vout_SendEventMouseHidden(vout_thread_t *vout)
109 static inline void vout_SendEventFullscreen(vout_thread_t *vout, bool is_fullscreen)
111 if (!var_GetBool(vout, "fullscreen") != !is_fullscreen)
112 var_SetBool(vout, "fullscreen", is_fullscreen);
115 static inline void vout_SendEventDisplayFilled(vout_thread_t *vout, bool is_display_filled)
117 if (!var_GetBool(vout, "autoscale") != !is_display_filled)
118 var_SetBool(vout, "autoscale", is_display_filled);
121 static inline void vout_SendEventZoom(vout_thread_t *vout, int num, int den)
123 /* FIXME deadlock problems with current vout */
125 const float zoom = (float)num / (float)den;
127 /* XXX 0.1% is arbitrary */
128 if (fabs(zoom - var_GetFloat(vout, "scale")) > 0.001)
129 var_SetFloat(vout, "scale", zoom);
133 static inline void vout_SendEventOnTop(vout_thread_t *vout, bool is_on_top)
135 /* FIXME deadlock problems with current vout */
138 if (!var_GetBool(vout, "video-on-top") != !is_on_top)
139 var_SetBool(vout, "video-on-top", is_on_top);
144 * It must be called on source aspect ratio changes, with the new DAR (Display
145 * Aspect Ratio) value.
147 static inline void vout_SendEventSourceAspect(vout_thread_t *vout,
148 unsigned num, unsigned den)
150 /* FIXME the value stored in "aspect-ratio" are not reduced
151 * creating a lot of problems here */
154 if (num > 0 && den > 0) {
155 if (asprintf(&ar, "%u:%u", num, den) < 0)
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);
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)
177 /* I cannot use var_Set here, infinite loop otherwise */
181 var_Change(vout, "crop-left", VLC_VAR_SETVALUE, &val, NULL);
183 var_Change(vout, "crop-top", VLC_VAR_SETVALUE, &val, NULL);
185 var_Change(vout, "crop-right", VLC_VAR_SETVALUE, &val, NULL);
187 var_Change(vout, "crop-bottom", VLC_VAR_SETVALUE, &val, NULL);
189 /* FIXME the value stored in "crop" are not reduced
190 * creating a lot of problems here */
193 if (num > 0 && den > 0) {
194 if (asprintf(&crop, "%u:%u", num, den) < 0)
196 } else if (left > 0 || top > 0 || right > 0 || bottom > 0) {
197 if (asprintf(&crop, "%u+%u+%u+%u", left, top, right, bottom) < 0)
203 val.psz_string = crop;
204 var_Change(vout, "crop", VLC_VAR_SETVALUE, &val, NULL);
210 static inline void vout_SendEventSnapshot(vout_thread_t *vout, const char *filename)
212 /* Generate a media player event - Right now just trigger a global libvlc var
213 CHECK: Could not find a more local object. The goal is to communicate
214 vout_thread with libvlc_media_player or its input_thread */
215 var_SetString(vout->p_libvlc, "vout-snapshottaken", filename);
218 #warning "FIXME clean up postproc event"
220 extern void vout_InstallDeprecatedPostProcessing(vout_thread_t *);
221 extern void vout_UninstallDeprecatedPostProcessing(vout_thread_t *);
223 static inline void vout_SendEventPostProcessing(vout_thread_t *vout, bool is_available)
226 vout_InstallDeprecatedPostProcessing(vout);
228 vout_UninstallDeprecatedPostProcessing(vout);
231 static inline void vout_SendEventFilters(vout_thread_t *vout)
233 vout_filter_t **filter;
236 vout_ControlGetFilters(vout, &filter, &filter_count);
238 char *list = strdup("");
239 for (int i = 0; i < filter_count; i++) {
242 if (asprintf(&psz, "%s%s%s",
243 list, i > 0 ? ":" : "", filter[i]->name) < 0) {
254 val.psz_string = list;
255 var_Change(vout, "video-filter", VLC_VAR_SETVALUE, &val, NULL);
259 for (int i = 0; i < filter_count; i++)
260 vout_filter_Delete(filter[i]);