Meta: rework ringbuffer meta

ringbuffer: remove size and mask from the ringbuffer, we have that
elsewhere in the user of the ringbuffer.
Remove the buffer data offset and size fields and replace with a
ringbuffer. We then have a ringbuffer in all buffer data, which
simplifies things.
We can now remove the ringbuffer metadata.
This commit is contained in:
Wim Taymans 2017-11-15 17:25:36 +01:00
parent 49d8f6792e
commit 2923b623b3
27 changed files with 199 additions and 374 deletions

View file

@ -25,6 +25,7 @@ extern "C" {
#endif
#include <spa/utils/defs.h>
#include <spa/utils/ringbuffer.h>
#include <spa/buffer/meta.h>
#include <spa/support/type-map.h>
@ -64,9 +65,8 @@ static inline void spa_type_data_map(struct spa_type_map *map, struct spa_type_d
/** Chunk of memory */
struct spa_chunk {
uint32_t offset; /**< offset of valid data */
uint32_t size; /**< size of valid data */
int32_t stride; /**< stride of valid data */
struct spa_ringbuffer area; /**< ringbuffer with valid memory */
int32_t stride; /**< stride of ringbuffer increment */
};
/** Data for a buffer */

View file

@ -38,14 +38,12 @@ extern "C" {
#define SPA_TYPE_META__Header SPA_TYPE_META_BASE "Header"
#define SPA_TYPE_META__Pointer SPA_TYPE_META_BASE "Pointer"
#define SPA_TYPE_META__VideoCrop SPA_TYPE_META_BASE "VideoCrop"
#define SPA_TYPE_META__Ringbuffer SPA_TYPE_META_BASE "Ringbuffer"
#define SPA_TYPE_META__Shared SPA_TYPE_META_BASE "Shared"
struct spa_type_meta {
uint32_t Header;
uint32_t Pointer;
uint32_t VideoCrop;
uint32_t Ringbuffer;
uint32_t Shared;
};
@ -55,7 +53,6 @@ static inline void spa_type_meta_map(struct spa_type_map *map, struct spa_type_m
type->Header = spa_type_map_get_id(map, SPA_TYPE_META__Header);
type->Pointer = spa_type_map_get_id(map, SPA_TYPE_META__Pointer);
type->VideoCrop = spa_type_map_get_id(map, SPA_TYPE_META__VideoCrop);
type->Ringbuffer = spa_type_map_get_id(map, SPA_TYPE_META__Ringbuffer);
type->Shared = spa_type_map_get_id(map, SPA_TYPE_META__Shared);
}
}
@ -87,11 +84,6 @@ struct spa_meta_video_crop {
int32_t width, height; /**< width and height */
};
/** Ringbuffer metadata */
struct spa_meta_ringbuffer {
struct spa_ringbuffer ringbuffer; /**< the ringbuffer */
};
/** Describes the shared memory of a buffer is stored */
struct spa_meta_shared {
int32_t flags; /**< flags */

View file

@ -33,21 +33,10 @@ extern "C" {
#define SPA_TYPE_PARAM_META__type SPA_TYPE_PARAM_META_BASE "type"
#define SPA_TYPE_PARAM_META__size SPA_TYPE_PARAM_META_BASE "size"
#define SPA_TYPE_PARAM_META__ringbufferSize SPA_TYPE_PARAM_META_BASE "ringbufferSize"
#define SPA_TYPE_PARAM_META__ringbufferMinAvail SPA_TYPE_PARAM_META_BASE "ringbufferMinAvail"
#define SPA_TYPE_PARAM_META__ringbufferStride SPA_TYPE_PARAM_META_BASE "ringbufferStride"
#define SPA_TYPE_PARAM_META__ringbufferBlocks SPA_TYPE_PARAM_META_BASE "ringbufferBlocks"
#define SPA_TYPE_PARAM_META__ringbufferAlign SPA_TYPE_PARAM_META_BASE "ringbufferAlign"
struct spa_type_param_meta {
uint32_t Meta;
uint32_t type;
uint32_t size;
uint32_t ringbufferSize;
uint32_t ringbufferMinAvail;
uint32_t ringbufferStride;
uint32_t ringbufferBlocks;
uint32_t ringbufferAlign;
};
static inline void
@ -61,11 +50,6 @@ spa_type_param_meta_map(struct spa_type_map *map,
{ OFF(Meta), SPA_TYPE_PARAM__Meta },
{ OFF(type), SPA_TYPE_PARAM_META__type },
{ OFF(size), SPA_TYPE_PARAM_META__size },
{ OFF(ringbufferSize), SPA_TYPE_PARAM_META__ringbufferSize },
{ OFF(ringbufferMinAvail), SPA_TYPE_PARAM_META__ringbufferMinAvail },
{ OFF(ringbufferStride), SPA_TYPE_PARAM_META__ringbufferStride },
{ OFF(ringbufferBlocks), SPA_TYPE_PARAM_META__ringbufferBlocks },
{ OFF(ringbufferAlign), SPA_TYPE_PARAM_META__ringbufferAlign },
};
#undef OFF
for (i = 0; i < SPA_N_ELEMENTS(tab); i++)

View file

@ -38,12 +38,9 @@ struct spa_ringbuffer;
struct spa_ringbuffer {
uint32_t readindex; /*< the current read index */
uint32_t writeindex; /*< the current write index */
uint32_t size; /*< the size of the ringbuffer */
uint32_t mask; /*< mask as \a size - 1, only valid if \a size is
* a power of 2. */
};
#define SPA_RINGBUFFER_INIT(size) (struct spa_ringbuffer) { 0, 0, (size), (size)-1 }
#define SPA_RINGBUFFER_INIT() (struct spa_ringbuffer) { 0, 0 }
/**
* Initialize a spa_ringbuffer with \a size.
@ -51,28 +48,28 @@ struct spa_ringbuffer {
* \param rbuf a spa_ringbuffer
* \param size the number of elements in the ringbuffer
*/
static inline void spa_ringbuffer_init(struct spa_ringbuffer *rbuf, uint32_t size)
static inline void spa_ringbuffer_init(struct spa_ringbuffer *rbuf)
{
*rbuf = SPA_RINGBUFFER_INIT(size);
*rbuf = SPA_RINGBUFFER_INIT();
}
/**
* Clear \a rbuf, sets the pointers so that the ringbuffer is empty.
* Sets the pointers so that the ringbuffer contains \a size bytes.
*
* \param rbuf a spa_ringbuffer
*/
static inline void spa_ringbuffer_clear(struct spa_ringbuffer *rbuf)
static inline void spa_ringbuffer_set_avail(struct spa_ringbuffer *rbuf, uint32_t size)
{
rbuf->readindex = 0;
rbuf->writeindex = 0;
rbuf->writeindex = size;
}
/**
* Get the read index and available bytes for reading.
*
* \param rbuf a spa_ringbuffer
* \param index the value of readindex, should be masked to get the
* offset in the ringbuffer memory
* \param index the value of readindex, should be taken modulo the size of the
* ringbuffer memory to get the offset in the ringbuffer memory
* \return number of available bytes to read. values < 0 mean
* there was an underrun. values > rbuf->size means there
* was an overrun.
@ -84,20 +81,22 @@ static inline int32_t spa_ringbuffer_get_read_index(struct spa_ringbuffer *rbuf,
}
/**
* Read \a len bytes from \a rbuf starting \a offset. \a offset must be masked
* with the size of \a rbuf and len should be smaller than the size.
* Read \a len bytes from \a rbuf starting \a offset. \a offset must be taken
* modulo \a size and len should be smaller than \a size.
*
* \param rbuf a #struct spa_ringbuffer
* \param buffer memory to read from
* \param offset offset in \a buffer to read from
* \param size the size of \a memory
* \param offset offset in \a memory to read from
* \param data destination memory
* \param len number of bytes to read
*/
static inline void
spa_ringbuffer_read_data(struct spa_ringbuffer *rbuf,
const void *buffer, uint32_t offset, void *data, uint32_t len)
const void *buffer, uint32_t size,
uint32_t offset, void *data, uint32_t len)
{
uint32_t first = SPA_MIN(len, rbuf->size - offset);
uint32_t first = SPA_MIN(len, size - offset);
memcpy(data, buffer + offset, first);
if (SPA_UNLIKELY(len > first))
memcpy(data + first, buffer, len - first);
@ -118,8 +117,8 @@ static inline void spa_ringbuffer_read_update(struct spa_ringbuffer *rbuf, int32
* Get the write index and the number of bytes inside the ringbuffer.
*
* \param rbuf a spa_ringbuffer
* \param index the value of writeindex, should be masked to get the
* offset in the ringbuffer memory
* \param index the value of writeindex, should be taken modulo the size of the
* ringbuffer memory to get the offset in the ringbuffer memory
* \return the fill level of \a rbuf. values < 0 mean
* there was an underrun. values > rbuf->size means there
* was an overrun. Subtract from the buffer size to get
@ -132,20 +131,22 @@ static inline int32_t spa_ringbuffer_get_write_index(struct spa_ringbuffer *rbuf
}
/**
* Write \a len bytes to \a rbuf starting \a offset. \a offset must be masked
* with the size of \a rbuf and len should be smaller than the size.
* Write \a len bytes to \a buffer starting \a offset. \a offset must be taken
* modulo \a size and len should be smaller than \a size.
*
* \param rbuf a spa_ringbuffer
* \param buffer memory to write to
* \param offset offset in \a buffer to write to
* \param size the size of \a memory
* \param offset offset in \a memory to write to
* \param data source memory
* \param len number of bytes to write
*/
static inline void
spa_ringbuffer_write_data(struct spa_ringbuffer *rbuf,
void *buffer, uint32_t offset, const void *data, uint32_t len)
void *buffer, uint32_t size,
uint32_t offset, const void *data, uint32_t len)
{
uint32_t first = SPA_MIN(len, rbuf->size - offset);
uint32_t first = SPA_MIN(len, size - offset);
memcpy(buffer + offset, data, first);
if (SPA_UNLIKELY(len > first))
memcpy(buffer, data + first, len - first);