Commit e670c8c4 authored by Jean-Paul Saman's avatar Jean-Paul Saman

Revert "Mostly revert "libvlc: add mouse events as libvlc_MediaPlayerEvents""

This reverts commit e51d033c.

Conflicts:

	include/vlc/libvlc_events.h
	src/control/media_player.c
	src/control/media_player_internal.h
parent fe408e0f
......@@ -71,6 +71,10 @@ enum libvlc_event_e {
libvlc_MediaPlayerTitleChanged,
libvlc_MediaPlayerSnapshotTaken,
libvlc_MediaPlayerLengthChanged,
libvlc_MediaPlayerMouseMoved,
libvlc_MediaPlayerMouseButton,
libvlc_MediaPlayerMouseClick,
libvlc_MediaPlayerMouseObject,
libvlc_MediaListItemAdded=0x200,
libvlc_MediaListWillAddItem,
......@@ -211,6 +215,33 @@ typedef struct libvlc_event_t
{
libvlc_media_t * new_media;
} media_player_media_changed;
/* Mouse events */
struct
{
int x;
int y;
} media_player_mouse_moved;
struct
{
int mb_left;
int mb_center;
int mb_right;
int mb_wheel_up;
int mb_wheel_down;
} media_player_mouse_button;
struct
{
int clicked;
} media_player_mouse_clicked;
struct
{
int moved;
} media_player_mouse_object;
} u; /**< Type-dependent event description */
} libvlc_event_t;
......
/*****************************************************************************
* media_player.c: Libvlc API Media Instance management functions
*****************************************************************************
* Copyright (C) 2005-2009 the VideoLAN team
* Copyright (C) 2005-2010 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
......@@ -58,6 +58,21 @@ static int
snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
/* Mouse events */
static int
mouse_moved( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int
mouse_button( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int
mouse_clicked( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int
mouse_object( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
/* */
static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi );
/*
......@@ -156,6 +171,51 @@ input_thread_t *libvlc_get_input_thread( libvlc_media_player_t *p_mi )
return p_input_thread;
}
/*
* Get vout thread from current input
*
* Object lock is NOT held.
*/
static vout_thread_t *get_vout_thread( libvlc_media_player_t *p_mi )
{
vout_thread_t *p_vout;
p_vout = input_GetVout( p_mi->input.p_thread );
if( p_vout )
{
var_AddCallback( p_vout, "mouse-button-down", mouse_button, p_mi );
var_AddCallback( p_vout, "mouse-moved", mouse_moved, p_mi );
var_AddCallback( p_vout, "mouse-clicked", mouse_clicked, p_mi );
var_AddCallback( p_vout, "mouse-object", mouse_object, p_mi );
}
return p_vout;
}
/*
* Release the associated vout thread.
*
* Object lock is NOT held.
*/
static void release_vout_thread( libvlc_media_player_t *p_mi )
{
vout_thread_t *p_vout;
assert( p_mi );
if( !p_mi->input.p_vout )
return;
p_vout = p_mi->input.p_vout;
var_DelCallback( p_vout, "mouse-button-down", mouse_button, p_mi );
var_DelCallback( p_vout, "mouse-moved", mouse_moved, p_mi );
var_DelCallback( p_vout, "mouse-clicked", mouse_clicked, p_mi );
var_DelCallback( p_vout, "mouse-object", mouse_object, p_mi );
vlc_object_release( p_vout );
p_mi->input.p_vout = NULL;
}
/*
* Set the internal state of the media_player. (media player Internal)
*
......@@ -303,9 +363,17 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
from_mtime(var_GetTime( p_input, "length" ));
libvlc_event_send( p_mi->p_event_manager, &event );
}
else if( newval.i_int == INPUT_EVENT_VOUT )
{
lock_input( p_mi );
/* release old vout */
release_vout_thread( p_mi );
/* remember new vout */
p_mi->input.p_vout = get_vout_thread( p_mi );
unlock_input( p_mi );
}
return VLC_SUCCESS;
}
/**************************************************************************
......@@ -327,6 +395,77 @@ static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
return VLC_SUCCESS;
}
/**************************************************************************
* Mouse Events.
*************************************************************************/
static int
mouse_moved( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this);
libvlc_media_player_t *mp = p_data;
libvlc_event_t event;
event.type = libvlc_MediaPlayerMouseMoved;
event.u.media_player_mouse_moved.x = newval.coords.x;
event.u.media_player_mouse_moved.y = newval.coords.y;
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
static int
mouse_button( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this);
libvlc_media_player_t *mp = p_data;
libvlc_event_t event;
int pressed = newval.i_int;
event.type = libvlc_MediaPlayerMouseButton;
event.u.media_player_mouse_button.mb_left = (pressed & (1<<MOUSE_BUTTON_LEFT));
event.u.media_player_mouse_button.mb_center = (pressed & (1<<MOUSE_BUTTON_CENTER));
event.u.media_player_mouse_button.mb_right = (pressed & (1<<MOUSE_BUTTON_RIGHT));
event.u.media_player_mouse_button.mb_wheel_up = (pressed & (1<<MOUSE_BUTTON_WHEEL_UP));
event.u.media_player_mouse_button.mb_wheel_down = (pressed & (1<<MOUSE_BUTTON_WHEEL_DOWN));
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
static int
mouse_clicked( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this);
libvlc_media_player_t *mp = p_data;
libvlc_event_t event;
event.type = libvlc_MediaPlayerMouseClick;
event.u.media_player_mouse_clicked.clicked = newval.b_bool ? 1 : 0;
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
static int
mouse_object( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
VLC_UNUSED(psz_cmd); VLC_UNUSED(oldval); VLC_UNUSED(p_this);
libvlc_media_player_t *mp = p_data;
libvlc_event_t event;
event.type = libvlc_MediaPlayerMouseObject;
event.u.media_player_mouse_object.moved = (newval.b_bool ? 1 : 0);
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
static input_thread_t *find_input (vlc_object_t *obj)
{
libvlc_media_player_t *mp = (libvlc_media_player_t *)obj;
......@@ -428,6 +567,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
mp->p_libvlc_instance = instance;
mp->input.p_thread = NULL;
mp->input.p_resource = NULL;
mp->input.p_vout = NULL;
vlc_mutex_init (&mp->input.lock);
mp->i_refcount = 1;
mp->p_event_manager = libvlc_event_manager_new(mp, instance);
......@@ -461,6 +601,12 @@ libvlc_media_player_new( libvlc_instance_t *instance )
register_event(mp, MediaChanged);
/* mouse events */
register_event(mp, MouseMoved);
register_event(mp, MouseButton);
register_event(mp, MouseClick);
register_event(mp, MouseObject);
/* Attach a var callback to the global object to provide the glue between
* vout_thread that generates the event and media_player that re-emits it
* with its own event manager
......@@ -505,9 +651,14 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
var_DelCallback( p_mi->p_libvlc,
"snapshot-file", snapshot_was_taken, p_mi );
/* Fallback for those who don't use NDEBUG */
if( p_mi->input.p_vout )
release_vout_thread( p_mi );
/* No need for lock_input() because no other threads knows us anymore */
if( p_mi->input.p_thread )
release_input_thread(p_mi, true);
if( p_mi->input.p_resource )
{
input_resource_Delete( p_mi->input.p_resource );
......@@ -569,6 +720,7 @@ void libvlc_media_player_set_media(
/* FIXME I am not sure if it is a user request or on die(eof/error)
* request here */
release_vout_thread( p_mi );
release_input_thread( p_mi,
p_mi->input.p_thread &&
!p_mi->input.p_thread->b_eof &&
......@@ -728,6 +880,7 @@ void libvlc_media_player_stop( libvlc_media_player_t *p_mi )
libvlc_state_t state = libvlc_media_player_get_state( p_mi );
lock_input(p_mi);
release_vout_thread( p_mi );
release_input_thread( p_mi, true ); /* This will stop the input thread */
/* Force to go to stopped state, in case we were in Ended, or Error
......
......@@ -2,7 +2,7 @@
* libvlc_internal.h : Definition of opaque structures for libvlc exported API
* Also contains some internal utility functions
*****************************************************************************
* Copyright (C) 2005-2009 the VideoLAN team
* Copyright (C) 2005-2010 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
......@@ -33,6 +33,7 @@
#include <vlc/libvlc_structures.h>
#include <vlc/libvlc_media.h>
#include <vlc_input.h>
#include <vlc_vout.h>
struct libvlc_media_player_t
{
......@@ -45,6 +46,7 @@ struct libvlc_media_player_t
{
input_thread_t *p_thread;
input_resource_t *p_resource;
vout_thread_t *p_vout;
vlc_mutex_t lock;
} input;
......
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