[vlc-devel] commit: libvlc: Fix a bunch of messed up mtime_t to libvlc_time_t. ( Pierre d'Herbemont )

git version control git at videolan.org
Sat Jan 16 18:26:14 CET 2010


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Sat Jan 16 16:11:08 2010 +0100| [a6b1ff10ee67506615e2b4f608f5fd9694608f92] | committer: Pierre d'Herbemont 

libvlc: Fix a bunch of messed up mtime_t to libvlc_time_t.

Apparently libvlc_time_t is millisec, whereas mtime_t is microsecs.
Most event callbacks where carying an incorrect mtime_t value.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a6b1ff10ee67506615e2b4f608f5fd9694608f92
---

 src/control/libvlc_internal.h |   16 ++++++++++++++++
 src/control/media.c           |    6 +++---
 src/control/media_player.c    |   20 +++++++-------------
 3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/control/libvlc_internal.h b/src/control/libvlc_internal.h
index 7e784cd..bc545a5 100644
--- a/src/control/libvlc_internal.h
+++ b/src/control/libvlc_internal.h
@@ -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
diff --git a/src/control/media.c b/src/control/media.c
index abd19f5..07c8b08 100644
--- a/src/control/media.c
+++ b/src/control/media.c
@@ -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 ));
 }
 
 /**************************************************************************
diff --git a/src/control/media_player.c b/src/control/media_player.c
index 52813e2..3bd4fa6 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -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 );
 }
 




More information about the vlc-devel mailing list