aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>2022-05-05 11:37:24 +0900
committer坂本 貴史 <o-takashi@sakamocchi.jp>2022-05-05 16:09:50 +0900
commit643009db8a09bebdd4b1bcc1651985c6b18dfe1c (patch)
treefab5d3c15c7c2f517c6261931aeace0223febd3b
parent35c31ee8db09e5103721ba22e5dc7ec50156e2f9 (diff)
downloadlibhinoko-643009db8a09bebdd4b1bcc1651985c6b18dfe1c.tar.gz
fw_iso_ctx: code refactoring to move frame read function
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
-rw-r--r--src/fw_iso_ctx.c15
-rw-r--r--src/fw_iso_ctx_private.c31
-rw-r--r--src/fw_iso_ctx_private.h3
3 files changed, 35 insertions, 14 deletions
diff --git a/src/fw_iso_ctx.c b/src/fw_iso_ctx.c
index f85c918..72ec18c 100644
--- a/src/fw_iso_ctx.c
+++ b/src/fw_iso_ctx.c
@@ -528,24 +528,11 @@ void hinoko_fw_iso_ctx_read_frames(HinokoFwIsoCtx *self, guint offset,
guint *frame_size)
{
HinokoFwIsoCtxPrivate *priv;
- unsigned int bytes_per_buffer;
g_return_if_fail(HINOKO_IS_FW_ISO_CTX(self));
priv = hinoko_fw_iso_ctx_get_instance_private(self);
- bytes_per_buffer = priv->bytes_per_chunk * priv->chunks_per_buffer;
- if (offset > bytes_per_buffer) {
- *frames = NULL;
- *frame_size = 0;
- return;
- }
-
- *frames = priv->addr + offset;
-
- if (offset + length < bytes_per_buffer)
- *frame_size = length;
- else
- *frame_size = bytes_per_buffer - offset;
+ fw_iso_ctx_state_read_frame(priv, offset, length, frames, frame_size);
}
/**
diff --git a/src/fw_iso_ctx_private.c b/src/fw_iso_ctx_private.c
index bc6b6bd..c8f6dc8 100644
--- a/src/fw_iso_ctx_private.c
+++ b/src/fw_iso_ctx_private.c
@@ -470,3 +470,34 @@ void fw_iso_ctx_state_stop(struct fw_iso_ctx_state *state)
state->data_length = 0;
state->curr_offset = 0;
}
+
+/**
+ * fw_iso_ctx_state_read_frames:
+ * @state: A [struct@FwIsoCtxState].
+ * @offset: offset from head of buffer.
+ * @length: the number of bytes to read.
+ * @frames: (array length=frame_size)(out)(transfer none)(nullable): The array to fill the same
+ * data frame as @frame_size.
+ * @frame_size: this value is for a case to truncate due to the end of buffer.
+ *
+ * Read frames to given buffer.
+ */
+void fw_iso_ctx_state_read_frame(struct fw_iso_ctx_state *state, guint offset, guint length,
+ const guint8 **frame, guint *frame_size)
+{
+ unsigned int bytes_per_buffer;
+
+ bytes_per_buffer = state->bytes_per_chunk * state->chunks_per_buffer;
+ if (offset > bytes_per_buffer) {
+ *frame = NULL;
+ *frame_size = 0;
+ return;
+ }
+
+ *frame = state->addr + offset;
+
+ if (offset + length < bytes_per_buffer)
+ *frame_size = length;
+ else
+ *frame_size = bytes_per_buffer - offset;
+}
diff --git a/src/fw_iso_ctx_private.h b/src/fw_iso_ctx_private.h
index eb6a9e9..8de0fdb 100644
--- a/src/fw_iso_ctx_private.h
+++ b/src/fw_iso_ctx_private.h
@@ -63,6 +63,9 @@ gboolean fw_iso_ctx_state_start(struct fw_iso_ctx_state *state, const guint16 *c
guint32 sync, HinokoFwIsoCtxMatchFlag tags, GError **error);
void fw_iso_ctx_state_stop(struct fw_iso_ctx_state *state);
+void fw_iso_ctx_state_read_frame(struct fw_iso_ctx_state *state, guint offset, guint length,
+ const guint8 **frame, guint *frame_size);
+
void hinoko_fw_iso_ctx_allocate(HinokoFwIsoCtx *self, const char *path,
HinokoFwIsoCtxMode mode, HinokoFwScode scode,
guint channel, guint header_size,