UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
main.cpp File Reference
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <set>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include "ldgm-session-cpu.h"
#include "ldgm-session-gpu.h"
#include "timer-util.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Macros

#define COLUMN_WEIGHT   3 /* Number of 1's in a columns of parity matrix */
 
#define ITERATIONS   100
 
#define PACKET_LOSS   0.08 /* Packet loss rate */
 
#define ROW_WEIGHT   3 /* Number of 1's in a row of parity matrix */
 

Functions

void compare_int_arrays (int *a, int *b, int size)
 
int demo (int m, int k, int frame_size, char *matrix_fname, char *data_fname, int cpu, int gpu)
 
void demo_gpu ()
 
void fillParityMatrix (char **matrix, int height, int width)
 
int main (int argc, char *argv[])
 
void printData (char *data, int count, int packet_size)
 
void printMatrix (char **m, int height, int width)
 
void usage ()
 

Macro Definition Documentation

◆ COLUMN_WEIGHT

#define COLUMN_WEIGHT   3 /* Number of 1's in a columns of parity matrix */

Definition at line 39 of file main.cpp.

Referenced by demo().

◆ ITERATIONS

#define ITERATIONS   100

Definition at line 42 of file main.cpp.

Referenced by demo().

◆ PACKET_LOSS

#define PACKET_LOSS   0.08 /* Packet loss rate */

Definition at line 41 of file main.cpp.

Referenced by demo().

◆ ROW_WEIGHT

#define ROW_WEIGHT   3 /* Number of 1's in a row of parity matrix */

Definition at line 38 of file main.cpp.

Function Documentation

◆ compare_int_arrays()

void compare_int_arrays ( int * a,
int * b,
int size )

Definition at line 140 of file main.cpp.

141{
142 bool equal = true;
143 int idx = -1;
144 for ( int i = 0; i < size; i++ )
145 {
146 if ( a[i] != b[i] )
147 {
148 equal = false;
149 idx = i;
150 printf ( "p1: %d, p2: %d\n", a[i], b[i] );
151 break;
152// printf ( "Difference at integer position: %d\n", idx );
153// printf ( "Difference at packet position: %d\n", idx/2048 );
154 }
155 }
156 printf ( "Arrays are %s.\n", (equal)?"equal":"not equal" );
157
158}

◆ demo()

int demo ( int m,
int k,
int frame_size,
char * matrix_fname,
char * data_fname,
int cpu,
int gpu )

Definition at line 166 of file main.cpp.

