Skip to content
Browse files

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@mansr.com>
  • Loading branch information...
1 parent d3d3a32 commit 896bb0d742a513b1bb5b9a770dbffd2cd436bed6 @mansr mansr committed Jun 21, 2012
Showing with 18 additions and 19 deletions.
  1. +4 −4 avconv.c
  2. +2 −2 avplay.c
  3. +2 −3 libavformat/avio.c
  4. +2 −2 libavformat/hls.c
  5. +2 −2 libavformat/hlsproto.c
  6. +2 −3 libavformat/rtmphttp.c
  7. +2 −2 tools/aviocat.c
  8. +2 −1 tools/pktdumper.c
View
8 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");
View
4 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;
}
View
5 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)
View
4 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 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
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;
View
4 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 @@ static int hls_read(URLContext *h, uint8_t *buf, int size)
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;
}
View
5 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)
View
4 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);
}
}
View
3 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;
}

0 comments on commit 896bb0d

Please sign in to comment.
Something went wrong with that request. Please try again.