代码拉取完成,页面将自动刷新
#include "RingBuffer.h"
#include "iostream"
using namespace std;
#ifdef _WIN32
#include <windows.h>
#ifndef imsleep
#define imsleep(microsecond) Sleep(microsecond) // ms
#endif
#else
#include <unistd.h>
#define imsleep(microsecond) usleep(1000 * microsecond) // ms
#endif
RingBuffer::RingBuffer(int _buffer_size, int _frame_size)
{
buffer_size = _buffer_size;
frame_size = _frame_size;
p_buffer = new unsigned char *[buffer_size];
for (size_t i = 0; i < buffer_size; i++)
{
p_buffer[i] = new unsigned char[frame_size];
}
}
unsigned char *RingBuffer::get_next_to_push(void)
{
unsigned char *temp = p_buffer[now_point];
now_point++;
now_point %= buffer_size;
return temp;
}
unsigned char *RingBuffer::get_next_to_read(void)
{
while (need_to_read == now_point)
{
imsleep(3);
}
unsigned char *temp = p_buffer[need_to_read];
need_to_read++;
need_to_read %= buffer_size;
return temp;
}
void RingBuffer::test_buffer(void)
{
}
RingBuffer::~RingBuffer()
{
for (size_t i = 0; i < buffer_size; i++)
{
delete[] p_buffer[i];
}
delete[] p_buffer;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。