mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Move ring buffer out of toxcore/util into toxav.
Toxcore itself doesn't use this data structure. Only toxav does, so now toxav owns the code for it.
This commit is contained in:
parent
15cb426166
commit
f60900c4b8
|
@ -184,6 +184,7 @@ if(BUILD_TOXAV)
|
|||
toxav/bwcontroller.c
|
||||
toxav/group.c
|
||||
toxav/msi.c
|
||||
toxav/ring_buffer.c
|
||||
toxav/rtp.c
|
||||
toxav/toxav.c
|
||||
toxav/toxav_old.c
|
||||
|
|
|
@ -22,6 +22,22 @@
|
|||
* -lopencv_highgui -lopencv_imgproc -lsndfile -pthread -lvpx -lopus -lsodium -lportaudio
|
||||
*/
|
||||
|
||||
// XXX: Hack because toxav doesn't really expose ring_buffer, but this av test
|
||||
// uses it. Not all of these functions are used, but when linking statically,
|
||||
// not renaming them will cause multiple definition errors, so we need to rename
|
||||
// all of them.
|
||||
#define RingBuffer TestRingBuffer
|
||||
#define rb_full test_rb_full
|
||||
#define rb_empty test_rb_empty
|
||||
#define rb_write test_rb_write
|
||||
#define rb_read test_rb_read
|
||||
#define rb_new test_rb_new
|
||||
#define rb_kill test_rb_kill
|
||||
#define rb_size test_rb_size
|
||||
#define rb_data test_rb_data
|
||||
#include "../toxav/ring_buffer.c"
|
||||
|
||||
#include "../toxav/ring_buffer.h"
|
||||
#include "../toxav/toxav.h"
|
||||
#include "../toxcore/network.h" /* current_time_monotonic() */
|
||||
#include "../toxcore/tox.h"
|
||||
|
|
|
@ -16,6 +16,8 @@ libtoxav_la_SOURCES = ../toxav/rtp.h \
|
|||
../toxav/video.c \
|
||||
../toxav/bwcontroller.h \
|
||||
../toxav/bwcontroller.c \
|
||||
../toxav/ring_buffer.h \
|
||||
../toxav/ring_buffer.c \
|
||||
../toxav/toxav.h \
|
||||
../toxav/toxav.c \
|
||||
../toxav/toxav_old.c
|
||||
|
@ -39,4 +41,4 @@ libtoxav_la_LIBADD = libtoxcore.la \
|
|||
$(PTHREAD_LIBS) \
|
||||
$(AV_LIBS)
|
||||
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#include "bwcontroller.h"
|
||||
|
||||
#include "ring_buffer.h"
|
||||
|
||||
#include "../toxcore/logger.h"
|
||||
#include "../toxcore/util.h"
|
||||
|
||||
|
|
92
toxav/ring_buffer.c
Normal file
92
toxav/ring_buffer.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include "ring_buffer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct RingBuffer {
|
||||
uint16_t size; /* Max size */
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
void **data;
|
||||
};
|
||||
|
||||
bool rb_full(const RingBuffer *b)
|
||||
{
|
||||
return (b->end + 1) % b->size == b->start;
|
||||
}
|
||||
bool rb_empty(const RingBuffer *b)
|
||||
{
|
||||
return b->end == b->start;
|
||||
}
|
||||
void *rb_write(RingBuffer *b, void *p)
|
||||
{
|
||||
void *rc = NULL;
|
||||
|
||||
if ((b->end + 1) % b->size == b->start) { /* full */
|
||||
rc = b->data[b->start];
|
||||
}
|
||||
|
||||
b->data[b->end] = p;
|
||||
b->end = (b->end + 1) % b->size;
|
||||
|
||||
if (b->end == b->start) {
|
||||
b->start = (b->start + 1) % b->size;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
bool rb_read(RingBuffer *b, void **p)
|
||||
{
|
||||
if (b->end == b->start) { /* Empty */
|
||||
*p = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
*p = b->data[b->start];
|
||||
b->start = (b->start + 1) % b->size;
|
||||
return true;
|
||||
}
|
||||
RingBuffer *rb_new(int size)
|
||||
{
|
||||
RingBuffer *buf = calloc(sizeof(RingBuffer), 1);
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf->size = size + 1; /* include empty elem */
|
||||
|
||||
if (!(buf->data = calloc(buf->size, sizeof(void *)))) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
void rb_kill(RingBuffer *b)
|
||||
{
|
||||
if (b) {
|
||||
free(b->data);
|
||||
free(b);
|
||||
}
|
||||
}
|
||||
uint16_t rb_size(const RingBuffer *b)
|
||||
{
|
||||
if (rb_empty(b)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return
|
||||
b->end > b->start ?
|
||||
b->end - b->start :
|
||||
(b->size - b->start) + b->end;
|
||||
}
|
||||
uint16_t rb_data(const RingBuffer *b, void **dest)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
for (; i < rb_size(b); i++) {
|
||||
dest[i] = b->data[(b->start + i) % b->size];
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
18
toxav/ring_buffer.h
Normal file
18
toxav/ring_buffer.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#ifndef RING_BUFFER_H
|
||||
#define RING_BUFFER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Ring buffer */
|
||||
typedef struct RingBuffer RingBuffer;
|
||||
bool rb_full(const RingBuffer *b);
|
||||
bool rb_empty(const RingBuffer *b);
|
||||
void *rb_write(RingBuffer *b, void *p);
|
||||
bool rb_read(RingBuffer *b, void **p);
|
||||
RingBuffer *rb_new(int size);
|
||||
void rb_kill(RingBuffer *b);
|
||||
uint16_t rb_size(const RingBuffer *b);
|
||||
uint16_t rb_data(const RingBuffer *b, void **dest);
|
||||
|
||||
#endif /* RING_BUFFER_H */
|
|
@ -26,6 +26,7 @@
|
|||
#include "video.h"
|
||||
|
||||
#include "msi.h"
|
||||
#include "ring_buffer.h"
|
||||
#include "rtp.h"
|
||||
|
||||
#include "../toxcore/logger.h"
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <pthread.h>
|
||||
|
||||
struct RTPMessage;
|
||||
struct RingBuffer;
|
||||
|
||||
typedef struct VCSession_s {
|
||||
/* encoding */
|
||||
|
@ -47,7 +48,7 @@ typedef struct VCSession_s {
|
|||
|
||||
/* decoding */
|
||||
vpx_codec_ctx_t decoder[1];
|
||||
RingBuffer *vbuf_raw; /* Un-decoded data */
|
||||
struct RingBuffer *vbuf_raw; /* Un-decoded data */
|
||||
|
||||
uint64_t linfts; /* Last received frame time stamp */
|
||||
uint32_t lcfd; /* Last calculated frame duration for incoming video payload */
|
||||
|
|
|
@ -193,93 +193,3 @@ int create_recursive_mutex(pthread_mutex_t *mutex)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct RingBuffer {
|
||||
uint16_t size; /* Max size */
|
||||
uint16_t start;
|
||||
uint16_t end;
|
||||
void **data;
|
||||
};
|
||||
|
||||
bool rb_full(const RingBuffer *b)
|
||||
{
|
||||
return (b->end + 1) % b->size == b->start;
|
||||
}
|
||||
bool rb_empty(const RingBuffer *b)
|
||||
{
|
||||
return b->end == b->start;
|
||||
}
|
||||
void *rb_write(RingBuffer *b, void *p)
|
||||
{
|
||||
void *rc = NULL;
|
||||
|
||||
if ((b->end + 1) % b->size == b->start) { /* full */
|
||||
rc = b->data[b->start];
|
||||
}
|
||||
|
||||
b->data[b->end] = p;
|
||||
b->end = (b->end + 1) % b->size;
|
||||
|
||||
if (b->end == b->start) {
|
||||
b->start = (b->start + 1) % b->size;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
bool rb_read(RingBuffer *b, void **p)
|
||||
{
|
||||
if (b->end == b->start) { /* Empty */
|
||||
*p = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
*p = b->data[b->start];
|
||||
b->start = (b->start + 1) % b->size;
|
||||
return true;
|
||||
}
|
||||
RingBuffer *rb_new(int size)
|
||||
{
|
||||
RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1);
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf->size = size + 1; /* include empty elem */
|
||||
|
||||
if (!(buf->data = (void **)calloc(buf->size, sizeof(void *)))) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
void rb_kill(RingBuffer *b)
|
||||
{
|
||||
if (b) {
|
||||
free(b->data);
|
||||
free(b);
|
||||
}
|
||||
}
|
||||
uint16_t rb_size(const RingBuffer *b)
|
||||
{
|
||||
if (rb_empty(b)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return
|
||||
b->end > b->start ?
|
||||
b->end - b->start :
|
||||
(b->size - b->start) + b->end;
|
||||
}
|
||||
uint16_t rb_data(const RingBuffer *b, void **dest)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
for (; i < rb_size(b); i++) {
|
||||
dest[i] = b->data[(b->start + i) % b->size];
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -58,15 +58,4 @@ int load_state(load_state_callback_func load_state_callback, void *outer,
|
|||
/* Returns -1 if failed or 0 if success */
|
||||
int create_recursive_mutex(pthread_mutex_t *mutex);
|
||||
|
||||
/* Ring buffer */
|
||||
typedef struct RingBuffer RingBuffer;
|
||||
bool rb_full(const RingBuffer *b);
|
||||
bool rb_empty(const RingBuffer *b);
|
||||
void *rb_write(RingBuffer *b, void *p);
|
||||
bool rb_read(RingBuffer *b, void **p);
|
||||
RingBuffer *rb_new(int size);
|
||||
void rb_kill(RingBuffer *b);
|
||||
uint16_t rb_size(const RingBuffer *b);
|
||||
uint16_t rb_data(const RingBuffer *b, void **dest);
|
||||
|
||||
#endif /* __UTIL_H__ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user