int layered_encoder_set_parameters(u_char *state, char *cmd) { u_char *nbuf; lay_state *n, *cur; codec_id_t cid; char *s; uint8_t layers; uint32_t nl; int success = FALSE; assert(state != NULL); assert(cmd != NULL); /* Create a temporary encoder, try to set its params */ layered_encoder_create(&nbuf, &nl); n = (lay_state*)nbuf; assert(n != NULL); if(strcmp(cmd, "None")==0) { /*might happen from load_settings */ debug_msg("layered codec not recognised\n"); goto done; } s = (char *) strtok(cmd, "/"); if(s==NULL) { debug_msg("layered_codec_not_recognised\n"); goto done; } cid = codec_get_by_name(s); if (!codec_id_is_valid(cid)) { debug_msg("layered codec not recognized\n"); goto done; } n->codec_id = cid; s = (char *) strtok(NULL, "/"); layers = atoi(s); if(layers>codec_can_layer(cid) || layers>LAY_MAX_LAYERS) { debug_msg("Too many layers (%d)\n", layers); goto done; } n->n_layers = layers; layered_encoder_reset(state); /* Take bits from temporary encoder state we want */ cur = (lay_state*)state; cur->codec_id = n->codec_id; cur->n_layers = n->n_layers; success = TRUE; done: nbuf = (u_char*)n; layered_encoder_destroy(&nbuf, nl); return success; }
int audio_device_get_safe_config(audio_config **ppac) { if (ac_create(ppac)) { audio_config *pac = *ppac; pac->device = audio_get_null_device(); pac->primary = codec_get_by_name("PCMU-8K-Mono"); pac->render_3d = FALSE; assert(pac->primary); return TRUE; } return FALSE; }
int main(int argc, char *argv[]) { const char *codec_name, *repair_name; codec_id_t cid; repair_id_t rid; struct s_sndfile *sf_in = NULL, *sf_out = NULL; sndfile_fmt_t sff; double drop = 0.0; int ac, did_query = FALSE; int csra = TRUE; /* codec specific repair allowed */ long seed = 100; codec_init(); ac = 1; while(ac < argc && argv[ac][0] == '-') { if (strlen(argv[ac]) > 2) { /* should be -codecs or -repairs */ switch(argv[ac][1]) { case 'c': list_codecs(); break; case 'r': list_repairs(); break; default: usage(); } did_query = TRUE; } else { if (argc - ac < 1) { usage(); } switch(argv[ac][1]) { case 's': seed = atoi(argv[++ac]); break; case 'd': drop = strtod(argv[++ac], NULL); break; case 'c': cid = codec_get_by_name(argv[++ac]); codec_name = argv[ac]; break; case 'n': csra = FALSE; break; case 'r': resolve_repair(argv[++ac], &rid, &repair_name); break; case 'u': units_per_packet = atoi(argv[++ac]); break; default: usage(); } } ac++; } if (did_query == TRUE) { /* Not sensible to be running query and executing test */ exit(-1); } if (argc - ac != 2) { usage(); } if (snd_read_open(&sf_in, argv[ac], NULL) == FALSE) { fprintf(stderr, "Could not open %s\n", argv[ac]); exit(-1); } ac++; if (snd_get_format(sf_in, &sff) == FALSE) { fprintf(stderr, "Failed to get format of %s\n", argv[ac]); exit(-1); } if (snd_write_open(&sf_out, argv[ac], "au", &sff) == FALSE) { fprintf(stderr, "Could not open %s\n", argv[ac]); exit(-1); } if (file_and_codec_compatible(&sff, cid) == FALSE) { fprintf(stderr, "Codec and file type are not compatible\n"); exit(-1); } printf("# Parameters #\tseed: %ld #\tdrop: %.2f #\tcodec: %s #\tunits per packet: %d #\trepair: %s #\tcodec specific repair (when available): %d #\tsource file: %s #\tdestination file %s\n", seed, drop, codec_name, units_per_packet, repair_name, csra, argv[argc - 2], argv[argc - 1]); repair_set_codec_specific_allowed(csra); init_drop(seed, drop); test_repair(sf_out, cid, rid, sf_in); /* snd_read_close(&sf_in) not needed because files gets closed * at eof automatically. */ snd_write_close(&sf_out); codec_exit(); xmemdmp(); return 0; }
void session_init(session_t *sp, int index, int mode) { codec_id_t cid; const codec_format_t *cf = NULL; const converter_details_t *conv = NULL; const cc_details_t *ccd = NULL; uint8_t i; memset(sp, 0, sizeof(session_t)); codec_init(); sanity_check_payloads(); vu_table_init(); cid = codec_get_by_name("DVI-8K-Mono"); assert(cid); cf = codec_get_format(cid); sp->cur_ts = ts_map32(8000,0); sp->encodings[0] = codec_get_payload(cid); /* user chosen encoding for primary */ sp->num_encodings = 1; /* Number of encodings applied */ ccd = channel_get_null_coder(); channel_encoder_create(ccd->descriptor, &sp->channel_coder); conv = converter_get_details(0); sp->converter = conv->id; sp->other_session = NULL; /* Completed in main_engine.c if we're a transoder */ sp->id = index; sp->mode = mode; sp->rtp_session_count = 0; for (i = 0; i < MAX_LAYERS; i++) { sp->rx_rtp_port[i] = sp->tx_rtp_port[i] = sp->rx_rtcp_port[i] = sp->tx_rtcp_port[i] = PORT_UNINIT; sp->rtp_session[i] = NULL; } sp->rx_rtp_port[0] = 5004; /* Default ports per: */ sp->tx_rtp_port[0] = 5004; /* draft-ietf-avt-profile-new-00 */ sp->rx_rtcp_port[0] = 5005; sp->tx_rtcp_port[0] = 5005; sp->ttl = 127; sp->filter_loopback = TRUE; sp->playing_audio = TRUE; sp->lecture = FALSE; sp->auto_lecture = 0; sp->receive_audit_required = FALSE; sp->silence_detection = SILENCE_DETECTION_OFF; sp->sync_on = FALSE; sp->agc_on = FALSE; sp->ui_on = FALSE; sp->meter = TRUE; /* Powermeter operation */ sp->in_file = NULL; sp->out_file = NULL; sp->local_file_player = NULL; sp->mbus_engine_addr = NULL; sp->mbus_engine = NULL; sp->mbus_ui_addr = NULL; sp->mbus_video_addr = xstrdup("(media:video module:engine)"); sp->min_playout = 0; sp->max_playout = 1000; sp->last_depart_ts = 0; sp->loopback_gain = 0; sp->layers = 1; sp->ui_activated = FALSE; sp->encrkey = NULL; sp->logger = NULL; sp->mbus_waiting = FALSE; sp->mbus_waiting_token = NULL; sp->mbus_go = FALSE; sp->mbus_go_token = NULL; sp->magic = 0xcafebabe; /* Magic number for debugging */ source_list_create(&sp->active_sources); sp->title = "Untitled session"; strncpy(sp->asc_address[0], "127.0.0.3", MAXHOSTNAMELEN); /* Yeuch! This value should never be used! */ }
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; }