void settings_load_late(session_t *sp) { /* FIXME: This needs to be updated for the transcoder */ uint32_t my_ssrc; struct utsname u; char hostfmt[] = "RAT v" RAT_VERSION " %s %s (%s)"; char *field, username[32] = ""; load_init(); /* Initial settings come from the common prefs file... */ /* * We check to see it SDES items are set first. If they are * then presumeably it has come from the command line and * so it should override saved settings. */ my_ssrc = rtp_my_ssrc(sp->rtp_session[0]); if (settings_username(username, sizeof(username) - 1) == FALSE) { sprintf(username, "Unknown"); } field = setting_load_str("rtpName", username); if (rtp_get_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_NAME) == NULL) { debug_msg("username %s %s\n", field, username); rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_NAME, field, strlen(field)); } field = setting_load_str("rtpEmail", ""); if (rtp_get_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_EMAIL) == NULL) { rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_EMAIL, field, strlen(field)); } field = setting_load_str("rtpPhone", ""); if (rtp_get_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_PHONE) == NULL) { rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_PHONE, field, strlen(field)); } field = setting_load_str("rtpLoc", ""); if (rtp_get_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_LOC) == NULL) { rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_LOC, field, strlen(field)); } field = setting_load_str("rtpNote", ""); if (rtp_get_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_NOTE) == NULL) { rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_NOTE, field, strlen(field)); } field = (char*)xmalloc(3 * 256 + sizeof(hostfmt)); uname(&u); sprintf(field, hostfmt, u.sysname, u.release, u.machine); rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_TOOL, field, strlen(field)); xfree(field); /* This is evil [csp] */ field = xstrdup(" rattest"); field[0] = 3; rtp_set_sdes(sp->rtp_session[0], my_ssrc, RTCP_SDES_PRIV, field, strlen(field)); xfree(field); init_part_two(); /* Switch to pulling settings from the RAT specific prefs file... */ load_done(); }
rtp_session_t * init_rtp_session(uint32_t port, char *addr){ rtp_session_t *rtp; char *mcast_if = NULL; double rtcp_bw = DEFAULT_RTCP_BW; int ttl = DEFAULT_TTL; struct module tmod; struct tx *tx_session; rtp = (rtp_session_t *) malloc(sizeof(rtp_session_t)); if (rtp == NULL){ error_msg("rtp_session: malloc error"); return NULL; } rtp->port = port; rtp->addr = addr; module_init_default(&tmod); struct rtp *rtp_conn = rtp_init_if(addr, mcast_if, 0, port, ttl, rtcp_bw, 0, dummy_callback, (void *)NULL, 0); if (rtp_conn == NULL){ error_msg("rtp_session: rtp_init error"); return NULL; } rtp_set_option(rtp_conn, RTP_OPT_WEAK_VALIDATION, 1); rtp_set_sdes(rtp_conn, rtp_my_ssrc(rtp_conn), RTCP_SDES_TOOL, PACKAGE_STRING, strlen(PACKAGE_STRING)); rtp_set_send_buf(rtp_conn, DEFAULT_SEND_BUFFER_SIZE); tx_session = tx_init_h264(&tmod, MTU, TX_MEDIA_VIDEO, NULL, NULL); if (tx_session == NULL){ error_msg("rtp_session: tx_init error"); return NULL; } rtp->rtp = rtp_conn; rtp->tx_session = tx_session; return rtp; }
int os_sound_start (call_t * ca, int port) { int p, cond; int bits = 16; int stereo = 0; /* 0 is mono */ int rate = 8000; int blocksize = 512; if (ca->local_sendrecv == _SENDRECV || ca->local_sendrecv == _RECVONLY) { ca->fd = open (AUDIO_DEVICE, O_RDWR | O_NONBLOCK); if (ca->fd < 0) return -EWOULDBLOCK; fcntl (ca->fd, F_SETFL, fcntl (ca->fd, F_GETFL) & ~O_NONBLOCK); ioctl (ca->fd, SNDCTL_DSP_RESET, 0); p = bits; /* 16 bits */ ioctl (ca->fd, SNDCTL_DSP_SAMPLESIZE, &p); p = stereo; /* number of channels */ ioctl (ca->fd, SNDCTL_DSP_CHANNELS, &p); #ifdef USE_PCM p = AFMT_S16_NE; /* choose LE or BE (endian) */ ioctl (ca->fd, SNDCTL_DSP_SETFMT, &p); #else if (ca->payload == 0) p = AFMT_MU_LAW; else if (ca->payload == 8) p = AFMT_A_LAW; else if (ca->payload == 110 || ca->payload == 111) p = AFMT_S16_NE; /* choose LE or BE (endian) */ ioctl (ca->fd, SNDCTL_DSP_SETFMT, &p); #endif p = rate; /* rate in khz */ ioctl (ca->fd, SNDCTL_DSP_SPEED, &p); ioctl (ca->fd, SNDCTL_DSP_GETBLKSIZE, &min_size); if (min_size > blocksize) { cond = 1; p = min_size / blocksize; while (cond) { int i = ioctl (ca->fd, SNDCTL_DSP_SUBDIVIDE, &p); /* fprintf(stderr, "SUB_DIVIDE said error=%i,errno=%i\n",i,errno); */ if ((i == 0) || (p == 1)) cond = 0; else p = p / 2; } } ioctl (ca->fd, SNDCTL_DSP_GETBLKSIZE, &min_size); if (min_size > blocksize) { fprintf (stderr, "dsp block size set to %i.", min_size); exit (0); } else { /* no need to access the card with less latency than needed */ min_size = blocksize; } OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "blocksize = %i\n", min_size)); } else { /* send a wav file! */ ca->fd = open (ca->wav_file, O_RDONLY); if (ca->fd < 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "Could not open wav file: %s\n", ca->wav_file)); return -1; } } #ifdef SPEEX_SUPPORT { float vbr_qual; int value; int quality; ca->speex_enc = speex_encoder_init (&speex_nb_mode); /* 8kHz */ /* 16kHz speex_enc = speex_encoder_init(&speex_wb_mode); */ /* 32kHz speex_enc = speex_encoder_init(&speex_uwb_mode); */ ca->speex_dec = speex_decoder_init (&speex_nb_mode); value = 1; speex_decoder_ctl (ca->speex_dec, SPEEX_SET_ENH, &value); quality = 8; /* 15kb */ speex_encoder_ctl (ca->speex_enc, SPEEX_SET_QUALITY, &quality); /* ou bien le bit rate: value = 15000; // 15kb speex_encoder_ctl(ca->speex_enc, SPEEX_SET_BITRATE, &value); */ /* silence suppression (VAD) value = 1; // 15kb speex_encoder_ctl(ca->speex_enc, SPEEX_SET_VAD, &value); Discontinuous transmission (DTX) value = 1; // 15kb speex_encoder_ctl(ca->speex_enc, SPEEX_SET_DTX, &value); Variable Bit Rate (VBR) value = 1; // 15kb speex_encoder_ctl(ca->speex_enc, SPEEX_SET_VBR, &value); vbr_qual = 5,0; // between 0 and 10 speex_encoder_ctl(ca->speex_enc, SPEEX_SET_VBR_QUALITY, &vbr_qual); Average bit rate: (ABR) value = 15000; // 15kb speex_encoder_ctl(ca->speex_enc, SPEEX_SET_ABR, &value); */ speex_encoder_ctl (ca->speex_enc, SPEEX_GET_FRAME_SIZE, &ca->speex_fsize); ca->speex_nb_packet = 1; speex_bits_init (&(ca->speex_bits)); speex_bits_init (&(ca->dec_speex_bits)); } #endif if (ca->local_sendrecv == _SENDRECV) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "starting sendrecv session\n")); } else if (ca->local_sendrecv == _SENDONLY) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "starting sendonly session\n")); } else { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO2, NULL, "starting recvonly session\n")); } ca->rtp_session = rtp_init (ca->remote_sdp_audio_ip, port, ca->remote_sdp_audio_port, 16, 64000, rtp_event_handler, (void *) ca); if (ca->rtp_session) { const char *username = "******"; /* should be taken from the SDP */ const char *telephone = "0033-MY-NUMBER"; const char *app_name = "josua"; uint32_t my_ssrc = rtp_my_ssrc (ca->rtp_session); /* set local participant info */ rtp_set_sdes (ca->rtp_session, my_ssrc, RTCP_SDES_NAME, username, strlen (username)); rtp_set_sdes (ca->rtp_session, my_ssrc, RTCP_SDES_PHONE, telephone, strlen (telephone)); rtp_set_sdes (ca->rtp_session, my_ssrc, RTCP_SDES_TOOL, app_name, strlen (app_name)); /* Filter out local packets if requested */ /* rtp_set_option(ca->rtp_session, RTP_OPT_FILTER_MY_PACKETS, filter_me); */ rtp_set_option (ca->rtp_session, RTP_OPT_WEAK_VALIDATION, TRUE); ca->enable_audio = 1; ca->audio_thread = osip_thread_create (20000, os_sound_start_thread, ca); } else { fprintf (stderr, "Could not initialize session for %s port %d\n", ca->remote_sdp_audio_ip, ca->remote_sdp_audio_port); } return 0; }