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,319 @@
/* $Id: of_2d_parity.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-C 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_2D_PARITY_MATRIX_CODEC
#ifndef OF_2D_PARITY_H
#define OF_2D_PARITY_H
typedef struct of_2d_symbol_stats_op
{
UINT32 nb_xor_for_IT;
UINT32 nb_xor_for_ML;
} of_2d_symbol_stats_op_t;
/**
* 2d-parity stable codec specific control block structure.
*/
typedef struct of_2d_parity_cb
{
/*****************************************************************************
* of_linear_binary_code_cb *
******************************************************************************/
/* *
************************************************************************** *
* of_cb_t * *
************************************************************************** */
of_codec_id_t codec_id; /* must begin with fec_codec_id * */
of_codec_type_t codec_type; /* must be 2nd item * */
UINT32 nb_source_symbols; /** k parameter (AKA code dimension).* */
UINT32 nb_repair_symbols; /** r = n - k parameter. * */
UINT32 encoding_symbol_length; /** symbol length. * */
/************************************************************************* */
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.
// This matrix is also used as a generator matrix
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;
#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;/* */
/*****************************************************************************/
/** 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;
/** ESI of first non decoded source symbol.
* Used by is_decoding_complete function. */
UINT32 first_non_decoded;
} of_2d_parity_cb_t;
/*
* Function prototypes.
*/
/**
* This function create the codec instance for the 2D parity codec.
*
* @fn of_status_t of_2d_parity_create_codec_instance (of_2d_parity_cb_t** of_cb)
* @brief create a 2D parity codec instance
* @param of_cb (IN/OUT) address of the pointer to a 2D parity 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_2d_parity_create_codec_instance (of_2d_parity_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_2d_parity_release_codec_instance (of_2d_parity_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_2d_parity_release_codec_instance (of_2d_parity_cb_t* ofcb);
/**
*
* @fn of_status_t of_2d_parity_set_fec_parameters (of_2d_parity_cb_t* ofcb, of_2d_parity_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_2d_parity_set_fec_parameters (of_2d_parity_cb_t* ofcb,
of_2d_parity_parameters_t* params);
/**
* @fn of_status_t of_2d_parity_set_callback_functions (of_2d_parity_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_2d_parity_set_callback_functions (of_2d_parity_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_2d_parity_build_repair_symbol (of_2d_parity_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_2d_parity_build_repair_symbol (of_2d_parity_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_2d_parity_decode_with_new_symbol (of_2d_parity_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_2d_parity_decode_with_new_symbol (of_2d_parity_cb_t* ofcb,
void* new_symbol,
UINT32 new_symbol_esi);
/**
* @fn of_status_t of_2d_parity_set_available_symbols (of_2d_parity_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_2d_parity_set_available_symbols (of_2d_parity_cb_t* ofcb,
void* const encoding_symbols_tab[]);
/**
* @fn of_status_t of_2d_parity_finish_decoding (of_2d_parity_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_2d_parity_finish_decoding (of_2d_parity_cb_t* ofcb);
/**
* @fn bool of_2d_parity_is_decoding_complete (of_2d_parity_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_2d_parity_is_decoding_complete (of_2d_parity_cb_t* ofcb);
/**
* @fn of_status_t of_2d_parity_get_source_symbols_tab (of_2d_parity_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_2d_parity_get_source_symbols_tab (of_2d_parity_cb_t* ofcb,
void* source_symbols_tab[]);
/**
* @fn of_status_t of_2d_parity_set_control_parameter (of_2d_parity_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_2d_parity_set_control_parameter(of_2d_parity_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length);
/**
* @fn of_status_t of_2d_parity_get_control_parameter (of_2d_parity_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_2d_parity_get_control_parameter(of_2d_parity_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length);
#endif //OF_USE_DECODER
#endif //OF_2D_PARITY_H
#endif /* #ifdef OF_USE_2D_PARITY_MATRIX_CODEC */

