]> git.sesse.net Git - vlc/blobdiff - src/control/mediacontrol_util.c
async event handling: Push is now O(1) instead of O(n).
[vlc] / src / control / mediacontrol_util.c
index b651bc77bd64d4a89ca097701af52acaee48b9cb..b34dfa38feb41df6fa3dfabf4fda37a9712b4929 100644 (file)
 # include "config.h"
 #endif
 
+#include "mediacontrol_internal.h"
 #include <vlc/mediacontrol.h>
-#include <vlc/libvlc.h>
 
+#include <vlc_common.h>
 #include <vlc_vout.h>
 #include <vlc_osd.h>
-#include "mediacontrol_internal.h"
 
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
-#include <errno.h>                                                 /* ENOMEM */
 #include <stdio.h>
-#include <ctype.h>
 
 #ifdef HAVE_UNISTD_H
 #    include <unistd.h>
 #endif
-#ifdef HAVE_SYS_TIME_H
-#    include <sys/time.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#    include <sys/types.h>
-#endif
+#include <sys/types.h>
 
 libvlc_time_t private_mediacontrol_unit_convert( libvlc_media_player_t *p_media_player,
                                                  mediacontrol_PositionKey from,
                                                  mediacontrol_PositionKey to,
-                                                 vlc_int64_t value )
+                                                 int64_t value )
 {
     if( to == from )
         return value;
@@ -100,12 +93,12 @@ libvlc_time_t private_mediacontrol_unit_convert( libvlc_media_player_t *p_media_
         {
             /* FIXME */
             /* vlc < 0.8 API */
-/*             return ( vlc_int64_t )( value * 50 * p_input->stream.i_mux_rate / f_fps ); */
+/*             return ( int64_t )( value * 50 * p_input->stream.i_mux_rate / f_fps ); */
             return 0;
         }
 
         if( to == mediacontrol_MediaTime )
-            return( vlc_int64_t )( value * 1000.0 / ( double )f_fps );
+            return( int64_t )( value * 1000.0 / ( double )f_fps );
 
         /* Cannot happen */
         break;
@@ -142,11 +135,11 @@ private_mediacontrol_position2microsecond( libvlc_media_player_t * p_media_playe
         l_time = libvlc_media_player_get_time( p_media_player, &ex );
         /* Ignore exception, we will assume a 0 time value */
 
-        l_pos = 1000 * private_mediacontrol_unit_convert( p_media_player,
-                                                          pos->key,
-                                                          mediacontrol_MediaTime,
-                                                          pos->value );
-        return l_time + l_pos;
+        l_pos = private_mediacontrol_unit_convert( p_media_player,
+                                                   pos->key,
+                                                   mediacontrol_MediaTime,
+                                                   pos->value );
+        return 1000 * ( l_time + l_pos );
         break;
     }
     case mediacontrol_ModuloPosition:
@@ -164,32 +157,18 @@ private_mediacontrol_position2microsecond( libvlc_media_player_t * p_media_playe
         l_time = libvlc_media_player_get_time( p_media_player, &ex );
         /* Ignore exception, we will assume a 0 time value */
 
-        l_pos = ( 1000 * private_mediacontrol_unit_convert( p_media_player,
-                                                            pos->key,
-                                                            mediacontrol_MediaTime,
-                                                            pos->value ) );
+        l_pos = private_mediacontrol_unit_convert( p_media_player,
+                                                   pos->key,
+                                                   mediacontrol_MediaTime,
+                                                   pos->value );
 
-        return ( l_time + l_pos ) % l_length;
+        return 1000 * ( ( l_time + l_pos ) % l_length );
         break;
     }
     }
     return 0;
 }
 
-mediacontrol_RGBPicture*
-private_mediacontrol_RGBPicture__alloc( int datasize )
-{
-    mediacontrol_RGBPicture* pic;
-
-    pic = ( mediacontrol_RGBPicture * )malloc( sizeof( mediacontrol_RGBPicture ) );
-    if( ! pic )
-        return NULL;
-
-    pic->size = datasize;
-    pic->data = ( char* )malloc( datasize * sizeof( char ) );
-    return pic;
-}
-
 void
 mediacontrol_RGBPicture__free( mediacontrol_RGBPicture* pic )
 {
@@ -245,13 +224,25 @@ mediacontrol_exception_free( mediacontrol_Exception *exception )
     free( exception );
 }
 
+/**
+ * Allocates and initializes a mediacontrol_RGBPicture object.
+ *
+ * @param i_width: picture width
+ * @param i_height: picture width
+ * @param i_chroma: picture chroma
+ * @param l_date: picture timestamp
+ * @param p_data: pointer to the data. The data will be directly used, not copied.
+ * @param i_datasize: data size in bytes
+ *
+ * @return the new object, or NULL on error.
+ */
 mediacontrol_RGBPicture*
-private_mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, vlc_int64_t l_date,
-                                char* p_data, int i_datasize )
+private_mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, int64_t l_date,
+                                       char* p_data, int i_datasize )
 {
     mediacontrol_RGBPicture *retval;
 
-    retval = private_mediacontrol_RGBPicture__alloc( i_datasize );
+    retval = ( mediacontrol_RGBPicture * )malloc( sizeof( mediacontrol_RGBPicture ) );
     if( retval )
     {
         retval->width  = i_width;
@@ -259,7 +250,7 @@ private_mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma,
         retval->type   = i_chroma;
         retval->date   = l_date;
         retval->size   = i_datasize;
-        memcpy( retval->data, p_data, i_datasize );
+        retval->data   = p_data;
     }
     return retval;
 }