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 "RaptorQ/v1/wrapper/C_RAW_API.h"
#include "RaptorQ/v1/RaptorQ.hpp"
#include <future>
#include <utility>
struct RAPTORQ_LOCAL RaptorQ_ptr
{
void *ptr;
const RaptorQ_type type;
RaptorQ_ptr (const RaptorQ_type _type) : ptr (nullptr), type (_type) {}
};
typedef enum {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
} RAPTORQ_LOCAL RaptorQ_Future_Type;
struct RAPTORQ_LOCAL RaptorQ_future
{
const RaptorQ_Future_Type type;
RaptorQ_future (const RaptorQ_Future_Type t)
:type (t) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_enc
{
const struct RaptorQ_future base;
std::future<RaptorQ__v1::Error> f;
RaptorQ_future_enc ()
:base (RaptorQ_Future_Type::RQ_FUTURE_ENCODER) {}
};
struct RAPTORQ_LOCAL RaptorQ_future_dec
{
const struct RaptorQ_future base;
std::future<std::pair<RaptorQ__v1::Error, uint16_t>> f;
RaptorQ_future_dec ()
:base (RaptorQ_Future_Type::RQ_FUTURE_DECODER) {}
};
// precomputation caching
static RaptorQ_Compress RAPTORQ_LOCAL v1_supported_compressions();
static RaptorQ_Compress RAPTORQ_LOCAL v1_get_compression();
static bool RAPTORQ_LOCAL v1_set_compression (
const RaptorQ_Compress compression);
static size_t RAPTORQ_LOCAL v1_shared_cache_size (const size_t shared_cache);
static size_t RAPTORQ_LOCAL v1_local_cache_size (const size_t local_cache);
static size_t RAPTORQ_LOCAL v1_get_shared_cache_size ();
static size_t RAPTORQ_LOCAL v1_get_local_cache_size ();
// constructors
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder_nodata (RaptorQ_type type,
const uint16_t symbols,
const size_t symbol_size);
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Encoder (RaptorQ_type type,
const void* from, const void* to,
const size_t symbol_size);
struct RaptorQ_ptr* RAPTORQ_LOCAL v1_Decoder (RaptorQ_type type,
const uint16_t symbols,
const size_t symbol_size,
const RaptorQ_Compute report);
// common functions
static uint16_t RAPTORQ_LOCAL v1_symbols (const RaptorQ_ptr *ptr);
static size_t RAPTORQ_LOCAL v1_symbol_size (const RaptorQ_ptr *ptr);
static RaptorQ_Error RAPTORQ_LOCAL v1_future_state (struct RaptorQ_future *f);
static RaptorQ_Error RAPTORQ_LOCAL v1_future_wait_for (struct RaptorQ_future *f,
const uint64_t time,
const RaptorQ_Unit_Time unit);
static void RAPTORQ_LOCAL v1_future_wait (struct RaptorQ_future *f);
static void RAPTORQ_LOCAL v1_future_free (struct RaptorQ_future **f);
// encoder-specific
static uint32_t RAPTORQ_LOCAL v1_max_repair (const RaptorQ_ptr *enc);
static size_t RAPTORQ_LOCAL v1_add_data (const RaptorQ_ptr *enc, void *from,
const void *to);
static void RAPTORQ_LOCAL v1_clear_data (const RaptorQ_ptr *enc);
static size_t RAPTORQ_LOCAL v1_needed_bytes (const RaptorQ_ptr *enc);
static bool RAPTORQ_LOCAL v1_compute_sync (const RaptorQ_ptr *enc);
static RaptorQ_future_enc* RAPTORQ_LOCAL v1_compute (const RaptorQ_ptr *enc);
static RaptorQ_Error RAPTORQ_LOCAL v1_enc_future_get (
struct RaptorQ_future_enc *f);
static size_t RAPTORQ_LOCAL v1_encode (const RaptorQ_ptr *enc, void *from,
const void *to, const uint32_t id);
// decoder-specific
static RaptorQ_Error RAPTORQ_LOCAL v1_add_symbol (const RaptorQ_ptr *dec,
void *from,
const void *to,
const uint32_t esi);
static bool RAPTORQ_LOCAL v1_can_decode (const RaptorQ_ptr *dec);
static void RAPTORQ_LOCAL v1_stop (const RaptorQ_ptr *dec);
static uint16_t RAPTORQ_LOCAL v1_needed_symbols (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_poll (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_wait_sync (const RaptorQ_ptr *dec);
static RaptorQ_future_dec* RAPTORQ_LOCAL v1_wait (const RaptorQ_ptr *dec);
static RaptorQ_dec_result RAPTORQ_LOCAL v1_dec_future_get (
struct RaptorQ_future_dec *f);
struct RaptorQ_base_api* RAPTORQ_API RaptorQ_api (uint32_t version)
{
if (version != 1)
return nullptr;
auto api = new RaptorQ_v1();
api->base.version = 1;
// precomputation caching
api->supported_compressions = &v1_supported_compressions;
api->get_compression = &v1_get_compression;
api->set_compression = &v1_set_compression;
api->shared_cache_size = &v1_shared_cache_size;
api->local_cache_size = &v1_local_cache_size;
api->get_shared_cache_size = &v1_get_shared_cache_size;
api->get_local_cache_size = &v1_get_local_cache_size;
// constructors
api->Encoder_nodata = &v1_Encoder_nodata;
api->Encoder = &v1_Encoder;
api->Decoder = &v1_Decoder;
// common functions
api->symbols = &v1_symbols;
api->symbol_size = &v1_symbol_size;
api->future_state = &v1_future_state;
api->future_wait_for = &v1_future_wait_for;
api->future_wait = &v1_future_wait;
api->future_free = &v1_future_free;
// encoder-specific functions
api->max_repair = &v1_max_repair;
api->add_data = &v1_add_data;
api->clear_data = &v1_clear_data;
api->needed_bytes = &v1_needed_bytes;
api->compute_sync = &v1_compute_sync;
api->compute = &v1_compute;
api->enc_future_get = &v1_enc_future_get;
api->encode = &v1_encode;
// decoder-specific functions
api->add_symbol = &v1_add_symbol;
api->can_decode = &v1_can_decode;
api->stop = &v1_stop;
api->needed_symbols = &v1_needed_symbols;
api->poll = &v1_poll;
api->wait_sync = &v1_wait_sync;
api->wait = &v1_wait;
api->dec_future_get = &v1_dec_future_get;
return reinterpret_cast<RaptorQ_base_api *> (api);
}
///////////////////////////
// Precomputation caching
///////////////////////////
static RaptorQ_Compress v1_supported_compressions()
{
return static_cast<RaptorQ_Compress>(RaptorQ__v1::supported_compressions());
}
static RaptorQ_Compress v1_get_compression()
{ return static_cast<RaptorQ_Compress>(RaptorQ__v1::get_compression()); }
static bool v1_set_compression (const RaptorQ_Compress compression)
{
return static_cast<RaptorQ_Compress> (RaptorQ__v1::set_compression (
static_cast<RaptorQ__v1::Compress> (compression)));
}
static size_t v1_shared_cache_size (const size_t shared_cache)
{ return RaptorQ__v1::shared_cache_size (shared_cache); }
static size_t v1_local_cache_size (const size_t local_cache)
{ return RaptorQ__v1::local_cache_size (local_cache); }
static size_t v1_get_shared_cache_size ()
{ return RFC6330__v1::get_shared_cache_size(); }
Loading full blame...