Commit bb4d4abf authored by Thomas Guillem's avatar Thomas Guillem

player: rework aout/vout callbacks

Document that vlc_player_t functions should not be called from these callbacks.
A player function could trigger an action on the vout/aout and cause a callback
to be called => deadlock.

Remove the vlc_player_t * argument, it was never used.

Add the audio_output_t *argument for aout callbacks. It's not currently used,
it is added as symmetry with vout callbacks.
parent 5ca9d7ea
......@@ -2115,11 +2115,8 @@ typedef struct vlc_player_aout_listener_id vlc_player_aout_listener_id;
*
* Can be registered with vlc_player_aout_AddListener().
*
* These callbacks are *not* called with the player locked. It is safe to lock
* the player and call any vlc_player functions from these callbacks.
*
* @warning To avoid deadlocks, users should never call audio_output_t
* functions from these callbacks.
* @warning To avoid deadlocks, users should never call audio_output_t and
* vlc_player_t functions from these callbacks.
*/
struct vlc_player_aout_cbs
{
......@@ -2128,34 +2125,34 @@ struct vlc_player_aout_cbs
*
* @see vlc_player_aout_SetVolume()
*
* @param player unlocked player instance
* @param aout the main aout of the player
* @param new_volume volume in the range [0;2.f]
* @param data opaque pointer set by vlc_player_aout_AddListener()
*/
void (*on_volume_changed)(vlc_player_t *player,
float new_volume, void *data);
void (*on_volume_changed)(audio_output_t *aout, float new_volume,
void *data);
/**
* Called when the mute state has changed
*
* @see vlc_player_aout_Mute()
*
* @param player unlocked player instance
* @param aout the main aout of the player
* @param new_mute true if muted
* @param data opaque pointer set by vlc_player_aout_AddListener()
*/
void (*on_mute_changed)(vlc_player_t *player,
bool new_muted, void *data);
void (*on_mute_changed)(audio_output_t *aout, bool new_muted,
void *data);
/**
* Called when the audio device has changed
*
* @param player unlocked player instance
* @param aout the main aout of the player
* @param device the device name
* @param data opaque pointer set by vlc_player_aout_AddListener()
*/
void (*on_device_changed)(vlc_player_t *player, const char *device,
void *data);
void (*on_device_changed)(audio_output_t *aout, const char *device,
void *data);
};
/**
......@@ -2330,15 +2327,12 @@ enum vlc_player_vout_action
*
* Can be registered with vlc_player_vout_AddListener().
*
* These callbacks are *not* called with the player locked. It is safe to lock
* the player and call any vlc_player functions from these callbacks.
*
* @note The state changed from the callbacks can be either applied on the
* player (and all future video outputs), or on a specified video output. The
* state is applied on the player when the vout argument is NULL.
*
* @warning To avoid deadlocks, users should never call vout_thread_t functions
* from these callbacks.
* @warning To avoid deadlocks, users should never call vout_thread_t and
* vlc_player_t functions from these callbacks.
*/
struct vlc_player_vout_cbs
{
......@@ -2347,26 +2341,24 @@ struct vlc_player_vout_cbs
*
* @see vlc_player_vout_SetFullscreen()
*
* @param player unlocked player instance
* @param vout cf. vlc_player_vout_cbs note
* @param enabled true when fullscreen is enabled
* @param data opaque pointer set by vlc_player_vout_AddListener()
*/
void (*on_fullscreen_changed)(vlc_player_t *player,
vout_thread_t *vout, bool enabled, void *data);
void (*on_fullscreen_changed)(vout_thread_t *vout, bool enabled,
void *data);
/**
* Called when the player and/or vout wallpaper mode has changed
*
* @see vlc_player_vout_SetWallpaperModeEnabled()
*
* @param player unlocked player instance
* @param vout cf. vlc_player_vout_cbs note
* @param enabled true when wallpaper mode is enabled
* @param data opaque pointer set by vlc_player_vout_AddListener()
*/
void (*on_wallpaper_mode_changed)(vlc_player_t *player,
vout_thread_t *vout, bool enabled, void *data);
void (*on_wallpaper_mode_changed)(vout_thread_t *vout, bool enabled,
void *data);
};
......
......@@ -430,9 +430,9 @@ on_vout_changed(vlc_player_t *player, enum vlc_player_vout_action action,
// player aout callbacks
static void
on_volume_changed(vlc_player_t *player, float new_volume, void *data)
on_volume_changed(audio_output_t *aout, float new_volume, void *data)
{
(void) player;
(void) aout;
libvlc_media_player_t *mp = data;
......@@ -444,9 +444,9 @@ on_volume_changed(vlc_player_t *player, float new_volume, void *data)
}
static void
on_mute_changed(vlc_player_t *player, bool new_muted, void *data)
on_mute_changed(audio_output_t *aout, bool new_muted, void *data)
{
(void) player;
(void) aout;
libvlc_media_player_t *mp = data;
......@@ -458,9 +458,9 @@ on_mute_changed(vlc_player_t *player, bool new_muted, void *data)
}
static void
on_audio_device_changed(vlc_player_t *player, const char *device, void *data)
on_audio_device_changed(audio_output_t *aout, const char *device, void *data)
{
(void) player;
(void) aout;
libvlc_media_player_t *mp = data;
......
......@@ -151,11 +151,10 @@ static void player_on_position_changed(vlc_player_t *,
static void player_on_media_meta_changed(vlc_player_t *,
input_item_t *, void *);
static void player_aout_on_volume_changed(vlc_player_t *, float, void *);
static void player_aout_on_mute_changed(vlc_player_t *, bool, void *);
static void player_aout_on_volume_changed(audio_output_t *, float, void *);
static void player_aout_on_mute_changed(audio_output_t *, bool, void *);
static void player_vout_on_fullscreen_changed(vlc_player_t *,
vout_thread_t *, bool, void *);
static void player_vout_on_fullscreen_changed(vout_thread_t *, bool, void *);
/*****************************************************************************
* Module descriptor
......@@ -1142,28 +1141,27 @@ player_on_media_meta_changed(vlc_player_t *player,
}
static void
player_aout_on_volume_changed(vlc_player_t *player, float volume, void *data)
player_aout_on_volume_changed(audio_output_t *aout, float volume, void *data)
{
add_event_signal(data,
&(callback_info_t){ .signal = SIGNAL_VOLUME_CHANGE });
(void) player; (void) volume;
(void) aout; (void) volume;
}
static void
player_aout_on_mute_changed(vlc_player_t *player, bool muted, void *data)
player_aout_on_mute_changed(audio_output_t *aout, bool muted, void *data)
{
add_event_signal(data,
&(callback_info_t){ .signal = SIGNAL_VOLUME_MUTED });
(void) player; (void) muted;
(void) aout; (void) muted;
}
static void
player_vout_on_fullscreen_changed(vlc_player_t *player,
vout_thread_t *vout, bool enabled,
player_vout_on_fullscreen_changed(vout_thread_t *vout, bool enabled,
void *data)
{
add_event_signal(data, &(callback_info_t){ .signal = SIGNAL_FULLSCREEN });
(void) player; (void) vout; (void) enabled;
(void) vout; (void) enabled;
}
/*****************************************************************************
......
......@@ -353,8 +353,8 @@ player_on_position_changed(vlc_player_t *player,
}
static void
player_aout_on_volume_changed(vlc_player_t *player, float volume, void *data)
{ VLC_UNUSED(player);
player_aout_on_volume_changed(audio_output_t *aout, float volume, void *data)
{ VLC_UNUSED(aout);
intf_thread_t *p_intf = data;
vlc_mutex_lock(&p_intf->p_sys->status_lock);
msg_rc(STATUS_CHANGE "( audio volume: %ld )",
......
......@@ -506,18 +506,18 @@ static const struct vlc_player_cbs player_callbacks = {
#pragma mark - video specific callback implementations
static void cb_player_vout_fullscreen_changed(vlc_player_t *p_player, vout_thread_t *p_vout, bool isFullscreen, void *p_data)
static void cb_player_vout_fullscreen_changed(vout_thread_t *p_vout, bool isFullscreen, void *p_data)
{
VLC_UNUSED(p_player); VLC_UNUSED(p_vout);
VLC_UNUSED(p_vout);
dispatch_async(dispatch_get_main_queue(), ^{
VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
[playerController fullscreenChanged:isFullscreen];
});
}
static void cb_player_vout_wallpaper_mode_changed(vlc_player_t *p_player, vout_thread_t *p_vout, bool wallpaperModeEnabled, void *p_data)
static void cb_player_vout_wallpaper_mode_changed(vout_thread_t *p_vout, bool wallpaperModeEnabled, void *p_data)
{
VLC_UNUSED(p_player); VLC_UNUSED(p_vout);
VLC_UNUSED(p_vout);
dispatch_async(dispatch_get_main_queue(), ^{
VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
[playerController wallpaperModeChanged:wallpaperModeEnabled];
......@@ -531,18 +531,18 @@ static const struct vlc_player_vout_cbs player_vout_callbacks = {
#pragma mark - video specific callback implementations
static void cb_player_aout_volume_changed(vlc_player_t *p_player, float volume, void *p_data)
static void cb_player_aout_volume_changed(audio_output_t *aout, float volume, void *p_data)
{
VLC_UNUSED(p_player);
VLC_UNUSED(aout);
dispatch_async(dispatch_get_main_queue(), ^{
VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
[playerController volumeChanged:volume];
});
}
static void cb_player_aout_mute_changed(vlc_player_t *p_player, bool muted, void *p_data)
static void cb_player_aout_mute_changed(audio_output_t *aout, bool muted, void *p_data)
{
VLC_UNUSED(p_player);
VLC_UNUSED(aout);
dispatch_async(dispatch_get_main_queue(), ^{
VLCPlayerController *playerController = (__bridge VLCPlayerController *)p_data;
[playerController muteChanged:muted];
......
......@@ -20,7 +20,7 @@
extern "C" {
static void on_player_aout_device_changed(vlc_player_t *,const char *device, void *data)
static void on_player_aout_device_changed(audio_output_t *,const char *device, void *data)
{
AudioDeviceModel* that = static_cast<AudioDeviceModel*>(data);
QMetaObject::invokeMethod(that, [that, device=QString::fromUtf8(device)](){
......
......@@ -790,7 +790,7 @@ static void on_player_vout_changed(vlc_player_t *player, enum vlc_player_vout_ac
//player vout callbacks
static void on_player_vout_fullscreen_changed(vlc_player_t *, vout_thread_t* vout, bool is_fullscreen, void *data)
static void on_player_vout_fullscreen_changed(vout_thread_t* vout, bool is_fullscreen, void *data)
{
PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
msg_Dbg( that->p_intf, "on_player_vout_fullscreen_changed %s", is_fullscreen ? "fullscreen" : "windowed");
......@@ -808,7 +808,7 @@ static void on_player_vout_fullscreen_changed(vlc_player_t *, vout_thread_t* vou
});
}
static void on_player_vout_wallpaper_mode_changed(vlc_player_t *, vout_thread_t* vout, bool enabled, void *data)
static void on_player_vout_wallpaper_mode_changed(vout_thread_t* vout, bool enabled, void *data)
{
PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
msg_Dbg( that->p_intf, "on_player_vout_wallpaper_mode_changed");
......@@ -828,7 +828,7 @@ static void on_player_vout_wallpaper_mode_changed(vlc_player_t *, vout_thread_t*
//player aout callbacks
static void on_player_aout_volume_changed(vlc_player_t *, float volume, void *data)
static void on_player_aout_volume_changed(audio_output_t *, float volume, void *data)
{
PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
msg_Dbg( that->p_intf, "on_player_aout_volume_changed");
......@@ -838,7 +838,7 @@ static void on_player_aout_volume_changed(vlc_player_t *, float volume, void *da
});
}
static void on_player_aout_mute_changed(vlc_player_t *, bool muted, void *data)
static void on_player_aout_mute_changed(audio_output_t *, bool muted, void *data)
{
PlayerControllerPrivate* that = static_cast<PlayerControllerPrivate*>(data);
msg_Dbg( that->p_intf, "on_player_aout_mute_changed");
......
......@@ -259,17 +259,17 @@ void on_player_vout_changed( vlc_player_t *player,
VlcProc::onGenericCallback( "vout", val, data );
}
void on_player_aout_volume_changed( vlc_player_t *player,
void on_player_aout_volume_changed( audio_output *aout,
float volume, void *data )
{
(void)player;
(void)aout;
vlc_value_t val = { .f_float = volume };
VlcProc::onGenericCallback( "volume", val, data );
}
void on_player_aout_mute_changed( vlc_player_t *player, bool mute, void *data )
void on_player_aout_mute_changed( audio_output_t *aout, bool mute, void *data )
{
(void)player;
(void)aout;
vlc_value_t val = { .b_bool = mute};
VlcProc::onGenericCallback( "mute", val, data );
}
......
......@@ -35,7 +35,7 @@
vlc_list_foreach(listener, &player->aout_listeners, node) \
{ \
if (listener->cbs->event) \
listener->cbs->event(player, ##__VA_ARGS__, listener->cbs_data); \
listener->cbs->event(__VA_ARGS__, listener->cbs_data); \
} \
vlc_mutex_unlock(&player->aout_listeners_lock); \
} while(0)
......@@ -89,7 +89,8 @@ vlc_player_AoutCallback(vlc_object_t *this, const char *var,
{
if (oldval.f_float != newval.f_float)
{
vlc_player_aout_SendEvent(player, on_volume_changed, newval.f_float);
vlc_player_aout_SendEvent(player, on_volume_changed,
(audio_output_t *)this, newval.f_float);
vlc_player_osd_Volume(player, false);
}
}
......@@ -97,7 +98,8 @@ vlc_player_AoutCallback(vlc_object_t *this, const char *var,
{
if (oldval.b_bool != newval.b_bool)
{
vlc_player_aout_SendEvent(player, on_mute_changed, newval.b_bool);
vlc_player_aout_SendEvent(player, on_mute_changed,
(audio_output_t *)this, newval.b_bool);
vlc_player_osd_Volume(player, true);
}
}
......@@ -108,7 +110,7 @@ vlc_player_AoutCallback(vlc_object_t *this, const char *var,
/* support NULL values for string comparison */
if (old != new && (!old || !new || strcmp(old, new)))
vlc_player_aout_SendEvent(player, on_device_changed,
newval.psz_string);
(audio_output_t *)this, newval.psz_string);
}
else
vlc_assert_unreachable();
......
......@@ -34,7 +34,7 @@
vlc_list_foreach(listener, &player->vout_listeners, node) \
{ \
if (listener->cbs->event) \
listener->cbs->event(player, ##__VA_ARGS__, listener->cbs_data); \
listener->cbs->event(__VA_ARGS__, listener->cbs_data); \
} \
vlc_mutex_unlock(&player->vout_listeners_lock); \
} while(0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment