Add library OpenFEC v1.4.2

This commit is contained in:
dijunkun
2023-11-09 01:00:39 -08:00
parent f833a503ae
commit 6d89a2aa35
77 changed files with 20282 additions and 1 deletions

View File

@@ -0,0 +1,99 @@
/* $Id: of_codec_profile.h 199 2014-10-21 14:25:02Z roca $ */
/*
* OpenFEC.org AL-FEC Library.
* (c) Copyright 2009 - 2012 INRIA - All rights reserved
* Contact: vincent.roca@inria.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
/****** GENERAL SETUP OPTIONS; EDIT AS APPROPRIATE ****************************/
#define OF_USE_LDPC_STAIRCASE_CODEC
#ifdef OF_DEBUG
/* additional parameter for memory statistic purposes */
#define MEM_STATS_ARG ,ofcb->stats
#define MEM_STATS ,stats
#else
#define MEM_STATS_ARG
#define MEM_STATS
#endif
/**
* Define if you want to enable the use of the ML (Maximum Likelyhood) decoding.
* If enabled, in practice decoding will start with IT decoding and end with ML
* decoding (in this case a Gaussian Elimination) if needed.
*
* Warning: ML decoding enables to reach the best erasure recovery capabilities,
* at the expense of potentially significant computation loads, depending on
* the size and complexity of the simplified system at the end of IT decoding.
*
* See the MAX_NB_SOURCE_SYMBOLS_DEFAULT/MAX_NB_ENCODING_SYMBOLS_DEFAULT
* constants that enable to limit the computation overheads.
*/
#define ML_DECODING
#ifdef ML_DECODING
#define OF_LDPC_STAIRCASE_ML_DECODING
#endif
/**
* Define IL_SUPPORT in debug mode if you want to have the possibility to
* produce H/G matrix images, e.g. to include in a report on new LDPC code
* evaluation.
* More precisely, we are relying on the DevIL library (http://openil.sourceforge.net/).
* Please install it on your machine before compiling the OpenFEC library
* if needed.
*/
//#define IL_SUPPORT
/**
* Default maximum number of source and encoding symbols for this codec.
* This value depends in particular on the kind of decoder used. To this
* limit, codec implementation details might add other limits (e.g. if
* the ESI values are stored in UINT16 instead of UINT32...).
*
* Hints:
* If ML decoding is enabled and used, then limit yourself to a value
* that is not too high, since decoding might finish with a Gaussian
* elimination on the simplified system.
* In situations where decoding is restricted to IT, the main limit is
* the available memory. It usually means you can set very large values.
*/
#ifndef OF_LDPC_STAIRCASE_MAX_NB_SOURCE_SYMBOLS_DEFAULT
#ifdef ML_DECODING
#define OF_LDPC_STAIRCASE_MAX_NB_SOURCE_SYMBOLS_DEFAULT 50000
#define OF_LDPC_STAIRCASE_MAX_NB_ENCODING_SYMBOLS_DEFAULT 50000
#else
#define OF_LDPC_STAIRCASE_MAX_NB_SOURCE_SYMBOLS_DEFAULT 100000
#define OF_LDPC_STAIRCASE_MAX_NB_ENCODING_SYMBOLS_DEFAULT 100000
#endif
#endif

View File

@@ -0,0 +1,57 @@
/* $Id: of_ldpc_includes.h 189 2014-07-16 08:53:50Z roca $ */
/*
* OpenFEC.org AL-FEC Library.
* (c) Copyright 2009 - 2012 INRIA - All rights reserved
* Contact: vincent.roca@inria.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
#ifndef OF_LDPC_INCLUDES
#define OF_LDPC_INCLUDES
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "../../lib_common/of_openfec_api.h"
/*
* the remaining includes will only be considered if of_codec_profile.h is
* included above by of_openfec_api.h => of_openfec_profile.h
*/
#ifdef OF_USE_LDPC_STAIRCASE_CODEC
#include "../../lib_common/linear_binary_codes_utils/of_linear_binary_code.h"
#include "of_ldpc_staircase_api.h"
#include "of_ldpc_staircase.h"
#endif //OF_USE_LDPC_STAIRCASE_CODEC
#endif //OF_LDPC_INCLUDES

View File

