UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
ldgm Struct Reference

#include <ldgm.h>

Inheritance diagram for ldgm:
Inheritance graph
Collaboration diagram for ldgm:
Collaboration graph

Public Member Functions

 ldgm (const char *cfg)
 
 ldgm (int packet_size, int frame_size, double max_expected_loss)
 
 ldgm (unsigned int k, unsigned int m, unsigned int c, unsigned int seed)
 
bool decode (char *in, int in_len, char **out, int *len, const std::map< int, int > &)
 
std::shared_ptr< video_frame > encode (std::shared_ptr< video_frame >)
 
void set_params (unsigned int k, unsigned int m, unsigned int c, unsigned int seed)
 
- Public Member Functions inherited from fec
virtual ~fec ()
 
virtual audio_frame2 encode (audio_frame2 const &)
 

Private Member Functions

void init (unsigned int k, unsigned int m, unsigned int c, unsigned int seed=DEFAULT_LDGM_SEED)
 

Private Attributes

unsigned int m_c
 
std::shared_ptr< LDGM_session > m_coding_session
 
unsigned int m_k
 
unsigned int m_m
 
unsigned int m_seed
 

Additional Inherited Members

- Static Public Member Functions inherited from fec
static fec * create_from_config (const char *str, bool is_audio) noexcept
 
static fec * create_from_desc (struct fec_desc) noexcept
 
static enum fec_type fec_type_from_pt (int pt) throw ()
 
static int pt_from_fec_type (enum tx_media_type media_type, enum fec_type fec_type, bool encrypted) throw ()
 

Detailed Description

Definition at line 54 of file ldgm.h.

Constructor & Destructor Documentation

◆ ldgm() [1/3]

ldgm::ldgm ( unsigned int k,
unsigned int m,
unsigned int c,
unsigned int seed )

Definition at line 239 of file ldgm.cpp.

240{
241 init(k, m, c, seed);
242}
void init(unsigned int k, unsigned int m, unsigned int c, unsigned int seed=DEFAULT_LDGM_SEED)
Definition ldgm.cpp:212

References init().

Here is the call graph for this function:

◆ ldgm() [2/3]

ldgm::ldgm ( int packet_size,
int frame_size,
double max_expected_loss )

Definition at line 336 of file ldgm.cpp.

337{
338 packet_type_t packet_type;
339 int nearest = INT_MAX;
340 loss_t loss = -1.0;
341 int k, m, c;
342
343 assert(max_expected_loss >= 0.0 && max_expected_loss <= 100.0);
344
345 if(frame_size < 2000000 && packet_size >= (STD1500 + JUMBO9000) / 2) {
346 throw string("LDGM: with frames smaller than 2M you should use standard Ethernet frames.");
347 }
348
349 if(packet_size < (STD1500 + JUMBO9000) / 2) {
350 packet_type = STD1500;
351 } else {
352 packet_type = JUMBO9000;
353 }
354
355 for(unsigned int i = 1; i < sizeof(losses) / sizeof(loss_t); ++i) {
356 if(max_expected_loss >= losses[i - 1] && max_expected_loss <= losses[i]) {
357 loss = losses[i];
358 break;
359 }
360 }
361
362 if(loss == -1.0) {
363 ostringstream oss;
364 oss << "LDGM: Cannot provide predefined settings for correction of loss of " << setprecision(2)
365 << max_expected_loss << endl <<
366 "LDGM: You have to try and set LDGM parameters manually. You can inform us if you need better protection.";
367 throw oss.str();
368 }
369
370 printf("LDGM: Choosing maximal loss %2.2f percent.\n", loss);
371
372 for(unsigned int i = 0; i < sizeof(suggested_configurations) / sizeof(configuration_t); ++i) {
373 if(suggested_configurations[i].packet_type == packet_type &&
375 if(abs(suggested_configurations[i].frame_size - frame_size) < abs(nearest - frame_size)) {
380 }
381 }
382 }
383
384 if (nearest == INT_MAX) {
385 throw string("LDGM: Could not find matching configuration for your request.\n"
386 "Please, set LDGM parameters manually.");
387 }
388
389 double difference_from_frame_size = abs(nearest - frame_size) / (double) frame_size;
390 if(difference_from_frame_size > 0.2) {
391 LOG(LOG_LEVEL_WARNING) << "LDGM: Chosen LDGM setting for frame size that is " << difference_from_frame_size * 100.0 << "% " << (nearest - frame_size > 0 ? "higher" : "lower") << " than your frame size.\n";
392 LOG(LOG_LEVEL_WARNING) << "You may wish to set the parameters manually.\n";
393 }
394
395 if(difference_from_frame_size > 0.5) {
396 throw string("");
397 }
398
399 init(k, m, c);
400}
static __device__ vec2 abs(const vec2 &v)
Definition cuda_dxt.cu:118
#define LOG(level)
Definition debug.h:313
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
loss_t losses[]
Definition ldgm.cpp:101
double loss_t
Definition ldgm.cpp:99
packet_type_t
Definition ldgm.cpp:81
@ STD1500
Definition ldgm.cpp:82
@ JUMBO9000
Definition ldgm.cpp:83
const configuration_t suggested_configurations[]
Definition ldgm.cpp:114
static struct @51 loss[MAX_HISTORY]

