summaryrefslogtreecommitdiff
path: root/include/uvcgadget/timer.h
diff options
context:
space:
mode:
authorDaniel Scally <dan.scally@ideasonboard.com>2022-11-30 13:31:08 +0000
committerDaniel Scally <dan.scally@ideasonboard.com>2022-11-30 13:48:26 +0000
commit1c18c451f3a48507e876cfdb03c0a6f2187f62cb (patch)
tree1ea466f89e854c35236b7a229981f123a6b8496d /include/uvcgadget/timer.h
parent90955f728061d0cbec4b470849a7f564637a6e3a (diff)
lib/timer: Add timer infrastructure
Some sources simply fill the buffers passed by the USB subsystem and return them as quickly as possible. Particularly with compressed formats operating at superspeed this rapidly results in unrealistic frame rates. Add infrastructure that allows us to define a specific framerate and introduce blocking calls that constrain those sources to the framerates expected by the host. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
Diffstat (limited to 'include/uvcgadget/timer.h')
-rw-r--r--include/uvcgadget/timer.h59
1 files changed, 59 insertions, 0 deletions
diff --git a/include/uvcgadget/timer.h b/include/uvcgadget/timer.h
new file mode 100644
index 0000000..de93287
--- /dev/null
+++ b/include/uvcgadget/timer.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * libuvcgadget timer utils
+ *
+ * Copyright (C) 2022 Daniel Scally
+ *
+ * Contact: Daniel Scally <dan.scally@ideasonboard.com>
+ */
+
+struct timer;
+
+/*
+ * timer_new - Create a new timer
+ *
+ * Allocates and returns a new struct timer. This must be configured with
+ * timer_set_fps() and then armed with timer_arm(), following which calls to
+ * timer_wait() will block until the expiration of a period as defined by
+ * timer_set_fps().
+ *
+ * Timers allocated with this function should be removed with timer_destroy()
+ */
+struct timer *timer_new(void);
+
+/*
+ * timer_set_fps - Configure the timer's wait period
+ *
+ * Configure the timer to wait for a period of time such that expirations per
+ * second matches @fps
+ */
+void timer_set_fps(struct timer *timer, int fps);
+
+/*
+ * timer_arm
+ *
+ * Arms the timer such that calls to timer_wait() become blocking until the
+ * expiration of a period.
+ */
+int timer_arm(struct timer *timer);
+
+/*
+ * timer_disarm
+ *
+ * Disarms the timer such that calls to timer_wait() return without blocking.
+ */
+int timer_disarm(struct timer *timer);
+
+/*
+ * timer_wait
+ *
+ * If the timer is armed, block until the expiration of a period
+ */
+void timer_wait(struct timer *timer);
+
+/*
+ * timer_destroy
+ *
+ * Close the timer's file descriptor and free the memory
+ */
+void timer_destroy(struct timer *timer);