Sunday, 15 August 2010

voip - iOS pjsip 2.2 loud speaker switch fails -



voip - iOS pjsip 2.2 loud speaker switch fails -

during phone call seek switch voice internal speaker loud speaker on ios device using pjsip 2.2 library. returns true success, physically doesn't alter sound destination.

i utilize next code

- (bool)setloud:(bool)loud { if (loud) { @try { pjmedia_aud_dev_route route = pjmedia_aud_dev_route_loudspeaker; pj_status_t pj_status = pjsua_snd_set_setting(pjmedia_aud_dev_cap_output_route, &route, pj_true); if (pj_status == pj_success) { homecoming yes; } else { homecoming no; } } @catch (nsexception *exception) { homecoming no; } } else { @try { pjmedia_aud_dev_route route = pjmedia_aud_dev_route_earpiece; pj_status_t pj_status = pjsua_snd_set_setting(pjmedia_aud_dev_cap_output_route, &route, pj_true); if (pj_status == pj_success) { homecoming yes; } else { homecoming no; } } @catch (nsexception *exception) { homecoming no; } } }

could suggest how can create work?

with introduction of ios 7, should using avaudiosession handle sound management. took me long time work figured out problem of why sound not automatically routing iphone speaker. problem when reply call, pjsip automatically overriding avaudiosessionportoverride performing before phone call answered. tackle problem, have override output sound port after answering call.

to create voip application work efficiently background mode, decided handle sound routing in custom callback method named on_call_state. method, on_call_state, called pjsip when phone call state has changed. can read here, http://www.pjsip.org/pjsip/docs/html/group__pjsip__inv.htm, there many different flags can check when phone call state has changed. states used in illustration pjsip_inv_state_connecting , pjsip_inv_state_disconnected.

pjsip_inv_state_connecting called when sound phone call connects peer.

pjsip_inv_state_disconnected called when sound phone call ends peer.

class="lang-c prettyprint-override">static void on_call_state(pjsua_call_id call_id, pjsip_event *e) { pjsua_call_info ci; pj_unused_arg(e); pjsua_call_get_info(call_id, &ci); pj_log(3,(this_file, "call %d state=%.*s", call_id, (int)ci.state_text.slen, ci.state_text.ptr)); if (ci.state == pjsip_inv_state_connecting) { bool success; avaudiosession *session = [avaudiosession sharedinstance]; nserror *error = nil; success = [session setcategory:avaudiosessioncategoryplayandrecord withoptions:avaudiosessioncategoryoptionmixwithothers error:&error]; if (!success) nslog(@"avaudiosession error setcategory: %@", [error localizeddescription]); success = [session overrideoutputaudioport:avaudiosessionportoverridespeaker error:&error]; if (!success) nslog(@"avaudiosession error overrideoutputaudioport: %@", [error localizeddescription]); success = [session setactive:yes error:&error]; if (!success) nslog(@"avaudiosession error setactive: %@", [error localizeddescription]); } else if (ci.state == pjsip_inv_state_disconnected) { bool success; avaudiosession *session = [avaudiosession sharedinstance]; nserror *error = nil; success = [session setactive:no error:&error]; if (!success) nslog(@"avaudiosession error setactive: %@", [error localizeddescription]); } }

voip pjsip speaker speakerphone

No comments:

Post a Comment