[FFmpeg-cvslog] Replace usleep() calls with av_usleep()

Mans Rullgard git at videolan.org
Fri Jun 22 22:36:34 CEST 2012


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Thu Jun 21 20:31:44 2012 +0100| [896bb0d742a513b1bb5b9a770dbffd2cd436bed6] | committer: Mans Rullgard

Replace usleep() calls with av_usleep()

This reduces the dependency on unistd.h which is not available
on all systems.

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=896bb0d742a513b1bb5b9a770dbffd2cd436bed6
---

 avconv.c               |    8 ++++----
 avplay.c               |    4 ++--
 libavformat/avio.c     |    5 ++---
 libavformat/hls.c      |    4 ++--
 libavformat/hlsproto.c |    4 ++--
 libavformat/rtmphttp.c |    5 ++---
 tools/aviocat.c        |    4 ++--
 tools/pktdumper.c      |    3 ++-
 8 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/avconv.c b/avconv.c
index 7abf10d..bc6a8fb 100644
--- a/avconv.c
+++ b/avconv.c
@@ -27,7 +27,6 @@
 #include <errno.h>
 #include <signal.h>
 #include <limits.h>
-#include <unistd.h>
 #include "libavformat/avformat.h"
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
@@ -45,6 +44,7 @@
 #include "libavutil/avstring.h"
 #include "libavutil/libm.h"
 #include "libavutil/imgutils.h"
+#include "libavutil/time.h"
 #include "libavformat/os_support.h"
 
 # include "libavfilter/avfilter.h"
@@ -1876,7 +1876,7 @@ static void rate_emu_sleep(InputStream *ist)
         int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
         int64_t now = av_gettime() - ist->start;
         if (pts > now)
-            usleep(pts - now);
+            av_usleep(pts - now);
     }
 }
 
@@ -2793,7 +2793,7 @@ static void *input_thread(void *arg)
         ret = av_read_frame(f->ctx, &pkt);
 
         if (ret == AVERROR(EAGAIN)) {
-            usleep(10000);
+            av_usleep(10000);
             ret = 0;
             continue;
         } else if (ret < 0)
@@ -2948,7 +2948,7 @@ static int transcode(void)
             if (no_packet_count) {
                 no_packet_count = 0;
                 memset(no_packet, 0, nb_input_files);
-                usleep(10000);
+                av_usleep(10000);
                 continue;
             }
             av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");
diff --git a/avplay.c b/avplay.c
index e9389ff..6acb6c1 100644
--- a/avplay.c
+++ b/avplay.c
@@ -31,6 +31,7 @@
 #include "libavutil/dict.h"
 #include "libavutil/parseutils.h"
 #include "libavutil/samplefmt.h"
+#include "libavutil/time.h"
 #include "libavformat/avformat.h"
 #include "libavdevice/avdevice.h"
 #include "libswscale/swscale.h"
@@ -54,7 +55,6 @@
 #undef main /* We don't want SDL to override our main() */
 #endif
 
-#include <unistd.h>
 #include <assert.h>
 
 const char program_name[] = "avplay";
@@ -952,7 +952,7 @@ static int refresh_thread(void *opaque)
             is->refresh = 1;
             SDL_PushEvent(&event);
         }
-        usleep(is->audio_st && is->show_audio ? rdftspeed * 1000 : 5000); // FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly
+        av_usleep(is->audio_st && is->show_audio ? rdftspeed * 1000 : 5000); // FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly
     }
     return 0;
 }
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 371500e..5acaf30 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -19,11 +19,10 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <unistd.h>
-
 #include "libavutil/avstring.h"
 #include "libavutil/dict.h"
 #include "libavutil/opt.h"
+#include "libavutil/time.h"
 #include "os_support.h"
 #include "avformat.h"
 #if CONFIG_NETWORK
@@ -237,7 +236,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int
             if (fast_retries)
                 fast_retries--;
             else
-                usleep(1000);
+                av_usleep(1000);
         } else if (ret < 1)
             return ret < 0 ? ret : len;
         if (ret)
diff --git a/libavformat/hls.c b/libavformat/hls.c
index e876735..253463e 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -30,9 +30,9 @@
 #include "libavutil/mathematics.h"
 #include "libavutil/opt.h"
 #include "libavutil/dict.h"
+#include "libavutil/time.h"
 #include "avformat.h"
 #include "internal.h"
-#include <unistd.h>
 #include "avio_internal.h"
 #include "url.h"
 
@@ -407,7 +407,7 @@ reload:
             while (av_gettime() - v->last_load_time < reload_interval) {
                 if (ff_check_interrupt(c->interrupt_callback))
                     return AVERROR_EXIT;
-                usleep(100*1000);
+                av_usleep(100*1000);
             }
             /* Enough time has elapsed since the last reload */
             goto reload;
diff --git a/libavformat/hlsproto.c b/libavformat/hlsproto.c
index 044b7ff..179bdf1 100644
--- a/libavformat/hlsproto.c
+++ b/libavformat/hlsproto.c
@@ -26,11 +26,11 @@
  */
 
 #include "libavutil/avstring.h"
+#include "libavutil/time.h"
 #include "avformat.h"
 #include "internal.h"
 #include "url.h"
 #include "version.h"
-#include <unistd.h>
 
 /*
  * An apple http stream consists of a playlist with media segment files,
@@ -308,7 +308,7 @@ retry:
         while (av_gettime() - s->last_load_time < reload_interval) {
             if (ff_check_interrupt(&h->interrupt_callback))
                 return AVERROR_EXIT;
-            usleep(100*1000);
+            av_usleep(100*1000);
         }
         goto retry;
     }
diff --git a/libavformat/rtmphttp.c b/libavformat/rtmphttp.c
index 544b493..499341a 100644
--- a/libavformat/rtmphttp.c
+++ b/libavformat/rtmphttp.c
@@ -24,11 +24,10 @@
  * RTMP HTTP protocol
  */
 
-#include <unistd.h>
-
 #include "libavutil/avstring.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/opt.h"
+#include "libavutil/time.h"
 #include "internal.h"
 #include "http.h"
 
@@ -126,7 +125,7 @@ static int rtmp_http_read(URLContext *h, uint8_t *buf, int size)
                 if (rt->nb_bytes_read == 0) {
                     /* Wait 50ms before retrying to read a server reply in
                      * order to reduce the number of idle requets. */
-                    usleep(50000);
+                    av_usleep(50000);
                 }
 
                 if ((ret = rtmp_http_write(h, "", 1)) < 0)
diff --git a/tools/aviocat.c b/tools/aviocat.c
index f5da526..52a96bd 100644
--- a/tools/aviocat.c
+++ b/tools/aviocat.c
@@ -20,8 +20,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 
+#include "libavutil/time.h"
 #include "libavformat/avformat.h"
 
 static int usage(const char *argv0, int ret)
@@ -82,7 +82,7 @@ int main(int argc, char **argv)
         if (bps) {
             avio_flush(output);
             while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos)
-                usleep(50 * 1000);
+                av_usleep(50 * 1000);
         }
     }
 
diff --git a/tools/pktdumper.c b/tools/pktdumper.c
index c3a3a21..d23cd96 100644
--- a/tools/pktdumper.c
+++ b/tools/pktdumper.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "libavutil/time.h"
 #include "libavformat/avformat.h"
 
 #define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"
@@ -122,7 +123,7 @@ int main(int argc, char **argv)
     avformat_close_input(&fctx);
 
     while (donotquit)
-        usleep(60 * 1000000);
+        av_usleep(60 * 1000000);
 
     return 0;
 }



More information about the ffmpeg-cvslog mailing list