int main() { u_char *s; u_int32 slen; redundancy_encoder_create(&s, &slen); redundancy_encoder_set_parameters(s, "dvi-8k-mono/0/dvi-8k-mono/2"); redundancy_encoder_destroy(&s, slen); xmemdmp(); return TRUE; }
int redundancy_encoder_set_parameters(u_char *state, char *cmd) { u_char *encbuf; red_enc_state *n, *cur; const codec_format_t *cf; uint32_t nl, po; codec_id_t cid; char *s; int success = FALSE; assert(state != NULL); assert(cmd != NULL); /* Create a temporary encoder, try to set it's params */ redundancy_encoder_create(&encbuf, &nl); n = (red_enc_state*)encbuf; assert(n != NULL); s = (char *) strtok(cmd, "/"); cid = codec_get_by_name(s); if (!codec_id_is_valid(cid)) { debug_msg("codec not recognized\n"); goto done; } s = (char *) strtok(NULL, "/"); po = atoi(s); if (po > 20) { debug_msg("offset too big\n"); goto done; } n->layer[0].cid = cid; n->layer[0].pkts_off = po; n->n_layers = 1; while (n->n_layers < RED_MAX_LAYERS) { s = (char *) strtok(NULL, "/"); if (s == NULL) break; cid = codec_get_by_name(s); if (!codec_id_is_valid(cid)) { debug_msg("codec not recognized\n"); goto done; } s = (char *) strtok(NULL, "/"); if (s == NULL) { debug_msg("Incomplete layer info\n"); goto done; } po = atoi(s); if (po > 20) { debug_msg("offset too big\n"); goto done; } n->layer[n->n_layers].cid = cid; n->layer[n->n_layers].pkts_off = po; n->n_layers ++; } redundancy_encoder_reset(state); /* Take bits from temporary encoder state we want */ cur = (red_enc_state*)state; memcpy(cur->layer, n->layer, sizeof(red_layer)*RED_MAX_LAYERS); cur->n_layers = n->n_layers; /* work out history = duration of audio frame * maximum offset */ cf = codec_get_format(cur->layer[cur->n_layers - 1].cid); cur->history = ts_map32(cf->format.sample_rate, codec_get_samples_per_frame(cur->layer[cur->n_layers - 1].cid) * cur->layer[cur->n_layers - 1].pkts_off); success = TRUE; done: encbuf = (u_char*)n; redundancy_encoder_destroy(&encbuf, nl); return success; }