Commit 041b6f0f authored by Jean-Paul Saman's avatar Jean-Paul Saman

libvlc: activex: logo filter: add mouse grab and release event

The mouse-release event signals that the video-filter detected a release on the object. This is needed,
because it is not possible to detect release from within JavaScript reliably and have the filter (eg: logo)
update its objects position during the dragging.
parent a1395fa1
......@@ -71,6 +71,8 @@ enum libvlc_event_e {
libvlc_MediaPlayerTitleChanged,
libvlc_MediaPlayerSnapshotTaken,
libvlc_MediaPlayerLengthChanged,
libvlc_MediaPlayerMouseGrab,
libvlc_MediaPlayerMouseRelease,
libvlc_MediaListItemAdded=0x200,
libvlc_MediaListWillAddItem,
......@@ -211,6 +213,20 @@ typedef struct libvlc_event_t
{
libvlc_media_t * new_media;
} media_player_media_changed;
/* Mouse events */
struct
{
int x;
int y;
} media_player_mouse_grab;
struct
{
int x;
int y;
} media_player_mouse_release;
} u; /**< Type-dependent event description */
} libvlc_event_t;
......
/*****************************************************************************
* logo.c : logo video plugin for vlc
*****************************************************************************
* Copyright (C) 2003-2006 the VideoLAN team
* Copyright (C) 2003-2010 the VideoLAN team
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
......@@ -153,6 +153,7 @@ typedef struct
struct filter_sys_t
{
filter_t *p_blend;
vout_thread_t *p_vout;
vlc_mutex_t lock;
......@@ -250,6 +251,8 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub )
}
}
p_sys->p_vout = vlc_object_find( p_filter, VLC_OBJECT_VOUT, FIND_ANYWHERE );
/* */
config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
p_filter->p_cfg );
......@@ -317,6 +320,9 @@ static void Close( vlc_object_t *p_this )
var_DelCallback( p_filter, ppsz_filter_callbacks[i],
LogoCallback, p_sys );
if( p_sys->p_vout )
vlc_object_release( p_sys->p_vout );
if( p_sys->p_blend )
filter_DeleteBlend( p_sys->p_blend );
......@@ -534,13 +540,15 @@ static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse,
p_sys->i_pos_y = __MIN( __MAX( p_sys->i_pos_y + i_dy, 0 ),
p_filter->fmt_in.video.i_height - i_logo_h );
/* object under mouse has moved */
var_SetBool( p_filter->p_parent, "mouse-object", true );
}
else if( b_over )
if( p_sys->p_vout )
{
/* object under mouse stoped moving */
var_SetBool( p_filter->p_parent, "mouse-object", false );
/* mouse-object: area of interest */
if( p_sys->b_mouse_grab )
var_SetCoords( p_sys->p_vout, "mouse-grab", p_sys->i_pos_x, p_sys->i_pos_y );
else
var_SetCoords( p_sys->p_vout, "mouse-release", p_sys->i_pos_x, p_sys->i_pos_y );
}
if( p_sys->b_mouse_grab || b_over )
......
......@@ -185,6 +185,9 @@ library AXVLC
const int DISPID_MediaPlayerSeekableChangedEvent = 212;
const int DISPID_MediaPlayerPausableChangedEvent = 213;
const int DISPID_MediaPlayerMouseGrabEvent = 214;
const int DISPID_MediaPlayerMouseReleaseEvent = 215;
[
uuid(DF48072F-5EF8-434e-9B40-E2F3AE759B5F),
helpstring("Event interface for VLC control"),
......@@ -230,6 +233,11 @@ library AXVLC
void MediaPlayerSeekableChanged([in] VARIANT_BOOL seekable);
[id(DISPID_MediaPlayerPausableChangedEvent), helpstring("Pause setting changed")]
void MediaPlayerPausableChanged([in] VARIANT_BOOL pausable);
[id(DISPID_MediaPlayerMouseGrabEvent), helpstring("Mouse grabs object in video output")]
void MediaPlayerMouseGrab([in] long x, [in] long y);
[id(DISPID_MediaPlayerMouseReleaseEvent), helpstring("Mouse released object in video output")]
void MediaPlayerMouseRelease([in] long x, [in] long y);
};
[
......
......@@ -821,6 +821,10 @@ void __RPC_STUB IVLCControl_put_AutoLoop_Stub(
#define DISPID_MediaPlayerPausableChangedEvent (213)
#define DISPID_MediaPlayerMouseGrabEvent (214)
#define DISPID_MediaPlayerMouseReleaseEvent (215)
/*****************************************************************************
* DVLCEvents dispinterface
*/
......
......@@ -1185,6 +1185,51 @@ static void handle_pausable_changed_event(const libvlc_event_t* event, void *par
}
#undef B
/* mouse events */
void VLCPlugin::fireOnMediaPlayerMouseGrabEvent(long x, long y)
{
DISPPARAMS params;
params.cArgs = 2;
params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
params.rgvarg[1].vt = VT_I4;
params.rgvarg[1].lVal = x;
params.rgvarg[0].vt = VT_I4;
params.rgvarg[0].lVal = y;
params.rgdispidNamedArgs = NULL;
params.cNamedArgs = 0;
vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerMouseGrabEvent, &params);
};
void VLCPlugin::fireOnMediaPlayerMouseReleaseEvent(long x, long y)
{
DISPPARAMS params;
params.cArgs = 2;
params.rgvarg = (VARIANTARG *) CoTaskMemAlloc(sizeof(VARIANTARG) * params.cArgs) ;
memset(params.rgvarg, 0, sizeof(VARIANTARG) * params.cArgs);
params.rgvarg[1].vt = VT_I4;
params.rgvarg[1].lVal = x;
params.rgvarg[0].vt = VT_I4;
params.rgvarg[0].lVal = y;
params.rgdispidNamedArgs = NULL;
params.cNamedArgs = 0;
vlcConnectionPointContainer->fireEvent(DISPID_MediaPlayerMouseReleaseEvent, &params);
};
static void handle_mouse_grab_event(const libvlc_event_t* event, void *param)
{
VLCPlugin *plugin = (VLCPlugin*)param;
plugin->fireOnMediaPlayerMouseGrabEvent(event->u.media_player_mouse_grab.x,
event->u.media_player_mouse_grab.y);
}
static void handle_mouse_release_event(const libvlc_event_t* event, void *param)
{
VLCPlugin *plugin = (VLCPlugin*)param;
plugin->fireOnMediaPlayerMouseReleaseEvent(event->u.media_player_mouse_release.x,
event->u.media_player_mouse_release.y);
}
/* */
bool VLCPlugin::playlist_select( int idx )
......@@ -1277,6 +1322,11 @@ void VLCPlugin::player_register_events()
handle_seekable_changed_event, this);
libvlc_event_attach(eventManager, libvlc_MediaPlayerPausableChanged,
handle_pausable_changed_event, this);
libvlc_event_attach(eventManager, libvlc_MediaPlayerMouseGrab,
handle_mouse_grab_event, this);
libvlc_event_attach(eventManager, libvlc_MediaPlayerMouseRelease,
handle_mouse_release_event, this);
}
}
......@@ -1316,6 +1366,11 @@ void VLCPlugin::player_unregister_events()
handle_seekable_changed_event, this);
libvlc_event_detach(eventManager, libvlc_MediaPlayerPausableChanged,
handle_pausable_changed_event, this);
libvlc_event_detach(eventManager, libvlc_MediaPlayerMouseGrab,
handle_mouse_grab_event, this);
libvlc_event_detach(eventManager, libvlc_MediaPlayerMouseRelease,
handle_mouse_release_event, this);
}
}
......
......@@ -255,6 +255,9 @@ public:
void fireOnMediaPlayerSeekableChangedEvent(VARIANT_BOOL seekable);
void fireOnMediaPlayerPausableChangedEvent(VARIANT_BOOL pausable);
void fireOnMediaPlayerMouseGrabEvent(long x, long y);
void fireOnMediaPlayerMouseReleaseEvent(long x, long y);
// controlling IUnknown interface
LPUNKNOWN pUnkOuter;
......
......@@ -48,6 +48,42 @@ function onVLCPluginReady()
updateVolume(0);
}
function registerVLCEvent(event, handler)
{
var vlc = getVLC("vlc");
if (vlc) {
if (vlc.attachEvent) {
// Microsoft
vlc.attachEvent (event, handler);
} else if (vlc.addEventListener) {
// Mozilla: DOM level 2
vlc.addEventListener (event, handler, false);
} else {
// DOM level 0
eval("vlc.on" + event + " = handler");
}
}
}
function unregisterVLCEvent(event, handler)
{
var vlc = getVLC("vlc");
if (vlc) {
if (vlc.detachEvent) {
// Microsoft
vlc.detachEvent (event, handler);
} else if (vlc.removeEventListener) {
// Mozilla: DOM level 2
vlc.removeEventListener (event, handler, false);
} else {
// DOM level 0
eval("vlc.on" + event + " = null");
}
}
}
//--></SCRIPT>
<BODY onLoad="init();">
......@@ -88,6 +124,7 @@ Insert VideoLAN.VLCPlugin.2
<TR><TD colspan="2">
<TABLE><TR>
<TD valign="top" width="550">
logo object: <SPAN id="objectTextField" style="text-align:center"></SPAN>
<!--
Insert Slider widget
-->
......@@ -191,7 +228,7 @@ Insert Slider widget
<OPTION value=9>Y</OPTION>
</SELECT>
</TD>
</TR>
</TR>
<TR>
<TD>Logo video filter:
<INPUT type=button value="Enable" onClick='getVLC("vlc").video.logo.enable();'>
......@@ -204,10 +241,10 @@ Insert Slider widget
<OPTION value=4>Repeat</OPTION>
<OPTION value=5>Delay</OPTION>
<OPTION value=6>X</OPTION>
<OPTION value=7>Y</OPTION>
<OPTION value=7>Y</OPTION>
</SELECT>
</TD>
</TR>
</TR>
<TR>
<TD>
<INPUT type=button id="telx" value="Teletext off" onClick='doToggleTeletext();'>
......@@ -223,6 +260,34 @@ var rate = 0;
var prevState = 0;
var telxState = false;
function handleMouseGrab(event,moved)
{
var vlc = getVLC("vlc");
if (vlc && vlc.video) {
var newpos = "";
if (vlc.video.logo) {
newpos = "("+ vlc.video.logo.x + "," + vlc.video.logo.y+ ")";
}
if (moved) {
document.getElementById("objectTextField").innerHTML = "yes: " + newpos;
} else {
document.getElementById("objectTextField").innerHTML = "no: " + newpos;
}
}
}
function handleMouseRelease(event,X,Y)
{
var newpos = "";
newpos = "("+ X + "," + Y + ")";
document.getElementById("objectTextField").innerHTML = "released at " + newpos;
}
registerVLCEvent('MediaPlayerMouseGrab', handleMouseGrab);
registerVLCEvent('MediaPlayerMouseRelease', handleMouseRelease);
function doSetSlider()
{
var vlc = getVLC("vlc");
......@@ -665,7 +730,7 @@ function doMarqueeOption(option, value)
vlc.video.marquee.y = val;
}
}
function doLogoOption(option, value)
{
var vlc = getVLC("vlc");
......
......@@ -274,6 +274,8 @@ static const event_name_t event_list[] = {
DEF(MediaPlayerTitleChanged)
DEF(MediaPlayerSnapshotTaken)
DEF(MediaPlayerLengthChanged)
DEF(MediaPlayerMouseGrab)
DEF(MediaPlayerMouseRelease)
DEF(MediaListItemAdded)
DEF(MediaListWillAddItem)
......
/*****************************************************************************
* 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,16 @@ 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_grab( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data );
static int
mouse_released( 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 +166,47 @@ 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-grab", mouse_grab, p_mi );
var_AddCallback( p_vout, "mouse-release", mouse_released, 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-grab", mouse_grab, p_mi );
var_DelCallback( p_vout, "mouse-release", mouse_released, 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 +354,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 +386,41 @@ static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
return VLC_SUCCESS;
}
/**************************************************************************
* Mouse Events.
*************************************************************************/
static int
mouse_grab( 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_MediaPlayerMouseGrab;
event.u.media_player_mouse_grab.x = newval.coords.x;
event.u.media_player_mouse_grab.y = newval.coords.y;
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
static int
mouse_released( 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_MediaPlayerMouseRelease;
event.u.media_player_mouse_release.x = newval.coords.x;
event.u.media_player_mouse_release.y = newval.coords.y;
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 +522,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 +556,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
register_event(mp, MediaChanged);
/* mouse events */
register_event(mp, MouseGrab);
register_event(mp, MouseRelease);
/* 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 +604,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 +673,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 &&
......@@ -729,6 +834,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;
......
......@@ -404,7 +404,8 @@ vout_thread_t * vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
var_Create( p_vout, "mouse-clicked", VLC_VAR_COORDS );
/* Mouse object (area of interest in a video filter) */
var_Create( p_vout, "mouse-object", VLC_VAR_BOOL );
var_Create( p_vout, "mouse-grab", VLC_VAR_COORDS );
var_Create( p_vout, "mouse-release", VLC_VAR_COORDS );
/* Attach the new object now so we can use var inheritance below */
vlc_object_attach( p_vout, p_parent );
......
......@@ -368,7 +368,8 @@ void vout_IntfInit( vout_thread_t *p_vout )
var_Create( p_vout, "mouse-button-down", VLC_VAR_INTEGER );
var_Create( p_vout, "mouse-moved", VLC_VAR_COORDS );
var_Create( p_vout, "mouse-clicked", VLC_VAR_COORDS );
var_Create( p_vout, "mouse-object", VLC_VAR_BOOL );
var_Create( p_vout, "mouse-grab", VLC_VAR_COORDS );
var_Create( p_vout, "mouse-release", VLC_VAR_COORDS );
var_Create( p_vout, "intf-change", VLC_VAR_BOOL );
var_SetBool( p_vout, "intf-change", true );
......
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