[PATCH] Use sem_timedwait() in place of nanosleep().

Stefano Sabatini stefano.sabatini-lala
Fri Jan 28 15:19:34 CET 2011


---
 configure             |    2 +-
 libavdevice/linuxfb.c |   11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 9f9c2a4..03e7e6e 100755
--- a/configure
+++ b/configure
@@ -1395,7 +1395,7 @@ alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
 alsa_outdev_deps="alsa_asoundlib_h"
 bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
 dv1394_indev_deps="dv1394 dv_demuxer"
-linuxfb_indev_deps="linux_fb_h"
+linuxfb_indev_deps="linux_fb_h pthreads"
 jack_indev_deps="jack_jack_h"
 libdc1394_indev_deps="libdc1394"
 oss_indev_deps_any="soundcard_h sys_soundcard_h"
diff --git a/libavdevice/linuxfb.c b/libavdevice/linuxfb.c
index e174edf..ba5dbc0 100644
--- a/libavdevice/linuxfb.c
+++ b/libavdevice/linuxfb.c
@@ -32,6 +32,7 @@
 #include <sys/time.h>
 #include <sys/mman.h>
 #include <time.h>
+#include <semaphore.h>
 #include <linux/fb.h>
 
 #include "libavutil/mem.h"
@@ -74,6 +75,7 @@ typedef struct {
     int frame_size;          ///< size in bytes of a grabbed frame
     AVRational time_base;    ///< time base
     int64_t time_frame;      ///< current time
+    sem_t sem;               ///< semaphore used for waiting the next grab
 
     int frame_linesize;      ///< linesize of the output frame
     int linesize;            ///< linesize of the read framebuffer
@@ -154,6 +156,12 @@ av_cold static int linuxfb_read_header(AVFormatContext *avctx, AVFormatParameter
         goto fail;
     }
 
+    if (sem_init(&fb->sem, 0, 0) == -1) {
+        ret = AVERROR(errno);
+        av_log(avctx, AV_LOG_ERROR, "Error in seminit(): %s\n", strerror(errno));
+        goto fail;
+    }
+
     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
     st->codec->codec_id   = CODEC_ID_RAWVIDEO;
     st->codec->width      = fb->width;
@@ -192,9 +200,10 @@ static int linuxfb_read_packet(AVFormatContext *avctx, AVPacket *pkt)
         }
         if (avctx->flags & AVFMT_FLAG_NONBLOCK)
             return AVERROR(EAGAIN);
+
         ts.tv_sec  =  delay / 1000000;
         ts.tv_nsec = (delay % 1000000) * 1000;
-        nanosleep(&ts, NULL);
+        sem_timedwait(&fb->sem, &ts);
     }
 
     if ((ret = av_new_packet(pkt, fb->frame_size)) < 0)
-- 
1.7.2.3


--45Z9DzgjV8m4Oswq--



More information about the ffmpeg-devel mailing list