167{
168 Timer_util t;
169
170// LDGM_session_gpu* coding_session_gpu = new LDGM_session_gpu();
171 LDGM_session_cpu* coding_session_cpu = new LDGM_session_cpu();
172 LDGM_session_cpu* coding_session_cpu_2 = new LDGM_session_cpu();
173
174 // coding_session_gpu->set_params ( k, m, COLUMN_WEIGHT);
175 coding_session_cpu->set_params ( k, m, COLUMN_WEIGHT);
176 coding_session_cpu_2->set_params ( k, m, COLUMN_WEIGHT);
177 //coding_session_gpu->set_data_fname(data_fname);
178
179 coding_session_cpu->set_pcMatrix ( matrix_fname);
180 coding_session_cpu_2->set_pcMatrix ( matrix_fname);
181 //coding_session_gpu->set_pcMatrix ( matrix_fname);
182
183 //generate data
184 void *data;
185
186 //allocate memory with address aligned to 16 bytes
187 int e = posix_memalign(&data, 16, frame_size);
188
189 if ( e != 0 ) {
190 fprintf ( stderr, "Unable to allocate memory using posix_memalign.\n");
191 return EXIT_FAILURE;
192 }
193
194 for ( int i = 0; i < frame_size; ++i)
195 memset((char*)data+i, rand() % 256, 1);
196
197 //alocate space for parity packets
198
199// void *parity;
200 //allocate memory with address aligned to 16 bytes
201// e = posix_memalign(&parity, 16, (size_t)m*packet_size);
202//
203// if ( e != 0 ) {
204// fprintf ( stderr, "Unable to allocate memory using posix_memalign.\n");
205// return EXIT_FAILURE;
206// }
207
208
209// coding_session->add_src_head ( (char*) data, src_block, (uint16_t)0);
210
211 //print first K data packets
212// printData ( (char*) data, K, PACKET_SIZE);
213// printData ( (char*) parity, M, PACKET_SIZE);
214// void *parity2;
215 //allocate memory with address aligned to 16 bytes
216// e = posix_memalign(&parity2, 16, (size_t)m*packet_size);
217
218// if ( e != 0 ) {
219// fprintf ( stderr, "Unable to allocate memory using posix_memalign.\n");
220// return EXIT_FAILURE;
221// }
222
223// printf ( "k %d m %d frame_size %d, matrix %s data %s cpu %d gpu %d\n",
224// k, m, frame_size, matrix_fname, data_fname, cpu, gpu);
225
226// char *output = coding_session_cpu->encode_frame( (char*) data, packet_size);
227
228
229 char* output;
230 int buf_size;
231 int f_size;
232 char *decoded;
233 map<int, int> valid_data;
234 int ps;
235 srand(time(NULL));
236 if (cpu)
237 {
238 t.start();
239
240 for ( int i = 0; i < ITERATIONS; i++)
241 {
242 printf ( "encoding\n" );
243 output = coding_session_cpu->encode_frame ( (char*) data, frame_size, &buf_size );
244 ps = 1392; // coding_session_cpu->get_packet_size();
245 int total = 0;
246
247 valid_data.clear();
248
249 for ( int j = 0; j < buf_size ; j += ps) {
250 int size = ps;
251 if(j + ps > buf_size) {
252 size = buf_size - j;
253 }
254 if(rand() % 100 > PACKET_LOSS * 100 ) {
255 valid_data.insert(pair<int,int>(j, size));
256 total += size;
257 } else {
258 if(j == 0) {
259 fprintf(stderr, "Dropping first packet!!!!!!!!!!!!\n");
260 }
261 memset(output + j, 0x0, size);
262 }
263 }
264
265 int c;
266 printf ( "received bytes: %d\n", total );
267 printf ( "decoding\n" );
268 decoded = coding_session_cpu_2->decode_frame(output, buf_size, &f_size, valid_data);
269 printf ( "f_size: %d\n", f_size );
270 static int good = 0;
271 static int bad = 0;
272 if(f_size) good++; else bad++;
273 fprintf(stderr, "good: %d bad: %d\n", good, bad);
274
275 for (int x= 0; x < f_size; ++x) {
276 if(((char *)data)[x] != decoded[x]) {
277 fprintf(stderr, "Different character %d / %d (original size %d)\n", x, f_size, frame_size);
278 break;
279 }
280 }
281 //memset(decoded, 0, f_size);
282 coding_session_cpu->free_out_buf(output);
283 }
284 t.end();
285 // printf ( "CPU encoded in: %.6lf\n", t.elapsed_time(start, end) );
286 }
287 if (gpu)
288 {
289 t.start();
290
291 for ( int i = 0; i < ITERATIONS; i++)
292 // coding_session_gpu->encode ( (char*) data, (char*) frame_size );
293
294 t.end();
295 printf ( "GPU encoded in: %.6lf\n", t.elapsed_time() );
296 }
297
298
299#if 0
300 ofstream out;
301 out.open(data_fname, ios::out | ios::app);
302
303 out << t.elapsed_time() << ",";
304
305 out.close();
306
307 union int_bytes {
308 unsigned int number;
309 unsigned char bytes[4];
310 };
311 union int_bytes fs;
312 memcpy(&(fs.bytes), output, 4);
313
314 // printf ( "frame_size: \t\t%d\n", fs.number );
315 // printf ( "packet_size: \t\t%d\n", coding_session_cpu->get_packet_size() );
316
317
318 // printData ( (char*) output, 5, coding_session_cpu->get_packet_size());
319
320
321 coding_session_cpu->free_out_buf(output);
322#endif
323 delete coding_session_cpu;
324 delete coding_session_cpu_2;
325 // delete coding_session_gpu;
326 free ( data );
327
328 return EXIT_SUCCESS;
329}
char * decode_frame(char *received_data, int buf_size, int *frame_size, std::map< int, int > valid_data)
void free_out_buf(char *buf)
void set_pcMatrix(char *matrix)
char * encode_frame(char *frame, int frame_size, int *out_buf_size)
void set_params(unsigned short k, unsigned short m, unsigned short rw)
This class implements timer utils.
Definition timer-util.h:26
void end()
Definition timer-util.h:36
double elapsed_time() const
Definition timer-util.h:46
void start()
Definition timer-util.h:32
#define PACKET_LOSS
Definition main.cpp:41
#define ITERATIONS
Definition main.cpp:42
#define COLUMN_WEIGHT
Definition main.cpp:39