References abs(), configuration_t::c, configuration_t::frame_size, init(), JUMBO9000, configuration_t::k, LOG, LOG_LEVEL_WARNING, loss, losses, configuration_t::m, STD1500, and suggested_configurations.

Here is the call graph for this function:

◆ ldgm() [3/3]

ldgm::ldgm ( const char * cfg)

Definition at line 282 of file ldgm.cpp.

283{
284 unsigned int k = DEFAULT_K,
285 m = DEFAULT_M,
286 c = DEFAULT_C;
287
288 if(cfg && strlen(cfg) > 0) {
289 if(strcasecmp(cfg, "help") == 0) {
290 usage();
291 throw 0;
292 }
293 char *save_ptr = NULL;
294 char *item;
295 char *tmp = strdup(cfg);
296 item = strtok_r(tmp, ":", &save_ptr);
297 if(item) {
298 k = atoi(item);
299 }
300 item = strtok_r(NULL, ":", &save_ptr);
301 if(item) {
302 m = atoi(item);
303 item = strtok_r(NULL, ":", &save_ptr);
304 if(item) {
305 c = atoi(item);
306 }
307 } else {
308 throw string("[LDGM] Was set k value but not m.");
309 }
310 free(tmp);
311 }
312
313 if(c < MIN_C || c > MAX_C) {
314 ostringstream oss;
315 oss << "[LDGM] C value shoud be inside interval [" << MIN_C << ", " << MAX_C << "]";
316 throw oss.str();
317 }
318
319 if(k > MAX_K) {
320 ostringstream oss;
321 oss << "[LDGM] K value exceeds maximal value " << MAX_K;
322 throw oss.str();
323 }
324
325 if(k < MINIMAL_VALUE || m < MINIMAL_VALUE) {
326 ostringstream oss;
327 oss << "[LDGM] Either k or m is lower than minimal value " << MINIMAL_VALUE;
328 throw oss.str();
329 }
330
331 printf("[LDGM] Using values k = %u, m = %u, c = %u.\n", k, m, c);
332
333 init(k, m, c);
334}
void usage()
Definition main.cpp:28
#define DEFAULT_M
Definition ldgm.cpp:141
#define DEFAULT_C
Definition ldgm.cpp:142
#define MAX_C
Definition ldgm.cpp:144
#define MINIMAL_VALUE
Definition ldgm.cpp:138
#define DEFAULT_K
Definition ldgm.cpp:140
#define MIN_C
Definition ldgm.cpp:143
#define MAX_K
Definition ldgm.cpp:145
Definition hd-rum.c:27

References DEFAULT_C, DEFAULT_K, DEFAULT_M, init(), MAX_C, MAX_K, MIN_C, MINIMAL_VALUE, and usage().

Here is the call graph for this function:

Member Function Documentation

◆ decode()

