Forráskód Böngészése

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 éve
szülő
commit
3aa6b50fbe
1 módosított fájl, 14 hozzáadás és 0 törlés
  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