Newer
Older
* Copyright (c) 2015-2016, Luca Fulchir<luca@fulchir.it>, All rights reserved.
*
* This file is part of "libRaptorQ".
*
* libRaptorQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* libRaptorQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and a copy of the GNU Lesser General Public License
* along with libRaptorQ. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cRaptorQ.h"
#include "RaptorQ.hpp"
#include <memory>
struct RAPTORQ_LOCAL RaptorQ_ptr
{
void *ptr;
const RaptorQ_type type;
RaptorQ_ptr (const RaptorQ_type _type) : ptr (nullptr), type (_type) {}
};
struct RaptorQ_ptr *RaptorQ_Enc (const RaptorQ_type type, void *data,
const uint64_t size,
const uint16_t min_subsymbol_size,
const uint16_t symbol_size,
const size_t max_memory)
{
reinterpret_cast<uint8_t*> (data),
reinterpret_cast<uint8_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
reinterpret_cast<uint16_t*> (data),
reinterpret_cast<uint16_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
reinterpret_cast<uint32_t*> (data),
reinterpret_cast<uint32_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
reinterpret_cast<uint64_t*> (data),
reinterpret_cast<uint64_t*> (data) + size,
min_subsymbol_size,
symbol_size,
max_memory));
break;
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
}
return ret.release();
}
struct RaptorQ_ptr *RaptorQ_Dec (const RaptorQ_type type,
const RaptorQ_OTI_Common_Data common,
const RaptorQ_OTI_Scheme_Specific_Data scheme)
{
std::unique_ptr<RaptorQ_ptr> ret (new RaptorQ_ptr (type));
switch (type) {
new RaptorQ__v1::Decoder<uint16_t*, uint16_t*> (common,scheme));
new RaptorQ__v1::Decoder<uint32_t*, uint32_t*> (common,scheme));
new RaptorQ__v1::Decoder<uint64_t*, uint64_t*> (common,scheme));
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
return new RaptorQ_ptr (RaptorQ_type::RQ_NONE);
///////////////////////////
// Precomputation caching
///////////////////////////
uint64_t RaptorQ_shared_cache_size (const uint64_t shared_cache)
{
}
bool RaptorQ_local_cache_size (const uint64_t local_cache)
{
///////////
// Encoding
///////////
RaptorQ_OTI_Common_Data RaptorQ_OTI_Common (struct RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->type == RaptorQ_type::RQ_NONE ||
enc->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
RaptorQ_OTI_Scheme_Specific_Data RaptorQ_OTI_Scheme (struct RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->type == RaptorQ_type::RQ_NONE ||
enc->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
if (ptr == nullptr || ptr->type == RaptorQ_type::RQ_NONE ||
ptr->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
if (ptr == nullptr || ptr->type == RaptorQ_type::RQ_NONE ||
ptr->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
uint32_t RaptorQ_block_size (RaptorQ_ptr *ptr, const uint8_t sbn)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::RQ_NONE ||
ptr->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
uint16_t RaptorQ_symbols (RaptorQ_ptr *ptr, const uint8_t sbn)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::RQ_NONE ||
ptr->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
uint32_t RaptorQ_max_repair (RaptorQ_ptr *enc, const uint8_t sbn)
{
if (enc == nullptr || enc->type == RaptorQ_type::RQ_NONE ||
enc->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
size_t RaptorQ_precompute_max_memory (RaptorQ_ptr *enc)
{
if (enc == nullptr || enc->type == RaptorQ_type::RQ_NONE ||
enc->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
void RaptorQ_precompute (RaptorQ_ptr *enc, const uint8_t threads,
const bool background)
{
if (enc == nullptr || enc->type == RaptorQ_type::RQ_NONE ||
enc->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return;
#endif
}
uint64_t RaptorQ_encode_id (RaptorQ_ptr *enc, void **data, const uint64_t size,
const uint32_t id)
{
uint8_t sbn = id >> 24;
uint32_t esi = (id << 8) >> 8;
return RaptorQ_encode (enc, data, size, esi, sbn);
}
uint64_t RaptorQ_encode (RaptorQ_ptr *enc, void **data, const uint64_t size,
const uint32_t esi,
const uint8_t sbn)
{
enc->ptr == nullptr || data == nullptr || *data == nullptr) {
return 0;
}
// uhm... better ideas?
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
switch (enc->type) {
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_DEC_8:
case RaptorQ_type::RQ_DEC_16:
case RaptorQ_type::RQ_DEC_32:
case RaptorQ_type::RQ_DEC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
uint32_t RaptorQ_id (const uint32_t esi, const uint8_t sbn)
{
uint32_t ret = static_cast<uint32_t> (sbn) << 24;
ret += esi % static_cast<uint32_t> (std::pow (2, 24));
return ret;
}
uint64_t RAPTORQ_API RaptorQ_bytes (struct RaptorQ_ptr *dec)
{
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
return 0;
}
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return 0;
#endif
}
uint64_t RaptorQ_decode (RaptorQ_ptr *dec, void **data, const size_t size)
dec->ptr == nullptr || data == nullptr) {
return false;
}
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
uint64_t RaptorQ_decode_block (RaptorQ_ptr *dec, void **data, const size_t size,
dec->ptr == nullptr || data == nullptr) {
return false;
}
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
ret = (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
}
bool RaptorQ_add_symbol_id (RaptorQ_ptr *dec, void **data, const uint32_t size,
const uint32_t id)
{
uint8_t sbn = id >> 24;
uint32_t esi = (id << 8) >> 8;
return RaptorQ_add_symbol (dec, data, size, esi, sbn);
}
bool RaptorQ_add_symbol (RaptorQ_ptr *dec, void **data, const uint32_t size,
const uint32_t esi,
const uint8_t sbn)
{
dec->ptr == nullptr || data == nullptr) {
return false;
}
uint8_t *p_8;
uint16_t *p_16;
uint32_t *p_32;
uint64_t *p_64;
switch (dec->type) {
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
case RaptorQ_type::RQ_ENC_8:
case RaptorQ_type::RQ_ENC_16:
case RaptorQ_type::RQ_ENC_32:
case RaptorQ_type::RQ_ENC_64:
case RaptorQ_type::RQ_NONE:
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return false;
#endif
}
///////////////////////
// General: free memory
///////////////////////
void RaptorQ_free (struct RaptorQ_ptr **ptr)
{
if (ptr == nullptr || *ptr == nullptr ||
(*ptr)->type == RaptorQ_type::RQ_NONE || (*ptr)->ptr == nullptr) {
uptr = std::unique_ptr<RaptorQ_ptr> (*ptr);
*ptr = nullptr;
uptr = std::unique_ptr<RaptorQ_ptr> (*ptr);
*ptr = nullptr;
switch (uptr->type) {
delete reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
delete reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
return;
}
void RaptorQ_free_block (struct RaptorQ_ptr *ptr, const uint8_t sbn)
{
if (ptr == nullptr || ptr->type == RaptorQ_type::RQ_NONE ||
ptr->ptr == nullptr)
return (reinterpret_cast<RaptorQ__v1::Encoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Encoder<uint64_t*, uint64_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint8_t*, uint8_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint16_t*, uint16_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint32_t*, uint32_t*>*> (
return (reinterpret_cast<RaptorQ__v1::Decoder<uint64_t*, uint64_t*>*> (
#ifndef USING_CLANG
// uncomment the return and:
// clang: WARN: will never be executed (exaustive switch)
// if commented, GCC: warn: control reaches end of non-void
// ...make up your mind, guys?
return;
#endif