Simplify bytebuf naming
Rename read_available to can_read and write_available to can_write. This is more readable.
This commit is contained in:
@@ -69,14 +69,14 @@ sc_audiobuf_commit_write(struct sc_audiobuf *buf, uint32_t samples) {
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
sc_audiobuf_read_available(struct sc_audiobuf *buf) {
|
||||
size_t bytes = sc_bytebuf_read_available(&buf->buf);
|
||||
sc_audiobuf_can_read(struct sc_audiobuf *buf) {
|
||||
size_t bytes = sc_bytebuf_can_read(&buf->buf);
|
||||
return sc_audiobuf_to_samples(buf, bytes);
|
||||
}
|
||||
|
||||
static inline uint32_t
|
||||
sc_audiobuf_write_available(struct sc_audiobuf *buf) {
|
||||
size_t bytes = sc_bytebuf_write_available(&buf->buf);
|
||||
sc_audiobuf_can_write(struct sc_audiobuf *buf) {
|
||||
size_t bytes = sc_bytebuf_can_write(&buf->buf);
|
||||
return sc_audiobuf_to_samples(buf, bytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ sc_bytebuf_destroy(struct sc_bytebuf *buf) {
|
||||
void
|
||||
sc_bytebuf_read(struct sc_bytebuf *buf, uint8_t *to, size_t len) {
|
||||
assert(len);
|
||||
assert(len <= sc_bytebuf_read_available(buf));
|
||||
assert(len <= sc_bytebuf_can_read(buf));
|
||||
assert(buf->tail != buf->head); // the buffer could not be empty
|
||||
|
||||
size_t right_limit = buf->tail < buf->head ? buf->head : buf->alloc_size;
|
||||
@@ -50,7 +50,7 @@ sc_bytebuf_read(struct sc_bytebuf *buf, uint8_t *to, size_t len) {
|
||||
void
|
||||
sc_bytebuf_skip(struct sc_bytebuf *buf, size_t len) {
|
||||
assert(len);
|
||||
assert(len <= sc_bytebuf_read_available(buf));
|
||||
assert(len <= sc_bytebuf_can_read(buf));
|
||||
assert(buf->tail != buf->head); // the buffer could not be empty
|
||||
|
||||
buf->tail = (buf->tail + len) % buf->alloc_size;
|
||||
@@ -78,7 +78,7 @@ sc_bytebuf_write_step1(struct sc_bytebuf *buf, size_t len) {
|
||||
void
|
||||
sc_bytebuf_write(struct sc_bytebuf *buf, const uint8_t *from, size_t len) {
|
||||
assert(len);
|
||||
assert(len <= sc_bytebuf_write_available(buf));
|
||||
assert(len <= sc_bytebuf_can_write(buf));
|
||||
|
||||
sc_bytebuf_write_step0(buf, from, len);
|
||||
sc_bytebuf_write_step1(buf, len);
|
||||
@@ -99,6 +99,6 @@ sc_bytebuf_prepare_write(struct sc_bytebuf *buf, const uint8_t *from,
|
||||
|
||||
void
|
||||
sc_bytebuf_commit_write(struct sc_bytebuf *buf, size_t len) {
|
||||
assert(len <= sc_bytebuf_write_available(buf));
|
||||
assert(len <= sc_bytebuf_can_write(buf));
|
||||
sc_bytebuf_write_step1(buf, len);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ sc_bytebuf_commit_write(struct sc_bytebuf *buf, size_t len);
|
||||
* It is an error to read more bytes than available.
|
||||
*/
|
||||
static inline size_t
|
||||
sc_bytebuf_read_available(struct sc_bytebuf *buf) {
|
||||
sc_bytebuf_can_read(struct sc_bytebuf *buf) {
|
||||
return (buf->alloc_size + buf->head - buf->tail) % buf->alloc_size;
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ sc_bytebuf_read_available(struct sc_bytebuf *buf) {
|
||||
* It is an error to write more bytes than available.
|
||||
*/
|
||||
static inline size_t
|
||||
sc_bytebuf_write_available(struct sc_bytebuf *buf) {
|
||||
sc_bytebuf_can_write(struct sc_bytebuf *buf) {
|
||||
return (buf->alloc_size + buf->tail - buf->head - 1) % buf->alloc_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the actual capacity of the buffer (read available + write available)
|
||||
* Return the actual capacity of the buffer (can_read() + can_write())
|
||||
*/
|
||||
static inline size_t
|
||||
sc_bytebuf_capacity(struct sc_bytebuf *buf) {
|
||||
|
||||
Reference in New Issue
Block a user