event.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * event.h: vout event
00003  *****************************************************************************
00004  * Copyright (C) 2009 Laurent Aimar
00005  * $Id: 38c7be40bda53fa6d38c87aa3ae6ba4455492486 $
00006  *
00007  * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify it
00010  * under the terms of the GNU Lesser General Public License as published by
00011  * the Free Software Foundation; either version 2.1 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017  * GNU Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public License
00020  * along with this program; if not, write to the Free Software Foundation,
00021  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 #include <vlc_common.h>
00025 #include <vlc_playlist.h>
00026 #include <math.h>
00027 
00028 #include "vout_control.h"
00029 
00030 /* TODO/FIXME
00031  *
00032  * It should be converted to something like input_thread_t:
00033  * one intf-event can be grabbed by a callback, all others
00034  * variable only var_Change
00035  *
00036  * Maybe a intf-mouse can be used too (don't like it).
00037  *
00038  * (Some case may infinite loop otherwise here)
00039  */
00040 
00041 static inline void vout_SendEventClose(vout_thread_t *vout)
00042 {
00043     /* Ask to stop
00044      * FIXME works only for input handled by the playlist
00045      */
00046     playlist_t *playlist = pl_Get(vout);
00047     playlist_Stop(playlist);
00048 }
00049 static inline void vout_SendEventKey(vout_thread_t *vout, int key)
00050 {
00051     var_SetInteger(vout->p_libvlc, "key-pressed", key);
00052 }
00053 static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
00054 {
00055     var_SetCoords(vout, "mouse-moved", x, y);
00056 }
00057 static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
00058 {
00059     int key;
00060     var_OrInteger(vout, "mouse-button-down", 1 << button);
00061 
00062     switch (button)
00063     {
00064     case MOUSE_BUTTON_LEFT:
00065     {
00066         /* FIXME? */
00067         int x, y;
00068         var_GetCoords(vout, "mouse-moved", &x, &y);
00069         var_SetCoords(vout, "mouse-clicked", x, y);
00070         var_SetBool(vout->p_libvlc, "intf-popupmenu", false);
00071         return;
00072     }
00073     case MOUSE_BUTTON_CENTER:
00074         var_ToggleBool(vout->p_libvlc, "intf-toggle-fscontrol");
00075         return;
00076     case MOUSE_BUTTON_RIGHT:
00077         var_SetBool(vout->p_libvlc, "intf-popupmenu", true);
00078         return;
00079     case MOUSE_BUTTON_WHEEL_UP:    key = KEY_MOUSEWHEELUP;    break;
00080     case MOUSE_BUTTON_WHEEL_DOWN:  key = KEY_MOUSEWHEELDOWN;  break;
00081     case MOUSE_BUTTON_WHEEL_LEFT:  key = KEY_MOUSEWHEELLEFT;  break;
00082     case MOUSE_BUTTON_WHEEL_RIGHT: key = KEY_MOUSEWHEELRIGHT; break;
00083     }
00084     vout_SendEventKey(vout, key);
00085 }
00086 static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
00087 {
00088     var_NAndInteger(vout, "mouse-button-down", 1 << button);
00089 }
00090 static inline void vout_SendEventMouseDoubleClick(vout_thread_t *vout)
00091 {
00092     //vout_ControlSetFullscreen(vout, !var_GetBool(vout, "fullscreen"));
00093     //var_ToggleBool(vout, "fullscreen");
00094     var_SetInteger(vout->p_libvlc, "key-action", ACTIONID_TOGGLE_FULLSCREEN);
00095 }
00096 static inline void vout_SendEventMouseVisible(vout_thread_t *vout)
00097 {
00098     /* TODO */
00099     VLC_UNUSED(vout);
00100 }
00101 static inline void vout_SendEventMouseHidden(vout_thread_t *vout)
00102 {
00103     /* TODO */
00104     VLC_UNUSED(vout);
00105 }
00106 
00107 static inline void vout_SendEventFullscreen(vout_thread_t *vout, bool is_fullscreen)
00108 {
00109     var_SetBool(vout, "fullscreen", is_fullscreen);
00110 }
00111 
00112 static inline void vout_SendEventDisplayFilled(vout_thread_t *vout, bool is_display_filled)
00113 {
00114     if (!var_GetBool(vout, "autoscale") != !is_display_filled)
00115         var_SetBool(vout, "autoscale", is_display_filled);
00116 }
00117 
00118 static inline void vout_SendEventZoom(vout_thread_t *vout, int num, int den)
00119 {
00120     VLC_UNUSED(vout);
00121     VLC_UNUSED(num);
00122     VLC_UNUSED(den);
00123     /* FIXME deadlock problems with current vout */
00124 #if 0
00125     const float zoom = (float)num / (float)den;
00126 
00127     /* XXX 0.1% is arbitrary */
00128     if (fabs(zoom - var_GetFloat(vout, "scale")) > 0.001)
00129         var_SetFloat(vout, "scale", zoom);
00130 #endif
00131 }
00132 
00133 static inline void vout_SendEventOnTop(vout_thread_t *vout, bool is_on_top)
00134 {
00135     VLC_UNUSED(vout);
00136     VLC_UNUSED(is_on_top);
00137     /* FIXME deadlock problems with current vout */
00138 #if 0
00139 
00140     if (!var_GetBool(vout, "video-on-top") != !is_on_top)
00141         var_SetBool(vout, "video-on-top", is_on_top);
00142 #endif
00143 }
00144 
00145 /**
00146  * It must be called on source aspect ratio changes, with the new DAR (Display
00147  * Aspect Ratio) value.
00148  */
00149 static inline void vout_SendEventSourceAspect(vout_thread_t *vout,
00150                                               unsigned num, unsigned den)
00151 {
00152     VLC_UNUSED(vout);
00153     VLC_UNUSED(num);
00154     VLC_UNUSED(den);
00155     /* FIXME the value stored in "aspect-ratio" are not reduced
00156      * creating a lot of problems here */
00157 #if 0
00158     char *ar;
00159     if (num > 0 && den > 0) {
00160         if (asprintf(&ar, "%u:%u", num, den) < 0)
00161             return;
00162     } else {
00163         ar = strdup("");
00164     }
00165 
00166     char *current = var_GetString(vout, "aspect-ratio");
00167     msg_Err(vout, "vout_SendEventSourceAspect %s -> %s", current, ar);
00168     if (ar && current && strcmp(ar, current))
00169         var_SetString(vout, "aspect-ratio", ar);
00170 
00171     free(current);
00172     free(ar);
00173 #endif
00174 }
00175 static inline void vout_SendEventSourceCrop(vout_thread_t *vout,
00176                                             unsigned num, unsigned den,
00177                                             unsigned left, unsigned top,
00178                                             unsigned right, unsigned bottom)
00179 {
00180     VLC_UNUSED(num);
00181     VLC_UNUSED(den);
00182 
00183     vlc_value_t val;
00184 
00185     /* I cannot use var_Set here, infinite loop otherwise */
00186 
00187     /* */
00188     val.i_int = left;
00189     var_Change(vout, "crop-left",   VLC_VAR_SETVALUE, &val, NULL);
00190     val.i_int = top;
00191     var_Change(vout, "crop-top",    VLC_VAR_SETVALUE, &val, NULL);
00192     val.i_int = right;
00193     var_Change(vout, "crop-right",  VLC_VAR_SETVALUE, &val, NULL);
00194     val.i_int = bottom;
00195     var_Change(vout, "crop-bottom", VLC_VAR_SETVALUE, &val, NULL);
00196 
00197     /* FIXME the value stored in "crop" are not reduced
00198      * creating a lot of problems here */
00199 #if 0
00200     char *crop;
00201     if (num > 0 && den > 0) {
00202         if (asprintf(&crop, "%u:%u", num, den) < 0)
00203             crop = NULL;
00204     } else if (left > 0 || top > 0 || right > 0 || bottom > 0) {
00205         if (asprintf(&crop, "%u+%u+%u+%u", left, top, right, bottom) < 0)
00206             crop = NULL;
00207     } else {
00208         crop = strdup("");
00209     }
00210     if (crop) {
00211         val.psz_string = crop;
00212         var_Change(vout, "crop", VLC_VAR_SETVALUE, &val, NULL);
00213         free(crop);
00214     }
00215 #endif
00216 }
00217 #if 0
00218 static inline void vout_SendEventSnapshot(vout_thread_t *vout, const char *filename)
00219 {
00220     /* signal creation of a new snapshot file */
00221     var_SetString(vout->p_libvlc, "snapshot-file", filename);
00222 }
00223 
00224 #warning "FIXME clean up postproc event"
00225 
00226 extern void vout_InstallDeprecatedPostProcessing(vout_thread_t *);
00227 extern void vout_UninstallDeprecatedPostProcessing(vout_thread_t *);
00228 
00229 static inline void vout_SendEventPostProcessing(vout_thread_t *vout, bool is_available)
00230 {
00231     if (is_available)
00232         vout_InstallDeprecatedPostProcessing(vout);
00233     else
00234         vout_UninstallDeprecatedPostProcessing(vout);
00235 }
00236 
00237 static inline void vout_SendEventFilters(vout_thread_t *vout)
00238 {
00239     vout_filter_t **filter;
00240     int           filter_count;
00241 
00242     vout_ControlGetFilters(vout, &filter, &filter_count);
00243 
00244     char *list = strdup("");
00245     for (int i = 0; i < filter_count; i++) {
00246         char *psz;
00247 
00248         if (asprintf(&psz, "%s%s%s",
00249                      list, i > 0 ? ":" : "", filter[i]->name) < 0) {
00250             free(list);
00251             list = NULL;
00252             break;
00253         }
00254         free(list);
00255         list = psz;
00256     }
00257 
00258     if (list) {
00259         vlc_value_t val;
00260         val.psz_string = list;
00261         var_Change(vout, "video-filter", VLC_VAR_SETVALUE, &val, NULL);
00262         free(list);
00263     }
00264 
00265     for (int i = 0; i < filter_count; i++)
00266         vout_filter_Delete(filter[i]);
00267     free(filter);
00268 }
00269 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines