On Fri, May 27, 2011 at 15:27, Diego Biurrun <[email protected]> wrote: > Well, maybe you want to update your patch to address the other > occurrences of usleep and replace them all?
Sounds reasonable. Also updated the change rationale. -- Jindrich Makovicka
From dd438f5fc92c5b8eb14830b1a81aa9f55d4d11f3 Mon Sep 17 00:00:00 2001 From: Jindrich Makovicka <[email protected]> Date: Fri, 27 May 2011 20:59:20 +0200 Subject: [PATCH] replace usleep() with nanosleep() According to usleep() manpage: POSIX.1-2001 declares this function obsolete; use nanosleep(2) instead. POSIX.1-2008 removes the specification of usleep(). Signed-off-by: Jindrich Makovicka <[email protected]> --- ffmpeg.c | 13 ++++++++++--- ffplay.c | 8 +++++++- libavdevice/bktr.c | 7 ++++++- libavformat/applehttp.c | 7 +++++-- libavformat/applehttpproto.c | 5 ++++- libavformat/avio.c | 10 +++++++--- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index f27513d..e944b6b 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -1640,8 +1640,12 @@ static int output_packet(AVInputStream *ist, int ist_index, if (rate_emu) { int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE); int64_t now = av_gettime() - ist->start; - if (pts > now) - usleep(pts - now); + if (pts > now) { + struct timespec ts; + ts.tv_sec = (pts - now) / AV_TIME_BASE; + ts.tv_nsec = ((pts - now) % AV_TIME_BASE) * 1000; + nanosleep(&ts, NULL); + } } /* if output time reached then transcode raw format, encode packets and output them */ @@ -2532,9 +2536,12 @@ static int transcode(AVFormatContext **output_files, /* if none, if is finished */ if (file_index < 0) { if(no_packet_count){ + struct timespec ts; no_packet_count=0; memset(no_packet, 0, sizeof(no_packet)); - usleep(10000); + ts.tv_sec = 0; + ts.tv_nsec = 10000000; + nanosleep(&ts, NULL); continue; } break; diff --git a/ffplay.c b/ffplay.c index 3bcab54..2027f8c 100644 --- a/ffplay.c +++ b/ffplay.c @@ -939,13 +939,19 @@ static int refresh_thread(void *opaque) VideoState *is= opaque; while(!is->abort_request){ SDL_Event event; + int sleep_ms; + struct timespec ts; event.type = FF_REFRESH_EVENT; event.user.data1 = opaque; if(!is->refresh){ 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 + sleep_ms = is->audio_st && is->show_audio ? rdftspeed : 5; + ts.tv_sec = sleep_ms / 1000; + //FIXME ideally we should wait the correct time but SDLs event passing is so slow it would be silly + ts.tv_nsec = (sleep_ms % 1000) * 1000000; + nanosleep(&ts, NULL); } return 0; } diff --git a/libavdevice/bktr.c b/libavdevice/bktr.c index e8ff557..44b09f1 100644 --- a/libavdevice/bktr.c +++ b/libavdevice/bktr.c @@ -41,6 +41,7 @@ # include <dev/ic/bt8xx.h> #endif #include <unistd.h> +#include <time.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/mman.h> @@ -216,7 +217,11 @@ static void bktr_getframe(uint64_t per_frame) curtime = av_gettime(); if (!last_frame_time || ((last_frame_time + per_frame) > curtime)) { - if (!usleep(last_frame_time + per_frame + per_frame / 8 - curtime)) { + uint64_t sleeptime = last_frame_time + per_frame + per_frame / 8 - curtime; + struct timespec ts; + ts.tv_sec = sleeptime / AV_TIME_BASE; + ts.tv_nsec = (sleeptime % AV_TIME_BASE) * 1000; + if (!nanosleep(&ts, NULL)) { if (!nsignals) av_log(NULL, AV_LOG_INFO, "SLEPT NO signals - %d microseconds late\n", diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c index e3b1500..be58fbf 100644 --- a/libavformat/applehttp.c +++ b/libavformat/applehttp.c @@ -30,7 +30,7 @@ #include "libavutil/opt.h" #include "avformat.h" #include "internal.h" -#include <unistd.h> +#include <time.h> #include "avio_internal.h" #include "url.h" @@ -386,9 +386,12 @@ reload: return AVERROR_EOF; while (av_gettime() - v->last_load_time < v->target_duration*1000000) { + struct timespec ts; if (url_interrupt_cb()) return AVERROR_EXIT; - usleep(100*1000); + ts.tv_sec = 0; + ts.tv_nsec = 100 * 1000000; + nanosleep(&ts, NULL); } /* Enough time has elapsed since the last reload */ goto reload; diff --git a/libavformat/applehttpproto.c b/libavformat/applehttpproto.c index 85f3cfc..1c546a9 100644 --- a/libavformat/applehttpproto.c +++ b/libavformat/applehttpproto.c @@ -266,9 +266,12 @@ retry: if (s->finished) return AVERROR_EOF; while (av_gettime() - s->last_load_time < s->target_duration*1000000) { + struct timespec ts; if (url_interrupt_cb()) return AVERROR_EXIT; - usleep(100*1000); + ts.tv_sec = 0; + ts.tv_nsec = 100 * 1000000; + nanosleep(&ts, NULL); } goto retry; } diff --git a/libavformat/avio.c b/libavformat/avio.c index ac15407..2be9a46 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <unistd.h> +#include <time.h> #include "libavutil/avstring.h" #include "libavutil/opt.h" @@ -277,8 +277,12 @@ static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int ret = 0; if (fast_retries) fast_retries--; - else - usleep(1000); + else { + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + nanosleep(&ts, NULL); + } } else if (ret < 1) return ret < 0 ? ret : len; if (ret) -- 1.7.5.1
_______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