References COLUMN_WEIGHT, LDGM_session_cpu::decode_frame(), Timer_util::elapsed_time(), LDGM_session::encode_frame(), Timer_util::end(), LDGM_session_cpu::free_out_buf(), ITERATIONS, PACKET_LOSS, LDGM_session::set_params(), LDGM_session::set_pcMatrix(), and Timer_util::start().

Referenced by main().

Here is the call graph for this function:

◆ demo_gpu()

void demo_gpu ( )

◆ fillParityMatrix()

void fillParityMatrix ( char ** matrix,
int height,
int width )

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 57 of file main.cpp.

58{
59 short m, k, column_weight;
60 int frame_size;
61
62 opterr = 0;
63 int c;
64 int gpu = 0;
65 int cpu = 0;
66 char fname[32];
67 char matrix_fname[32];
68
69 while ( ( c = getopt ( argc, argv, "cf:gk:m:o:t:w:")) != -1 ) {
70 switch(c) {
71 case 'w':
72 column_weight = atoi ( optarg );
73 break;
74 case 'c':
75 if(gpu)
76 {
77 fprintf (stderr, "Only one of the options 'c' 'g' can be chosen.\n" );
78 return EXIT_FAILURE;
79 }
80 cpu = 1;
81 break;
82 case 'f':
83 frame_size = atoi ( optarg );
84 break;
85 case 'g':
86 if(cpu)
87 {
88 fprintf (stderr, "Only one of the options 'c' 'g' can be chosen.\n" );
89 return EXIT_FAILURE;
90 }
91 gpu = 1;
92 break;
93 case 'k':
94 k = atoi ( optarg );
95 break;
96 case 'm':
97 m = atoi ( optarg );
98 break;
99 case 'o':
100 sprintf(fname, optarg, 32);
101 break;
102 case 't':
103 sprintf(matrix_fname, optarg, 32);
104 break;
105 case '?':
106 if ( optopt == 'c' || optopt == 'k' || optopt == 'm' )
107 fprintf ( stderr, "Option -%c requires an argument.\n", optopt);
108 else if ( isprint ( optopt))
109 fprintf ( stderr, "Unknown option '-%c'.\n", optopt);
110 else
111 fprintf ( stderr, "Uknown option character '\\x%x'.\n", optopt);
112
113 return 1;
114 default:
115 abort();
116 }
117 }
118
119 demo( k, m, frame_size, matrix_fname, fname, cpu, gpu);
120
121 // demo_gpu();
122
123 return EXIT_SUCCESS;
124} /* ---------- end of function main ---------- */
int demo(int m, int k, int frame_size, char *matrix_fname, char *data_fname, int cpu, int gpu)
Definition main.cpp:166

References demo().

Here is the call graph for this function:

◆ printData()

void printData ( char * data,
int count,
int packet_size )

Definition at line 339 of file main.cpp.

340{
341 for ( int k = 0; k < count ; ++k) {
342 for ( int i = 0; i < packet_size; ++i )
343 printf ( "%d|", *((unsigned char*)(data) + k*packet_size + i ));
344 printf ( "---\n" );
345 }
346}
int count
Definition hd-rum.c:44

References count.

◆ printMatrix()

void printMatrix ( char ** m,
int height,
int width )

Definition at line 354 of file main.cpp.

355{
356 for(int i = 0; i < height; ++i) {
357 for(int j = 0; j < width; ++j) {
358 printf("%3d", (unsigned char)m[i][j]);
359 }
360 printf("\n");
361 }
362 return;
363} /* ----- end of function printMatrix ----- */

◆ usage()

void usage ( void )

Definition at line 134 of file main.cpp.

135{
136 printf ( "\nUsage:\n" );
137
138}