… | |
… | |
26 | |
26 | |
27 | void **b_addr; |
27 | void **b_addr; |
28 | void **b_mmap; |
28 | void **b_mmap; |
29 | int *b_sz; |
29 | int *b_sz; |
30 | SV **b_sv; |
30 | SV **b_sv; |
31 | int **idx; /* the decoding indices */ |
31 | int *idx; /* the decoding indices */ |
32 | } *Algorithm__FEC; |
32 | } *Algorithm__FEC; |
33 | |
33 | |
34 | static void |
34 | static void |
35 | chk_array (SV *sv, int size, const char *func, const char *var) |
35 | chk_array (SV *sv, int size, const char *func, const char *var) |
36 | { |
36 | { |
… | |
… | |
230 | SV * blocks |
230 | SV * blocks |
231 | SV * indices |
231 | SV * indices |
232 | CODE: |
232 | CODE: |
233 | { |
233 | { |
234 | int i; |
234 | int i; |
|
|
235 | int *idx; |
235 | |
236 | |
236 | chk_array (blocks, self->dp, "set_decode_blocks", "blocks"); |
237 | chk_array (blocks, self->dp, "set_decode_blocks", "blocks"); |
237 | chk_array (indices, self->dp, "set_decode_blocks", "indices"); |
238 | chk_array (indices, self->dp, "set_decode_blocks", "indices"); |
238 | |
239 | |
239 | Newz (0, self->idx, self->dp, int); |
240 | Newz (0, idx, self->dp, int); |
240 | |
241 | |
241 | /* copy and check */ |
242 | /* copy and check */ |
242 | for (i = 0; i < self->dp; i++) |
243 | for (i = 0; i < self->dp; i++) |
243 | { |
244 | { |
244 | self->idx[i] = SvIV (*av_fetch ((AV *)SvRV (indices), i, 1)); |
245 | idx[i] = SvIV (*av_fetch ((AV *)SvRV (indices), i, 1)); |
245 | |
246 | |
246 | if (self->idx[i] < 0 || self->idx[i] >= self->ep) |
247 | if (idx[i] < 0 || idx[i] >= self->ep) |
247 | { |
248 | { |
248 | free_files (); |
249 | Safefree (idx); |
249 | croak ("index %d in array out of bounds (0 <= %d < %d != true)", |
250 | croak ("index %d in array out of bounds (0 <= %d < %d != true)", |
250 | i, self->idx[i], self->ep); |
251 | i, idx[i], self->ep); |
251 | } |
252 | } |
252 | } |
253 | } |
253 | |
254 | |
254 | /* |
255 | /* |
255 | * do the same shuffling as fec_decode does here, |
256 | * do the same shuffling as fec_decode does here, |
256 | * so we know the order. |
257 | * so we know the order. |
257 | */ |
258 | */ |
258 | for (i = 0; i < self->dp; i++) |
259 | for (i = 0; i < self->dp; i++) |
259 | while (self->idx[i] < self->dp && self->idx[i] != i) |
260 | while (idx[i] < self->dp && idx[i] != i) |
260 | { |
261 | { |
261 | SV **a, **b, **e, **f; |
262 | SV **a, **b, **e, **f; |
262 | int d; |
263 | int d; |
263 | void *p; |
264 | void *p; |
264 | SV *s; |
265 | SV *s; |
265 | int j = self->idx[i]; |
266 | int j = idx[i]; |
266 | |
267 | |
267 | if (self->idx[j] == j) |
268 | if (idx[j] == j) |
268 | { |
269 | { |
269 | free_files (); |
270 | Safefree (idx); |
270 | croak ("error while shuffling, duplicate indices?"); |
271 | croak ("error while shuffling, duplicate indices?"); |
271 | } |
272 | } |
272 | |
273 | |
273 | a = av_fetch ((AV *)SvRV (indices), i, 1); |
274 | a = av_fetch ((AV *)SvRV (indices), i, 1); |
274 | b = av_fetch ((AV *)SvRV (indices), j, 1); |
275 | b = av_fetch ((AV *)SvRV (indices), j, 1); |
275 | e = av_fetch ((AV *)SvRV (blocks ), i, 1); |
276 | e = av_fetch ((AV *)SvRV (blocks ), i, 1); |
276 | f = av_fetch ((AV *)SvRV (blocks ), j, 1); |
277 | f = av_fetch ((AV *)SvRV (blocks ), j, 1); |
277 | |
278 | |
278 | d = self->idx[i]; self->idx[i] = self->idx[j]; self->idx[j] = d; |
279 | d = idx[i]; idx[i] = idx[j]; idx[j] = d; |
279 | s = *a; *a = *b; *b = s; |
280 | s = *a; *a = *b; *b = s; |
280 | s = *e; *e = *f; *f = s; |
281 | s = *e; *e = *f; *f = s; |
281 | } |
282 | } |
282 | |
283 | |
283 | open_files (self, (AV *)SvRV (blocks), 1); |
284 | open_files (self, (AV *)SvRV (blocks), 1); |
|
|
285 | self->idx = idx; |
284 | } |
286 | } |
285 | |
287 | |
286 | void |
288 | void |
287 | decode (self) |
289 | decode (self) |
288 | Algorithm::FEC self |
290 | Algorithm::FEC self |
289 | CODE: |
291 | CODE: |
290 | |
292 | |
291 | if (!self->idx) |
293 | if (!self->idx) |
292 | croak ("index array must be set by a prior call to set_decode_blocks"; |
294 | croak ("index array must be set by a prior call to set_decode_blocks"); |
293 | |
295 | |
294 | force_addrs (self, self->dp); |
296 | force_addrs (self, self->dp); |
295 | self->imp->fec_decode (self->code, self->b_addr, self->idx, self->sz); |
297 | self->imp->fec_decode (self->code, self->b_addr, self->idx, self->sz); |
296 | free_files (self); |
298 | free_files (self); |
297 | |
299 | |