44 f = fopen(fname,
"rb");
47 printf (
"Error opening matrix file\n" );
48 printf (
"exiting\n" );
51 unsigned int k_f, m_f, w_f;
52 if (fscanf(f,
"%d %d %d", &k_f, &m_f, &w_f) != 3) {
53 throw string(
"Parity matrix read error!");
57 if (w_f < 2 || w_f >
MAX_W) {
58 throw string(
"Invalid parameter in parity matrix (allowed range [2.." + to_string(
MAX_W) +
"])!");
64 oss <<
"Parity matrix size mismatch\nExpected K = " <<
param_k <<
"% M = " <<
param_m <<
65 "\nReceived K = " << k_f <<
", M = " << m_f <<
"\n";
68 if (fseek (f, 1, SEEK_CUR ) != 0) {
73 for (
int i = 0; i < (int)w_f*
param_m; i++) {
74 if (fread (
pcm+i,
sizeof(
int), 1, f) != 1) {
75 throw string(
"Parity matrix read error!");
133 int align_coef =
param_k*
sizeof(int);
135 if ( (frame_size + header_size) % align_coef == 0 )
136 buf_size = frame_size + header_size;
138 buf_size = ( ( (frame_size + header_size) / align_coef ) + 1 ) * align_coef;
145 *out_buf_size = buf_size;
151 printf (
"Unable to allocate memory\n" );
154 memset(out_buf, 0, header_size);
155 memset((
char*)out_buf + frame_size + header_size, 0, align_coef);
159 int *hdr = (
int*)out_buf;
162 memcpy( ((
char*)out_buf) + header_size,
frame, frame_size);
167 this->
encode ( (
char*)out_buf, ((
char*)out_buf)+
param_k*ps );
175 return (
char*)out_buf;
230 int overall_size = my_hdr_size + frame_size;
231 int align_coef =
param_k*
sizeof(int);
233 if ( (overall_size + header_size) % align_coef == 0 )
234 buf_size = overall_size + header_size;
236 buf_size = ( ( (overall_size + header_size) / align_coef ) + 1 ) * align_coef;
243 *out_buf_size = buf_size;
249 printf (
"Unable to allocate aligned memory\n" );
252 memset(out_buf, 0, buf_size);
256 int32_t *hdr = (int32_t*)out_buf;
259 memcpy( ((
char*)out_buf) + header_size, my_hdr, my_hdr_size);
260 memcpy( ((
char*)out_buf) + header_size + my_hdr_size,
frame, frame_size);
263 int my_frame_size=my_hdr_size+frame_size;
268 crc =
crc32buf((
char*)out_buf+header_size,my_frame_size);
270 memcpy( ((
char*)out_buf) + 4, &crc, 4);
271 memcpy( ((
char*)out_buf) + 8, &my_frame_size, 4);
278 this->
encode ( (
char*)out_buf, ((
char*)out_buf)+
param_k*ps );
346 return (
char*)out_buf;
360 for (
int m = 0; m <
param_m; ++m) {
364 auto &node = graph->
nodes.at(idx);
367 n2.neighbours.push_back(idx);
402 for (
int i = 0; i <
param_k; i++)
403 if( ! graph->
nodes.at(i).isDone() ) {
struct video_frame * frame
static const int HEADER_SIZE
virtual void * alloc_buf(int size)=0
void set_pcMatrix(char *matrix)
virtual void encode(char *data, char *parity)=0
bool needs_decoding(Tanner_graph *tanner_graph)
unsigned short max_row_weight
char * encode_frame(char *frame, int frame_size, int *out_buf_size)
char * encode_hdr_frame(char *hdr, int hdr_size, char *frame, int frame_size, int *out_buf_size)
unsigned short packet_size
void create_edges(Tanner_graph *g)
std::map< int, Node > nodes
This class implements timer utils.
double elapsed_time_ms() const
long elapsed_time_us() const
uint32_t crc32buf(const char *buf, size_t len)
constexpr const int MAX_W