[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 a7e4b28..7e3bdf2 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 71fa653..c7da998 100644
--- a/libavdevice/linuxfb.c
+++ b/libavdevice/linuxfb.c
@@ -34,6 +34,7 @@
#include <sys/time.h>
#include <sys/mman.h>
#include <time.h>
+#include <semaphore.h>
#include <linux/fb.h>
#include "libavutil/mem.h"
@@ -76,6 +77,7 @@ typedef struct {
int frame_size; ///< size in bytes of a grabbed frame
AVRational time_base; ///< time base
int64_t time_frame; ///< time for the next frame to output (in 1/1000000 units)
+ 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
@@ -153,6 +155,12 @@ av_cold static int linuxfb_read_header(AVFormatContext *avctx, AVFormatParameter
fb->visible_data = fb->data +
(fb_varinfo.xoffset + fb_fixinfo.line_length * fb_varinfo.yoffset) * bytes_per_pixel;
+ 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;
@@ -198,9 +206,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
--5I6of5zJg18YgZEa--
More information about the ffmpeg-devel
mailing list