]> git.sesse.net Git - vlc/commitdiff
libvlc: Fix a bunch of messed up mtime_t to libvlc_time_t.
authorPierre d'Herbemont <pdherbemont@free.fr>
Sat, 16 Jan 2010 15:11:08 +0000 (16:11 +0100)
committerPierre d'Herbemont <pdherbemont@free.fr>
Sat, 16 Jan 2010 17:26:08 +0000 (18:26 +0100)
Apparently libvlc_time_t is millisec, whereas mtime_t is microsecs.
Most event callbacks where carying an incorrect mtime_t value.

src/control/libvlc_internal.h
src/control/media.c
src/control/media_player.c

index 7e784cd70909f882b71646a833db951c3e5543ae..bc545a598e94f6c57688274f38664f079058e035 100644 (file)
@@ -111,4 +111,20 @@ void libvlc_event_attach_async( libvlc_event_manager_t * p_event_manager,
                            libvlc_exception_raise( p_e ); \
                            return 0; }
 
+static inline void clear_if_needed(libvlc_exception_t *e)
+{
+    if (libvlc_exception_raised(e))
+        libvlc_exception_clear(e);
+}
+
+static inline libvlc_time_t from_mtime(mtime_t time)
+{
+    return (time + 500ULL)/ 1000ULL;
+}
+
+static inline mtime_t to_mtime(libvlc_time_t time)
+{
+    return time * 1000ULL;
+}
+
 #endif
index abd19f5646d2babf88c465c4ff48f7ea61d250a1..07c8b081975f05d8cb9fac7a1f53c39c23fcfec1 100644 (file)
@@ -147,8 +147,8 @@ static void input_item_duration_changed( const vlc_event_t *p_event,
 
     /* Construct the event */
     event.type = libvlc_MediaDurationChanged;
-    event.u.media_duration_changed.new_duration = 
-        p_event->u.input_item_duration_changed.new_duration;
+    event.u.media_duration_changed.new_duration =
+        from_mtime(p_event->u.input_item_duration_changed.new_duration);
 
     /* Send the event */
     libvlc_event_send( p_md->p_event_manager, &event );
@@ -597,7 +597,7 @@ libvlc_media_get_duration( libvlc_media_t * p_md, libvlc_exception_t *p_e )
     if (!input_item_IsPreparsed( p_md->p_input_item ))
         return -1;
 
-    return input_item_GetDuration( p_md->p_input_item ) / 1000;
+    return from_mtime(input_item_GetDuration( p_md->p_input_item ));
 }
 
 /**************************************************************************
index 52813e21d43a456fa1ce31fb20d48c1ca4e8897a..3bd4fa6411cb1e76f9ad28002f27f63d3be02072 100644 (file)
@@ -80,12 +80,6 @@ static inline void unlock(libvlc_media_player_t *mp)
     vlc_mutex_unlock(&mp->object_lock);
 }
 
-static inline void clear_if_needed(libvlc_exception_t *e)
-{
-    if (libvlc_exception_raised(e))
-        libvlc_exception_clear(e);
-}
-
 /*
  * Release the associated input thread.
  *
@@ -287,14 +281,14 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
         /* */
         event.type = libvlc_MediaPlayerTimeChanged;
         event.u.media_player_time_changed.new_time =
-                                               var_GetTime( p_input, "time" );
+           from_mtime(var_GetTime( p_input, "time" ));
         libvlc_event_send( p_mi->p_event_manager, &event );
     }
     else if( newval.i_int == INPUT_EVENT_LENGTH )
     {
         event.type = libvlc_MediaPlayerLengthChanged;
         event.u.media_player_length_changed.new_length =
-                                               var_GetTime( p_input, "length" );
+           from_mtime(var_GetTime( p_input, "length" ));
         libvlc_event_send( p_mi->p_event_manager, &event );
     }
 
@@ -803,10 +797,10 @@ libvlc_time_t libvlc_media_player_get_length(
     if( !p_input_thread )
         return -1;
 
-    i_time = var_GetTime( p_input_thread, "length" );
+    i_time = from_mtime(var_GetTime( p_input_thread, "length" ));
     vlc_object_release( p_input_thread );
 
-    return (i_time+500LL)/1000LL;
+    return i_time;
 }
 
 libvlc_time_t libvlc_media_player_get_time(
@@ -820,9 +814,9 @@ libvlc_time_t libvlc_media_player_get_time(
     if( !p_input_thread )
         return -1;
 
-    i_time = var_GetTime( p_input_thread , "time" );
+    i_time = from_mtime(var_GetTime( p_input_thread , "time" ));
     vlc_object_release( p_input_thread );
-    return (i_time+500LL)/1000LL;
+    return i_time;
 }
 
 void libvlc_media_player_set_time(
@@ -836,7 +830,7 @@ void libvlc_media_player_set_time(
     if( !p_input_thread )
         return;
 
-    var_SetTime( p_input_thread, "time", i_time*1000LL );
+    var_SetTime( p_input_thread, "time", to_mtime(i_time) );
     vlc_object_release( p_input_thread );
 }