..
This commit is contained in:
parent
fb9288ef58
commit
146ef6197d
3 changed files with 15 additions and 15 deletions
|
@ -576,13 +576,13 @@ int main(int argc, const char* argv[])
|
||||||
|
|
||||||
if (flags & REWIND_FLAG_REAL_TIME_1)
|
if (flags & REWIND_FLAG_REAL_TIME_1)
|
||||||
{
|
{
|
||||||
PushData(ringBuffers + 0, number, incomingBuffer->data, length);
|
PokeData(ringBuffers + 0, number, incomingBuffer->data, length);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & REWIND_FLAG_REAL_TIME_2)
|
if (flags & REWIND_FLAG_REAL_TIME_2)
|
||||||
{
|
{
|
||||||
PushData(ringBuffers + 1, number, incomingBuffer->data, length);
|
PokeData(ringBuffers + 1, number, incomingBuffer->data, length);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
RingBuffer.c
20
RingBuffer.c
|
@ -3,12 +3,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void PushData(struct RingBuffer* buffer, uint32_t number, uint8_t* data, size_t length)
|
void PokeData(struct RingBuffer* buffer, uint32_t number, uint8_t* data, size_t length)
|
||||||
{
|
{
|
||||||
number %= BUFFER_LENGTH;
|
number %= BUFFER_LENGTH;
|
||||||
|
|
||||||
buffer->delay += (buffer->flags == 0); // Postpone processing if buffer empty
|
buffer->delay += buffer->marks == 0; // Postpone processing if buffer empty
|
||||||
buffer->flags |= (1 << number); // Set processing flag for the record
|
buffer->marks |= 1 << number; // Set processing flag for the record
|
||||||
|
|
||||||
struct BufferRecord* record = buffer->records + number;
|
struct BufferRecord* record = buffer->records + number;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ void PushData(struct RingBuffer* buffer, uint32_t number, uint8_t* data, size_t
|
||||||
|
|
||||||
void ProcessBuffer(struct RingBuffer* buffer, int handle, struct sockaddr_in* address)
|
void ProcessBuffer(struct RingBuffer* buffer, int handle, struct sockaddr_in* address)
|
||||||
{
|
{
|
||||||
if (buffer->flags == 0)
|
if (buffer->marks == 0)
|
||||||
{
|
{
|
||||||
// Nothing to process
|
// Nothing to process
|
||||||
return;
|
return;
|
||||||
|
@ -31,17 +31,17 @@ void ProcessBuffer(struct RingBuffer* buffer, int handle, struct sockaddr_in* ad
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mask = (1 << buffer->pointer);
|
size_t mark = (1 << buffer->index);
|
||||||
|
|
||||||
if (buffer->flags & mask)
|
if (buffer->marks & mark)
|
||||||
{
|
{
|
||||||
// Transmit scheduled data
|
// Transmit scheduled data
|
||||||
struct BufferRecord* record = buffer->records + buffer->pointer;
|
struct BufferRecord* record = buffer->records + buffer->index;
|
||||||
sendto(handle, record->data, record->length, 0, (struct sockaddr*)address, sizeof(struct sockaddr_in));
|
sendto(handle, record->data, record->length, 0, (struct sockaddr*)address, sizeof(struct sockaddr_in));
|
||||||
// Clear processing flag
|
// Clear processing flag
|
||||||
buffer->flags ^= mask;
|
buffer->marks ^= mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->pointer ++;
|
buffer->index ++;
|
||||||
buffer->pointer %= BUFFER_LENGTH;
|
buffer->index %= BUFFER_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,13 +21,13 @@ struct BufferRecord
|
||||||
|
|
||||||
struct RingBuffer
|
struct RingBuffer
|
||||||
{
|
{
|
||||||
size_t flags;
|
size_t marks;
|
||||||
size_t delay;
|
size_t delay;
|
||||||
size_t pointer;
|
size_t index;
|
||||||
struct BufferRecord records[BUFFER_LENGTH];
|
struct BufferRecord records[BUFFER_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
void PushData(struct RingBuffer* buffer, uint32_t number, uint8_t* data, size_t length);
|
void PokeData(struct RingBuffer* buffer, uint32_t number, uint8_t* data, size_t length);
|
||||||
void ProcessBuffer(struct RingBuffer* buffer, int handle, struct sockaddr_in* address);
|
void ProcessBuffer(struct RingBuffer* buffer, int handle, struct sockaddr_in* address);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Add table
Reference in a new issue