View File

@@ -0,0 +1,464 @@
/* $Id: of_2d_parity_api.c 185 2014-07-15 09:57:16Z 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-C 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_2d_parity_includes.h"
#ifdef OF_USE_2D_PARITY_MATRIX_CODEC
of_status_t of_2d_parity_create_codec_instance (of_2d_parity_cb_t** of_cb)
{
of_codec_type_t codec_type; /* temporary value */
of_2d_parity_cb_t *cb;
OF_ENTER_FUNCTION
cb = (of_2d_parity_cb_t*) of_realloc (*of_cb, sizeof (of_2d_parity_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_2D_PARITY_MATRIX_STABLE;
cb->codec_type = codec_type;
cb->max_nb_source_symbols = OF_2D_PARITY_MATRIX_MAX_NB_SOURCE_SYMBOLS_DEFAULT; /* init it immediately... */
cb->max_nb_encoding_symbols = OF_2D_PARITY_MATRIX_MAX_NB_ENCODING_SYMBOLS_DEFAULT; /* init it immediately... */
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
of_status_t of_2d_parity_release_codec_instance (of_2d_parity_cb_t* ofcb)
{
UINT32 i;
OF_ENTER_FUNCTION
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->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);
}
}
#endif
#ifdef OF_2D_PARITY_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);
}
#endif
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
of_status_t of_2d_parity_set_fec_parameters (of_2d_parity_cb_t* ofcb,
of_2d_parity_parameters_t* params)
{
of_mod2entry *e;
UINT32 row;
UINT32 seq;
OF_ENTER_FUNCTION
#ifdef OF_DEBUG
ofcb->stats_xor = of_calloc(1, sizeof(of_2d_symbol_stats_op_t));
ofcb->stats_symbols = of_calloc(1,sizeof(of_symbols_stats_t));
#endif
if ((ofcb->nb_source_symbols = params->nb_source_symbols) > ofcb->max_nb_source_symbols) {
OF_PRINT_ERROR(("of_2d_parity_set_fec_parameters: ERROR, invalid nb_source_symbols parameter (got %d, maximum is %d)",
ofcb->nb_source_symbols, ofcb->max_nb_source_symbols));
goto error;
}
ofcb->nb_repair_symbols = params->nb_repair_symbols;
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_2d_parity_set_fec_parameters: ERROR, invalid number of encoding symbols (got %d, maximum is %d)",
ofcb->nb_total_symbols, ofcb->max_nb_encoding_symbols));
goto error;
}
ofcb->encoding_symbol_length = params->encoding_symbol_length;
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, 0, 0))
ofcb->pchk_matrix = of_create_pchk_matrix (ofcb->nb_repair_symbols, ofcb->nb_total_symbols, Evenboth,
0, 0, false, Type2DMATRIX, 1);
if (ofcb->pchk_matrix == NULL)
{
OF_PRINT_ERROR(("of_2d_parity_set_fec_parameters : ERROR, parity check matrix can't be created with this parameters.."))
goto error;
}
#ifdef OF_DEBUG
if (of_verbosity >= 2)
{
of_mod2sparse_matrix_stats(stdout, ofcb->pchk_matrix, ofcb->nb_source_symbols, ofcb->nb_repair_symbols);
}
#endif
#ifdef OF_2D_PARITY_ML_DECODING
ofcb->pchk_matrix_simplified = 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]++;
}
}
}
#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_2D_PARITY_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
OF_EXIT_FUNCTION
return OF_STATUS_OK;
no_mem:
OF_PRINT_ERROR(("out of memory"));
error:
OF_EXIT_FUNCTION
return OF_STATUS_FATAL_ERROR;
}
of_status_t of_2d_parity_set_callback_functions (
of_2d_parity_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_2d_parity_build_repair_symbol (of_2d_parity_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_2d_parity_build_repair_symbol: Error, bad esi of encoding symbol (%d)", 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", 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_2d_parity_decode_with_new_symbol (of_2d_parity_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_2d_parity_set_available_symbols (of_2d_parity_cb_t* ofcb,
void* const encoding_symbols_tab[])
{
OF_ENTER_FUNCTION
UINT32 i;
for (i = 0; i < ofcb->nb_total_symbols; i++)
{
if (encoding_symbols_tab[i] != NULL)
{
ofcb->encoding_symbols_tab[i] = of_calloc (1, ofcb->encoding_symbol_length);
memcpy (ofcb->encoding_symbols_tab[i], encoding_symbols_tab[i], ofcb->encoding_symbol_length);
}
}
OF_EXIT_FUNCTION
return OF_STATUS_OK;
}
of_status_t of_2d_parity_finish_decoding (of_2d_parity_cb_t* ofcb)
{
OF_ENTER_FUNCTION
#ifdef OF_2D_PARITY_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_2d_parity_is_decoding_complete (of_2d_parity_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_2d_parity_get_source_symbols_tab(of_2d_parity_cb_t* ofcb,
void* source_symbols_tab[])
{
OF_ENTER_FUNCTION
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_2d_parity_set_control_parameter (of_2d_parity_cb_t* ofcb,
UINT32 type,
void* value,
UINT32 length)
{
OF_PRINT_ERROR(("of_2d_parity_set_control_parameter: ERROR, not implemented...\n"))
return OF_STATUS_ERROR;
}
of_status_t of_2d_parity_get_control_parameter (of_2d_parity_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;
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_2D_PARITY_MATRIX_CODEC */

View File

@@ -0,0 +1,62 @@
/* $Id: of_2d_parity_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-C 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_2D_PARITY_MATRIX_CODEC
#ifndef OF_CODEC_STABLE_2D_PARITY_API
#define OF_CODEC_STABLE_2D_PARITY_API
#include "../../lib_common/of_types.h"
/**
* @struct of_2d_parity_parameters_t
* @brief 2D parity 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_2d_parity_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...
*/
} of_2d_parity_parameters_t;
#endif /* OF_CODEC_STABLE_2D_PARITY_API */
#endif /* #ifdef OF_USE_2D_PARITY_MATRIX_CODEC */

View File

@@ -0,0 +1,55 @@
/* $Id: of_2d_parity_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-C 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_2D_PARITY_INCLUDES
#define OF_2D_PARITY_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_2D_PARITY_MATRIX_CODEC
#include "../../lib_common/linear_binary_codes_utils/of_linear_binary_code.h"
#include "of_2d_parity_api.h"
#include "of_2d_parity.h"
#endif //OF_USE_2D_PARITY_MATRIX_CODEC
#endif //OF_2D_PARITY_INCLUDES

View File

@@ -0,0 +1,112 @@
/* $Id: of_codec_profile.h 175 2014-07-11 09:58:38Z 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-C 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_2D_PARITY_MATRIX_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_2D_PARITY_ML_DECODING
#endif
/**
* This optimization is only significant in 32-bit architectures.
* With LP64 architectures, padding will be needed, adding 32 more bits,
* which makes this optimization useless...
*
* NB: not yet operational...
*/
#if defined (__LP64__) || (__WORDSIZE == 64)
// useless with 64-bit architectures
#else
#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_2D_PARITY_MATRIX_MAX_NB_SOURCE_SYMBOLS_DEFAULT
#ifdef ML_DECODING
#define OF_2D_PARITY_MATRIX_MAX_NB_SOURCE_SYMBOLS_DEFAULT 16
#define OF_2D_PARITY_MATRIX_MAX_NB_ENCODING_SYMBOLS_DEFAULT 24
#else
#define OF_2D_PARITY_MATRIX_MAX_NB_SOURCE_SYMBOLS_DEFAULT 16
#define OF_2D_PARITY_MATRIX_MAX_NB_ENCODING_SYMBOLS_DEFAULT 24
#endif
#endif