event.h

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

Generated on Mon Nov 22 07:55:20 2010 for VLC by  doxygen 1.5.6