@@ -0,0 +1,328 @@
/* $Id: of_ldpc_staircase.h 184 2014-07-15 09:42:57Z roca $ */
/*
* OpenFEC.org AL-FEC Library.
* (c) Copyright 2009 - 2012 INRIA - All rights reserved
* Contact: vincent.roca@inria.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
#ifdef OF_USE_LDPC_STAIRCASE_CODEC
#ifndef OF_LDPC_STAIRCASE_H
#define OF_LDPC_STAIRCASE_H
/**
* LDPC-Staircase stable codec specific control block structure.
*/
typedef struct of_ldpc_staircase_cb
{
/****** of_linear_binary_code_cb part { *******************************/
/****** of_cb part { **************************************************/
of_codec_id_t codec_id;
of_codec_type_t codec_type;
UINT32 nb_source_symbols; /** k parameter (AKA code dimension). */
UINT32 nb_repair_symbols; /** r = n - k parameter. */
UINT32 encoding_symbol_length; /** symbol length. */
/****** } of_cb part **************************************************/
UINT32 nb_total_symbols; /** n parameter (AKA code length). */
/* parity check matrix */
of_mod2sparse *pchk_matrix;
/** usage statistics for this codec instance. */
of_symbol_stats_op_t *stats_xor;
#ifdef OF_DEBUG
of_symbols_stats_t *stats_symbols;
#endif
UINT32 nb_source_symbol_ready; // Number of source symbols ready
UINT32 nb_repair_symbol_ready; // Number of parity symbols ready
#ifdef ML_DECODING /* { */
UINT32 *index_rows; // Indirection index to access initial m_chekValues array
UINT32 *index_cols; // Indirection index to access initial symbol array
UINT32 remain_cols; // Nb of non empty remaining cols in the future simplified matrix
UINT32 remain_rows; // Nb of non empty remaining rows in the future simplified matrix
of_mod2sparse *pchk_matrix_simplified; // Simplified Parity Check Matrix in sparse mode format
of_mod2sparse *original_pchkMatrix;
of_mod2sparse *pchk_matrix_gauss; // Parity Check matrix in sparse mode format.
UINT32 dec_step; // Current step in the Gauss decoding algorithm
UINT32 threshold_simplification; // threshold (number of symbols) above which we
// run the Gaussian Elimination algorithm
#endif /* } ML_DECODING */
#ifdef OF_USE_DECODER /* { */
/** table of all check values, i.e. that contain the constant term of each equation. */
void** tab_const_term_of_equ;
/** table containing the number of encoding symbols of each equation. */
UINT16* tab_nb_enc_symbols_per_equ;
/** table containing the number of unknow symbols (i.e. neither received nor decoded
* at that time) of each equation. */
UINT16* tab_nb_unknown_symbols;
/** table containing the number of equations in which a repair symbol is included. */
UINT16* tab_nb_equ_for_repair;
void** repair_symbols_values;
void** tmp_tab_symbols;
UINT16 nb_tmp_symbols;
#endif /* } OF_USE_DECODER */
void **encoding_symbols_tab;
/** callbacks registered by the application. */
void* (*decoded_source_symbol_callback) (void *context,
UINT32 size, /* size of decoded source symbol */
UINT32 esi); /* encoding symbol ID in {0..k-1} */
void* (*decoded_repair_symbol_callback) (void *context,
UINT32 size, /* size of decoded repair symbol */
UINT32 esi); /* encoding symbol ID in {0..k-1} */
void* context_4_callback;
/****** } of_linear_binary_code_cb part *******************************/
/** Maximum number of source symbols supported by this codec for practical reasons. */
UINT32 max_nb_source_symbols;
/** Maximum number of encoding symbols supported by this codec for practical reasons. */
UINT32 max_nb_encoding_symbols;
/** Seed used to build this code. */
UINT32 prng_seed;
/** Target number or "1s" per column for H1 (see RFC5170). */
UINT8 N1;
/** During H1 creation, have extra entries been added per row to make the row hamming weight at least two? */
bool extra_entries_added_in_pchk;
/** ESI of first non decoded source symbol. Used by is_decoding_complete function. */
UINT32 first_non_decoded;
} of_ldpc_staircase_cb_t;
/*
* Function prototypes.
*/
/**
* This function create the codec instance for the LDPC-SC codec.
*
* @fn of_status_t of_ldpc_staircase_create_codec_instance (of_ldpc_staircase_cb_t** of_cb)
* @brief create a LDPC-SC codec instance
* @param of_cb (IN/OUT) address of the pointer to a LDPC-SC codec control block. This pointer is updated
* by this function.
* In case of success, it points to a session structure allocated by the
* library. In case of failure it points to NULL.
* @return Error status. The ofcb pointer is updated according to the success return
* status.
*/
of_status_t of_ldpc_staircase_create_codec_instance (of_ldpc_staircase_cb_t** of_cb);
/**
* This function releases all the internal resources used by this FEC codec instance.
* None of the source symbol buffers will be free'ed by this function, even those decoded by
* the library if any, regardless of whether a callback has been registered or not. It's the
* responsibility of the caller to free them.
*
* @fn of_status_t of_ldpc_staircase_release_codec_instance (of_ldpc_staircase_cb_t* ofcb)
* @brief release all resources used by the codec
* @param ofcb (IN) Pointer to the control block.
* @return Error status.
*/
of_status_t of_ldpc_staircase_release_codec_instance (of_ldpc_staircase_cb_t* ofcb);
/**
*
* @fn of_status_t of_ldpc_staircase_set_fec_parameters (of_ldpc_staircase_cb_t* ofcb, of_ldpc_parameters_t* params)
* @brief set all the FEC codec parameters (e.g. k, n, or symbol size)
* @param ofcb (IN) Pointer to the control block.
* @param params (IN) pointer to a structure containing the FEC parameters associated to
* a specific FEC codec.
* @return Error status.
*/
of_status_t of_ldpc_staircase_set_fec_parameters (of_ldpc_staircase_cb_t* ofcb,
of_ldpc_parameters_t* params);
/**
* @fn of_status_t of_ldpc_staircase_set_callback_functions (of_ldpc_staircase_cb_t *ofcb,void* (*decoded_source_symbol_callback)
* (void *context,UINT32 size,UINT32 esi), void* (*decoded_repair_symbol_callback)
* (void *context,UINT32 size,UINT32 esi),void* context_4_callback)
* @brief set various callbock functions (see header of_open_fec_api.h)
* @param ofcb (IN) Pointer to the session.
*
* @param decoded_source_symbol_callback
* (IN) Pointer to the function, within the application, that
* needs to be called each time a source symbol is decoded.
* If this callback is not initialized, the symbol is managed
* internally.
*
* @param decoded_repair_symbol_callback
* (IN) Pointer to the function, within the application, that
* needs to be called each time a repair symbol is decoded.
* If this callback is not initialized, the symbol is managed
* internally.
*
* @param context_4_callback (IN) Pointer to the application-specific context that will be
* passed to the callback function (if any). This context is not
* interpreted by this function.
*
* @return Completion status (LDPC_OK or LDPC_ERROR).
*/
of_status_t of_ldpc_staircase_set_callback_functions (of_ldpc_staircase_cb_t* ofcb,
void* (*decoded_source_symbol_callback) (void *context,
UINT32 size, /* size of decoded source symbol */
UINT32 esi), /* encoding symbol ID in {0..k-1} */
void* (*decoded_repair_symbol_callback) (void *context,
UINT32 size, /* size of decoded repair symbol */
UINT32 esi), /* encoding symbol ID in {0..k-1} */
void* context_4_callback);
#ifdef OF_USE_ENCODER
/**
* @fn of_status_t of_ldpc_staircase_build_repair_symbol (of_ldpc_staircase_cb_t* ofcb, void* encoding_symbols_tab[], UINT32 esi_of_symbol_to_build)
* @brief build a repair symbol (encoder only)
* @param ofcb (IN) Pointer to the session.
* @param encoding_symbols_tab (IN/OUT) table of source and repair symbols.
* The entry for the repair symbol to build can either point
* to a buffer allocated by the application, or let to NULL
* meaning that of_build_repair_symbol will allocate memory.
* @param esi_of_symbol_to_build
* (IN) encoding symbol ID of the repair symbol to build in
* {k..n-1}
* @return Error status.
*/
of_status_t of_ldpc_staircase_build_repair_symbol (of_ldpc_staircase_cb_t* ofcb,
void* encoding_symbols_tab[],
UINT32 esi_of_symbol_to_build);
#endif //OF_USE_ENCODER
#ifdef OF_USE_DECODER
/**
* @fn of_status_t of_ldpc_staircase_decode_with_new_symbol (of_ldpc_staircase_cb_t* ofcb, void* const new_symbol_buf, UINT32 new_symbol_esi)
* @brief (try to) decode with a newly received symbol
* @param ofcb (IN) Pointer to the session.
* @param new_symbol (IN) Pointer to the encoding symbol now available (i.e. a new
* symbol received by the application, or a decoded symbol in case
* of a recursive call).
* @param new_symbol_esi (IN) Encoding symbol ID of the newly symbol available, in {0..n-1}.
* @return Error status (NB: this function does not return OF_STATUS_FAILURE).
*/
of_status_t of_ldpc_staircase_decode_with_new_symbol (of_ldpc_staircase_cb_t* ofcb,
void* new_symbol,
UINT32 new_symbol_esi);
/**
* @fn of_status_t of_ldpc_staircase_set_available_symbols (of_ldpc_staircase_cb_t* ofcb, void* const encoding_symbols_tab[]);
* @brief inform the decoder of all the available (received) symbols
* @param ofcb (IN) Pointer to the session.
* @param encoding_symbols_tab (IN) Pointer to the available encoding symbols table. To each
* available symbol the corresponding entry in the table must point
* to the associated buffer. Entries set to NULL are interpreted as
* corresponding to erased symbols.
* @return Error status.
*/
of_status_t of_ldpc_staircase_set_available_symbols (of_ldpc_staircase_cb_t* ofcb,
void* const encoding_symbols_tab[]);
/**
* @fn of_status_t of_ldpc_staircase_finish_decoding (of_ldpc_staircase_cb_t* ofcb)
* @brief finish decoding with available symbols
* @param ofcb (IN) Pointer to the session.
* @return Error status. Returns OF_STATUS_FAILURE if decoding failed, or
* OF_STATUS_OK if decoding succeeded, or OF_STATUS_*_ERROR in case
* of (fatal) error.
*/
of_status_t of_ldpc_staircase_finish_decoding (of_ldpc_staircase_cb_t* ofcb);
/**
* @fn bool of_ldpc_staircase_is_decoding_complete (of_ldpc_staircase_cb_t* ofcb)
* @brief check if decoding is finished
* @param ofcb (IN) Pointer to the session.
* @return Boolean. Warning, this is one of the very functions of the library that
* does not return an error status.
*/
bool of_ldpc_staircase_is_decoding_complete (of_ldpc_staircase_cb_t* ofcb);
/**
* @fn of_status_t of_ldpc_staircase_get_source_symbols_tab (of_ldpc_staircase_cb_t* ofcb, void* source_symbols_tab[])
* @brief get the table of available source symbols (after decoding)
* @param ofcb (IN) Pointer to the session.
* @param source_symbols_tab (IN/OUT) table, that will be filled by the library and returned
* to the application.
* @return Error status.
*/
of_status_t of_ldpc_staircase_get_source_symbols_tab (of_ldpc_staircase_cb_t* ofcb,
void* source_symbols_tab[]);
/**
* @fn of_status_t of_ldpc_staircase_set_control_parameter (of_ldpc_staircase_cb_t* ofcb,UINT32 type,void* value,UINT32 length)
* @brief set a specific FEC parameter
* @param ofcb (IN) Pointer to the session.
* @param type (IN) Type of parameter. This type is FEC codec ID specific.
* @param value (IN) Pointer to the value of the parameter. The type of the object pointed
* is FEC codec ID specific.
* @param length (IN) length of pointer value
* @return Error status.
*/
of_status_t of_ldpc_staircase_set_control_parameter(of_ldpc_staircase_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length);
/**
* @fn of_status_t of_ldpc_staircase_get_control_parameter (of_ldpc_staircase_cb_t* ofcb, UINT32 type, void* value, UINT32 length)
* @brief get a specific FEC parameter
* @param ofcb (IN) Pointer to the session.
* @param type (IN) Type of parameter. This type is FEC codec ID specific.
* @param value (IN/OUT) Pointer to the value of the parameter. The type of the object
* pointed is FEC codec ID specific. This function updates the value object
* accordingly. The application, who knows the FEC codec ID, is responsible
* to allocating the approriate object pointed by the value pointer.
* @param length (IN) length of pointer value
* @return Error status.
*/
of_status_t of_ldpc_staircase_get_control_parameter(of_ldpc_staircase_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length);
/**
* @brief Create the LDPC-Staircase matrix as defined in RFC 5170.
* @param nb_rows (IN) number of rows, also equal to n-k.
* @param nb_cols (IN) number of columns, also equal to n.
* @param left_degree (IN) another name of the N1 parameter.
* @param seed (IN) seed to use for the PRNG.
* @param ofcb (IN/OUT)
* @return pointer to the parity check matrix that has just been allocated and initialized.
*/
of_mod2sparse* of_create_pchck_matrix_rfc5170_compliant (UINT32 nb_rows,
UINT32 nb_cols,
UINT32 left_degree,
UINT32 seed,
of_ldpc_staircase_cb_t *ofcb);
#endif //OF_USE_DECODER
#endif //OF_LDPC_STAIRCASE_H
#endif /* #ifdef OF_USE_LDPC_STAIRCASE_CODEC */

