move msleep and get_ms to tools, make public
Stefan Schuermans

Stefan Schuermans commited on 2023-08-18 09:57:23
Showing 5 changed files, with 41 additions and 29 deletions.

... ...
@@ -1,5 +1,5 @@
1 1
 # BlinkenLib
2
-# Copyright 2004-2019 Stefan Schuermans <stefan@schuermans.info>
2
+# Copyright 2004-2023 Stefan Schuermans <stefan@schuermans.info>
3 3
 # Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
 # a blinkenarea.org project
5 5
 
... ...
@@ -198,10 +198,10 @@ lib/libBlinkenLib.$(SHLIBEXT).$(VERSION): $(LIB_OBJS) | lib
198 198
 	$(CC) -shared $(LIB_LDFLAGS) -o $@ $+ $(LIB_LDLIBS)
199 199
 
200 200
 lib/libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR): lib/libBlinkenLib.$(SHLIBEXT).$(VERSION)
201
-	ln -s $(notdir $<) $@
201
+	ln -fs $(notdir $<) $@
202 202
 
203 203
 lib/libBlinkenLib.$(SHLIBEXT): lib/libBlinkenLib.$(SHLIBEXT).$(VERSION_MAJOR)
204
-	ln -s $(notdir $<) $@
204
+	ln -fs $(notdir $<) $@
205 205
 
206 206
 build/%.d: tools/%.c | build
207 207
 	$(CC) $(CFLAGS) -MM -MT $(@:.d=.o) -o $@ $<
... ...
@@ -1,5 +1,5 @@
1 1
 /* BlinkenLib
2
-   Copyright 2004-2014 Stefan Schuermans <stefan@schuermans.info>
2
+   Copyright 2004-2023 Stefan Schuermans <stefan@schuermans.info>
3 3
    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
    a blinkenarea.org project */
5 5
 
... ...
@@ -40,24 +40,6 @@ struct sBlinkenMovie {
40 40
   stBlinkenFrame **ppFrames;
41 41
 };
42 42
 
43
-#ifdef WIN32
44
-
45
-static void msleep(unsigned int ms) { Sleep(ms); }
46
-
47
-static unsigned int get_ms() { return GetTickCount(); }
48
-
49
-#else
50
-
51
-static void msleep(unsigned int ms) { usleep(ms * 1000); }
52
-
53
-static unsigned int get_ms() {
54
-  struct timeval tv;
55
-  gettimeofday(&tv, NULL);
56
-  return (unsigned int)(tv.tv_usec / 1000 + tv.tv_sec * 1000);
57
-}
58
-
59
-#endif
60
-
61 43
 stBlinkenMovie *BlinkenMovieNew(int height, int width, int channels,
62 44
                                 int maxval) {
63 45
   stBlinkenMovie *pMovie;
... ...
@@ -1908,7 +1890,7 @@ void BlinkenMovieSend(stBlinkenMovie *pMovie, SOCKET udpSocket,
1908 1890
       while (duration > 0) {
1909 1891
         send(udpSocket, buffer, len, 0);
1910 1892
         dur = maxidle > 0 ? mini(maxidle, duration) : duration;
1911
-        msleep(dur);
1893
+        BlinkenMSleep(dur);
1912 1894
         duration -= dur;
1913 1895
       }
1914 1896
     }
... ...
@@ -1938,7 +1920,7 @@ stBlinkenMovie *BlinkenMovieReceive(SOCKET udpSocket, int timeout,
1938 1920
   pMovie = NULL;
1939 1921
   proto = BlinkenProtoNone;
1940 1922
   pLastFrame = NULL;
1941
-  lastTime = get_ms();
1923
+  lastTime = BlinkenGetMs();
1942 1924
   for (;;) {
1943 1925
     // wait for next frame
1944 1926
     FD_ZERO(&readFds);
... ...
@@ -1986,7 +1968,7 @@ stBlinkenMovie *BlinkenMovieReceive(SOCKET udpSocket, int timeout,
1986 1968
           // append frame to movie
1987 1969
           if (BlinkenMovieAppendFrame(pMovie, pFrame) == 0) {
1988 1970
             // get current time
1989
-            curTime = get_ms();
1971
+            curTime = BlinkenGetMs();
1990 1972
             // set duration of last frame
1991 1973
             if (pLastFrame != NULL)
1992 1974
               BlinkenFrameSetDuration(pLastFrame, curTime - lastTime);
... ...
@@ -2004,7 +1986,7 @@ stBlinkenMovie *BlinkenMovieReceive(SOCKET udpSocket, int timeout,
2004 1986
   }   // for( ; ; )
2005 1987
 
2006 1988
   // get current time
2007
-  curTime = get_ms();
1989
+  curTime = BlinkenGetMs();
2008 1990
   // set duration of last frame
2009 1991
   if (pLastFrame != NULL)
2010 1992
     BlinkenFrameSetDuration(pLastFrame, curTime - lastTime);
... ...
@@ -1,11 +1,19 @@
1 1
 /* BlinkenLib
2
-   Copyright 2004-2014 Stefan Schuermans <stefan@schuermans.info>
2
+   Copyright 2004-2023 Stefan Schuermans <stefan@schuermans.info>
3 3
    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4 4
    a blinkenarea.org project */
5 5
 
6
+#include "Tools.h"
7
+
6 8
 #include <stdlib.h>
7 9
 
8
-#include "Tools.h"
10
+#ifdef WIN32
11
+#include <windows.h>
12
+#include <winsock2.h>
13
+#else
14
+#include <sys/time.h>
15
+#include <unistd.h>
16
+#endif
9 17
 
10 18
 void *BlinkenMalloc1D(int count1, int size) {
11 19
   if (count1 < 1)
... ...
@@ -41,3 +49,21 @@ void **BlinkenMalloc2D(int count1, int count2, int size) {
41 49
   }
42 50
   return ptr;
43 51
 }
52
+
53
+#ifdef WIN32
54
+
55
+void BlinkenMSleep(unsigned int ms) { Sleep(ms); }
56
+
57
+unsigned int BlinkenGetMs(void) { return GetTickCount(); }
58
+
59
+#else
60
+
61
+void BlinkenMSleep(unsigned int ms) { usleep(ms * 1000); }
62
+
63
+unsigned int BlinkenGetMs(void) {
64
+  struct timeval tv;
65
+  gettimeofday(&tv, NULL);
66
+  return (unsigned int)(tv.tv_usec / 1000 + tv.tv_sec * 1000);
67
+}
68
+
69
+#endif
... ...
@@ -26,6 +26,10 @@ void *BlinkenMalloc1D(int count1, int size);
26 26
 
27 27
 void **BlinkenMalloc2D(int count1, int count2, int size);
28 28
 
29
+void BlinkenMSleep(unsigned int ms);
30
+
31
+unsigned int BlinkenGetMs(void);
32
+
29 33
 #ifdef __cplusplus
30 34
 } // extern "C"
31 35
 #endif
... ...
@@ -1,4 +1,4 @@
1 1
 VERSION_MAJOR := 0
2 2
 VERSION_MINOR := 8
3
-VERSION_REVISION := 1
3
+VERSION_REVISION := 2
4 4
 VERSION := $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_REVISION)
5 5