diff options
author | Takashi Sakamoto <o-takashi@sakamocchi.jp> | 2022-05-05 11:37:24 +0900 |
---|---|---|
committer | 坂本 貴史 <o-takashi@sakamocchi.jp> | 2022-05-05 16:09:50 +0900 |
commit | ed4a4a0eb951ce6c94102978cede4730cc7eab24 (patch) | |
tree | fb9b0410d3802d13905961a0b17ef839a3fc2040 | |
parent | 8eca90bb42cd58087eb5db3dc83e58b5e4222649 (diff) | |
download | libhinoko-ed4a4a0eb951ce6c94102978cede4730cc7eab24.tar.gz |
fw_iso_ctx: code refactoring to split cycle timer getter function
It's planned to make Hinoko.FwIsoCtx as interface. It's convenient
for derived object to use private helper function apart from public API
to call virtual function.
This commit splits current implementaion of
Hinoko.FwIsoResource.get_cycle_timer() into public API part and private
implementation.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r-- | src/fw_iso_ctx.c | 9 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.c | 31 | ||||
-rw-r--r-- | src/fw_iso_ctx_private.h | 3 |
3 files changed, 35 insertions, 8 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c index 1953d5a..b390b41 100644 --- a/src/fw_iso_ctx.c +++ b/src/fw_iso_ctx.c @@ -266,14 +266,7 @@ void hinoko_fw_iso_ctx_get_cycle_timer(HinokoFwIsoCtx *self, gint clock_id, g_return_if_fail(error == NULL || *error == NULL); priv = hinoko_fw_iso_ctx_get_instance_private(self); - if (priv->fd < 0) { - generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED); - return; - } - - (*cycle_timer)->clk_id = clock_id; - if (ioctl(priv->fd, FW_CDEV_IOC_GET_CYCLE_TIMER2, *cycle_timer) < 0) - generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_GET_CYCLE_TIMER2"); + (void)fw_iso_ctx_state_get_cycle_timer(priv, clock_id, cycle_timer, error); } /** diff --git a/src/fw_iso_ctx_private.c b/src/fw_iso_ctx_private.c index 123cc8b..ba803b9 100644 --- a/src/fw_iso_ctx_private.c +++ b/src/fw_iso_ctx_private.c @@ -520,3 +520,34 @@ gboolean fw_iso_ctx_state_flush_completions(struct fw_iso_ctx_state *state, GErr return TRUE; } + +/** + * fw_iso_ctx_state_get_cycle_timer: + * @state: A [struct@FwIsoCtxState]. + * @clock_id: The numeric ID of clock source for the reference timestamp. One CLOCK_REALTIME(0), + * CLOCK_MONOTONIC(1), and CLOCK_MONOTONIC_RAW(2) is available in UAPI of Linux kernel. + * @cycle_timer: (inout): A [struct@CycleTimer] to store data of cycle timer. + * @error: A [struct@GLib.Error]. + * + * Retrieve the value of cycle timer register. This method call is available + * once any isochronous context is created. + */ +gboolean fw_iso_ctx_state_get_cycle_timer(struct fw_iso_ctx_state *state, gint clock_id, + HinokoCycleTimer *const *cycle_timer, GError **error) +{ + g_return_val_if_fail(cycle_timer != NULL, FALSE); + g_return_val_if_fail(error == NULL || *error == NULL, FALSE); + + if (state->fd < 0) { + generate_local_error(error, HINOKO_FW_ISO_CTX_ERROR_NOT_ALLOCATED); + return FALSE; + } + + (*cycle_timer)->clk_id = clock_id; + if (ioctl(state->fd, FW_CDEV_IOC_GET_CYCLE_TIMER2, *cycle_timer) < 0) { + generate_syscall_error(error, errno, "ioctl(%s)", "FW_CDEV_IOC_GET_CYCLE_TIMER2"); + return FALSE; + } + + return TRUE; +} diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h index ffc23dd..7cfa27f 100644 --- a/src/fw_iso_ctx_private.h +++ b/src/fw_iso_ctx_private.h @@ -68,6 +68,9 @@ void fw_iso_ctx_state_read_frame(struct fw_iso_ctx_state *state, guint offset, g gboolean fw_iso_ctx_state_flush_completions(struct fw_iso_ctx_state *state, GError **error); +gboolean fw_iso_ctx_state_get_cycle_timer(struct fw_iso_ctx_state *state, gint clock_id, + HinokoCycleTimer *const *cycle_timer, GError **error); + void hinoko_fw_iso_ctx_allocate(HinokoFwIsoCtx *self, const char *path, HinokoFwIsoCtxMode mode, HinokoFwScode scode, guint channel, guint header_size, |