bool ldgm::decode ( char * in,
int in_len,
char ** out,
int * out_len,
const std::map< int, int > &  )
virtual
Return values
trueif whole frame was reconstructed
falseif decoder was unable to reconstruct the frame However, if it was reconstructed at least partially (or the code is a systematic one) and length can be read, set len to a non-zero value.

Implements fec.

Definition at line 244 of file ldgm.cpp.

244 {
245 char *decoded;
246 decoded = m_coding_session->decode_frame(frame, size, out_size, packets);
247 if (*out_size > 0) {
248 *out = decoded;
249 return true;
250 } else {
251 return false;
252 }
253}
struct video_frame * frame
std::shared_ptr< LDGM_session > m_coding_session
Definition ldgm.h:66

References frame, and m_coding_session.

◆ encode()

shared_ptr< video_frame > ldgm::encode ( std::shared_ptr< video_frame > tx_frame)
virtual

Implements fec.

Definition at line 426 of file ldgm.cpp.

427{
428 // We need to have copy of coding session shared pointer in order to exit
429 // gracefully even when destructed LDGM state first with some frame still
430 // existing.
431 std::shared_ptr<LDGM_session> coding_session = this->m_coding_session;
432 shared_ptr<video_frame> out(vf_alloc_desc(video_desc_from_frame(tx_frame.get())),
433 [coding_session = std::move(coding_session)](struct video_frame *frame) {
434 for (unsigned int i = 0; i < frame->tile_count; ++i) {
435 coding_session->free_out_buf(frame->tiles[i].data);
436 }
437 vf_free(frame);
438 });
439
440 for (unsigned int i = 0; i < tx_frame->tile_count; ++i) {
441 video_payload_hdr_t video_hdr;
442 format_video_header(tx_frame.get(), i, 0, video_hdr);
443
444 check_packet_size(tx_frame->tiles[i].data_len, m_k);
445
446 int out_size;
447 char *output = m_coding_session->encode_hdr_frame((char *) video_hdr, sizeof(video_hdr),
448 tx_frame->tiles[i].data, tx_frame->tiles[i].data_len, &out_size);
449
450 out->tiles[i].data = output;
451 out->tiles[i].data_len = out_size;
452 }
453
454 out->fec_params.type = FEC_LDGM;
455 out->fec_params.k = m_k;
456 out->fec_params.m = m_m;
457 out->fec_params.c = m_c;
458 out->fec_params.seed = m_seed;
459 out->fec_params.symbol_size = m_coding_session->get_packet_size();
460
461 return out;
462}
void vf_free(struct video_frame *buf)
Frees video_frame structure.
struct video_desc video_desc_from_frame(const struct video_frame *frame)
Returns struct video_desc from video frame.
struct video_frame * vf_alloc_desc(struct video_desc desc)
Allocates video frame accordig given desc.
static void check_packet_size(size_t len, int k)
Definition ldgm.cpp:403
uint32_t video_payload_hdr_t[6]
Definition rtp_types.h:107
unsigned int m_seed
Definition ldgm.h:68
unsigned int m_c
Definition ldgm.h:67
unsigned int m_k
Definition ldgm.h:67
unsigned int m_m
Definition ldgm.h:67
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
void format_video_header(struct video_frame *frame, int tile_idx, int buffer_idx, uint32_t *video_hdr)
Definition transmit.cpp:445
@ FEC_LDGM
Definition types.h:203

References frame, m_coding_session, vf_alloc_desc(), vf_free(), and video_desc_from_frame().

Here is the call graph for this function:

◆ init()

void ldgm::init ( unsigned int k,
unsigned int m,
unsigned int c,
unsigned int seed = DEFAULT_LDGM_SEED )
private

Definition at line 212 of file ldgm.cpp.

