summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-04-06 19:05:50 +0200
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2018-04-06 19:05:50 +0200
commit87907a9016d1c84618a1a3e344bc7c5403056266 (patch)
tree8e627820f3e21a2adbd66b8f31aba669e1490488 /modules
parenta72f343dd192b02f062b78cc1cb34e0830fb5c5c (diff)
fakevideo: add support for non-threaded
Diffstat (limited to 'modules')
-rw-r--r--modules/fakevideo/fakevideo.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/fakevideo/fakevideo.c b/modules/fakevideo/fakevideo.c
index 946e181..03d0200 100644
--- a/modules/fakevideo/fakevideo.c
+++ b/modules/fakevideo/fakevideo.c
@@ -31,8 +31,13 @@
struct vidsrc_st {
const struct vidsrc *vs; /* inheritance */
struct vidframe *frame;
+#ifdef HAVE_PTHREAD
pthread_t thread;
bool run;
+#else
+ struct tmr tmr;
+ uint64_t ts;
+#endif
int fps;
vidsrc_frame_h *frameh;
void *arg;
@@ -47,6 +52,7 @@ static struct vidsrc *vidsrc;
static struct vidisp *vidisp;
+#ifdef HAVE_PTHREAD
static void *read_thread(void *arg)
{
struct vidsrc_st *st = arg;
@@ -66,16 +72,38 @@ static void *read_thread(void *arg)
return NULL;
}
+#else
+static void tmr_handler(void *arg)
+{
+ struct vidsrc_st *st = arg;
+ const uint64_t now = tmr_jiffies();
+
+ tmr_start(&st->tmr, 4, tmr_handler, st);
+
+ if (!st->ts)
+ st->ts = now;
+
+ if (now >= st->ts) {
+ st->frameh(st->frame, st->arg);
+
+ st->ts += (1000/st->fps);
+ }
+}
+#endif
static void src_destructor(void *arg)
{
struct vidsrc_st *st = arg;
+#ifdef HAVE_PTHREAD
if (st->run) {
st->run = false;
pthread_join(st->thread, NULL);
}
+#else
+ tmr_cancel(&st->tmr);
+#endif
mem_deref(st->frame);
}
@@ -134,12 +162,16 @@ static int src_alloc(struct vidsrc_st **stp, const struct vidsrc *vs,
vidframe_draw_vline(st->frame, x, 0, size->h, r, g, b);
}
+#ifdef HAVE_PTHREAD
st->run = true;
err = pthread_create(&st->thread, NULL, read_thread, st);
if (err) {
st->run = false;
goto out;
}
+#else
+ tmr_start(&st->tmr, 1, tmr_handler, st);
+#endif
out:
if (err)