View File

@@ -0,0 +1,570 @@
/* $Id: of_ldpc_staircase_api.c 186 2014-07-16 07:17:53Z roca $ */
/*
* OpenFEC.org AL-FEC Library.
* (c) Copyright 2009 - 2012 INRIA - All rights reserved
* Contact: vincent.roca@inria.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
#include "of_ldpc_includes.h"
#ifdef OF_USE_LDPC_STAIRCASE_CODEC
of_status_t of_ldpc_staircase_create_codec_instance (of_ldpc_staircase_cb_t** of_cb)
{
of_codec_type_t codec_type; /* temporary value */
of_ldpc_staircase_cb_t *cb;
OF_ENTER_FUNCTION
cb = (of_ldpc_staircase_cb_t*) of_realloc (*of_cb, sizeof (of_ldpc_staircase_cb_t));
/* realloc does not initialize the additional buffer space, so do that manually,
* then re-initialize a few parameters */
codec_type = cb->codec_type;
memset(cb, 0, sizeof(*cb));
*of_cb = cb;
cb->codec_id = OF_CODEC_LDPC_STAIRCASE_STABLE;
cb->codec_type = codec_type;
cb->max_nb_source_symbols = OF_LDPC_STAIRCASE_MAX_NB_SOURCE_SYMBOLS_DEFAULT; /* init it immediately... */
cb->max_nb_encoding_symbols = OF_LDPC_STAIRCASE_MAX_NB_ENCODING_SYMBOLS_DEFAULT; /* init it immediately... */
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
of_status_t of_ldpc_staircase_release_codec_instance (of_ldpc_staircase_cb_t* ofcb)
{
OF_ENTER_FUNCTION
UINT32 i;
if (ofcb->pchk_matrix != NULL)
{
of_mod2sparse_free(ofcb->pchk_matrix);
of_free (ofcb->pchk_matrix);
ofcb->pchk_matrix = NULL;
}
if (ofcb->encoding_symbols_tab != NULL)
{
/* do not try to free source buffers, it's the responsibility of the application
* using this library to free everything. Only try to free repair symbols. */
for (i = ofcb->nb_source_symbols; i < ofcb->nb_total_symbols; i++)
{
if (ofcb->encoding_symbols_tab[i] != NULL)
{
of_free (ofcb->encoding_symbols_tab[i]);
ofcb->encoding_symbols_tab[i] = NULL;
}
}
of_free (ofcb->encoding_symbols_tab);
ofcb->encoding_symbols_tab = NULL;
}
#ifdef OF_USE_DECODER
if (ofcb->codec_type & OF_DECODER)
{
if (ofcb->tmp_tab_symbols != NULL)
{
of_free(ofcb->tmp_tab_symbols);
ofcb->tmp_tab_symbols = NULL;
}
if (ofcb->tab_nb_enc_symbols_per_equ != NULL)
{
of_free (ofcb->tab_nb_enc_symbols_per_equ);
ofcb->tab_nb_enc_symbols_per_equ = NULL;
}
if (ofcb->tab_nb_equ_for_repair != NULL)
{
of_free (ofcb->tab_nb_equ_for_repair);
ofcb->tab_nb_equ_for_repair = NULL;
}
if (ofcb->tab_nb_unknown_symbols != NULL)
{
of_free (ofcb->tab_nb_unknown_symbols);
ofcb->tab_nb_unknown_symbols = NULL;
}
if (ofcb->tab_const_term_of_equ != NULL)
{
for (i = 0; i < ofcb->nb_repair_symbols; i++)
{
if (ofcb->tab_const_term_of_equ[i] != NULL)
{
of_free (ofcb->tab_const_term_of_equ[i]);
ofcb->tab_const_term_of_equ[i] = NULL;
}
}
of_free(ofcb->tab_const_term_of_equ);
}
of_free(ofcb->tmp_tab_symbols);
ofcb->tmp_tab_symbols=NULL;
}
#endif
#ifdef OF_LDPC_STAIRCASE_ML_DECODING
if (ofcb->index_rows != NULL)
{
of_free (ofcb->index_rows);
ofcb->index_rows = NULL;
}
if (ofcb->index_cols != NULL)
{
of_free (ofcb->index_cols);
ofcb->index_cols = NULL;
}
if (ofcb->pchk_matrix_simplified != NULL)
{
of_mod2sparse_free (ofcb->pchk_matrix_simplified);
of_free(ofcb->pchk_matrix_simplified);
ofcb->pchk_matrix_simplified = NULL;
}
if (ofcb->original_pchkMatrix != NULL)
{
of_mod2sparse_free (ofcb->original_pchkMatrix);
ofcb->original_pchkMatrix = NULL;
}
if (ofcb->pchk_matrix_gauss != NULL)
{
of_mod2sparse_free (ofcb->pchk_matrix_gauss);
ofcb->pchk_matrix_gauss = NULL;
}
#endif
#ifdef OF_DEBUG
if (ofcb->stats_xor != NULL) {
of_print_xor_symbols_statistics(ofcb->stats_xor);
of_free(ofcb->stats_xor);
}
if (ofcb->stats_symbols != NULL) {
of_free(ofcb->stats_symbols);
}
#endif
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
of_status_t of_ldpc_staircase_set_fec_parameters (of_ldpc_staircase_cb_t* ofcb,
of_ldpc_parameters_t* params)
{
of_mod2entry *e;
UINT32 row;
UINT32 seq;
OF_ENTER_FUNCTION
#ifdef OF_DEBUG
ofcb->stats_xor = of_calloc(1, sizeof(of_symbol_stats_op_t));
ofcb->stats_symbols = of_calloc(1, sizeof(of_symbols_stats_t));
#endif
if (params->N1 < 3)
{
OF_PRINT_ERROR(("of_ldpc_staircase_set_fec_parameters: invalid N1 value (%d), must be at least equal to 3.\n",
params->N1))
goto error;
}
if ((ofcb->nb_source_symbols = params->nb_source_symbols) > ofcb->max_nb_source_symbols)
{
OF_PRINT_ERROR(("of_ldpc_staircase_set_fec_parameters: ERROR, invalid nb_source_symbols parameter (got %d, maximum is %d)\n",
ofcb->nb_source_symbols, ofcb->max_nb_source_symbols));
goto error;
}
if ((ofcb->nb_repair_symbols = params->nb_repair_symbols) > ofcb->max_nb_encoding_symbols)
{
/* this test is needed because if the number of repair symbols is
* erroneously < 0, because we are using UINT32, this is transformed
* into a very large integer, which, when added to k, wraps once again
* and the test on nb_total_symbols returns true... */
OF_PRINT_ERROR(("of_ldpc_staircase_set_fec_parameters: ERROR, invalid number of repair symbols (got %d, maximum number of encoding symbols is %d)\n",
ofcb->nb_repair_symbols, ofcb->max_nb_encoding_symbols));
goto error;
}
ofcb->nb_total_symbols = ofcb->nb_source_symbols + ofcb->nb_repair_symbols;
if (ofcb->nb_total_symbols > ofcb->max_nb_encoding_symbols)
{
OF_PRINT_ERROR(("of_ldpc_staircase_set_fec_parameters: ERROR, invalid number of encoding symbols (got %d, maximum is %d)\n",
ofcb->nb_total_symbols, ofcb->max_nb_encoding_symbols));
goto error;
}
ofcb->encoding_symbol_length = params->encoding_symbol_length;
ofcb->prng_seed = params->prng_seed;
ofcb->N1 = params->N1;
OF_TRACE_LVL (1, ("%s: k=%u, n-k=%u, n=%u, symbol_length=%u, PRNG seed=%u, N1=%u\n", __FUNCTION__,
ofcb->nb_source_symbols, ofcb->nb_repair_symbols, ofcb->nb_total_symbols,
ofcb->encoding_symbol_length, ofcb->prng_seed, ofcb->N1))
/* it's now time to create the parity check matrix! */
ofcb->pchk_matrix = of_create_pchck_matrix_rfc5170_compliant
(ofcb->nb_repair_symbols,
ofcb->nb_total_symbols,
ofcb->N1,
ofcb->prng_seed,
ofcb);
if (ofcb->pchk_matrix == NULL)
{
OF_PRINT_ERROR(("of_ldpc_staircase_set_fec_parameters : ERROR, parity check matrix can't be created with this parameters..\n"))
goto error;
}
#ifdef IL_SUPPORT
/* print the matrix using the DevIL library */
of_mod2sparse_print_bitmap(ofcb->pchk_matrix);
#else
//of_mod2sparse_matrix_stats(stdout,ofcb->pchk_matrix,ofcb->nb_source_symbols, ofcb->nb_repair_symbols);
#endif
//#define PRINT_LDGM_VARIANT /* enable this constant to get a trace of the identity version of H */
#if defined(OF_DEBUG) && defined(PRINT_LDGM_VARIANT) && defined(IL_SUPPORT)
{
/*
* calculate and plot the identity variant, H_id, where the staircase is replaced by an identity.
* This is only for curiosity/research purposes. DO NOT use it otherwise.
*/
of_mod2dense *dm = NULL;
dm = of_mod2dense_allocate(ofcb->nb_repair_symbols, ofcb->nb_total_symbols, NULL);
of_mod2sparse_to_dense(ofcb->pchk_matrix, dm);
for (row = 0; row < ofcb->nb_repair_symbols - 1; row++)
{
of_mod2dense_xor_rows(dm, row, row + 1);
}
of_mod2dense_print_bitmap(dm);
of_mod2dense_density(dm);
of_mod2dense_free(dm, NULL);
}
#endif
if ((ofcb->encoding_symbols_tab = (void**) of_calloc (ofcb->nb_total_symbols, sizeof (void*))) == NULL) {
goto no_mem;
}
#ifdef OF_USE_DECODER
if (ofcb->codec_type & OF_DECODER)
{
ofcb->tab_nb_unknown_symbols = (UINT16*)
of_calloc (ofcb->nb_repair_symbols, sizeof (UINT16));
ofcb->tab_const_term_of_equ = (void**)
of_calloc (ofcb->nb_repair_symbols, sizeof (void*));
ofcb->tab_nb_equ_for_repair = (UINT16*)
of_calloc (ofcb->nb_repair_symbols, sizeof (UINT16));
ofcb->tab_nb_enc_symbols_per_equ = (UINT16*)
of_calloc (ofcb->nb_repair_symbols, sizeof (UINT16));
if (ofcb->tab_nb_unknown_symbols == NULL || ofcb->tab_const_term_of_equ == NULL ||
ofcb->tab_nb_equ_for_repair == NULL || ofcb->tab_nb_enc_symbols_per_equ == NULL) {
goto no_mem;
}
// and update the various tables now
for (row = 0; row < ofcb->nb_repair_symbols; row++)
{
for (e = of_mod2sparse_first_in_row (ofcb->pchk_matrix, row);
!of_mod2sparse_at_end (e);
e = of_mod2sparse_next_in_row (e))
{
ofcb->tab_nb_enc_symbols_per_equ[row]++;
ofcb->tab_nb_unknown_symbols[row]++;
}
}
for (seq = ofcb->nb_source_symbols; seq < (ofcb->nb_total_symbols); seq++)
{
for (e = of_mod2sparse_first_in_col (ofcb->pchk_matrix, of_get_symbol_col ((of_cb_t*)ofcb, seq));
!of_mod2sparse_at_end (e);
e = of_mod2sparse_next_in_col (e))
{
ofcb->tab_nb_equ_for_repair[seq - ofcb->nb_source_symbols]++;
}
}
ofcb->tmp_tab_symbols = (void**)of_malloc(sizeof(void*)*ofcb->nb_total_symbols);
}
#endif //OF_USE_DECODER
ofcb->nb_source_symbol_ready = 0; // Number of source symbols ready
ofcb->nb_repair_symbol_ready = 0; // Number of parity symbols ready
//ofcb->nb_non_dup_symbols_recvd = 0;// Number of non-duplicated symbols received
#ifdef OF_LDPC_STAIRCASE_ML_DECODING
ofcb->index_rows = NULL; // Indirection index to access initial m_chekValues array
ofcb->index_cols = NULL; // Indirection index to access initial symbol array
ofcb->remain_cols = 0; // Nb of non empty remaining cols in the future simplified matrix
ofcb->remain_rows = 0; // Nb of non empty remaining rows in the future simplified matrix
ofcb->pchk_matrix_simplified = NULL; // Simplified Parity Check Matrix in sparse mode format
ofcb->original_pchkMatrix = NULL;
ofcb->pchk_matrix_gauss = NULL; // Parity Check matrix in sparse mode format. This matrix
// is also used as a generator matrix in LDGM-* modes
ofcb->dec_step = 0; // Current step in the Gauss Elimination algorithm
ofcb->threshold_simplification = 0; // threshold (number of symbols) above which we
// run the Gauss Elimination algorithm
#endif
#ifdef OF_USE_DECODER
/*
* with LDPC-Staircase, if N1 is even, the last repair symbol is often null (if the code rate
* is above a certain threshold), so pretend we received it since we already know its value.
*/
if (ofcb->codec_type & OF_DECODER)
{
bool is_null; /* is last repair symbol null? */
if (of_ldpc_staircase_get_control_parameter(ofcb, OF_CRTL_LDPC_STAIRCASE_IS_LAST_SYMBOL_NULL,
(void*)&is_null, sizeof(is_null)) != OF_STATUS_OK) {
OF_PRINT_ERROR(("%s: ERROR: of_ldpc_staircase_get_control_parameter() failed\n", __FUNCTION__))
goto error;
}
if (is_null)
{
/*
* since the last repair symbol is known to be null, pretent we received it.
*/
void *null_symbol; /* that's the null repair symbol */
if ((null_symbol = of_calloc(1, ofcb->encoding_symbol_length)) == NULL)
{
goto no_mem;
}
OF_TRACE_LVL(1, ("%s: last repair is null, pretend we received it\n", __FUNCTION__))
if (of_ldpc_staircase_decode_with_new_symbol (ofcb, null_symbol, ofcb->nb_total_symbols - 1)
!= OF_STATUS_OK)
{
OF_PRINT_ERROR(("%s: ERROR: of_ldpc_staircase_decode_with_new_symbol() failed\n", __FUNCTION__))
goto error;
}
}
}
#endif //OF_USE_DECODER
OF_EXIT_FUNCTION
return OF_STATUS_OK;
no_mem:
OF_PRINT_ERROR(("out of memory\n"));
error:
OF_EXIT_FUNCTION
return OF_STATUS_FATAL_ERROR;
}
of_status_t of_ldpc_staircase_set_callback_functions (of_ldpc_staircase_cb_t* ofcb,
void* (*decoded_source_symbol_callback) (void *context,
UINT32 size, /* size of decoded source symbol */
UINT32 esi), /* encoding symbol ID in {0..k-1} */
void* (*decoded_repair_symbol_callback) (void *context,
UINT32 size, /* size of decoded repair symbol */
UINT32 esi), /* encoding symbol ID in {k..n-1} */
void* context_4_callback)
{
OF_ENTER_FUNCTION
ofcb->decoded_source_symbol_callback = decoded_source_symbol_callback;
ofcb->decoded_repair_symbol_callback = decoded_repair_symbol_callback;
ofcb->context_4_callback = context_4_callback;
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
#ifdef OF_USE_ENCODER
of_status_t of_ldpc_staircase_build_repair_symbol (of_ldpc_staircase_cb_t* ofcb,
void* encoding_symbols_tab[],
UINT32 esi_of_symbol_to_build)
{
of_mod2entry *e;
UINT32 col_to_build;
UINT32 esi;
void *to_add_buf;
void *parity_symbol;
OF_ENTER_FUNCTION
if (esi_of_symbol_to_build < ofcb->nb_source_symbols || esi_of_symbol_to_build >= ofcb->nb_total_symbols)
{
OF_PRINT_ERROR(("of_ldpc_staircase_build_repair_symbol: Error, bad esi of encoding symbol (%d)\n", esi_of_symbol_to_build))
goto error;
}
parity_symbol = encoding_symbols_tab[esi_of_symbol_to_build];
memset (parity_symbol, 0, ofcb->encoding_symbol_length);
col_to_build = of_get_symbol_col ((of_cb_t*)ofcb, esi_of_symbol_to_build);
e = of_mod2sparse_first_in_row (ofcb->pchk_matrix, col_to_build);
while (!of_mod2sparse_at_end (e))
{
// paritySymbol_index in {0.. n-k-1} range, so this test is ok
if (e->col != col_to_build)
{
// don't add paritySymbol to itself
esi = of_get_symbol_esi ((of_cb_t*)ofcb, e->col);
to_add_buf = (void*) encoding_symbols_tab[esi];
if (to_add_buf == NULL)
{
OF_PRINT_ERROR(("symbol %d is not allocated\n", esi));
goto error;
}
#ifdef OF_DEBUG
of_add_to_symbol (parity_symbol, to_add_buf, ofcb->encoding_symbol_length,&(ofcb->stats_xor->nb_xor_for_IT));
#else
of_add_to_symbol (parity_symbol, to_add_buf, ofcb->encoding_symbol_length);
#endif
}
e = of_mod2sparse_next_in_row (e);
}
OF_TRACE_LVL (1, ("%s: repair symbol (esi=%d) built\n", __FUNCTION__, esi_of_symbol_to_build))
OF_EXIT_FUNCTION
return OF_STATUS_OK;
error:
OF_EXIT_FUNCTION
return OF_STATUS_ERROR;
}
#endif //OF_USE_ENCODER
#ifdef OF_USE_DECODER
of_status_t of_ldpc_staircase_decode_with_new_symbol (of_ldpc_staircase_cb_t* ofcb,
void* new_symbol,
UINT32 new_symbol_esi)
{
OF_ENTER_FUNCTION
return of_linear_binary_code_decode_with_new_symbol((of_linear_binary_code_cb_t*)ofcb, new_symbol, new_symbol_esi);
}
of_status_t of_ldpc_staircase_set_available_symbols (of_ldpc_staircase_cb_t* ofcb,
void* const encoding_symbols_tab[])
{
UINT32 i;
OF_ENTER_FUNCTION
for (i = 0; i < ofcb->nb_total_symbols; i++)
{
if (encoding_symbols_tab[i] == NULL)
{
continue;
}
/* use the decode_with_new_symbol function */
of_linear_binary_code_decode_with_new_symbol((of_linear_binary_code_cb_t*)ofcb, encoding_symbols_tab[i], i);
/* NB: this approach is a little bit sub-optimal with LDPC codes, as symbols are submit for IT decoding in sequence.
* We should consider randomizing this order. */
}
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
of_status_t of_ldpc_staircase_finish_decoding (of_ldpc_staircase_cb_t* ofcb)
{
OF_ENTER_FUNCTION
#ifdef OF_LDPC_STAIRCASE_ML_DECODING
return of_linear_binary_code_finish_decoding_with_ml ((of_linear_binary_code_cb_t*)ofcb);
#else
return OF_STATUS_ERROR;
#endif
}
bool of_ldpc_staircase_is_decoding_complete (of_ldpc_staircase_cb_t* ofcb)
{
for (; ofcb->first_non_decoded < ofcb->nb_source_symbols; ofcb->first_non_decoded++)
{
if (ofcb->encoding_symbols_tab[ofcb->first_non_decoded] == NULL)
{
OF_TRACE_LVL (1, ("decoding not complete (%u source symbols ready, %u expected)\n",
ofcb->nb_source_symbol_ready, ofcb->nb_source_symbols))
//ASSERT(ofcb->nb_source_symbol_ready < ofcb->nb_source_symbols);
return false;
}
}
OF_TRACE_LVL (1, ("decoding is complete\n"))
//ASSERT(ofcb->nb_source_symbol_ready == ofcb->nb_source_symbols);
return true;
}
of_status_t of_ldpc_staircase_get_source_symbols_tab (of_ldpc_staircase_cb_t* ofcb,
void* source_symbols_tab[])
{
OF_ENTER_FUNCTION
/* copy the internal table containing the pointers to all source symbols into the table provided by the caller */
memcpy (source_symbols_tab, ofcb->encoding_symbols_tab, sizeof (void *) * ofcb->nb_source_symbols);
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
#endif //OF_USE_DECODER
of_status_t of_ldpc_staircase_set_control_parameter (of_ldpc_staircase_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length)
{
OF_PRINT_ERROR(("of_ldpc_staircase_set_control_parameter: ERROR, not implemented...\n"))
return OF_STATUS_ERROR;
}
of_status_t of_ldpc_staircase_get_control_parameter (of_ldpc_staircase_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length)
{
OF_ENTER_FUNCTION
switch (type) {
case OF_CTRL_GET_MAX_K:
if (value == NULL || length != sizeof(UINT32)) {
OF_PRINT_ERROR(("%s: OF_CTRL_GET_MAX_K ERROR: null value or bad length (got %d, expected %ld)\n",
__FUNCTION__, length, sizeof(UINT32)))
goto error;
}
*(UINT32*)value = ofcb->max_nb_source_symbols;
OF_TRACE_LVL(1, ("%s: OF_CTRL_GET_MAX_K (%d)\n", __FUNCTION__, *(UINT32*)value))
break;
case OF_CTRL_GET_MAX_N:
if (value == NULL || length != sizeof(UINT32)) {
OF_PRINT_ERROR(("%s: OF_CTRL_GET_MAX_N ERROR: null value or bad length (got %d, expected %ld)\n",
__FUNCTION__, length, sizeof(UINT32)))
goto error;
}
*(UINT32*)value = ofcb->max_nb_encoding_symbols;
OF_TRACE_LVL(1, ("%s: OF_CTRL_GET_MAX_N (%d)\n", __FUNCTION__, *(UINT32*)value))
break;
case OF_CRTL_LDPC_STAIRCASE_IS_LAST_SYMBOL_NULL:
if (ofcb->extra_entries_added_in_pchk == true)
{
/* the parity check matrix does not have exactly N1 "1s" per column, so the
* last repair symbol will not be NULL in general. */
*(bool*)value = false;
OF_TRACE_LVL(1, ("%s: OF_CRTL_LDPC_STAIRCASE_IS_LAST_SYMBOL_NULL (false) (extra entries added in pchk)\n", __FUNCTION__))
}
else
{
/* there are exacly N1 "1s" per column, so if this number if even, the last
* repair symbol is known to be always NULL, no matter the value of the source
* symbols. */
*(bool*)value = ((ofcb->N1 & 0x1) == 0) ? true : false;
OF_TRACE_LVL(1, ("%s: OF_CRTL_LDPC_STAIRCASE_IS_LAST_SYMBOL_NULL (%d)\n", __FUNCTION__, *(bool*)value))
}
break;
default:
OF_PRINT_ERROR(("%s: unknown type (%d)\n", __FUNCTION__, type))
goto error;
}
OF_EXIT_FUNCTION
return OF_STATUS_OK;
error:
OF_EXIT_FUNCTION
return OF_STATUS_ERROR;
}
#endif /* #ifdef OF_USE_LDPC_STAIRCASE_CODEC */

View File

@@ -0,0 +1,82 @@
/* $Id: of_ldpc_staircase_api.h 72 2012-04-13 13:27:26Z detchart $ */
/*
* OpenFEC.org AL-FEC Library.
* (c) Copyright 2009 - 2012 INRIA - All rights reserved
* Contact: vincent.roca@inria.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
#ifdef OF_USE_LDPC_STAIRCASE_CODEC
#ifndef OF_CODEC_STABLE_LDPC_STAIRCASE_API
#define OF_CODEC_STABLE_LDPC_STAIRCASE_API
#include "../../lib_common/of_types.h"
/**
* @struct of_ldpc_parameters_t
* @brief LDPC-Staircase stable codec specific FEC parameter structure.
*
* This structure contains the pieces of information required to initialize a codec instance,
* using the of_set_fec_parameters() function.
*/
typedef struct of_ldpc_parameters
{
UINT32 nb_source_symbols; /* must be 1st item */
UINT32 nb_repair_symbols; /* must be 2nd item */
UINT32 encoding_symbol_length; /* must be 3rd item */
/*
* FEC codec id specific attributes follow...
*/
INT32 prng_seed;
UINT8 N1;
} of_ldpc_parameters_t;
/**
* Control parameters for of_set_control_parameter()/of_get_control_parameter() functions:
* - range {0 .. 1023} inclusive are for generic parameters;
* - range {1024 .. above} inclusive are for code/codec specific parameters (and different
* codecs can re-use the same value);
* The "void * value" type depends on the type.
*/
/**
* Ask the OF library if the last repair symbol of an LDPC-Staircase code is equal to zero
* or not. This is used for various optimizations (e.g. it's useless to transmit a symbol
* that is known to be null). This call returns 1 if the property is true (i.e. the last
* repair symbol is actually NULL), 0 otherwise.
* Argument: bool
*/
#define OF_CRTL_LDPC_STAIRCASE_IS_LAST_SYMBOL_NULL 1024
#endif /* OF_CODEC_STABLE_LDPC_SCSTAIRCASE_API */
#endif /*#ifdef OF_USE_LDPC_STAIRCASE_CODEC */

View File

@@ -0,0 +1,181 @@
/* $Id: of_ldpc_staircase_pchk.c 184 2014-07-15 09:42:57Z roca $ */
/*
* The contents of this directory and its sub-directories are
* Copyright (c) 1995-2003 by Radford M. Neal
*
* Permission is granted for anyone to copy, use, modify, or distribute these
* programs and accompanying documents for any purpose, provided this copyright
* notice is retained and prominently displayed, along with a note saying
* that the original programs are available from Radford Neal's web page, and
* note is made of any changes made to these programs. These programs and
* documents are distributed without any warranty, express or implied. As the
* programs were written for research purposes only, they have not been tested
* to the degree that would be advisable in any important application. All use
* of these programs is entirely at the user's own risk.
*/
/*
* OpenFEC.org AL-FEC Library.
* (c) Copyright 2009 - 2011 INRIA - All rights reserved
* Contact: vincent.roca@inria.fr
*
* This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*/
#include "of_ldpc_includes.h"
#ifdef OF_USE_LDPC_STAIRCASE_CODEC
/* RFC5170 compliant fonction. DO NOT MODIFY */
of_mod2sparse* of_create_pchck_matrix_rfc5170_compliant (UINT32 nb_rows,
UINT32 nb_cols,
UINT32 left_degree,
UINT32 seed,
of_ldpc_staircase_cb_t *ofcb)
{
OF_ENTER_FUNCTION
of_mod2entry *e;
UINT32 added, uneven;
INT32 i, j, k;
INT32 t; /* left limit within the list of possible choices u[] */
UINT32 *u; /* table used to have a homogeneous 1 distrib. */
of_mod2sparse *pchkMatrix = NULL;
UINT32 skipCols = 0; // avoid warning
UINT32 nbDataCols = 0; // avoid warning
skipCols = nb_rows;
nbDataCols = nb_cols - skipCols;
/* a few sanity checks... */
if (left_degree > nb_rows)
{
OF_PRINT_ERROR(("number of 1s per column (i.e. N1=%d parameter) is greater than total number of rows (i.e. n-k=%d)\n",
left_degree, nb_rows));
OF_EXIT_FUNCTION
return NULL;
}
of_rfc5170_srand (seed);
pchkMatrix = of_mod2sparse_allocate (nb_rows, nb_cols);
/* create the initial version of the parity check matrix. */
/* evenboth make method only */
u = (UINT32*) of_calloc (left_degree * nbDataCols, sizeof * u);
/* initialize a list of possible choices to guarantee a homogeneous "1" distribution */
for (k = left_degree * nbDataCols - 1; k >= 0; k--)
{
u[k] = k % nb_rows;
}
uneven = 0;
t = 0; /* left limit within the list of possible choices, u[] */
for (j = skipCols; j < nb_cols; j++)
{
/* for each source symbol column */
for (k = 0; k < left_degree; k++)
{
/* add left_degree "1s" */
/* check that valid available choices remain */
for (i = t; i < left_degree * nbDataCols && of_mod2sparse_find (pchkMatrix, u[i], j); i++)
;
if (i < left_degree * nbDataCols)
{
/* choose one index within the list of possible choices */
do
{
i = t + of_rfc5170_rand (left_degree * nbDataCols - t);
}
while (of_mod2sparse_find (pchkMatrix, u[i], j));
of_mod2sparse_insert (pchkMatrix, u[i], j);
/* replace with u[t] which has never been chosen */
u[i] = u[t];
t++;
}
else
{
/* no choice left, choose one randomly.
* This happens if we're not lucky and if in the remaining possible
* choices, for instance for the last source symbol, the same row
* appears several times. */
uneven += 1;
do
{
i = of_rfc5170_rand (nb_rows);
}
while (of_mod2sparse_find (pchkMatrix, i, j));
of_mod2sparse_insert (pchkMatrix, i, j);
}
}
}
if (uneven > 0 && of_verbosity >= 1)
{
OF_PRINT_LVL(1, ("%s: Had to place %d checks in rows unevenly\n", __FUNCTION__, uneven))
}
of_free (u); /* VR: added */
/* Add extra bits to avoid rows with less than two checks. */
added = 0;
for (i = 0; i < nb_rows; i++)
{
e = of_mod2sparse_first_in_row (pchkMatrix, i);
if (of_mod2sparse_at_end (e))
{
j = (of_rfc5170_rand (nbDataCols)) + skipCols;
e = of_mod2sparse_insert (pchkMatrix, i, j);
added ++;
}
e = of_mod2sparse_first_in_row (pchkMatrix, i);
if (of_mod2sparse_at_end (of_mod2sparse_next_in_row (e)) && nbDataCols > 1)
{
do
{
j = (of_rfc5170_rand (nbDataCols)) + skipCols;
}
while (j == of_mod2sparse_col (e));
of_mod2sparse_insert (pchkMatrix, i, j);
added ++;
}
}
if (added >= 1)
{
ofcb->extra_entries_added_in_pchk = 1;
OF_TRACE_LVL(1,("%s: Added %d extra bit-checks to make row Hamming weight at least two\n", __FUNCTION__, added));
}
else
{
ofcb->extra_entries_added_in_pchk = 0; /* nothing added, there are exactly N1 entries per column. */
}
/* finally, create the staircase */
of_mod2sparse_insert (pchkMatrix, 0, 0); /* 1st row */
for (i = 1; i < nb_rows; i++)
{
/* for all other rows */
/* identity */
of_mod2sparse_insert (pchkMatrix, i, i);
/* staircase */
of_mod2sparse_insert (pchkMatrix, i, i - 1);
}
OF_EXIT_FUNCTION
return pchkMatrix;
}
#endif /* #ifdef OF_USE_LDPC_STAIRCASE_CODEC */