]> git.sesse.net Git - vlc/blobdiff - src/control/media_player.c
Remove a few fixmes
[vlc] / src / control / media_player.c
index 98ab5ad1a9499bc3ca45003b46b0e17815f1fb4c..4901319f47340e20e9ed7db7b34b4128e4690cbe 100644 (file)
@@ -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 );
 
 /*
@@ -122,27 +137,65 @@ static void release_input_thread( libvlc_media_player_t *p_mi, bool b_input_abor
  *
  * Function will lock the object.
  */
-input_thread_t *libvlc_get_input_thread( libvlc_media_player_t *p_mi,
-                                         libvlc_exception_t *p_e )
+input_thread_t *libvlc_get_input_thread( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread;
 
-    if( !p_mi ) RAISENULL( "Media Instance is NULL" );
+    assert( p_mi );
 
     lock(p_mi);
+    p_input_thread = p_mi->p_input_thread;
+    if( p_input_thread )
+        vlc_object_hold( p_input_thread );
+    else
+        libvlc_printerr( "No active input" );
+    unlock(p_mi);
 
-    if( !p_mi->p_input_thread )
+    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_thread;
+
+    p_vout_thread = input_GetVout( p_mi->p_input_thread );
+    if( p_vout_thread )
     {
-        unlock(p_mi);
-        RAISENULL( "Input is NULL" );
+        var_AddCallback( p_vout_thread, "mouse-button-down", mouse_button, p_mi );
+        var_AddCallback( p_vout_thread, "mouse-moved", mouse_moved, p_mi );
+        var_AddCallback( p_vout_thread, "mouse-clicked", mouse_clicked, p_mi );
+        var_AddCallback( p_vout_thread, "mouse-object", mouse_object, p_mi );
     }
 
-    p_input_thread = p_mi->p_input_thread;
-    vlc_object_hold( p_input_thread );
+    return p_vout_thread;
+}
 
-    unlock(p_mi);
+/*
+ * 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_thread;
 
-    return p_input_thread;
+    if( !p_mi || !p_mi->p_vout_thread )
+        return;
+
+    p_vout_thread = p_mi->p_vout_thread;
+
+    var_DelCallback( p_vout_thread, "mouse-button-down", mouse_button, p_mi );
+    var_DelCallback( p_vout_thread, "mouse-moved", mouse_moved, p_mi );
+    var_DelCallback( p_vout_thread, "mouse-clicked", mouse_clicked, p_mi );
+    var_DelCallback( p_vout_thread, "mouse-object", mouse_object, p_mi );
+
+    vlc_object_release( p_vout_thread );
+    p_mi->p_vout_thread = NULL;
 }
 
 /*
@@ -156,14 +209,16 @@ static void set_state( libvlc_media_player_t *p_mi, libvlc_state_t state,
     if(!b_locked)
         lock(p_mi);
     p_mi->state = state;
+
     libvlc_media_t *media = p_mi->p_md;
     if (media)
         libvlc_media_retain(media);
+
     if(!b_locked)
         unlock(p_mi);
 
-
-    if (media) {
+    if (media)
+    {
         // Also set the state of the corresponding media
         // This is strictly for convenience.
         libvlc_media_set_state(media, state);
@@ -290,6 +345,16 @@ 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( p_mi );
+        /* release old vout */
+        if( p_mi->p_vout_thread )
+            release_vout_thread( p_mi );
+        /* remember new vout */
+        p_mi->p_vout_thread = get_vout_thread( p_mi );
+        unlock( p_mi );
+    }
 
     return VLC_SUCCESS;
 
@@ -314,7 +379,91 @@ 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;
+    input_thread_t *p_input;
+
+    lock (mp);
+    p_input = mp->p_input_thread;
+    if (p_input)
+        vlc_object_hold (p_input);
+    unlock (mp);
+    return p_input;
+}
+
+/* */
 static void libvlc_media_player_destroy( libvlc_media_player_t * );
 
 
@@ -347,7 +496,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     }
     vlc_object_attach (mp, mp->p_libvlc);
 
-    /* Drawable */
+    /* Video */
     var_Create (mp, "drawable-xid", VLC_VAR_INTEGER);
 #ifdef WIN32
     var_Create (mp, "drawable-hwnd", VLC_VAR_ADDRESS);
