History

Replace usleep() calls with av_usleep()

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

Mans Rullgard committed 14 years ago

Commit 896bb0d1 parent d3d3a328 files · +18 −19Browse files

Unified · Split

8 files
  1. avconv.c +4 −4
  2. avplay.c +2 −2
  3. libavformat/avio.c +2 −3
  4. libavformat/hls.c +2 −2
  5. libavformat/hlsproto.c +2 −2
  6. libavformat/rtmphttp.c +2 −3
  7. tools/aviocat.c +2 −2
  8. tools/pktdumper.c +2 −1
avconv.c+4−4
@@ -27,7 +27,6 @@ · 26 unmodified lines
2727 #include <errno.h>
2828 #include <signal.h>
2929 #include <limits.h>
30−#include <unistd.h>
3130 #include "libavformat/avformat.h"
3231 #include "libavdevice/avdevice.h"
3332 #include "libswscale/swscale.h"
@@ -45,6 +44,7 @@ · 11 unmodified lines
4544 #include "libavutil/avstring.h"
4645 #include "libavutil/libm.h"
4746 #include "libavutil/imgutils.h"
47+#include "libavutil/time.h"
4848 #include "libavformat/os_support.h"
4949
5050 # include "libavfilter/avfilter.h"
@@ -1876,7 +1876,7 @@ static void rate_emu_sleep(InputStream *ist) · 1825 unmodified lines
18761876 int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
18771877 int64_t now = av_gettime() - ist->start;
18781878 if (pts > now)
1879− usleep(pts - now);
1879+ av_usleep(pts - now);
18801880 }
18811881 }
18821882
@@ -2793,7 +2793,7 @@ static void *input_thread(void *arg) · 910 unmodified lines
27932793 ret = av_read_frame(f->ctx, &pkt);
27942794
27952795 if (ret == AVERROR(EAGAIN)) {
2796− usleep(10000);
2796+ av_usleep(10000);
27972797 ret = 0;
27982798 continue;
27992799 } else if (ret < 0)
@@ -2948,7 +2948,7 @@ static int transcode(void) · 148 unmodified lines
29482948 if (no_packet_count) {
29492949 no_packet_count = 0;
29502950 memset(no_packet, 0, nb_input_files);
2951− usleep(10000);
2951+ av_usleep(10000);
29522952 continue;
29532953 }
29542954 av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");
avplay.c+2−2
@@ -31,6 +31,7 @@ · 30 unmodified lines
3131 #include "libavutil/dict.h"
3232 #include "libavutil/parseutils.h"
3333 #include "libavutil/samplefmt.h"
34+#include "libavutil/time.h"
3435 #include "libavformat/avformat.h"
3536 #include "libavdevice/avdevice.h"
3637 #include "libswscale/swscale.h"
@@ -54,7 +55,6 @@ · 17 unmodified lines
5455 #undef main /* We don't want SDL to override our main() */
5556 #endif
5657
57−#include <unistd.h>
5858 #include <assert.h>
5959
6060 const char program_name[] = "avplay";
@@ -952,7 +952,7 @@ static int refresh_thread(void *opaque) · 891 unmodified lines
952952 is->refresh = 1;
953953 SDL_PushEvent(&event);
954954 }
955− 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
955+ 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
956956 }
957957 return 0;
958958 }
libavformat/avio.c+2−3
@@ -19,11 +19,10 @@ · 18 unmodified lines
1919 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2020 */
2121
22−#include <unistd.h>
23−
2422 #include "libavutil/avstring.h"
2523 #include "libavutil/dict.h"
2624 #include "libavutil/opt.h"
25+#include "libavutil/time.h"
2726 #include "os_support.h"
2827 #include "avformat.h"
2928 #if CONFIG_NETWORK
@@ -237,7 +236,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int · 207 unmodified lines
237236 if (fast_retries)
238237 fast_retries--;
239238 else
240− usleep(1000);
239+ av_usleep(1000);
241240 } else if (ret < 1)
242241 return ret < 0 ? ret : len;
243242 if (ret)
libavformat/hls.c+2−2
@@ -30,9 +30,9 @@ · 29 unmodified lines
3030 #include "libavutil/mathematics.h"
3131 #include "libavutil/opt.h"
3232 #include "libavutil/dict.h"
33+#include "libavutil/time.h"
3334 #include "avformat.h"
3435 #include "internal.h"
35−#include <unistd.h>
3636 #include "avio_internal.h"
3737 #include "url.h"
3838
@@ -407,7 +407,7 @@ reload: · 368 unmodified lines
407407 while (av_gettime() - v->last_load_time < reload_interval) {
408408 if (ff_check_interrupt(c->interrupt_callback))
409409 return AVERROR_EXIT;
410− usleep(100*1000);
410+ av_usleep(100*1000);
411411 }
412412 /* Enough time has elapsed since the last reload */
413413 goto reload;
libavformat/hlsproto.c+2−2
@@ -26,11 +26,11 @@ · 25 unmodified lines
2626 */
2727
2828 #include "libavutil/avstring.h"
29+#include "libavutil/time.h"
2930 #include "avformat.h"
3031 #include "internal.h"
3132 #include "url.h"
3233 #include "version.h"
33−#include <unistd.h>
3434
3535 /*
3636 * An apple http stream consists of a playlist with media segment files,
@@ -308,7 +308,7 @@ retry: · 271 unmodified lines
308308 while (av_gettime() - s->last_load_time < reload_interval) {
309309 if (ff_check_interrupt(&h->interrupt_callback))
310310 return AVERROR_EXIT;
311− usleep(100*1000);
311+ av_usleep(100*1000);
312312 }
313313 goto retry;
314314 }
libavformat/rtmphttp.c+2−3
@@ -24,11 +24,10 @@ · 23 unmodified lines
2424 * RTMP HTTP protocol
2525 */
2626
27−#include <unistd.h>
28−
2927 #include "libavutil/avstring.h"
3028 #include "libavutil/intfloat.h"
3129 #include "libavutil/opt.h"
30+#include "libavutil/time.h"
3231 #include "internal.h"
3332 #include "http.h"
3433
@@ -126,7 +125,7 @@ static int rtmp_http_read(URLContext *h, uint8_t *buf, int size) · 91 unmodified lines
126125 if (rt->nb_bytes_read == 0) {
127126 /* Wait 50ms before retrying to read a server reply in
128127 * order to reduce the number of idle requets. */
129− usleep(50000);
128+ av_usleep(50000);
130129 }
131130
132131 if ((ret = rtmp_http_write(h, "", 1)) < 0)
tools/aviocat.c+2−2
@@ -20,8 +20,8 @@ · 19 unmodified lines
2020
2121 #include <stdio.h>
2222 #include <stdlib.h>
23−#include <unistd.h>
2423
24+#include "libavutil/time.h"
2525 #include "libavformat/avformat.h"
2626
2727 static int usage(const char *argv0, int ret)
@@ -82,7 +82,7 @@ int main(int argc, char **argv) · 54 unmodified lines
8282 if (bps) {
8383 avio_flush(output);
8484 while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos)
85− usleep(50 * 1000);
85+ av_usleep(50 * 1000);
8686 }
8787 }
8888
tools/pktdumper.c+2−1
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include <string.h>
2626 #include <unistd.h>
2727
28+#include "libavutil/time.h"
2829 #include "libavformat/avformat.h"
2930
3031 #define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"
@@ -122,7 +123,7 @@ int main(int argc, char **argv) · 91 unmodified lines
122123 avformat_close_input(&fctx);
123124
124125 while (donotquit)
125− usleep(60 * 1000000);
126+ av_usleep(60 * 1000000);
126127
127128 return 0;
128129 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t