213{
214 bool ldgm_device_gpu = false;
215
216 if (get_commandline_param("ldgm-device")) {
217 ldgm_device_gpu = strcasecmp(get_commandline_param("ldgm-device"), "GPU") == 0;
218 }
219
220 if (ldgm_device_gpu) {
221 LDGM_session_gpu *(*loader)();
222 loader = reinterpret_cast<LDGM_session_gpu *(*)()>(
223 const_cast<void *>(
224 load_library("ldgm_gpu",
226 if (!loader) {
227 throw string("GPU accelerated LDGM support is not compiled in");
228 } else {
229 m_coding_session = unique_ptr<LDGM_session>(loader());
230
231 }
232 } else {
233 m_coding_session = unique_ptr<LDGM_session>(new LDGM_session_cpu());
234 }
235
236 set_params(k, m, c, seed);
237}
const char * get_commandline_param(const char *key)
Definition host.cpp:894
#define LDGM_GPU_API_VERSION
Definition ldgm.h:49
const void * load_library(const char *name, enum library_class cls, int abi_version)
@ LIBRARY_CLASS_UNDEFINED
Definition lib_common.h:74
void set_params(unsigned int k, unsigned int m, unsigned int c, unsigned int seed)
Definition ldgm.cpp:161

References get_commandline_param(), LDGM_GPU_API_VERSION, LIBRARY_CLASS_UNDEFINED, load_library(), m_coding_session, and set_params().

Referenced by ldgm(), ldgm(), and ldgm().

Here is the call graph for this function:

◆ set_params()

void ldgm::set_params ( unsigned int k,
unsigned int m,
unsigned int c,
unsigned int seed )

Definition at line 161 of file ldgm.cpp.

162{
163 m_k = k;
164 m_m = m;
165 m_c = c;
166 m_seed = seed;
167
168 m_coding_session->set_params(k, m, c);
169
170 char filename[512];
171 char path[256];
172
173 int res;
174
175#ifdef _WIN32
176 TCHAR tmpPath[MAX_PATH];
177 UINT ret = GetTempPath(MAX_PATH, tmpPath);
178 if(ret == 0 || ret > MAX_PATH) {
179 fprintf(stderr, "Unable to get temporary directory name.\n");
180 throw 1;
181 }
182 snprintf(path, 256, "%s\\ultragrid\\", tmpPath);
183#else
184 snprintf(path, 256, "/var/tmp/ultragrid-%d/", (int) getuid());
185#endif
186
187 res = mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
188 if(res != 0) {
189 if(errno != EEXIST) {
190 perror("mkdir");
191 fprintf(stderr, "[LDGM] Unable to create data directory.\n");
192 throw 1;
193 }
194 }
195 snprintf(filename, 512, "%s/ldgm_matrix-%u-%u-%u-%u.bin", path, k, m, c, seed);
196 if(!file_exists(filename)) {
197 int ret = generate_ldgm_matrix(filename, k, m, c, seed, 0);
198 if(ret != 0) {
199 fprintf(stderr, "[LDGM] Unable to initialize LDGM matrix.\n");
200 throw 1;
201 }
202 }
203
204 m_coding_session->set_pcMatrix(filename);
205
206 MSG(INFO, "Using LDGM with k=%u m=%u c=%u\n", m_k, m_m, m_c);
207}
u32 UINT
Definition cuda_dxt.cu:13
#define MSG(l, fmt,...)
Definition debug.h:96
static bool file_exists(char *filename)
Definition ldgm.cpp:150
int generate_ldgm_matrix(char *fname, unsigned int k, unsigned int m, unsigned int column_weight, unsigned int seed, unsigned int extend_rows)

References file_exists(), generate_ldgm_matrix(), m_c, m_coding_session, m_k, m_m, m_seed, and MSG.

Referenced by init().

Here is the call graph for this function:

Member Data Documentation

◆ m_c

unsigned int ldgm::m_c
private

Definition at line 67 of file ldgm.h.

Referenced by set_params().

◆ m_coding_session

std::shared_ptr<LDGM_session> ldgm::m_coding_session
private

Definition at line 66 of file ldgm.h.

Referenced by decode(), encode(), init(), and set_params().

◆ m_k

unsigned int ldgm::m_k
private

Definition at line 67 of file ldgm.h.

Referenced by set_params().

◆ m_m

unsigned int ldgm::m_m
private

Definition at line 67 of file ldgm.h.

Referenced by set_params().

◆ m_seed

unsigned int ldgm::m_seed
private

Definition at line 68 of file ldgm.h.

Referenced by set_params().


The documentation for this struct was generated from the following files: