/* Create ringback tones */
if (app_config.no_tones == PJ_FALSE) {
unsigned samples_per_frame;
pjmedia_tone_desc tone[RING_CNT+RINGBACK_CNT];
pj_str_t name;
samples_per_frame = app_config.media_cfg.audio_frame_ptime *
app_config.media_cfg.clock_rate *
app_config.media_cfg.channel_count / 1000;
/* Ringback tone (call is ringing) */
name = pj_str("ringback");
status = pjmedia_tonegen_create2(app_config.pool, &name,
app_config.media_cfg.clock_rate,
app_config.media_cfg.channel_count,
samples_per_frame,
16, PJMEDIA_TONEGEN_LOOP,
&app_config.ringback_port);
if (status != PJ_SUCCESS)
goto on_error;
pj_bzero(&tone, sizeof(tone));
for (i=0; i<RINGBACK_CNT; ++i) {
tone[i].freq1 = RINGBACK_FREQ1;
tone[i].freq2 = RINGBACK_FREQ2;
tone[i].on_msec = RINGBACK_ON;
tone[i].off_msec = RINGBACK_OFF;
}
tone[RINGBACK_CNT-1].off_msec = RINGBACK_INTERVAL;
pjmedia_tonegen_play(app_config.ringback_port, RINGBACK_CNT, tone,
PJMEDIA_TONEGEN_LOOP);
status = pjsua_conf_add_port(app_config.pool, app_config.ringback_port,
&app_config.ringback_slot);
if (status != PJ_SUCCESS)
goto on_error;
/* Ring (to alert incoming call) */
name = pj_str("ring");
status = pjmedia_tonegen_create2(app_config.pool, &name,
app_config.media_cfg.clock_rate,
app_config.media_cfg.channel_count,
samples_per_frame,
16, PJMEDIA_TONEGEN_LOOP,
&app_config.ring_port);
if (status != PJ_SUCCESS)
goto on_error;
for (i=0; i<RING_CNT; ++i) {
tone[i].freq1 = RING_FREQ1;
tone[i].freq2 = RING_FREQ2;
tone[i].on_msec = RING_ON;
tone[i].off_msec = RING_OFF;
}
tone[RING_CNT-1].off_msec = RING_INTERVAL;
pjmedia_tonegen_play(app_config.ring_port, RING_CNT,
tone, PJMEDIA_TONEGEN_LOOP);
status = pjsua_conf_add_port(app_config.pool, app_config.ring_port,
&app_config.ring_slot);
if (status != PJ_SUCCESS)
goto on_error;
}