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
27#include <errno.h>27#include <errno.h>
28#include <signal.h>28#include <signal.h>
29#include <limits.h>29#include <limits.h>
30#include <unistd.h>
31#include "libavformat/avformat.h"30#include "libavformat/avformat.h"
32#include "libavdevice/avdevice.h"31#include "libavdevice/avdevice.h"
33#include "libswscale/swscale.h"32#include "libswscale/swscale.h"
@@ -45,6 +44,7 @@ · 11 unmodified lines
45#include "libavutil/avstring.h"44#include "libavutil/avstring.h"
46#include "libavutil/libm.h"45#include "libavutil/libm.h"
47#include "libavutil/imgutils.h"46#include "libavutil/imgutils.h"
47#include "libavutil/time.h"
48#include "libavformat/os_support.h"48#include "libavformat/os_support.h"
49 49
50# include "libavfilter/avfilter.h"50# include "libavfilter/avfilter.h"
@@ -1876,7 +1876,7 @@ static void rate_emu_sleep(InputStream *ist) · 1825 unmodified lines
1876 int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);1876 int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE);
1877 int64_t now = av_gettime() - ist->start;1877 int64_t now = av_gettime() - ist->start;
1878 if (pts > now)1878 if (pts > now)
1879 usleep(pts - now);1879 av_usleep(pts - now);
1880 }1880 }
1881}1881}
1882 1882
@@ -2793,7 +2793,7 @@ static void *input_thread(void *arg) · 910 unmodified lines
2793 ret = av_read_frame(f->ctx, &pkt);2793 ret = av_read_frame(f->ctx, &pkt);
2794 2794
2795 if (ret == AVERROR(EAGAIN)) {2795 if (ret == AVERROR(EAGAIN)) {
2796 usleep(10000);2796 av_usleep(10000);
2797 ret = 0;2797 ret = 0;
2798 continue;2798 continue;
2799 } else if (ret < 0)2799 } else if (ret < 0)
@@ -2948,7 +2948,7 @@ static int transcode(void) · 148 unmodified lines
2948 if (no_packet_count) {2948 if (no_packet_count) {
2949 no_packet_count = 0;2949 no_packet_count = 0;
2950 memset(no_packet, 0, nb_input_files);2950 memset(no_packet, 0, nb_input_files);
2951 usleep(10000);2951 av_usleep(10000);
2952 continue;2952 continue;
2953 }2953 }
2954 av_log(NULL, AV_LOG_VERBOSE, "No more inputs to read from, finishing.\n");2954 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
31#include "libavutil/dict.h"31#include "libavutil/dict.h"
32#include "libavutil/parseutils.h"32#include "libavutil/parseutils.h"
33#include "libavutil/samplefmt.h"33#include "libavutil/samplefmt.h"
34#include "libavutil/time.h"
34#include "libavformat/avformat.h"35#include "libavformat/avformat.h"
35#include "libavdevice/avdevice.h"36#include "libavdevice/avdevice.h"
36#include "libswscale/swscale.h"37#include "libswscale/swscale.h"
@@ -54,7 +55,6 @@ · 17 unmodified lines
54#undef main /* We don't want SDL to override our main() */55#undef main /* We don't want SDL to override our main() */
55#endif56#endif
56 57
57#include <unistd.h>
58#include <assert.h>58#include <assert.h>
59 59
60const char program_name[] = "avplay";60const char program_name[] = "avplay";
@@ -952,7 +952,7 @@ static int refresh_thread(void *opaque) · 891 unmodified lines
952 is->refresh = 1;952 is->refresh = 1;
953 SDL_PushEvent(&event);953 SDL_PushEvent(&event);
954 }954 }
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 silly955 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
956 }956 }
957 return 0;957 return 0;
958}958}
libavformat/avio.c+2−3
@@ -19,11 +19,10 @@ · 18 unmodified lines
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */20 */
21 21
22#include <unistd.h>
23
24#include "libavutil/avstring.h"22#include "libavutil/avstring.h"
25#include "libavutil/dict.h"23#include "libavutil/dict.h"
26#include "libavutil/opt.h"24#include "libavutil/opt.h"
25#include "libavutil/time.h"
27#include "os_support.h"26#include "os_support.h"
28#include "avformat.h"27#include "avformat.h"
29#if CONFIG_NETWORK28#if CONFIG_NETWORK
@@ -237,7 +236,7 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int · 207 unmodified lines
237 if (fast_retries)236 if (fast_retries)
238 fast_retries--;237 fast_retries--;
239 else238 else
240 usleep(1000);239 av_usleep(1000);
241 } else if (ret < 1)240 } else if (ret < 1)
242 return ret < 0 ? ret : len;241 return ret < 0 ? ret : len;
243 if (ret)242 if (ret)
libavformat/hls.c+2−2
@@ -30,9 +30,9 @@ · 29 unmodified lines
30#include "libavutil/mathematics.h"30#include "libavutil/mathematics.h"
31#include "libavutil/opt.h"31#include "libavutil/opt.h"
32#include "libavutil/dict.h"32#include "libavutil/dict.h"
33#include "libavutil/time.h"
33#include "avformat.h"34#include "avformat.h"
34#include "internal.h"35#include "internal.h"
35#include <unistd.h>
36#include "avio_internal.h"36#include "avio_internal.h"
37#include "url.h"37#include "url.h"
38 38
@@ -407,7 +407,7 @@ reload: · 368 unmodified lines
407 while (av_gettime() - v->last_load_time < reload_interval) {407 while (av_gettime() - v->last_load_time < reload_interval) {
408 if (ff_check_interrupt(c->interrupt_callback))408 if (ff_check_interrupt(c->interrupt_callback))
409 return AVERROR_EXIT;409 return AVERROR_EXIT;
410 usleep(100*1000);410 av_usleep(100*1000);
411 }411 }
412 /* Enough time has elapsed since the last reload */412 /* Enough time has elapsed since the last reload */
413 goto reload;413 goto reload;
libavformat/hlsproto.c+2−2
@@ -26,11 +26,11 @@ · 25 unmodified lines
26 */26 */
27 27
28#include "libavutil/avstring.h"28#include "libavutil/avstring.h"
29#include "libavutil/time.h"
29#include "avformat.h"30#include "avformat.h"
30#include "internal.h"31#include "internal.h"
31#include "url.h"32#include "url.h"
32#include "version.h"33#include "version.h"
33#include <unistd.h>
34 34
35/*35/*
36 * An apple http stream consists of a playlist with media segment files,36 * An apple http stream consists of a playlist with media segment files,
@@ -308,7 +308,7 @@ retry: · 271 unmodified lines
308 while (av_gettime() - s->last_load_time < reload_interval) {308 while (av_gettime() - s->last_load_time < reload_interval) {
309 if (ff_check_interrupt(&h->interrupt_callback))309 if (ff_check_interrupt(&h->interrupt_callback))
310 return AVERROR_EXIT;310 return AVERROR_EXIT;
311 usleep(100*1000);311 av_usleep(100*1000);
312 }312 }
313 goto retry;313 goto retry;
314 }314 }
libavformat/rtmphttp.c+2−3
@@ -24,11 +24,10 @@ · 23 unmodified lines
24 * RTMP HTTP protocol24 * RTMP HTTP protocol
25 */25 */
26 26
27#include <unistd.h>
28
29#include "libavutil/avstring.h"27#include "libavutil/avstring.h"
30#include "libavutil/intfloat.h"28#include "libavutil/intfloat.h"
31#include "libavutil/opt.h"29#include "libavutil/opt.h"
30#include "libavutil/time.h"
32#include "internal.h"31#include "internal.h"
33#include "http.h"32#include "http.h"
34 33
@@ -126,7 +125,7 @@ static int rtmp_http_read(URLContext *h, uint8_t *buf, int size) · 91 unmodified lines
126 if (rt->nb_bytes_read == 0) {125 if (rt->nb_bytes_read == 0) {
127 /* Wait 50ms before retrying to read a server reply in126 /* Wait 50ms before retrying to read a server reply in
128 * order to reduce the number of idle requets. */127 * order to reduce the number of idle requets. */
129 usleep(50000);128 av_usleep(50000);
130 }129 }
131 130
132 if ((ret = rtmp_http_write(h, "", 1)) < 0)131 if ((ret = rtmp_http_write(h, "", 1)) < 0)
tools/aviocat.c+2−2
@@ -20,8 +20,8 @@ · 19 unmodified lines
20 20
21#include <stdio.h>21#include <stdio.h>
22#include <stdlib.h>22#include <stdlib.h>
23#include <unistd.h>
24 23
24#include "libavutil/time.h"
25#include "libavformat/avformat.h"25#include "libavformat/avformat.h"
26 26
27static int usage(const char *argv0, int ret)27static int usage(const char *argv0, int ret)
@@ -82,7 +82,7 @@ int main(int argc, char **argv) · 54 unmodified lines
82 if (bps) {82 if (bps) {
83 avio_flush(output);83 avio_flush(output);
84 while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos)84 while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos)
85 usleep(50 * 1000);85 av_usleep(50 * 1000);
86 }86 }
87 }87 }
88 88
tools/pktdumper.c+2−1
@@ -25,6 +25,7 @@ · 24 unmodified lines
25#include <string.h>25#include <string.h>
26#include <unistd.h>26#include <unistd.h>
27 27
28#include "libavutil/time.h"
28#include "libavformat/avformat.h"29#include "libavformat/avformat.h"
29 30
30#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"31#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin"
@@ -122,7 +123,7 @@ int main(int argc, char **argv) · 91 unmodified lines
122 avformat_close_input(&fctx);123 avformat_close_input(&fctx);
123 124
124 while (donotquit)125 while (donotquit)
125 usleep(60 * 1000000);126 av_usleep(60 * 1000000);
126 127
127 return 0;128 return 0;
128}129}

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