@@ -357,16 +506,52 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     var_Create (mp, "drawable-nsobject", VLC_VAR_ADDRESS);
 #endif
 
-    /* Drawable input methods */
     var_Create (mp, "keyboard-events", VLC_VAR_BOOL);
     var_SetBool (mp, "keyboard-events", true);
     var_Create (mp, "mouse-events", VLC_VAR_BOOL);
+    var_SetBool (mp, "mouse-events", true);
+
+    var_Create (mp, "fullscreen", VLC_VAR_BOOL);
+    var_Create (mp, "autoscale", VLC_VAR_BOOL);
+    var_SetBool (mp, "autoscale", true);
+    var_Create (mp, "scale", VLC_VAR_FLOAT);
+    var_SetFloat (mp, "scale", 1.);
+    var_Create (mp, "aspect-ratio", VLC_VAR_STRING);
+    var_Create (mp, "crop", VLC_VAR_STRING);
+    var_Create (mp, "deinterlace", VLC_VAR_INTEGER);
+    var_Create (mp, "deinterlace-mode", VLC_VAR_STRING);
+
+    var_Create (mp, "vbi-page", VLC_VAR_INTEGER);
+
+    var_Create (mp, "marq-marquee", VLC_VAR_STRING);
+    var_Create (mp, "marq-color", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-opacity", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-refresh", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-size", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-timeout", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "marq-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+
+    var_Create (mp, "logo-file", VLC_VAR_STRING);
+    var_Create (mp, "logo-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "logo-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "logo-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "logo-repeat", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "logo-opacity", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+    var_Create (mp, "logo-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+
+     /* Audio */
+    var_Create (mp, "aout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+    var_Create (mp, "find-input-callback", VLC_VAR_ADDRESS);
+    var_SetAddress (mp, "find-input-callback", find_input);
 
     mp->p_md = NULL;
     mp->state = libvlc_NothingSpecial;
     mp->p_libvlc_instance = instance;
     mp->p_input_thread = NULL;
     mp->p_input_resource = NULL;
+    mp->p_vout_thread = NULL;
     mp->i_refcount = 1;
     mp->p_event_manager = libvlc_event_manager_new(mp, instance);
     if (unlikely(mp->p_event_manager == NULL))
@@ -399,6 +584,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
@@ -408,6 +599,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
      */
     var_AddCallback(mp->p_libvlc, "snapshot-file", snapshot_was_taken, mp);
 
+    libvlc_retain(instance);
     return mp;
 }
 
@@ -447,7 +639,10 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
     assert(!p_mi->p_input_thread);
 
     /* Fallback for those who don't use NDEBUG */
-    if (p_mi->p_input_thread)
+    if( p_mi->p_vout_thread )
+        release_vout_thread( p_mi );
+
+    if(p_mi->p_input_thread )
         release_input_thread(p_mi, true);
 
     if( p_mi->p_input_resource )
@@ -459,7 +654,10 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
     libvlc_event_manager_release( p_mi->p_event_manager );
     libvlc_media_release( p_mi->p_md );
     vlc_mutex_destroy( &p_mi->object_lock );
+
+    libvlc_instance_t *instance = p_mi->p_libvlc_instance;
     vlc_object_release( p_mi );
+    libvlc_release(instance);
 }
 
 /**************************************************************************
@@ -572,7 +770,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
 {
     input_thread_t * p_input_thread;
 
-    if( (p_input_thread = libvlc_get_input_thread( p_mi, NULL )) )
+    if( (p_input_thread = libvlc_get_input_thread( p_mi )) )
     {
         /* A thread already exists, send it a play message */
         input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
@@ -622,7 +820,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
  **************************************************************************/
 void libvlc_media_player_pause( libvlc_media_player_t *p_mi )
 {
-    input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi, NULL );
+    input_thread_t * p_input_thread = libvlc_get_input_thread( p_mi );
     if( !p_input_thread )
         return;
 
@@ -782,7 +980,7 @@ libvlc_time_t libvlc_media_player_get_length(
     input_thread_t *p_input_thread;
     libvlc_time_t i_time;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -797,7 +995,7 @@ libvlc_time_t libvlc_media_player_get_time( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     libvlc_time_t i_time;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -811,7 +1009,7 @@ void libvlc_media_player_set_time( libvlc_media_player_t *p_mi,
 {
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return;
 
@@ -824,7 +1022,7 @@ void libvlc_media_player_set_position( libvlc_media_player_t *p_mi,
 {
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return;
 
@@ -837,7 +1035,7 @@ float libvlc_media_player_get_position( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     float f_position;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1.0;
 
@@ -852,7 +1050,7 @@ void libvlc_media_player_set_chapter( libvlc_media_player_t *p_mi,
 {
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return;
 
@@ -865,7 +1063,7 @@ int libvlc_media_player_get_chapter( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     int i_chapter;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -880,7 +1078,7 @@ int libvlc_media_player_get_chapter_count( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     vlc_value_t val;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -897,7 +1095,7 @@ int libvlc_media_player_get_chapter_count_for_title(
     input_thread_t *p_input_thread;
     vlc_value_t val;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -919,7 +1117,7 @@ void libvlc_media_player_set_title( libvlc_media_player_t *p_mi,
 {
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return;
 
@@ -938,7 +1136,7 @@ int libvlc_media_player_get_title( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     int i_title;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -953,7 +1151,7 @@ int libvlc_media_player_get_title_count( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     vlc_value_t val;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -967,7 +1165,7 @@ void libvlc_media_player_next_chapter( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return;
 
@@ -982,7 +1180,7 @@ void libvlc_media_player_previous_chapter( libvlc_media_player_t *p_mi )
 {
     input_thread_t *p_input_thread;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return;
 
@@ -995,7 +1193,7 @@ void libvlc_media_player_previous_chapter( libvlc_media_player_t *p_mi )
 
 float libvlc_media_player_get_fps( libvlc_media_player_t *p_mi )
 {
-    input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
     double f_fps = 0.0;
 
     if( p_input_thread )
@@ -1011,7 +1209,7 @@ int libvlc_media_player_will_play( libvlc_media_player_t *p_mi )
 {
     bool b_will_play;
     input_thread_t *p_input_thread =
-                            libvlc_get_input_thread ( p_mi, NULL );
+                            libvlc_get_input_thread ( p_mi );
     if ( !p_input_thread )
         return false;
 
@@ -1026,7 +1224,7 @@ int libvlc_media_player_set_rate( libvlc_media_player_t *p_mi, float rate )
     input_thread_t *p_input_thread;
     bool b_can_rewind;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return -1;
 
@@ -1049,7 +1247,7 @@ float libvlc_media_player_get_rate( libvlc_media_player_t *p_mi )
     float f_rate;
     bool b_can_rewind;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if( !p_input_thread )
         return 0.0;  /* rate < 0 indicates rewind */
 
@@ -1079,7 +1277,7 @@ int libvlc_media_player_is_seekable( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     bool b_seekable;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if ( !p_input_thread )
         return false;
     b_seekable = var_GetBool( p_input_thread, "can-seek" );
@@ -1093,7 +1291,7 @@ libvlc_track_description_t *
         libvlc_get_track_description( libvlc_media_player_t *p_mi,
                                       const char *psz_variable )
 {
-    input_thread_t *p_input = libvlc_get_input_thread( p_mi, NULL );
+    input_thread_t *p_input = libvlc_get_input_thread( p_mi );
     libvlc_track_description_t *p_track_description = NULL,
                                *p_actual, *p_previous;
 
@@ -1125,7 +1323,6 @@ libvlc_track_description_t *
             if ( !p_actual )
             {
                 libvlc_track_description_release( p_track_description );
-                libvlc_exception_raise( p_e );
                 libvlc_printerr( "Not enough memory" );
                 goto end;
             }
@@ -1165,7 +1362,7 @@ int libvlc_media_player_can_pause( libvlc_media_player_t *p_mi )
     input_thread_t *p_input_thread;
     bool b_can_pause;
 
-    p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    p_input_thread = libvlc_get_input_thread ( p_mi );
     if ( !p_input_thread )
         return false;
     b_can_pause = var_GetBool( p_input_thread, "can-pause" );
@@ -1176,7 +1373,7 @@ int libvlc_media_player_can_pause( libvlc_media_player_t *p_mi )
 
 void libvlc_media_player_next_frame( libvlc_media_player_t *p_mi )
 {
-    input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi, NULL );
+    input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
     if( p_input_thread != NULL )
     {
         var_TriggerCallback( p_input_thread, "frame-next" );