diff options
author | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-04-06 19:05:50 +0200 |
---|---|---|
committer | Alfred E. Heggestad <alfred.heggestad@gmail.com> | 2018-04-06 19:05:50 +0200 |
commit | 87907a9016d1c84618a1a3e344bc7c5403056266 (patch) | |
tree | 8e627820f3e21a2adbd66b8f31aba669e1490488 | |
parent | a72f343dd192b02f062b78cc1cb34e0830fb5c5c (diff) |
fakevideo: add support for non-threaded
-rw-r--r-- | mk/modules.mk | 2 | ||||
-rw-r--r-- | modules/fakevideo/fakevideo.c | 32 |
2 files changed, 32 insertions, 2 deletions
diff --git a/mk/modules.mk b/mk/modules.mk index a8256a1..a479e6a 100644 --- a/mk/modules.mk +++ b/mk/modules.mk @@ -281,10 +281,8 @@ MODULES += aubridge aufile endif ifneq ($(USE_VIDEO),) MODULES += vidloop selfview vidbridge -ifneq ($(HAVE_PTHREAD),) MODULES += fakevideo endif -endif ifneq ($(USE_ALSA),) 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) |