[vlc-devel] [PATCH 1/2] hotkeys: use new playlist / player and refactor
Victorien Le Couviour--Tuffet
victorien.lecouviour.tuffet at gmail.com
Mon Dec 3 13:26:14 CET 2018
---
handle device cycling within the module (aout next device patch dropped)
modules/control/hotkeys.c | 2284 +++++++++++++++----------------------
1 file changed, 895 insertions(+), 1389 deletions(-)
diff --git a/modules/control/hotkeys.c b/modules/control/hotkeys.c
index 334abab534..0d3485849b 100644
--- a/modules/control/hotkeys.c
+++ b/modules/control/hotkeys.c
@@ -6,6 +6,7 @@
*
* Authors: Sigmund Augdal Helberg <dnumgis at videolan.org>
* Jean-Paul Saman <jpsaman #_at_# m2x.nl>
+ * Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet at gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,10 +23,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@@ -34,1566 +31,1075 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_interface.h>
-#include <vlc_input.h>
-#include <vlc_aout.h>
+#include <vlc_input_item.h>
#include <vlc_mouse.h>
#include <vlc_viewpoint.h>
-#include <vlc_vout_osd.h>
-#include <vlc_playlist_legacy.h>
+#include <vlc_player.h>
+#include <vlc_playlist.h>
#include <vlc_actions.h>
#include "math.h"
-#include <assert.h>
-
-/*****************************************************************************
- * intf_sys_t: description and status of FB interface
- *****************************************************************************/
struct intf_sys_t
{
- vlc_mutex_t lock;
- vout_thread_t *p_vout;
- input_thread_t *p_input;
- int slider_chan;
-
- /*subtitle_delaybookmarks: placeholder for storing subtitle sync timestamps*/
- struct
- {
- vlc_tick_t i_time_subtitle;
- vlc_tick_t i_time_audio;
- } subtitle_delaybookmarks;
-
+ vlc_playlist_t *playlist;
+ vlc_player_listener_id *player_listener;
struct
{
- bool b_can_change;
- bool b_button_pressed;
+ bool btn_pressed;
int x, y;
} vrnav;
};
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-static int Open ( vlc_object_t * );
-static void Close ( vlc_object_t * );
-static int ActionEvent( vlc_object_t *, char const *,
- vlc_value_t, vlc_value_t, void * );
-static void PlayBookmark( intf_thread_t *, int );
-static void SetBookmark ( intf_thread_t *, int );
-static void DisplayPosition( vout_thread_t *, int, input_thread_t * );
-static void DisplayVolume( vout_thread_t *, int, float );
-static void DisplayRate ( vout_thread_t *, float );
-static float AdjustRateFine( vlc_object_t *, const int );
-static void ClearChannels ( vout_thread_t *, int );
-
-#define DisplayMessage(vout, ...) \
- do { \
- if (vout) \
- vout_OSDMessage(vout, VOUT_SPU_CHANNEL_OSD, __VA_ARGS__); \
- } while(0)
-#define DisplayIcon(vout, icon) \
- do { if(vout) vout_OSDIcon(vout, VOUT_SPU_CHANNEL_OSD, icon); } while(0)
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
+static void handle_action(intf_thread_t *, vlc_action_id_t);
-vlc_module_begin ()
- set_shortname( N_("Hotkeys") )
- set_description( N_("Hotkeys management interface") )
- set_capability( "interface", 0 )
- set_callbacks( Open, Close )
- set_category( CAT_INTERFACE )
- set_subcategory( SUBCAT_INTERFACE_HOTKEYS )
+/*****************************
+ * interface action handling *
+ *****************************/
-vlc_module_end ()
+#define INTF_ACTION_HANDLER(name) \
+static inline void \
+action_handler_Intf##name(intf_thread_t *intf, vlc_action_id_t action_id)
-static void var_FreeList( size_t n, vlc_value_t *values, char **texts )
+INTF_ACTION_HANDLER()
{
- free( values );
-
- for( size_t i = 0; i < n; i++ )
- free( texts[i] );
- free( texts );
+ char const *varname;
+ switch (action_id)
+ {
+ case ACTIONID_QUIT:
+ return libvlc_Quit(intf->obj.libvlc);
+ case ACTIONID_INTF_TOGGLE_FSC:
+ case ACTIONID_INTF_HIDE:
+ varname = "intf-toggle-fscontrol";
+ break;
+ case ACTIONID_INTF_BOSS:
+ varname = "intf-boss";
+ break;
+ case ACTIONID_INTF_POPUP_MENU:
+ varname = "intf-popupmenu";
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
+ var_TriggerCallback(intf->obj.libvlc, varname);
}
-static void var_FreeStringList( size_t n, vlc_value_t *values, char **texts )
+INTF_ACTION_HANDLER(ActionCombo)
{
- for( size_t i = 0; i < n; i++ )
- free( values[i].psz_string );
-
- var_FreeList( n, values, texts );
+ vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+ vout_thread_t *vout = vlc_player_vout_Hold(player);
+ bool vrnav = var_GetBool(vout, "viewpoint-changeable");
+ vlc_object_release(vout);
+ switch (action_id)
+ {
+ case ACTIONID_COMBO_VOL_FOV_DOWN:
+ action_id = !vrnav
+ ? ACTIONID_VOL_DOWN
+ : ACTIONID_VIEWPOINT_FOV_OUT;
+ break;
+ case ACTIONID_COMBO_VOL_FOV_UP:
+ action_id = !vrnav
+ ? ACTIONID_VOL_UP
+ : ACTIONID_VIEWPOINT_FOV_IN;
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
+ handle_action(intf, action_id);
}
-static int MovedEvent( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
- intf_thread_t *p_intf = (intf_thread_t *)p_data;
- intf_sys_t *p_sys = p_intf->p_sys;
+/****************************
+ * playlist action handling *
+ ****************************/
- (void) p_this; (void) psz_var; (void) oldval;
+#define PLAYLIST_ACTION_HANDLER(name) \
+static inline void \
+action_handler_Playlist##name(vlc_playlist_t *playlist, \
+ vlc_action_id_t action_id)
- if( p_sys->vrnav.b_button_pressed )
+PLAYLIST_ACTION_HANDLER(Interact)
+{
+ switch (action_id)
{
- int i_horizontal = newval.coords.x - p_sys->vrnav.x;
- int i_vertical = newval.coords.y - p_sys->vrnav.y;
-
- vlc_viewpoint_t viewpoint = {
- .yaw = -i_horizontal * 0.05f,
- .pitch = -i_vertical * 0.05f,
- };
-
- input_UpdateViewpoint( p_sys->p_input, &viewpoint, false );
-
- p_sys->vrnav.x = newval.coords.x;
- p_sys->vrnav.y = newval.coords.y;
+ case ACTIONID_PLAY_CLEAR:
+ vlc_playlist_Clear(playlist);
+ break;
+ case ACTIONID_PREV:
+ vlc_playlist_Prev(playlist);
+ break;
+ case ACTIONID_NEXT:
+ vlc_playlist_Next(playlist);
+ break;
+ default:
+ vlc_assert_unreachable();
}
-
- return VLC_SUCCESS;
}
-static int ViewpointMovedEvent( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval,
- void *p_data )
+PLAYLIST_ACTION_HANDLER(Playback)
{
- intf_thread_t *p_intf = (intf_thread_t *)p_data;
- intf_sys_t *p_sys = p_intf->p_sys;
-
- (void) p_this; (void) psz_var; (void) oldval;
-
- input_UpdateViewpoint( p_sys->p_input, newval.p_address, false );
-
- return VLC_SUCCESS;
+ switch (action_id)
+ {
+ case ACTIONID_LOOP:
+ {
+ enum vlc_playlist_playback_repeat repeat_mode =
+ vlc_playlist_GetPlaybackRepeat(playlist);
+ switch (repeat_mode)
+ {
+ case VLC_PLAYLIST_PLAYBACK_REPEAT_NONE:
+ repeat_mode = VLC_PLAYLIST_PLAYBACK_REPEAT_ALL;
+ break;
+ case VLC_PLAYLIST_PLAYBACK_REPEAT_ALL:
+ repeat_mode = VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT;
+ break;
+ case VLC_PLAYLIST_PLAYBACK_REPEAT_CURRENT:
+ repeat_mode = VLC_PLAYLIST_PLAYBACK_REPEAT_NONE;
+ break;
+ }
+ vlc_playlist_SetPlaybackRepeat(playlist, repeat_mode);
+ break;
+ }
+ case ACTIONID_RANDOM:
+ {
+ enum vlc_playlist_playback_order order_mode =
+ vlc_playlist_GetPlaybackOrder(playlist);
+ order_mode =
+ order_mode == VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL
+ ? VLC_PLAYLIST_PLAYBACK_ORDER_RANDOM
+ : VLC_PLAYLIST_PLAYBACK_ORDER_NORMAL;
+ vlc_playlist_SetPlaybackOrder(playlist, order_mode);
+ break;
+ }
+ default:
+ vlc_assert_unreachable();
+ }
}
-static int ButtonEvent( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *p_data )
+static inline void
+playlist_bookmark_Set(intf_thread_t *intf,
+ vlc_playlist_t *playlist, char *name, int id)
{
- intf_thread_t *p_intf = p_data;
- intf_sys_t *p_sys = p_intf->p_sys;
-
- (void) psz_var;
+ var_Create(intf, name, VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+ vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+ input_item_t *item = vlc_player_GetCurrentMedia(player);
+ if (item)
+ {
+ char *uri = input_item_GetURI(item);
+ config_PutPsz(name, uri);
+ msg_Info(intf, "setting playlist bookmark %i to %s", id, uri);
+ free(uri);
+ }
+}
- if ((newval.i_int & (1 << MOUSE_BUTTON_LEFT)) && p_sys->vrnav.b_can_change)
+static inline void
+playlist_bookmark_Play(intf_thread_t *intf,
+ vlc_playlist_t *playlist, char *name)
+{
+ char *bookmark_uri = var_CreateGetString(intf, name);
+ size_t count = vlc_playlist_Count(playlist);
+ size_t i;
+ for (i = 0; i < count; ++i)
{
- if( !p_sys->vrnav.b_button_pressed )
- {
- p_sys->vrnav.b_button_pressed = true;
- var_GetCoords( p_this, "mouse-moved",
- &p_sys->vrnav.x, &p_sys->vrnav.y );
- }
+ vlc_playlist_item_t *plitem = vlc_playlist_Get(playlist, i);
+ input_item_t *item = vlc_playlist_item_GetMedia(plitem);
+ char *item_uri = input_item_GetURI(item);
+ if (!strcmp(bookmark_uri, item_uri))
+ break;
+ free(item_uri);
}
+ if (i != count)
+ vlc_playlist_PlayAt(playlist, i);
+ free(bookmark_uri);
+}
+
+INTF_ACTION_HANDLER(PlaylistBookmark)
+{
+ bool set = action_id >= ACTIONID_SET_BOOKMARK1 &&
+ action_id <= ACTIONID_SET_BOOKMARK10;
+ int id = set ? ACTIONID_SET_BOOKMARK1 : ACTIONID_PLAY_BOOKMARK1;
+ id -= action_id - 1;
+ char *bookmark_name;
+ if (asprintf(&bookmark_name, "bookmark%i", id) == -1)
+ return;
+ vlc_playlist_t *playlist = intf->p_sys->playlist;
+ if (set)
+ playlist_bookmark_Set(intf, playlist, bookmark_name, id);
else
- p_sys->vrnav.b_button_pressed = false;
+ playlist_bookmark_Play(intf, playlist, bookmark_name);
+ free(bookmark_name);
+}
- unsigned pressed = newval.i_int & ~oldval.i_int;
+/**************************
+ * player action handling *
+ **************************/
- if (pressed & (1 << MOUSE_BUTTON_LEFT))
- var_SetBool(pl_Get(p_intf), "intf-popupmenu", false);
- if (pressed & (1 << MOUSE_BUTTON_CENTER))
- var_TriggerCallback(pl_Get(p_intf), "intf-toggle-fscontrol");
-#ifndef _WIN32
- if (pressed & (1 << MOUSE_BUTTON_RIGHT))
-#else
- if ((oldval.i_int & (1 << MOUSE_BUTTON_RIGHT))
- && !(newval.i_int & (1 << MOUSE_BUTTON_RIGHT)))
-#endif
- var_SetBool(pl_Get(p_intf), "intf-popupmenu", true);
+#define PLAYER_ACTION_HANDLER(name) \
+static inline void action_handler_Player##name(vlc_player_t *player, \
+ vlc_action_id_t action_id)
- for (int i = MOUSE_BUTTON_WHEEL_UP; i <= MOUSE_BUTTON_WHEEL_RIGHT; i++)
- if (pressed & (1 << i))
+PLAYER_ACTION_HANDLER(State)
+{
+ switch (action_id)
+ {
+ case ACTIONID_PLAY_PAUSE:
{
- int keycode = KEY_MOUSEWHEEL_FROM_BUTTON(i);
- var_SetInteger(p_intf->obj.libvlc, "key-pressed", keycode);
+ enum vlc_player_state state = vlc_player_GetState(player);
+ if (state == VLC_PLAYER_STATE_PAUSED)
+ vlc_player_Resume(player);
+ else
+ vlc_player_Pause(player);
+ break;
}
-
- return VLC_SUCCESS;
+ case ACTIONID_PLAY:
+ vlc_player_Start(player);
+ break;
+ case ACTIONID_PAUSE:
+ vlc_player_Pause(player);
+ break;
+ case ACTIONID_STOP:
+ vlc_player_Stop(player);
+ break;
+ case ACTIONID_FRAME_NEXT:
+ vlc_player_NextVideoFrame(player);
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
}
-static void ChangeVout( intf_thread_t *p_intf, vout_thread_t *p_vout )
+INTF_ACTION_HANDLER(PlayerSeek)
{
- intf_sys_t *p_sys = p_intf->p_sys;
-
- int slider_chan;
- bool b_vrnav_can_change;
- if( p_vout != NULL )
+ vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
+ if (!vlc_player_CanSeek(player))
+ return;
+ char const *varname;
+ int sign = +1;
+ switch (action_id)
{
- slider_chan = vout_RegisterSubpictureChannel( p_vout );
- b_vrnav_can_change = var_GetBool( p_vout, "viewpoint-changeable" );
+ case ACTIONID_JUMP_BACKWARD_EXTRASHORT:
+ sign = -1;
+ /* fall through */
+ case ACTIONID_JUMP_FORWARD_EXTRASHORT:
+ varname = "extrashort-jump-size";
+ break;
+ case ACTIONID_JUMP_BACKWARD_SHORT:
+ sign = -1;
+ /* fall through */
+ case ACTIONID_JUMP_FORWARD_SHORT:
+ varname = "short-jump-size";
+ break;
+ case ACTIONID_JUMP_BACKWARD_MEDIUM:
+ sign = -1;
+ /* fall through */
+ case ACTIONID_JUMP_FORWARD_MEDIUM:
+ varname = "medium-jump-size";
+ break;
+ case ACTIONID_JUMP_BACKWARD_LONG:
+ sign = -1;
+ /* fall through */
+ case ACTIONID_JUMP_FORWARD_LONG:
+ varname = "long-jump-size";
+ break;
+ default:
+ vlc_assert_unreachable();
}
+ int jmpsz = var_InheritInteger(intf->obj.libvlc, varname);
+ if (jmpsz >= 0)
+ vlc_player_JumpTime(player, vlc_tick_from_sec(jmpsz * sign));
+}
- vout_thread_t *p_old_vout = p_sys->p_vout;
- if( p_old_vout != NULL && p_sys->vrnav.b_can_change )
- var_DelCallback( p_old_vout, "viewpoint-moved", ViewpointMovedEvent,
- p_intf );
+PLAYER_ACTION_HANDLER(Position)
+{
+ VLC_UNUSED(action_id);
+ vout_thread_t *vout = vlc_player_vout_Hold(player);
+ if (vout_OSDEpg(vout, vlc_player_GetCurrentMedia(player)))
+ vlc_player_DisplayPosition(player);
+ vlc_object_release(vout);
+}
- vlc_mutex_lock( &p_sys->lock );
- p_sys->p_vout = p_vout;
- if( p_vout != NULL )
+PLAYER_ACTION_HANDLER(NavigateMedia)
+{
+ switch (action_id)
{
- p_sys->slider_chan = slider_chan;
- p_sys->vrnav.b_can_change = b_vrnav_can_change;
+ case ACTIONID_PROGRAM_SID_PREV:
+ vlc_player_SelectPrevProgram(player);
+ break;
+ case ACTIONID_PROGRAM_SID_NEXT:
+ vlc_player_SelectNextProgram(player);
+ break;
+ case ACTIONID_TITLE_PREV:
+ vlc_player_SelectPrevTitle(player);
+ break;
+ case ACTIONID_TITLE_NEXT:
+ vlc_player_SelectNextTitle(player);
+ break;
+ case ACTIONID_CHAPTER_PREV:
+ vlc_player_SelectPrevChapter(player);
+ break;
+ case ACTIONID_CHAPTER_NEXT:
+ vlc_player_SelectNextChapter(player);
+ break;
+ case ACTIONID_DISC_MENU:
+ vlc_player_Navigate(player, VLC_PLAYER_NAV_MENU);
+ break;
+ default:
+ vlc_assert_unreachable();
}
- else
- p_sys->vrnav.b_can_change = false;
- vlc_mutex_unlock( &p_sys->lock );
+}
- if( p_old_vout != NULL )
+PLAYER_ACTION_HANDLER(Track)
+{
+ switch (action_id)
{
- var_DelCallback( p_old_vout, "mouse-button-down", ButtonEvent,
- p_intf );
- var_DelCallback( p_old_vout, "mouse-moved", MovedEvent, p_intf );
- vlc_object_release( p_old_vout );
+ case ACTIONID_AUDIO_TRACK:
+ vlc_player_SelectNextTrack(player, AUDIO_ES);
+ break;
+ case ACTIONID_SUBTITLE_REVERSE_TRACK:
+ vlc_player_SelectPrevTrack(player, SPU_ES);
+ break;
+ case ACTIONID_SUBTITLE_TRACK:
+ vlc_player_SelectNextTrack(player, SPU_ES);
+ break;
+ default:
+ vlc_assert_unreachable();
}
+}
- if( p_vout != NULL )
+PLAYER_ACTION_HANDLER(Delay)
+{
+ enum { AUDIODELAY, SUBDELAY } type;
+ int delta = 50;
+ switch (action_id)
{
- var_AddCallback( p_vout, "mouse-moved", MovedEvent, p_intf );
- var_AddCallback( p_vout, "mouse-button-down", ButtonEvent, p_intf );
-
- if( p_sys->vrnav.b_can_change )
- var_AddCallback( p_vout, "viewpoint-moved",
- ViewpointMovedEvent, p_intf );
+ case ACTIONID_AUDIODELAY_DOWN:
+ delta = -50;
+ /* fall-through */
+ case ACTIONID_AUDIODELAY_UP:
+ type = AUDIODELAY;
+ break;
+ case ACTIONID_SUBDELAY_DOWN:
+ delta = -50;
+ /* fall-through */
+ case ACTIONID_SUBDELAY_UP:
+ type = SUBDELAY;
+ break;
+ default:
+ vlc_assert_unreachable();
}
+ enum vlc_player_whence whence = VLC_PLAYER_WHENCE_RELATIVE;
+ delta = VLC_TICK_FROM_MS(delta);
+ if (type == AUDIODELAY)
+ vlc_player_SetAudioDelay(player, delta, whence);
+ else
+ vlc_player_SetSubtitleDelay(player, delta, whence);
}
-static int InputEvent( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t val, void *p_data )
+static inline float
+AdjustRateFine(float rate, int const dir)
{
- input_thread_t *p_input = (input_thread_t *)p_this;
- intf_thread_t *p_intf = p_data;
-
- (void) psz_var; (void) oldval;
-
- if( val.i_int == INPUT_EVENT_VOUT )
- ChangeVout( p_intf, input_GetVout( p_input ) );
-
- return VLC_SUCCESS;
+ float rate_min = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
+ float rate_max = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
+ int sign = rate < 0 ? -1 : 1;
+ rate = floor(fabs(rate) / 0.1 + dir + 0.05) * 0.1;
+ if (rate < rate_min)
+ rate = rate_min;
+ else if (rate > rate_max)
+ rate = rate_max;
+ return rate * sign;
}
-static void ChangeInput( intf_thread_t *p_intf, input_thread_t *p_input )
+PLAYER_ACTION_HANDLER(Rate)
{
- intf_sys_t *p_sys = p_intf->p_sys;
-
- input_thread_t *p_old_input = p_sys->p_input;
- vout_thread_t *p_old_vout = NULL;
- if( p_old_input != NULL )
+ switch (action_id)
{
- /* First, remove callbacks from previous input. It's safe to access it
- * unlocked, since it's written from this thread */
- var_DelCallback( p_old_input, "intf-event", InputEvent, p_intf );
-
- p_old_vout = p_sys->p_vout;
- /* Remove mouse events before setting new input, since callbacks may
- * access it */
- if( p_old_vout != NULL )
+ case ACTIONID_RATE_SLOWER:
+ vlc_player_DecrementRate(player);
+ break;
+ case ACTIONID_RATE_FASTER:
+ vlc_player_IncrementRate(player);
+ break;
+ default:
{
- if( p_sys->vrnav.b_can_change )
- var_DelCallback( p_old_vout, "viewpoint-moved",
- ViewpointMovedEvent, p_intf );
-
- var_DelCallback( p_old_vout, "mouse-button-down", ButtonEvent,
- p_intf );
- var_DelCallback( p_old_vout, "mouse-moved", MovedEvent,
- p_intf );
+ float rate;
+ switch (action_id)
+ {
+ case ACTIONID_RATE_NORMAL:
+ rate = 1.f;
+ break;
+ case ACTIONID_RATE_SLOWER_FINE:
+ case ACTIONID_RATE_FASTER_FINE:
+ {
+ int const dir = action_id == ACTIONID_RATE_SLOWER_FINE ?
+ -1 : +1;
+ rate = vlc_player_GetRate(player);
+ rate = AdjustRateFine(rate, dir);
+ break;
+ }
+ default:
+ vlc_assert_unreachable();
+ }
+ vlc_player_ChangeRate(player, rate);
+ break;
}
}
+}
- /* Replace input and vout locked */
- vlc_mutex_lock( &p_sys->lock );
- p_sys->p_input = p_input ? vlc_object_hold( p_input ) : NULL;
- p_sys->p_vout = NULL;
- p_sys->vrnav.b_can_change = false;
- vlc_mutex_unlock( &p_sys->lock );
+PLAYER_ACTION_HANDLER(ToggleSubtitle)
+{
+ VLC_UNUSED(action_id);
+ vlc_player_ToggleSubtitle(player);
+}
- /* Release old input and vout objects unlocked */
- if( p_old_input != NULL )
+PLAYER_ACTION_HANDLER(SyncSubtitle)
+{
+ switch (action_id)
{
- if( p_old_vout != NULL )
- vlc_object_release( p_old_vout );
- vlc_object_release( p_old_input );
+ case ACTIONID_SUBSYNC_MARKAUDIO:
+ vlc_player_SetSubtitleSync(
+ player, VLC_PLAYER_SUBTITLE_SYNC_MARK_AUDIO);
+ break;
+ case ACTIONID_SUBSYNC_MARKSUB:
+ vlc_player_SetSubtitleSync(
+ player, VLC_PLAYER_SUBTITLE_SYNC_MARK_SUBTITLE);
+ break;
+ case ACTIONID_SUBSYNC_APPLY:
+ // FIXME is that still the case?
+ /* Warning! Can yield a pause in the playback.
+ * For example, the following succession of actions will yield a 5 second delay :
+ * - Pressing Shift-H (ACTIONID_SUBSYNC_MARKAUDIO)
+ * - wait 5 second
+ * - Press Shift-J (ACTIONID_SUBSYNC_MARKSUB)
+ * - Press Shift-K (ACTIONID_SUBSYNC_APPLY)
+ * --> 5 seconds pause
+ * This is due to var_SetTime() (and ultimately UpdatePtsDelay())
+ * which causes the video to pause for an equivalent duration
+ * (This problem is also present in the "Track synchronization" window) */
+ vlc_player_SetSubtitleSync(player, VLC_PLAYER_SUBTITLE_SYNC_APPLY);
+ break;
+ case ACTIONID_SUBSYNC_RESET:
+ vlc_player_SetSubtitleSync(player, VLC_PLAYER_SUBTITLE_SYNC_RESET);
+ break;
+ default:
+ vlc_assert_unreachable();
}
-
- /* Register input events */
- if( p_input != NULL )
- var_AddCallback( p_input, "intf-event", InputEvent, p_intf );
}
-static int PlaylistEvent( vlc_object_t *p_this, char const *psz_var,
- vlc_value_t oldval, vlc_value_t val, void *p_data )
+PLAYER_ACTION_HANDLER(Navigate)
{
- intf_thread_t *p_intf = p_data;
-
- (void) p_this; (void) psz_var; (void) oldval;
-
- ChangeInput( p_intf, val.p_address );
-
- return VLC_SUCCESS;
+ enum vlc_player_nav nav;
+ switch (action_id)
+ {
+#define PLAYER_NAV_FROM_ACTION(navval) \
+ case ACTIONID_NAV_##navval: \
+ nav = VLC_PLAYER_NAV_##navval; \
+ break;
+ PLAYER_NAV_FROM_ACTION(ACTIVATE)
+ PLAYER_NAV_FROM_ACTION(UP)
+ PLAYER_NAV_FROM_ACTION(DOWN)
+ PLAYER_NAV_FROM_ACTION(LEFT)
+ PLAYER_NAV_FROM_ACTION(RIGHT)
+#undef PLAYER_NAV_FROM_ACTION
+ default:
+ vlc_assert_unreachable();
+ }
+ vlc_player_Navigate(player, nav);
}
-/*****************************************************************************
- * Open: initialize interface
- *****************************************************************************/
-static int Open( vlc_object_t *p_this )
+PLAYER_ACTION_HANDLER(Viewpoint)
{
- intf_thread_t *p_intf = (intf_thread_t *)p_this;
- intf_sys_t *p_sys;
- p_sys = malloc( sizeof( intf_sys_t ) );
- if( !p_sys )
- return VLC_ENOMEM;
-
- p_intf->p_sys = p_sys;
-
- p_sys->p_vout = NULL;
- p_sys->p_input = NULL;
- p_sys->vrnav.b_can_change = false;
- p_sys->vrnav.b_button_pressed = false;
- p_sys->subtitle_delaybookmarks.i_time_audio = VLC_TICK_INVALID;
- p_sys->subtitle_delaybookmarks.i_time_subtitle = VLC_TICK_INVALID;
-
- vlc_mutex_init( &p_sys->lock );
-
- var_AddCallback( p_intf->obj.libvlc, "key-action", ActionEvent, p_intf );
-
- var_AddCallback( pl_Get(p_intf), "input-current", PlaylistEvent, p_intf );
-
- return VLC_SUCCESS;
+ vlc_viewpoint_t viewpoint;
+ switch (action_id)
+ {
+ case ACTIONID_VIEWPOINT_FOV_IN:
+ viewpoint.fov = -1.f;
+ break;
+ case ACTIONID_VIEWPOINT_FOV_OUT:
+ viewpoint.fov = +1.f;
+ break;
+ case ACTIONID_VIEWPOINT_ROLL_CLOCK:
+ viewpoint.roll = -1.f;
+ break;
+ case ACTIONID_VIEWPOINT_ROLL_ANTICLOCK:
+ viewpoint.roll = +1.f;
+ break;
+ default:
+ vlc_assert_unreachable();
+ }
+ vlc_player_UpdateViewpoint(player, &viewpoint,
+ VLC_PLAYER_WHENCE_RELATIVE);
}
-/*****************************************************************************
- * Close: destroy interface
- *****************************************************************************/
-static void Close( vlc_object_t *p_this )
+PLAYER_ACTION_HANDLER(Record)
{
- intf_thread_t *p_intf = (intf_thread_t *)p_this;
- intf_sys_t *p_sys = p_intf->p_sys;
-
- var_DelCallback( pl_Get(p_intf), "input-current", PlaylistEvent, p_intf );
-
- var_DelCallback( p_intf->obj.libvlc, "key-action", ActionEvent, p_intf );
-
- ChangeInput( p_intf, NULL );
-
- vlc_mutex_destroy( &p_sys->lock );
-
- /* Destroy structure */
- free( p_sys );
+ VLC_UNUSED(action_id);
+ vlc_player_ToggleRecording(player);
}
-static int PutAction( intf_thread_t *p_intf, input_thread_t *p_input,
- vout_thread_t *p_vout, int slider_chan, bool b_vrnav,
- int i_action )
+static int
+AudioDeviceCycle(audio_output_t *aout, char **p_name)
{
-#define DO_ACTION(x) PutAction( p_intf, p_input, p_vout, slider_chan, b_vrnav, x)
- intf_sys_t *p_sys = p_intf->p_sys;
- playlist_t *p_playlist = pl_Get( p_intf );
+ int ret = -1;
+
+ char *device = aout_DeviceGet(aout);
+ if (!device)
+ goto end;
+ char **ids, **names;
+ int n = aout_DevicesList(aout, &ids, &names);
+ if (n == -1)
+ goto end;
+
+ int index;
+ for (index = 0; index < n; ++index)
+ if (!strcmp(ids[index], device))
+ {
+ index = (index + 1) % n;
+ break;
+ }
+ ret = aout_DeviceSet(aout, ids[index]);
+ if (p_name != NULL)
+ *p_name = strdup(names[index]);
- /* Quit */
- switch( i_action )
+ free(device);
+ for (int i = 0; i < n; ++i)
{
- /* Libvlc / interface actions */
- case ACTIONID_QUIT:
- libvlc_Quit( p_intf->obj.libvlc );
-
- ClearChannels( p_vout, slider_chan );
- DisplayMessage( p_vout, _( "Quit" ) );
- break;
+ free(ids[i]);
+ free(names[i]);
+ }
+ free(ids);
+ free(names);
+end:
+ return ret;
+}
- case ACTIONID_INTF_TOGGLE_FSC:
- case ACTIONID_INTF_HIDE:
- var_TriggerCallback( p_playlist, "intf-toggle-fscontrol" );
+PLAYER_ACTION_HANDLER(Aout)
+{
+ switch (action_id)
+ {
+ case ACTIONID_VOL_DOWN:
+ vlc_player_aout_DecrementVolume(player, 1, NULL);
break;
- case ACTIONID_INTF_BOSS:
- var_TriggerCallback( p_playlist, "intf-boss" );
+ case ACTIONID_VOL_UP:
+ vlc_player_aout_IncrementVolume(player, 1, NULL);
break;
- case ACTIONID_INTF_POPUP_MENU:
- var_TriggerCallback( p_playlist, "intf-popupmenu" );
+ case ACTIONID_VOL_MUTE:
+ vlc_player_aout_ToggleMute(player);
break;
-
- /* Playlist actions (including audio) */
- case ACTIONID_LOOP:
+ case ACTIONID_AUDIODEVICE_CYCLE:
{
- /* Toggle Normal -> Loop -> Repeat -> Normal ... */
- const char *mode;
- if( var_GetBool( p_playlist, "repeat" ) )
+ audio_output_t *aout = vlc_player_aout_Hold(player);
+ if (!aout)
+ break;
+ char *devname;
+ if (!AudioDeviceCycle(aout, &devname))
{
- var_SetBool( p_playlist, "repeat", false );
- mode = N_("Off");
- }
- else
- if( var_GetBool( p_playlist, "loop" ) )
- { /* FIXME: this is not atomic, we should use a real tristate */
- var_SetBool( p_playlist, "loop", false );
- var_SetBool( p_playlist, "repeat", true );
- mode = N_("One");
+ vlc_player_vout_OSDMessage(player, _("Audio device: %s"), devname);
+ free(devname);
}
- else
- {
- var_SetBool( p_playlist, "loop", true );
- mode = N_("All");
- }
- DisplayMessage( p_vout, _("Loop: %s"), vlc_gettext(mode) );
+ vlc_object_release(aout);
break;
}
+ default:
+ vlc_assert_unreachable();
+ }
+}
- case ACTIONID_RANDOM:
- {
- const bool state = var_ToggleBool( p_playlist, "random" );
- DisplayMessage( p_vout, _("Random: %s"),
- vlc_gettext( state ? N_("On") : N_("Off") ) );
+PLAYER_ACTION_HANDLER(Vouts)
+{
+ switch (action_id)
+ {
+ case ACTIONID_TOGGLE_FULLSCREEN:
+ vlc_player_vout_ToggleFullscreen(player);
break;
- }
-
- case ACTIONID_NEXT:
- DisplayMessage( p_vout, _("Next") );
- playlist_Next( p_playlist );
+ case ACTIONID_LEAVE_FULLSCREEN:
+ vlc_player_vout_SetFullscreen(player, false);
break;
- case ACTIONID_PREV:
- DisplayMessage( p_vout, _("Previous") );
- playlist_Prev( p_playlist );
+ case ACTIONID_SNAPSHOT:
+ vlc_player_vout_Snapshot(player);
break;
-
- case ACTIONID_STOP:
- playlist_Stop( p_playlist );
+ case ACTIONID_WALLPAPER:
+ vlc_player_vout_ToggleWallpaperMode(player);
break;
+ default:
+ vlc_assert_unreachable();
+ }
+}
- case ACTIONID_RATE_NORMAL:
- var_SetFloat( p_playlist, "rate", 1.f );
- DisplayRate( p_vout, 1.f );
- break;
- case ACTIONID_FASTER:
- var_TriggerCallback( p_playlist, "rate-faster" );
- DisplayRate( p_vout, var_GetFloat( p_playlist, "rate" ) );
- break;
- case ACTIONID_SLOWER:
- var_TriggerCallback( p_playlist, "rate-slower" );
- DisplayRate( p_vout, var_GetFloat( p_playlist, "rate" ) );
- break;
- case ACTIONID_RATE_FASTER_FINE:
- case ACTIONID_RATE_SLOWER_FINE:
- {
- const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
- float rate = AdjustRateFine( VLC_OBJECT(p_playlist), i_dir );
+/************************
+ * vout action handling *
+ ************************/
- var_SetFloat( p_playlist, "rate", rate );
- DisplayRate( p_vout, rate );
- break;
- }
+#define VOUT_ACTION_HANDLER(name) \
+static inline void \
+action_handler_Vout##name(vout_thread_t *vout, vlc_action_id_t action_id)
- case ACTIONID_PLAY_BOOKMARK1:
- case ACTIONID_PLAY_BOOKMARK2:
- case ACTIONID_PLAY_BOOKMARK3:
- case ACTIONID_PLAY_BOOKMARK4:
- case ACTIONID_PLAY_BOOKMARK5:
- case ACTIONID_PLAY_BOOKMARK6:
- case ACTIONID_PLAY_BOOKMARK7:
- case ACTIONID_PLAY_BOOKMARK8:
- case ACTIONID_PLAY_BOOKMARK9:
- case ACTIONID_PLAY_BOOKMARK10:
- PlayBookmark( p_intf, i_action - ACTIONID_PLAY_BOOKMARK1 + 1 );
- break;
-
- case ACTIONID_SET_BOOKMARK1:
- case ACTIONID_SET_BOOKMARK2:
- case ACTIONID_SET_BOOKMARK3:
- case ACTIONID_SET_BOOKMARK4:
- case ACTIONID_SET_BOOKMARK5:
- case ACTIONID_SET_BOOKMARK6:
- case ACTIONID_SET_BOOKMARK7:
- case ACTIONID_SET_BOOKMARK8:
- case ACTIONID_SET_BOOKMARK9:
- case ACTIONID_SET_BOOKMARK10:
- SetBookmark( p_intf, i_action - ACTIONID_SET_BOOKMARK1 + 1 );
- break;
- case ACTIONID_PLAY_CLEAR:
- playlist_Clear( p_playlist, pl_Unlocked );
- break;
- case ACTIONID_VOL_UP:
- {
- float vol;
- if( playlist_VolumeUp( p_playlist, 1, &vol ) == 0 )
- DisplayVolume( p_vout, slider_chan, vol );
- break;
- }
- case ACTIONID_VOL_DOWN:
+static inline void
+vout_CycleVariable(vout_thread_t *vout,
+ char const *varname, int vartype, bool next)
+{
+ vlc_value_t val;
+ var_Get(vout, varname, &val);
+ size_t num_choices;
+ vlc_value_t *choices;
+ var_Change(vout, varname, VLC_VAR_GETCHOICES,
+ &num_choices, &choices, NULL);
+
+ vlc_value_t *choice = choices;
+ for (size_t curidx = 0; curidx < num_choices; ++curidx, ++choice)
+ if ((vartype == VLC_VAR_FLOAT &&
+ choice->f_float == val.f_float) ||
+ (vartype == VLC_VAR_STRING &&
+ !strcmp(choice->psz_string, val.psz_string)))
{
- float vol;
- if( playlist_VolumeDown( p_playlist, 1, &vol ) == 0 )
- DisplayVolume( p_vout, slider_chan, vol );
+ curidx += next ? +1 : -1;
+ if (next && curidx == num_choices)
+ curidx = 0;
+ else if (!next && curidx == (size_t)-1)
+ curidx = num_choices - 1;
+ choice = choices + curidx;
break;
}
- case ACTIONID_VOL_MUTE:
- {
- int mute = playlist_MuteGet( p_playlist );
- if( mute < 0 )
- break;
- mute = !mute;
- if( playlist_MuteSet( p_playlist, mute ) )
- break;
-
- float vol = playlist_VolumeGet( p_playlist );
- if( mute || vol == 0.f )
- {
- ClearChannels( p_vout, slider_chan );
- DisplayIcon( p_vout, OSD_MUTE_ICON );
- }
- else
- DisplayVolume( p_vout, slider_chan, vol );
- break;
- }
-
- case ACTIONID_AUDIODEVICE_CYCLE:
- {
- audio_output_t *p_aout = playlist_GetAout( p_playlist );
- if( p_aout == NULL )
- break;
-
- char **ids, **names;
- int n = aout_DevicesList( p_aout, &ids, &names );
- if( n == -1 )
- break;
-
- char *dev = aout_DeviceGet( p_aout );
- const char *devstr = (dev != NULL) ? dev : "";
-
- int idx = 0;
- for( int i = 0; i < n; i++ )
- {
- if( !strcmp(devstr, ids[i]) )
- idx = (i + 1) % n;
- }
- free( dev );
-
- if( !aout_DeviceSet( p_aout, ids[idx] ) )
- DisplayMessage( p_vout, _("Audio Device: %s"), names[idx] );
- vlc_object_release( p_aout );
+ if (choice == choices + num_choices)
+ choice = choices;
+ if (vartype == VLC_VAR_FLOAT)
+ var_SetFloat(vout, varname, choice->f_float);
+ else if (vartype == VLC_VAR_STRING)
+ var_SetString(vout, varname, choice->psz_string);
+
+ if (vartype == VLC_VAR_STRING)
+ {
+ free(val.psz_string);
+ for (size_t i = 0; i < num_choices; ++i)
+ free(choices[i].psz_string);
+ }
+ free(choices);
+}
- for( int i = 0; i < n; i++ )
- {
- free( ids[i] );
- free( names[i] );
- }
- free( ids );
- free( names );
- break;
- }
+#define vout_CycleVariable(vout, varname, vartype, next) \
+ do \
+ { \
+ static_assert(vartype == VLC_VAR_FLOAT || \
+ vartype == VLC_VAR_STRING, \
+ "vartype must be either VLC_VAR_FLOAT or VLC_VAR_STRING"); \
+ vout_CycleVariable(vout, varname, vartype, next); \
+ } while (0)
- /* Playlist + input actions */
- case ACTIONID_PLAY_PAUSE:
- if( p_input )
- {
- ClearChannels( p_vout, slider_chan );
+VOUT_ACTION_HANDLER(AspectRatio)
+{
+ VLC_UNUSED(action_id);
+ vout_CycleVariable(vout, "aspect-ratio", VLC_VAR_STRING, true);
+}
- int state = var_GetInteger( p_input, "state" );
- DisplayIcon( p_vout, state != PAUSE_S ? OSD_PAUSE_ICON : OSD_PLAY_ICON );
- }
- playlist_TogglePause( p_playlist );
- break;
+VOUT_ACTION_HANDLER(Crop)
+{
+ if (action_id == ACTIONID_CROP)
+ {
+ vout_CycleVariable(vout, "crop", VLC_VAR_STRING, true);
+ return;
+ }
+ char const *varname;
+ int delta;
+ switch (action_id)
+ {
+#define CASE_CROP(crop, var) \
+ case ACTIONID_CROP_##crop: \
+ case ACTIONID_UNCROP_##crop: \
+ varname = "crop-"#var; \
+ delta = action_id == ACTIONID_CROP_##crop? +1 : -1; \
+ break;
+ CASE_CROP(TOP, top)
+ CASE_CROP(BOTTOM, bottom)
+ CASE_CROP(LEFT, left)
+ CASE_CROP(RIGHT, right)
+#undef CASE_CROP
+ default:
+ vlc_assert_unreachable();
+ }
+ int crop = var_GetInteger(vout, varname);
+ var_SetInteger(vout, varname, crop + delta);
+}
- case ACTIONID_PLAY:
- if( p_input && var_GetFloat( p_input, "rate" ) != 1.f )
- /* Return to normal speed */
- var_SetFloat( p_input, "rate", 1.f );
+VOUT_ACTION_HANDLER(Zoom)
+{
+ char const *varname = "zoom";
+ switch (action_id)
+ {
+ case ACTIONID_TOGGLE_AUTOSCALE:
+ if (var_GetFloat(vout, varname) != 1.f)
+ var_SetFloat(vout, varname, 1.f);
else
- {
- ClearChannels( p_vout, slider_chan );
- DisplayIcon( p_vout, OSD_PLAY_ICON );
- playlist_Play( p_playlist );
- }
+ var_ToggleBool(vout, "autoscale");
break;
-
- /* Playlist + video output actions */
- case ACTIONID_WALLPAPER:
+ case ACTIONID_SCALE_DOWN:
+ case ACTIONID_SCALE_UP:
{
- bool wp = var_ToggleBool( p_playlist, "video-wallpaper" );
- if( p_vout )
- var_SetBool( p_vout, "video-wallpaper", wp );
+ float zoom = var_GetFloat(vout, varname);
+ float delta = action_id == ACTIONID_SCALE_DOWN ?
+ -.1f : +.1f;
+ if ((zoom >= .3f || delta > 0) && (zoom <= 10.f || delta < 0))
+ var_SetFloat(vout, varname, zoom + delta);
break;
}
-
- /* Input actions */
- case ACTIONID_PAUSE:
- if( p_input && var_GetInteger( p_input, "state" ) != PAUSE_S )
- {
- ClearChannels( p_vout, slider_chan );
- DisplayIcon( p_vout, OSD_PAUSE_ICON );
- var_SetInteger( p_input, "state", PAUSE_S );
- }
- break;
-
- case ACTIONID_RECORD:
- if( p_input && var_GetBool( p_input, "can-record" ) )
- {
- const bool on = var_ToggleBool( p_input, "record" );
- DisplayMessage( p_vout, vlc_gettext(on
- ? N_("Recording") : N_("Recording done")) );
- }
- break;
-
- case ACTIONID_FRAME_NEXT:
- if( p_input )
- {
- var_TriggerCallback( p_input, "frame-next" );
- DisplayMessage( p_vout, _("Next frame") );
- }
+ case ACTIONID_ZOOM:
+ case ACTIONID_UNZOOM:
+ vout_CycleVariable(vout, varname, VLC_VAR_FLOAT,
+ action_id == ACTIONID_ZOOM);
break;
-
- case ACTIONID_SUBSYNC_MARKAUDIO:
+ default:
{
- p_sys->subtitle_delaybookmarks.i_time_audio = vlc_tick_now();
- DisplayMessage( p_vout, _("Sub sync: bookmarked audio time"));
+ static float const zoom_modes[] = { .25f, .5f, 1.f, 2.f };
+ var_SetFloat(vout, varname,
+ zoom_modes[action_id - ACTIONID_ZOOM_QUARTER]);
break;
}
- case ACTIONID_SUBSYNC_MARKSUB:
- if( p_input )
- {
- vlc_value_t val;
- vlc_value_t *list;
- size_t count;
+ }
+}
- var_Get( p_input, "spu-es", &val );
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &count, &list, (char ***)NULL );
+VOUT_ACTION_HANDLER(Deinterlace)
+{
+ if (action_id == ACTIONID_DEINTERLACE)
+ var_SetInteger(vout, "deinterlace",
+ var_GetInteger(vout, "deinterlace") ? 0 : 1);
+ else if (action_id == ACTIONID_DEINTERLACE_MODE)
+ vout_CycleVariable(vout, "deinterlace-mode", VLC_VAR_STRING, true);
+}
- if( count < 1 || val.i_int < 0 )
- {
- DisplayMessage( p_vout, _("No active subtitle") );
- }
- else
- {
- p_sys->subtitle_delaybookmarks.i_time_subtitle = vlc_tick_now();
- DisplayMessage(p_vout,
- _("Sub sync: bookmarked subtitle time"));
- }
- free(list);
- }
- break;
- case ACTIONID_SUBSYNC_APPLY:
- {
- /* Warning! Can yield a pause in the playback.
- * For example, the following succession of actions will yield a 5 second delay :
- * - Pressing Shift-H (ACTIONID_SUBSYNC_MARKAUDIO)
- * - wait 5 second
- * - Press Shift-J (ACTIONID_SUBSYNC_MARKSUB)
- * - Press Shift-K (ACTIONID_SUBSYNC_APPLY)
- * --> 5 seconds pause
- * This is due to var_SetTime() (and ultimately UpdatePtsDelay())
- * which causes the video to pause for an equivalent duration
- * (This problem is also present in the "Track synchronization" window) */
- if ( p_input )
- {
- if ( (p_sys->subtitle_delaybookmarks.i_time_audio == VLC_TICK_INVALID) || (p_sys->subtitle_delaybookmarks.i_time_subtitle == VLC_TICK_INVALID) )
- {
- DisplayMessage( p_vout, _( "Sub sync: set bookmarks first!" ) );
- }
- else
- {
- vlc_tick_t i_current_subdelay = var_GetInteger( p_input, "spu-delay" );
- vlc_tick_t i_additional_subdelay = p_sys->subtitle_delaybookmarks.i_time_audio - p_sys->subtitle_delaybookmarks.i_time_subtitle;
- vlc_tick_t i_total_subdelay = i_current_subdelay + i_additional_subdelay;
- var_SetInteger( p_input, "spu-delay", i_total_subdelay);
- ClearChannels( p_vout, slider_chan );
- DisplayMessage( p_vout, _( "Sub sync: corrected %"PRId64" ms (total delay = %"PRId64" ms)" ),
- MS_FROM_VLC_TICK( i_additional_subdelay ),
- MS_FROM_VLC_TICK( i_total_subdelay ) );
- p_sys->subtitle_delaybookmarks.i_time_audio = VLC_TICK_INVALID;
- p_sys->subtitle_delaybookmarks.i_time_subtitle = VLC_TICK_INVALID;
- }
- }
- break;
- }
- case ACTIONID_SUBSYNC_RESET:
- {
- var_SetInteger( p_input, "spu-delay", 0);
- ClearChannels( p_vout, slider_chan );
- DisplayMessage( p_vout, _( "Sub sync: delay reset" ) );
- p_sys->subtitle_delaybookmarks.i_time_audio = VLC_TICK_INVALID;
- p_sys->subtitle_delaybookmarks.i_time_subtitle = VLC_TICK_INVALID;
+VOUT_ACTION_HANDLER(SubtitleDisplay)
+{
+ switch (action_id)
+ {
+ case ACTIONID_SUBPOS_DOWN:
+ var_DecInteger(vout, "sub-margin");
break;
- }
-
- case ACTIONID_SUBDELAY_DOWN:
- case ACTIONID_SUBDELAY_UP:
- {
- vlc_tick_t diff = (i_action == ACTIONID_SUBDELAY_UP) ? VLC_TICK_FROM_MS(50) : VLC_TICK_FROM_MS(-50);
- if( p_input )
- {
- vlc_value_t val;
- vlc_value_t *list;
- size_t count;
-
- var_Get( p_input, "spu-es", &val );
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &count, &list, (char ***)NULL );
-
- if( count < 1 || val.i_int < 0 )
- {
- DisplayMessage( p_vout, _("No active subtitle") );
- free(list);
- break;
- }
- vlc_tick_t i_delay = var_GetInteger( p_input, "spu-delay" ) + diff;
-
- var_SetInteger( p_input, "spu-delay", i_delay );
- ClearChannels( p_vout, slider_chan );
- DisplayMessage( p_vout, _( "Subtitle delay %i ms" ),
- (int)MS_FROM_VLC_TICK(i_delay) );
- free(list);
- }
+ case ACTIONID_SUBPOS_UP:
+ var_IncInteger(vout, "sub-margin");
break;
- }
- case ACTIONID_AUDIODELAY_DOWN:
- case ACTIONID_AUDIODELAY_UP:
+ default:
{
- vlc_tick_t diff = (i_action == ACTIONID_AUDIODELAY_UP) ? VLC_TICK_FROM_MS(50) : VLC_TICK_FROM_MS(-50);
- if( p_input )
+ // FIXME all vouts
+ char const *varname = "sub-text-scale";
+ int scale;
+ if (action_id == ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL)
+ scale = 100;
+ else
{
- vlc_tick_t i_delay = var_GetInteger( p_input, "audio-delay" )
- + diff;
-
- var_SetInteger( p_input, "audio-delay", i_delay );
- ClearChannels( p_vout, slider_chan );
- DisplayMessage( p_vout, _( "Audio delay %i ms" ),
- (int)MS_FROM_VLC_TICK(i_delay) );
+ scale = var_GetInteger(vout, varname);
+ unsigned delta = (scale > 100 ? scale - 100 : 100 - scale) / 25;
+ delta = delta <= 1 ? 10 : 25;
+ if (action_id == ACTIONID_SUBTITLE_TEXT_SCALE_DOWN)
+ delta = -delta;
+ scale += delta;
+ scale -= scale % delta;
+ scale = VLC_CLIP(scale, 25, 500);
}
+ var_SetInteger(vout, varname, scale);
break;
}
+ }
+}
- case ACTIONID_AUDIO_TRACK:
- if( p_input )
- {
- vlc_value_t val;
- vlc_value_t *list;
- char **list2;
- size_t count;
-
- var_Get( p_input, "audio-es", &val );
- var_Change( p_input, "audio-es", VLC_VAR_GETCHOICES,
- &count, &list, &list2 );
-
- if( count > 1 )
- {
- size_t i;
-
- for( i = 0; i < count; i++ )
- if( val.i_int == list[i].i_int )
- break;
- /* value of audio-es was not in choices list */
- if( i == count )
- {
- msg_Warn( p_input,
- "invalid current audio track, selecting 0" );
- i = 0;
- }
- else if( i == count - 1 )
- i = 1;
- else
- i++;
- var_Set( p_input, "audio-es", list[i] );
- DisplayMessage( p_vout, _("Audio track: %s"), list2[i] );
- }
- var_FreeList( count, list, list2 );
- }
- break;
-
- case ACTIONID_SUBTITLE_TRACK:
- case ACTIONID_SUBTITLE_REVERSE_TRACK:
- if( p_input )
- {
- vlc_value_t val;
- vlc_value_t *list;
- char **list2;
- size_t count, i;
- var_Get( p_input, "spu-es", &val );
-
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &count, &list, &list2 );
-
- if( count <= 1 )
- {
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- _("N/A") );
- var_FreeList( count, list, list2 );
- break;
- }
- for( i = 0; i < count; i++ )
- if( val.i_int == list[i].i_int )
- break;
- /* value of spu-es was not in choices list */
- if( i == count )
- {
- msg_Warn( p_input,
- "invalid current subtitle track, selecting 0" );
- i = 0;
- }
- else if ((i == count - 1) && (i_action == ACTIONID_SUBTITLE_TRACK))
- i = 0;
- else if ((i == 0) && (i_action == ACTIONID_SUBTITLE_REVERSE_TRACK))
- i = count - 1;
- else
- i = (i_action == ACTIONID_SUBTITLE_TRACK) ? i+1 : i-1;
- var_SetInteger( p_input, "spu-es", list[i].i_int );
- DisplayMessage( p_vout, _("Subtitle track: %s"), list2[i] );
- var_FreeList( count, list, list2 );
- }
- break;
- case ACTIONID_SUBTITLE_TOGGLE:
- if( p_input )
- {
- vlc_value_t *list;
- char **list2;
- size_t count;
-
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &count, &list, &list2 );
+/****************
+ * action table *
+ ****************/
- if( count <= 1 )
- {
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- _("N/A") );
- var_FreeList( count, list, list2 );
- break;
- }
+struct vlc_action
+{
+ enum
+ {
+ NULL_ACTION = -1,
+ INTF_ACTION,
+ PLAYLIST_ACTION,
+ PLAYER_ACTION,
+ VOUT_ACTION,
+ } type;
+ struct
+ {
+ vlc_action_id_t first;
+ vlc_action_id_t last;
+ } range;
+ union
+ {
+ void *fptr;
+ void (*pf_intf)(intf_thread_t *, vlc_action_id_t);
+ void (*pf_playlist)(vlc_playlist_t *, vlc_action_id_t);
+ void (*pf_player)(vlc_player_t *, vlc_action_id_t);
+ void (*pf_vout)(vout_thread_t *vout, vlc_action_id_t);
+ } handler;
+ bool pl_need_lock;
+};
- int i_cur_id = var_GetInteger( p_input, "spu-es" );
- int i_new_id;
- if( i_cur_id == -1 )
- {
- /* subtitles were disabled: restore the saved track id */
- i_new_id = var_GetInteger( p_input, "spu-choice" );
- if( i_new_id != -1 )
- var_SetInteger( p_input, "spu-choice", -1 );
- }
- else
- {
- /* subtitles were enabled: save the track id and disable */
- i_new_id = -1;
- var_SetInteger( p_input, "spu-choice", i_cur_id );
- }
+static struct vlc_action const actions[] =
+{
+#define VLC_ACTION(typeval, first, last, name, lock) \
+ { \
+ .type = typeval, \
+ .range = { ACTIONID_##first, ACTIONID_##last }, \
+ .handler.fptr = action_handler_##name, \
+ .pl_need_lock = lock \
+ },
+#define VLC_ACTION_INTF(first, last, name, lock) \
+ VLC_ACTION(INTF_ACTION, first, last, Intf ## name, lock)
+#define VLC_ACTION_PLAYLIST(first, last, name) \
+ VLC_ACTION(PLAYLIST_ACTION, first, last, Playlist ## name, true)
+#define VLC_ACTION_PLAYER(first, last, name, lock) \
+ VLC_ACTION(PLAYER_ACTION, first, last, Player ## name, lock)
+#define VLC_ACTION_VOUT(first, last, name) \
+ VLC_ACTION(VOUT_ACTION, first, last, Vout ## name, false)
+
+ /* interface actions */
+ VLC_ACTION_INTF(QUIT, INTF_POPUP_MENU, , false)
+ VLC_ACTION_INTF(COMBO_VOL_FOV_DOWN, COMBO_VOL_FOV_UP, ActionCombo, false)
+ /* playlist actions */
+ VLC_ACTION_PLAYLIST(PLAY_CLEAR, NEXT, Interact)
+ VLC_ACTION_PLAYLIST(LOOP, RANDOM, Playback)
+ VLC_ACTION_INTF(SET_BOOKMARK1, PLAY_BOOKMARK10, PlaylistBookmark, true)
+ /* player actions */
+ VLC_ACTION_PLAYER(PLAY_PAUSE, FRAME_NEXT, State, true)
+ VLC_ACTION_INTF(JUMP_BACKWARD_EXTRASHORT, JUMP_FORWARD_LONG, PlayerSeek, true)
+ VLC_ACTION_PLAYER(POSITION, POSITION, Position, true)
+ VLC_ACTION_PLAYER(PROGRAM_SID_PREV, DISC_MENU, NavigateMedia, true)
+ VLC_ACTION_PLAYER(AUDIO_TRACK, SUBTITLE_TRACK, Track, true)
+ VLC_ACTION_PLAYER(AUDIODELAY_DOWN, SUBDELAY_UP, Delay, true)
+ VLC_ACTION_PLAYER(RATE_NORMAL, RATE_FASTER_FINE, Rate, true)
+ VLC_ACTION_PLAYER(SUBTITLE_TOGGLE, SUBTITLE_TOGGLE, ToggleSubtitle, true)
+ VLC_ACTION_PLAYER(SUBSYNC_MARKAUDIO, SUBSYNC_RESET, SyncSubtitle, true)
+ VLC_ACTION_PLAYER(NAV_ACTIVATE, NAV_RIGHT, Navigate, true)
+ VLC_ACTION_PLAYER(VIEWPOINT_FOV_IN, VIEWPOINT_ROLL_ANTICLOCK, Viewpoint, true)
+ VLC_ACTION_PLAYER(RECORD, RECORD, Record, true)
+ VLC_ACTION_PLAYER(VOL_DOWN, AUDIODEVICE_CYCLE, Aout, false)
+ VLC_ACTION_PLAYER(TOGGLE_FULLSCREEN, WALLPAPER, Vouts, false)
+ /* vout actions */
+ VLC_ACTION_VOUT(ASPECT_RATIO, ASPECT_RATIO, AspectRatio)
+ VLC_ACTION_VOUT(CROP, UNCROP_RIGHT, Crop)
+ VLC_ACTION_VOUT(TOGGLE_AUTOSCALE, ZOOM_DOUBLE, Zoom)
+ VLC_ACTION_VOUT(DEINTERLACE, DEINTERLACE_MODE, Deinterlace)
+ VLC_ACTION_VOUT(SUBPOS_DOWN, SUBTITLE_TEXT_SCALE_UP, SubtitleDisplay)
+ /* null action */
+ { .type = NULL_ACTION }
+
+#undef VLC_ACTION_VOUT
+#undef VLC_ACTION_PLAYER
+#undef VLC_ACTION_PLAYLIST
+#undef VLC_ACTION_INTF
+#undef VLC_ACTION
+};
- int i_new_index = 1; /* select first track by default */
- /* if subtitles were disabled with no saved id, use the first track */
- if( i_cur_id != -1 || i_new_id != -1 )
- {
- for( size_t i = 0; i < count; ++i )
- {
- if( i_new_id == list[i].i_int )
- {
- i_new_index = i;
- break;
- }
- }
- }
- var_SetInteger( p_input, "spu-es", list[i_new_index].i_int );
- DisplayMessage( p_vout, _("Subtitle track: %s"),
- list2[i_new_index] );
- var_FreeList( count, list, list2 );
- }
+static void
+handle_action(intf_thread_t *intf, vlc_action_id_t action_id)
+{
+ size_t action_idx;
+ for (action_idx = 0; actions[action_idx].type != NULL_ACTION; ++action_idx)
+ if (actions[action_idx].range.first <= action_id &&
+ actions[action_idx].range.last >= action_id)
break;
- case ACTIONID_PROGRAM_SID_NEXT:
- case ACTIONID_PROGRAM_SID_PREV:
- if( p_input )
- {
- vlc_value_t val;
- vlc_value_t *list;
- char **list2;
- size_t count, i;
- var_Get( p_input, "program", &val );
+ if (actions[action_idx].type == NULL_ACTION)
+ return msg_Warn(intf, "no handler for action %d", action_id);
+ struct vlc_action const *action = actions + action_idx;
- var_Change( p_input, "program", VLC_VAR_GETCHOICES,
- &count, &list, &list2 );
+ vlc_playlist_t *playlist = intf->p_sys->playlist;
+ if (action->pl_need_lock)
+ vlc_playlist_Lock(playlist);
- if( count <= 1 )
- {
- DisplayMessage( p_vout, _("Program Service ID: %s"),
- _("N/A") );
- var_FreeList( count, list, list2 );
- break;
- }
- for( i = 0; i < count; i++ )
- if( val.i_int == list[i].i_int )
- break;
- /* value of program sid was not in choices list */
- if( i == count )
- {
- msg_Warn( p_input,
- "invalid current program SID, selecting 0" );
- i = 0;
- }
- else if( i_action == ACTIONID_PROGRAM_SID_NEXT ) {
- if( i == count - 1 )
- i = 0;
- else
- i++;
- }
- else { /* ACTIONID_PROGRAM_SID_PREV */
- if( i == 0 )
- i = count - 1;
- else
- i--;
- }
- var_Set( p_input, "program", list[i] );
- DisplayMessage( p_vout, _("Program Service ID: %s"),
- list2[i] );
- var_FreeList( count, list, list2 );
- }
- break;
-
- case ACTIONID_JUMP_BACKWARD_EXTRASHORT:
- case ACTIONID_JUMP_FORWARD_EXTRASHORT:
- case ACTIONID_JUMP_BACKWARD_SHORT:
- case ACTIONID_JUMP_FORWARD_SHORT:
- case ACTIONID_JUMP_BACKWARD_MEDIUM:
- case ACTIONID_JUMP_FORWARD_MEDIUM:
- case ACTIONID_JUMP_BACKWARD_LONG:
- case ACTIONID_JUMP_FORWARD_LONG:
- {
- if( p_input == NULL || !var_GetBool( p_input, "can-seek" ) )
- break;
-
- const char *varname;
- int sign = +1;
- switch( i_action )
- {
- case ACTIONID_JUMP_BACKWARD_EXTRASHORT:
- sign = -1;
- /* fall through */
- case ACTIONID_JUMP_FORWARD_EXTRASHORT:
- varname = "extrashort-jump-size";
- break;
- case ACTIONID_JUMP_BACKWARD_SHORT:
- sign = -1;
- /* fall through */
- case ACTIONID_JUMP_FORWARD_SHORT:
- varname = "short-jump-size";
- break;
- case ACTIONID_JUMP_BACKWARD_MEDIUM:
- sign = -1;
- /* fall through */
- case ACTIONID_JUMP_FORWARD_MEDIUM:
- varname = "medium-jump-size";
- break;
- case ACTIONID_JUMP_BACKWARD_LONG:
- sign = -1;
- /* fall through */
- case ACTIONID_JUMP_FORWARD_LONG:
- varname = "long-jump-size";
- break;
- }
-
- int it = var_InheritInteger( p_input, varname );
- if( it < 0 )
- break;
- var_SetInteger( p_input, "time-offset", vlc_tick_from_sec( it * sign ) );
- DisplayPosition( p_vout, slider_chan, p_input );
- break;
- }
-
- /* Input navigation */
- case ACTIONID_TITLE_PREV:
- if( p_input )
- var_TriggerCallback( p_input, "prev-title" );
- break;
- case ACTIONID_TITLE_NEXT:
- if( p_input )
- var_TriggerCallback( p_input, "next-title" );
- break;
- case ACTIONID_CHAPTER_PREV:
- if( p_input )
- var_TriggerCallback( p_input, "prev-chapter" );
- break;
- case ACTIONID_CHAPTER_NEXT:
- if( p_input )
- var_TriggerCallback( p_input, "next-chapter" );
- break;
- case ACTIONID_DISC_MENU:
- if( p_input )
- var_SetInteger( p_input, "title 0", 2 );
- break;
- case ACTIONID_NAV_ACTIVATE:
- if( p_input )
- input_Control( p_input, INPUT_NAV_ACTIVATE, NULL );
- break;
- case ACTIONID_NAV_UP:
- if( p_input )
- input_Control( p_input, INPUT_NAV_UP, NULL );
- break;
- case ACTIONID_NAV_DOWN:
- if( p_input )
- input_Control( p_input, INPUT_NAV_DOWN, NULL );
- break;
- case ACTIONID_NAV_LEFT:
- if( p_input )
- input_Control( p_input, INPUT_NAV_LEFT, NULL );
- break;
- case ACTIONID_NAV_RIGHT:
- if( p_input )
- input_Control( p_input, INPUT_NAV_RIGHT, NULL );
+ switch (action->type)
+ {
+ case INTF_ACTION:
+ action->handler.pf_intf(intf, action_id);
break;
-
- /* Video Output actions */
- case ACTIONID_SNAPSHOT:
- if( p_vout )
- var_TriggerCallback( p_vout, "video-snapshot" );
+ case PLAYLIST_ACTION:
+ action->handler.pf_playlist(playlist, action_id);
break;
-
- case ACTIONID_TOGGLE_FULLSCREEN:
+ case PLAYER_ACTION:
+ case VOUT_ACTION:
{
- if( p_vout )
- {
- bool fs = var_ToggleBool( p_vout, "fullscreen" );
- var_SetBool( p_playlist, "fullscreen", fs );
- }
+ vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
+ if (action->type == PLAYER_ACTION)
+ action->handler.pf_player(player, action_id);
else
- var_ToggleBool( p_playlist, "fullscreen" );
- break;
- }
-
- case ACTIONID_LEAVE_FULLSCREEN:
- if( p_vout )
- var_SetBool( p_vout, "fullscreen", false );
- var_SetBool( p_playlist, "fullscreen", false );
- break;
-
- case ACTIONID_ASPECT_RATIO:
- if( p_vout )
- {
- vlc_value_t val;
- vlc_value_t *val_list;
- char **text_list;
- size_t count;
-
- var_Get( p_vout, "aspect-ratio", &val );
- if( var_Change( p_vout, "aspect-ratio", VLC_VAR_GETCHOICES,
- &count, &val_list, &text_list ) >= 0 )
- {
- size_t i;
- for( i = 0; i < count; i++ )
- {
- if( !strcmp( val_list[i].psz_string, val.psz_string ) )
- {
- i++;
- break;
- }
- }
- if( i == count ) i = 0;
- var_SetString( p_vout, "aspect-ratio",
- val_list[i].psz_string );
- DisplayMessage( p_vout, _("Aspect ratio: %s"),
- text_list[i] );
-
- var_FreeStringList( count, val_list, text_list );
- }
- free( val.psz_string );
- }
- break;
-
- case ACTIONID_CROP:
- if( p_vout )
- {
- vlc_value_t val;
- vlc_value_t *val_list;
- char **text_list;
- size_t count;
-
- var_Get( p_vout, "crop", &val );
- if( var_Change( p_vout, "crop", VLC_VAR_GETCHOICES,
- &count, &val_list, &text_list ) >= 0 )
- {
- size_t i;
- for( i = 0; i < count; i++ )
- {
- if( !strcmp( val_list[i].psz_string, val.psz_string ) )
- {
- i++;
- break;
- }
- }
- if( i == count ) i = 0;
- var_SetString( p_vout, "crop", val_list[i].psz_string );
- DisplayMessage( p_vout, _("Crop: %s"), text_list[i] );
-
- var_FreeStringList( count, val_list, text_list );
- }
- free( val.psz_string );
- }
- break;
- case ACTIONID_CROP_TOP:
- if( p_vout )
- var_IncInteger( p_vout, "crop-top" );
- break;
- case ACTIONID_UNCROP_TOP:
- if( p_vout )
- var_DecInteger( p_vout, "crop-top" );
- break;
- case ACTIONID_CROP_BOTTOM:
- if( p_vout )
- var_IncInteger( p_vout, "crop-bottom" );
- break;
- case ACTIONID_UNCROP_BOTTOM:
- if( p_vout )
- var_DecInteger( p_vout, "crop-bottom" );
- break;
- case ACTIONID_CROP_LEFT:
- if( p_vout )
- var_IncInteger( p_vout, "crop-left" );
- break;
- case ACTIONID_UNCROP_LEFT:
- if( p_vout )
- var_DecInteger( p_vout, "crop-left" );
- break;
- case ACTIONID_CROP_RIGHT:
- if( p_vout )
- var_IncInteger( p_vout, "crop-right" );
- break;
- case ACTIONID_UNCROP_RIGHT:
- if( p_vout )
- var_DecInteger( p_vout, "crop-right" );
- break;
-
- case ACTIONID_VIEWPOINT_FOV_IN:
- if( p_vout )
- input_UpdateViewpoint( p_input,
- &(vlc_viewpoint_t) { .fov = -1.f },
- false );
- break;
- case ACTIONID_VIEWPOINT_FOV_OUT:
- if( p_vout )
- input_UpdateViewpoint( p_input,
- &(vlc_viewpoint_t) { .fov = 1.f },
- false );
- break;
-
- case ACTIONID_VIEWPOINT_ROLL_CLOCK:
- if( p_vout )
- input_UpdateViewpoint( p_input,
- &(vlc_viewpoint_t) { .roll = -1.f },
- false );
- break;
- case ACTIONID_VIEWPOINT_ROLL_ANTICLOCK:
- if( p_vout )
- input_UpdateViewpoint( p_input,
- &(vlc_viewpoint_t) { .roll = 1.f },
- false );
- break;
-
- case ACTIONID_TOGGLE_AUTOSCALE:
- if( p_vout )
- {
- float f_scalefactor = var_GetFloat( p_vout, "zoom" );
- if ( f_scalefactor != 1.f )
- {
- var_SetFloat( p_vout, "zoom", 1.f );
- DisplayMessage( p_vout, _("Zooming reset") );
- }
- else
- {
- bool b_autoscale = !var_GetBool( p_vout, "autoscale" );
- var_SetBool( p_vout, "autoscale", b_autoscale );
- if( b_autoscale )
- DisplayMessage( p_vout, _("Scaled to screen") );
- else
- DisplayMessage( p_vout, _("Original Size") );
- }
- }
- break;
- case ACTIONID_SCALE_UP:
- if( p_vout )
- {
- float f_scalefactor = var_GetFloat( p_vout, "zoom" );
-
- if( f_scalefactor < 10.f )
- f_scalefactor += .1f;
- var_SetFloat( p_vout, "zoom", f_scalefactor );
- }
- break;
- case ACTIONID_SCALE_DOWN:
- if( p_vout )
- {
- float f_scalefactor = var_GetFloat( p_vout, "zoom" );
-
- if( f_scalefactor > .3f )
- f_scalefactor -= .1f;
- var_SetFloat( p_vout, "zoom", f_scalefactor );
- }
- break;
-
- case ACTIONID_ZOOM_QUARTER:
- case ACTIONID_ZOOM_HALF:
- case ACTIONID_ZOOM_ORIGINAL:
- case ACTIONID_ZOOM_DOUBLE:
- if( p_vout )
- {
- float f;
- switch( i_action )
- {
- case ACTIONID_ZOOM_QUARTER: f = 0.25; break;
- case ACTIONID_ZOOM_HALF: f = 0.5; break;
- case ACTIONID_ZOOM_ORIGINAL: f = 1.; break;
- /*case ACTIONID_ZOOM_DOUBLE:*/
- default: f = 2.; break;
- }
- var_SetFloat( p_vout, "zoom", f );
- }
- break;
- case ACTIONID_ZOOM:
- case ACTIONID_UNZOOM:
- if( p_vout )
- {
- vlc_value_t val;
- vlc_value_t *val_list;
- char **text_list;
- size_t count;
-
- var_Get( p_vout, "zoom", &val );
- if( var_Change( p_vout, "zoom", VLC_VAR_GETCHOICES,
- &count, &val_list, &text_list ) >= 0 )
- {
- size_t i;
- for( i = 0; i < count; i++ )
- {
- if( val_list[i].f_float == val.f_float )
- {
- if( i_action == ACTIONID_ZOOM )
- i++;
- else /* ACTIONID_UNZOOM */
- i--;
- break;
- }
- }
- if( i == count ) i = 0;
- if( i == (size_t)-1 ) i = count-1;
- var_SetFloat( p_vout, "zoom", val_list[i].f_float );
- DisplayMessage( p_vout, _("Zoom mode: %s"), text_list[i] );
-
- var_FreeList( count, val_list, text_list );
- }
- }
- break;
-
- case ACTIONID_DEINTERLACE:
- if( p_vout )
- {
- int i_deinterlace = var_GetInteger( p_vout, "deinterlace" );
- if( i_deinterlace != 0 )
- {
- var_SetInteger( p_vout, "deinterlace", 0 );
- DisplayMessage( p_vout, _("Deinterlace off") );
- }
- else
- {
- var_SetInteger( p_vout, "deinterlace", 1 );
-
- char *psz_mode = var_GetString( p_vout, "deinterlace-mode" );
- vlc_value_t *vlist;
- char **tlist;
- size_t count;
-
- if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &count, &vlist, &tlist ) )
- {
- const char *psz_text = NULL;
- for( size_t i = 0; i < count; i++ )
- {
- if( !strcmp( vlist[i].psz_string, psz_mode ) )
- {
- psz_text = tlist[i];
- break;
- }
- }
- DisplayMessage( p_vout, "%s (%s)", _("Deinterlace on"),
- psz_text ? psz_text : psz_mode );
-
- var_FreeStringList( count, vlist, tlist );
- }
- free( psz_mode );
- }
- }
- break;
- case ACTIONID_DEINTERLACE_MODE:
- if( p_vout )
{
- char *psz_mode = var_GetString( p_vout, "deinterlace-mode" );
- vlc_value_t *vlist;
- char **tlist;
- size_t count;
-
- if( psz_mode && !var_Change( p_vout, "deinterlace-mode", VLC_VAR_GETCHOICES, &count, &vlist, &tlist ))
- {
- const char *psz_text = NULL;
- size_t i;
-
- for( i = 0; i < count; i++ )
- {
- if( !strcmp( vlist[i].psz_string, psz_mode ) )
- {
- i++;
- break;
- }
- }
- if( i == count ) i = 0;
- psz_text = tlist[i];
- var_SetString( p_vout, "deinterlace-mode", vlist[i].psz_string );
-
- int i_deinterlace = var_GetInteger( p_vout, "deinterlace" );
- if( i_deinterlace != 0 )
- {
- DisplayMessage( p_vout, "%s (%s)", _("Deinterlace on"),
- psz_text ? psz_text : psz_mode );
- }
- else
- {
- DisplayMessage( p_vout, "%s (%s)", _("Deinterlace off"),
- psz_text ? psz_text : psz_mode );
- }
-
- var_FreeStringList( count, vlist, tlist );
- }
- free( psz_mode );
- }
- break;
-
- case ACTIONID_SUBPOS_DOWN:
- case ACTIONID_SUBPOS_UP:
- {
- if( p_input )
- {
- vlc_value_t val;
- vlc_value_t *list;
- size_t count;
-
- var_Get( p_input, "spu-es", &val );
-
- var_Change( p_input, "spu-es", VLC_VAR_GETCHOICES,
- &count, &list, (char ***)NULL );
- if( count < 1 || val.i_int < 0 )
- {
- DisplayMessage( p_vout,
- _("Subtitle position: no active subtitle") );
- free(list);
- break;
- }
-
- int i_pos;
- if( i_action == ACTIONID_SUBPOS_DOWN )
- i_pos = var_DecInteger( p_vout, "sub-margin" );
- else
- i_pos = var_IncInteger( p_vout, "sub-margin" );
-
- ClearChannels( p_vout, slider_chan );
- DisplayMessage( p_vout, _( "Subtitle position %d px" ), i_pos );
- free(list);
+ vout_thread_t *vout = vlc_player_vout_Hold(player);
+ action->handler.pf_vout(vout, action_id);
+ vlc_object_release(vout);
}
break;
}
-
- case ACTIONID_SUBTITLE_TEXT_SCALE_DOWN:
- case ACTIONID_SUBTITLE_TEXT_SCALE_UP:
- case ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL:
- if( p_vout )
- {
- int i_scale;
- if( i_action == ACTIONID_SUBTITLE_TEXT_SCALE_NORMAL )
- {
- i_scale = 100;
- }
- else
- {
- i_scale = var_GetInteger( p_playlist, "sub-text-scale" );
- unsigned increment = ((i_scale > 100 ? i_scale - 100 : 100 - i_scale) / 25) <= 1 ? 10 : 25;
- i_scale += ((i_action == ACTIONID_SUBTITLE_TEXT_SCALE_UP) ? 1 : -1) * increment;
- i_scale -= i_scale % increment;
- i_scale = VLC_CLIP( i_scale, 25, 500 );
- }
- var_SetInteger( p_playlist, "sub-text-scale", i_scale );
- DisplayMessage( p_vout, _( "Subtitle text scale %d%%" ), i_scale );
- }
- break;
-
- /* Input + video output */
- case ACTIONID_POSITION:
- if( p_vout && vout_OSDEpg( p_vout, input_GetItem( p_input ) ) )
- DisplayPosition( p_vout, slider_chan, p_input );
- break;
-
- case ACTIONID_COMBO_VOL_FOV_UP:
- if( b_vrnav )
- DO_ACTION( ACTIONID_VIEWPOINT_FOV_IN );
- else
- DO_ACTION( ACTIONID_VOL_UP );
- break;
- case ACTIONID_COMBO_VOL_FOV_DOWN:
- if( b_vrnav )
- DO_ACTION( ACTIONID_VIEWPOINT_FOV_OUT );
- else
- DO_ACTION( ACTIONID_VOL_DOWN );
- break;
+ default:
+ vlc_assert_unreachable();
}
- return VLC_SUCCESS;
+ if (action->pl_need_lock)
+ vlc_playlist_Unlock(playlist);
}
-/*****************************************************************************
- * ActionEvent: callback for hotkey actions
- *****************************************************************************/
-static int ActionEvent( vlc_object_t *libvlc, char const *psz_var,
- vlc_value_t oldval, vlc_value_t newval, void *p_data )
-{
- intf_thread_t *p_intf = (intf_thread_t *)p_data;
- intf_sys_t *p_sys = p_intf->p_sys;
-
- (void)libvlc;
- (void)psz_var;
- (void)oldval;
-
- vlc_mutex_lock( &p_intf->p_sys->lock );
- input_thread_t *p_input = p_sys->p_input ? vlc_object_hold( p_sys->p_input )
- : NULL;
- vout_thread_t *p_vout = p_sys->p_vout ? vlc_object_hold( p_sys->p_vout )
- : NULL;
- int slider_chan = p_sys->slider_chan;
- bool b_vrnav = p_sys->vrnav.b_can_change;
- vlc_mutex_unlock( &p_intf->p_sys->lock );
-
- int i_ret = PutAction( p_intf, p_input, p_vout, slider_chan, b_vrnav,
- newval.i_int );
-
- if( p_input != NULL )
- vlc_object_release( p_input );
- if( p_vout != NULL )
- vlc_object_release( p_vout );
-
- return i_ret;
-}
+/******************
+ * vout callbacks *
+ ******************/
-static void PlayBookmark( intf_thread_t *p_intf, int i_num )
+static int
+MouseButtonCallback(vlc_object_t *obj, char const *var,
+ vlc_value_t oldval, vlc_value_t newval, void *data)
{
- char *psz_bookmark_name;
- if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
- return;
+ VLC_UNUSED(var);
- playlist_t *p_playlist = pl_Get( p_intf );
- char *psz_bookmark = var_CreateGetString( p_intf, psz_bookmark_name );
+ intf_thread_t *intf = data;
+ intf_sys_t *sys = intf->p_sys;
+ vout_thread_t *vout = (vout_thread_t *)obj;
- PL_LOCK;
- playlist_item_t *p_item;
- ARRAY_FOREACH( p_item, p_playlist->items )
+ if ((newval.i_int & (1 << MOUSE_BUTTON_LEFT)) &&
+ var_GetBool(vout, "viewpoint-changeable"))
{
- char *psz_uri = input_item_GetURI( p_item->p_input );
- if( !strcmp( psz_bookmark, psz_uri ) )
+ if (!sys->vrnav.btn_pressed)
{
- free( psz_uri );
- playlist_ViewPlay( p_playlist, NULL, p_item );
- break;
+ sys->vrnav.btn_pressed = true;
+ var_GetCoords(vout, "mouse-moved", &sys->vrnav.x, &sys->vrnav.y);
}
- else
- free( psz_uri );
}
- PL_UNLOCK;
+ else
+ sys->vrnav.btn_pressed = false;
- free( psz_bookmark );
- free( psz_bookmark_name );
+ unsigned pressed = newval.i_int & ~oldval.i_int;
+ if (pressed & (1 << MOUSE_BUTTON_LEFT))
+ var_SetBool(intf->obj.libvlc, "intf-popupmenu", false);
+ if (pressed & (1 << MOUSE_BUTTON_CENTER))
+ var_TriggerCallback(intf->obj.libvlc, "intf-toggle-fscontrol");
+#ifndef _WIN32
+ if (pressed & (1 << MOUSE_BUTTON_RIGHT))
+#else
+ if ((oldval.i_int & (1 << MOUSE_BUTTON_RIGHT))
+ && !(newval.i_int & (1 << MOUSE_BUTTON_RIGHT)))
+#endif
+ var_SetBool(intf->obj.libvlc, "intf-popupmenu", true);
+ for (int i = MOUSE_BUTTON_WHEEL_UP; i <= MOUSE_BUTTON_WHEEL_RIGHT; i++)
+ if (pressed & (1 << i))
+ {
+ int keycode = KEY_MOUSEWHEEL_FROM_BUTTON(i);
+ var_SetInteger(intf->obj.libvlc, "key-pressed", keycode);
+ }
+
+ return VLC_SUCCESS;
}
-static void SetBookmark( intf_thread_t *p_intf, int i_num )
+static int
+MouseMovedCallback(vlc_object_t *obj, char const *var,
+ vlc_value_t ov, vlc_value_t newval, void *data)
{
- char *psz_bookmark_name;
- char *psz_uri = NULL;
- if( asprintf( &psz_bookmark_name, "bookmark%i", i_num ) == -1 )
- return;
-
- playlist_t *p_playlist = pl_Get( p_intf );
- var_Create( p_intf, psz_bookmark_name,
- VLC_VAR_STRING|VLC_VAR_DOINHERIT );
-
- PL_LOCK;
- playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
- if( p_item ) psz_uri = input_item_GetURI( p_item->p_input );
- PL_UNLOCK;
-
- if( p_item )
+ VLC_UNUSED(obj); VLC_UNUSED(var); VLC_UNUSED(ov);
+ intf_sys_t *sys = data;
+ vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
+ if (sys->vrnav.btn_pressed)
{
- config_PutPsz( psz_bookmark_name, psz_uri);
- msg_Info( p_intf, "setting playlist bookmark %i to %s", i_num, psz_uri);
+ int i_horizontal = newval.coords.x - sys->vrnav.x;
+ int i_vertical = newval.coords.y - sys->vrnav.y;
+ vlc_viewpoint_t viewpoint =
+ {
+ .yaw = -i_horizontal * 0.05f,
+ .pitch = -i_vertical * 0.05f,
+ };
+ vlc_player_Lock(player);
+ vlc_player_UpdateViewpoint(player, &viewpoint,
+ VLC_PLAYER_WHENCE_RELATIVE);
+ vlc_player_Unlock(player);
+ sys->vrnav.x = newval.coords.x;
+ sys->vrnav.y = newval.coords.y;
}
-
- free( psz_uri );
- free( psz_bookmark_name );
+ return VLC_SUCCESS;
}
-static void DisplayPosition( vout_thread_t *p_vout, int slider_chan,
- input_thread_t *p_input )
+static int
+ViewpointMovedCallback(vlc_object_t *obj, char const *var,
+ vlc_value_t ov, vlc_value_t newval, void *data)
{
- char psz_duration[MSTRTIME_MAX_SIZE];
- char psz_time[MSTRTIME_MAX_SIZE];
-
- if( p_vout == NULL ) return;
-
- ClearChannels( p_vout, slider_chan );
-
- int64_t t = SEC_FROM_VLC_TICK(var_GetInteger( p_input, "time" ));
- int64_t l = SEC_FROM_VLC_TICK(var_GetInteger( p_input, "length" ));
-
- secstotimestr( psz_time, t );
+ VLC_UNUSED(obj); VLC_UNUSED(var); VLC_UNUSED(ov);
+ vlc_player_t *player = data;
+ vlc_player_Lock(player);
+ vlc_player_UpdateViewpoint(player, (vlc_viewpoint_t *)newval.p_address,
+ VLC_PLAYER_WHENCE_RELATIVE);
+ vlc_player_Unlock(player);
+ return VLC_SUCCESS;
+}
- if( l > 0 )
- {
- secstotimestr( psz_duration, l );
- DisplayMessage( p_vout, "%s / %s", psz_time, psz_duration );
- }
- else if( t > 0 )
+static void
+player_on_vout_list_changed(vlc_player_t *player,
+ enum vlc_player_list_action action,
+ vout_thread_t *vout,
+ void *data)
+{
+ if (action == VLC_PLAYER_LIST_UPDATED)
+ return;
+ intf_thread_t *intf = data;
+ bool vrnav = var_GetBool(vout, "viewpoint-changeable");
+ if (action == VLC_PLAYER_LIST_ADDED)
{
- DisplayMessage( p_vout, "%s", psz_time );
+ var_AddCallback(vout, "mouse-button-down", MouseButtonCallback, intf);
+ var_AddCallback(vout, "mouse-moved", MouseMovedCallback, intf->p_sys);
+ if (vrnav)
+ var_AddCallback(vout, "viewpoint-moved",
+ ViewpointMovedCallback, player);
}
-
- if( var_GetBool( p_vout, "fullscreen" ) )
+ else
{
- vlc_value_t pos;
- var_Get( p_input, "position", &pos );
- vout_OSDSlider( p_vout, slider_chan,
- pos.f_float * 100, OSD_HOR_SLIDER );
+ var_DelCallback(vout, "mouse-button-down", MouseButtonCallback, intf);
+ var_DelCallback(vout, "mouse-moved", MouseMovedCallback, intf->p_sys);
+ if (vrnav)
+ var_DelCallback(vout, "viewpoint-moved",
+ ViewpointMovedCallback, player);
}
}
-static void DisplayVolume( vout_thread_t *p_vout, int slider_chan, float vol )
+static int
+ActionCallback(vlc_object_t *obj, char const *var,
+ vlc_value_t ov, vlc_value_t newval, void *data)
{
- if( p_vout == NULL )
- return;
- ClearChannels( p_vout, slider_chan );
-
- if( var_GetBool( p_vout, "fullscreen" ) )
- vout_OSDSlider( p_vout, slider_chan,
- lroundf(vol * 100.f), OSD_VERT_SLIDER );
- DisplayMessage( p_vout, _( "Volume %ld%%" ), lroundf(vol * 100.f) );
+ VLC_UNUSED(obj); VLC_UNUSED(var); VLC_UNUSED(ov);
+ handle_action(data, newval.i_int);
+ return VLC_SUCCESS;
}
-static void DisplayRate( vout_thread_t *p_vout, float f_rate )
-{
- DisplayMessage( p_vout, _("Speed: %.2fx"), (double) f_rate );
-}
+/****************************
+ * module opening / closing *
+ ****************************/
-static float AdjustRateFine( vlc_object_t *p_obj, const int i_dir )
+static int
+Open(vlc_object_t *this)
{
- const float f_rate_min = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
- const float f_rate_max = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
- float f_rate = var_GetFloat( p_obj, "rate" );
-
- int i_sign = f_rate < 0 ? -1 : 1;
-
- f_rate = floor( fabs(f_rate) / 0.1 + i_dir + 0.05 ) * 0.1;
-
- if( f_rate < f_rate_min )
- f_rate = f_rate_min;
- else if( f_rate > f_rate_max )
- f_rate = f_rate_max;
- f_rate *= i_sign;
-
- return f_rate;
+ intf_thread_t *intf = (intf_thread_t *)this;
+ intf_sys_t *sys = malloc(sizeof(intf_sys_t));
+ if (!sys)
+ return VLC_ENOMEM;
+ sys->vrnav.btn_pressed = false;
+ sys->playlist = vlc_intf_GetMainPlaylist(intf);
+ static struct vlc_player_cbs const player_cbs =
+ {
+ .on_vout_list_changed = player_on_vout_list_changed,
+ };
+ vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
+ vlc_player_Lock(player);
+ sys->player_listener = vlc_player_AddListener(player, &player_cbs, intf);
+ vlc_player_Unlock(player);
+ if (!sys->player_listener)
+ {
+ free(sys);
+ return VLC_EGENERIC;
+ }
+ var_AddCallback(intf->obj.libvlc, "key-action", ActionCallback, intf);
+ intf->p_sys = sys;
+ return VLC_SUCCESS;
}
-static void ClearChannels( vout_thread_t *p_vout, int slider_chan )
+static void
+Close(vlc_object_t *this)
{
- if( p_vout )
- {
- vout_FlushSubpictureChannel( p_vout, VOUT_SPU_CHANNEL_OSD );
- vout_FlushSubpictureChannel( p_vout, slider_chan );
- }
+ intf_thread_t *intf = (intf_thread_t *)this;
+ intf_sys_t *sys = intf->p_sys;
+ vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
+ vlc_player_Lock(player);
+ vlc_player_RemoveListener(player, sys->player_listener);
+ vlc_player_Unlock(player);
+ var_DelCallback(intf->obj.libvlc, "key-action", ActionCallback, intf);
+ free(sys);
}
+
+vlc_module_begin ()
+ set_shortname(N_("Hotkeys"))
+ set_description(N_("Hotkeys management interface"))
+ set_capability("interface", 0)
+ set_callbacks(Open, Close)
+ set_category(CAT_INTERFACE)
+ set_subcategory(SUBCAT_INTERFACE_HOTKEYS)
+vlc_module_end ()
--
2.19.2
More information about the vlc-devel
mailing list