瀏覽代碼

libobs/util: Add function to get circlebuf data offset

Allows getting pointer to an offset at a specific index within the
circlebuf data.  Useful for iterating through circlebuf data.
jp9000 9 年之前
父節點
當前提交
3aa6b50fbe
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      libobs/util/circlebuf.h

+ 14 - 0
libobs/util/circlebuf.h

@@ -254,6 +254,20 @@ static inline void circlebuf_pop_back(struct circlebuf *cb, void *data,
 		cb->end_pos -= size;
 }
 
+static inline void *circlebuf_data(struct circlebuf *cb, size_t idx)
+{
+	uint8_t *ptr = cb->data;
+	size_t offset = cb->start_pos + idx;
+
+	if (idx > cb->size)
+		return NULL;
+
+	if (offset >= cb->capacity)
+		offset -= cb->capacity;
+
+	return ptr + offset;
+}
+
 #ifdef __cplusplus
 }
 #endif