[vlc-devel] [PATCH] libvlc_MediaPlayerSnapshotTaken Event creation
basos g
noxelia at gmail.com
Thu Dec 11 15:20:59 CET 2008
It is emmited whenever a snapshot is taken by any means
(gui, libvlc, button ) and also passes the full path of
the new image as event data.
---
include/vlc/libvlc_events.h | 7 +++++++
src/control/event.c | 1 +
src/control/media_player.c | 35 +++++++++++++++++++++++++++++++++++
src/video_output/vout_intf.c | 8 ++++++++
4 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 1aa0f2f..4c9c1d9 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -66,6 +66,7 @@ typedef enum libvlc_event_type_t {
libvlc_MediaPlayerPositionChanged,
libvlc_MediaPlayerSeekableChanged,
libvlc_MediaPlayerPausableChanged,
+ libvlc_MediaPlayerSnapshotTaken,
libvlc_MediaListItemAdded,
libvlc_MediaListWillAddItem,
@@ -197,6 +198,12 @@ typedef struct libvlc_event_t
void * unused;
} media_media_discoverer_ended;
+ /* snapshot taken */
+ struct
+ {
+ char* psz_filename ;
+ } media_player_snapshot_taken ;
+
} u;
} libvlc_event_t;
diff --git a/src/control/event.c b/src/control/event.c
index a98f23c..8cd73cb 100644
--- a/src/control/event.c
+++ b/src/control/event.c
@@ -252,6 +252,7 @@ static const char event_type_to_name[][35] =
EVENT(libvlc_MediaPlayerPositionChanged),
EVENT(libvlc_MediaPlayerSeekableChanged),
EVENT(libvlc_MediaPlayerPausableChanged),
+ EVENT(libvlc_MediaPlayerSnapshotTaken),
EVENT(libvlc_MediaListItemAdded),
EVENT(libvlc_MediaListWillAddItem),
diff --git a/src/control/media_player.c b/src/control/media_player.c
index 0928900..92efba9 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -49,6 +49,9 @@ input_time_changed( vlc_object_t * p_this, char
const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
void * p_userdata );
+static int SnapshotTakenCallback( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data );
+
static const libvlc_state_t vlc_to_libvlc_state_array[] =
{
[INIT_S] = libvlc_NothingSpecial,
@@ -375,6 +378,16 @@ libvlc_media_player_new( libvlc_instance_t *
p_libvlc_instance,
libvlc_event_manager_register_event_type( p_mi->p_event_manager,
libvlc_MediaPlayerPausableChanged, p_e );
+ /* Snapshot initialization */
+ libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+ libvlc_MediaPlayerSnapshotTaken, p_e );
+ /* 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
+ */
+ var_Create( p_libvlc_instance->p_libvlc_int, "vout-snapshottaken",
VLC_VAR_STRING | VLC_VAR_ISCOMMAND );
+ var_AddCallback( p_libvlc_instance->p_libvlc_int,
"vout-snapshottaken", SnapshotTakenCallback, p_mi );
+
return p_mi;
}
@@ -581,6 +594,28 @@ libvlc_media_player_event_manager(
}
/**************************************************************************
+ * Trigger a snapshot Taken Event
+ *************************************************************************/
+static int SnapshotTakenCallback( 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* p_mi = (libvlc_media_player_t*) p_data ;
+ libvlc_event_t event ;
+ event.type = libvlc_MediaPlayerSnapshotTaken ;
+ event.u.media_player_snapshot_taken.psz_filename = newval.psz_string ;
+ /* Snapshot psz data is a vlc_variable owned by libvlc object .
+ Its memmory management is taken care by the obj*/
+ msg_Dbg( p_this, "about to emit libvlc_snapshot_taken.make
psz_str=0x%x (%s)",
+ event.u.media_player_snapshot_taken.psz_filename
,event.u.media_player_snapshot_taken.psz_filename );
+ libvlc_event_send( p_mi->p_event_manager, &event );
+
+ return VLC_SUCCESS;
+}
+
+/**************************************************************************
* Play
**************************************************************************/
void libvlc_media_player_play( libvlc_media_player_t *p_mi,
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 73993f7..d9b39d2 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -795,6 +795,14 @@ int vout_Snapshot( vout_thread_t *p_vout,
picture_t *p_pic )
msg_Dbg( p_vout, "snapshot taken (%s)", psz_filename );
vout_OSDMessage( VLC_OBJECT( p_vout ), DEFAULT_CHAN,
"%s", psz_filename );
+
+ /* Generate a media player event - Right now just trigger a global libvlc var
+ CHECK: Could not find a more local object. The goal is to communicate
+ vout_thread with libvlc_media_player or its input_thread*/
+ val.psz_string = psz_filename ;
+
+ var_Set( p_vout->p_libvlc, "vout-snapshottaken", val );
+ /* var_Set duplicates data for transport so we can free*/
free( psz_filename );
/* */
--
1.5.6.5
More information about the vlc-devel
mailing list