static void on_controls_response(GtkWidget *dialog, int response_id, GtkWidget *video_window){ gtk_widget_destroy(dialog); switch(response_id){ case GTK_RESPONSE_YES: video_window_set_fullscreen(video_window,TRUE); break; case GTK_RESPONSE_NO: video_window_set_fullscreen(video_window,FALSE); break; case GTK_RESPONSE_REJECT: { LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(video_window),"call"); linphone_core_terminate_call(linphone_gtk_get_core(),call); } break; case GTK_RESPONSE_APPLY: { LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(video_window),"call"); char *path = (char *)linphone_gtk_get_snapshot_path(); linphone_call_take_video_snapshot(call, path); } } }
static void notify_refer(SalOp *op, SalReferStatus status){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*) sal_op_get_user_pointer(op); LinphoneCallState cstate; if (call==NULL) { ms_warning("Receiving notify_refer for unknown call."); return ; } switch(status){ case SalReferTrying: cstate=LinphoneCallOutgoingProgress; break; case SalReferSuccess: cstate=LinphoneCallConnected; break; case SalReferFailed: cstate=LinphoneCallError; break; default: cstate=LinphoneCallError; } linphone_call_set_transfer_state(call, cstate); if (cstate==LinphoneCallConnected){ /*automatically terminate the call as the transfer is complete.*/ linphone_core_terminate_call(lc,call); } }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneCall *call=NULL; signal(SIGINT,stop); printf("Version: %s\n",linphone_core_get_version()); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. Here we only use the call_state_changed callbacksestablished in order to get notifications about the progress of the call. */ vtable.call_state_changed=call_state_changed; //vtable.text_received=text_received; /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ //linphone_core_disable_logs(); lc=linphone_core_new(&vtable,NULL,NULL,NULL); linphone_core_set_sip_port(lc, 9999); const char** devs = linphone_core_get_sound_devices(lc); printf("DEVICE: %s\n",devs[0]); printf("DEVICE: %s\n",devs[1]); //linphone_core_set_playback_device(lc,devs[1]); //linphone_core_set_capture_device(lc,devs[1]); linphone_core_iterate(lc); //LinphoneChatRoom* chat_room = linphone_core_create_chat_room(lc,"sip:[email protected]:9998"); //linphone_chat_room_send_message(chat_room,"Welcome in room!\n"); /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } if (call && linphone_call_get_state(call)!=LinphoneCallEnd){ /* terminate the call */ printf("Terminating the call...\n"); linphone_core_terminate_call(lc,call); /*at this stage we don't need the call object */ linphone_call_unref(call); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneCall *call=NULL; const char *dest=NULL; /* take the destination sip uri from the command line arguments */ if (argc>1){ dest=argv[1]; } signal(SIGINT,stop); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Fill the LinphoneCoreVTable with application callbacks. All are optional. Here we only use the call_state_changed callbacks in order to get notifications about the progress of the call. */ vtable.call_state_changed=call_state_changed; /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); if (dest){ /* Place an outgoing call */ call=linphone_core_invite(lc,dest); if (call==NULL){ printf("Could not place call to %s\n",dest); goto end; }else printf("Call to %s is in progress...",dest); linphone_call_ref(call); } /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ linphone_core_iterate(lc); ms_usleep(50000); } if (call && linphone_call_get_state(call)!=LinphoneCallEnd){ /* terminate the call */ printf("Terminating the call...\n"); linphone_core_terminate_call(lc,call); /*at this stage we don't need the call object */ linphone_call_unref(call); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }
int main(int argc, char *argv[]){ LinphoneCore *lc; LinphoneCoreVTable vtable={0}; LinphoneSoundDaemon *lsd; LsdPlayer *p; linphone_core_enable_logs(stdout); lc=linphone_core_new(&vtable,NULL,NULL,NULL); lsd=linphone_sound_daemon_new (NULL,44100,1); linphone_core_use_sound_daemon(lc,lsd); /* start a play */ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/hello8000.wav"); lsd_player_play (p,"share/hello8000.wav"); wait_a_bit (lc,2); /*start another one */ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/hello16000.wav"); lsd_player_enable_loop (p,TRUE); lsd_player_play (p,"share/hello16000.wav"); /* after a few seconds decrease the volume */ wait_a_bit (lc,3); lsd_player_set_gain (p,0.3); wait_a_bit(lc,5); /*now play some stereo music*/ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/rings/rock.wav"); lsd_player_play(p,"share/rings/rock.wav"); wait_a_bit(lc,2); /*now play some stereo music at 22khz in order to test stereo resampling */ p=linphone_sound_daemon_get_player(lsd); lsd_player_set_callback (p,play_finished); lsd_player_set_user_pointer (p,"share/rings/bigben.wav"); lsd_player_play(p,"share/rings/bigben.wav"); wait_a_bit(lc,6); /* now place an outgoing call if sip address argument is given */ if (argc>1){ linphone_core_invite(lc,argv[1]); wait_a_bit(lc,10); linphone_core_terminate_call(lc,NULL); } linphone_core_use_sound_daemon(lc,NULL); linphone_sound_daemon_destroy(lsd); linphone_core_destroy(lc); return 0; }
/** * Terminates the conference and the calls associated with it. * @param lc the linphone core * * All the calls that were merged to the conference are terminated, and the conference resources are destroyed. * * @returns 0 if successful, -1 otherwise **/ int linphone_core_terminate_conference(LinphoneCore *lc) { MSList *calls=lc->calls; while (calls) { LinphoneCall *call=(LinphoneCall*)calls->data; calls=calls->next; if (call->current_params.in_conference) { linphone_core_terminate_call(lc, call); } } return 0; }
static void call_forking_declined(bool_t declined_globaly){ LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc_tcp"); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,3000)); /*all devices from Marie should be ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000)); /*marie1 finally declines the call*/ linphone_core_decline_call(marie->lc,linphone_core_get_current_call(marie->lc), declined_globaly ? LinphoneReasonDeclined : LinphoneReasonBusy ); if (declined_globaly){ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); /*all devices should stop ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000)); }else{ /*pauline should continue ringing and be able to hear a call taken by marie2 */ linphone_core_accept_call(marie2->lc, linphone_core_get_current_call(marie2->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,2000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallStreamsRunning,1,2000)); liblinphone_tester_check_rtcp(pauline,marie2); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000)); linphone_core_terminate_call(marie2->lc,linphone_core_get_current_call(marie2->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); } linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); linphone_core_manager_destroy(marie3); ms_list_free(lcs); }
static void call_forking_with_push_notification_multiple(void){ LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc_tcp"); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); /*unfortunately marie gets unreachable due to crappy 3G operator or iOS bug...*/ linphone_core_set_network_reachable(marie2->lc,FALSE); linphone_core_invite_address(pauline->lc,marie->identity); /*marie1 will ring*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); /*pauline should hear ringback as well*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000)); /*the server is expected to send a push notification to marie2, this will wake up linphone, that will reconnect:*/ linphone_core_set_network_reachable(marie2->lc,TRUE); /*Marie shall receive the call immediately*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000)); /*marie2 accepts the call*/ linphone_core_accept_call(marie2->lc,linphone_core_get_current_call(marie2->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallStreamsRunning,1,1000)); /*call to marie1 should be cancelled*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); liblinphone_tester_check_rtcp(pauline,marie2); linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); }
void Cmeetphonemeet::OnClose() { ShowWindow(SW_HIDE); CDialog::OnClose(); //CDialog::OnDestroy(); LinphoneCore *lc = theApp.GetCore(); LinphoneCall *call = call=linphone_core_get_current_call(lc); if (call!=NULL) { linphone_core_terminate_call(lc,call); } linphone_core_terminate_all_calls(lc); //DestroyWindow(); }
static void linphone_conference_server_refer_received(LinphoneCore *core, const char *refer_to) { char method[20]; LinphoneAddress *refer_to_addr = linphone_address_new(refer_to); char *uri; LinphoneCall *call; if(refer_to_addr == NULL) return; strncpy(method, linphone_address_get_method_param(refer_to_addr), sizeof(method)); if(strcmp(method, "BYE") == 0) { linphone_address_clean(refer_to_addr); uri = linphone_address_as_string_uri_only(refer_to_addr); call = linphone_core_find_call_from_uri(core, uri); if(call) linphone_core_terminate_call(core, call); ms_free(uri); } linphone_address_destroy(refer_to_addr); }
static void call_forking(void){ LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc_tcp"); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,1000)); /*all devices from Marie should be ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallIncomingReceived,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallIncomingReceived,1,1000)); /*marie accepts the call on its first device*/ linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000)); /*other devices should stop ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie2->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie3->stat.number_of_LinphoneCallEnd,1,1000)); linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); linphone_core_manager_destroy(marie3); ms_list_free(lcs); }
static void linphone_core_disconnected(LinphoneCore *lc, LinphoneCall *call){ char temp[256]; char *from=NULL; if(call) from = linphone_call_get_remote_address_as_string(call); if (from) { snprintf(temp,sizeof(temp),"Remote end %s seems to have disconnected, the call is going to be closed.",from); free(from); } else { snprintf(temp,sizeof(temp),"Remote end seems to have disconnected, the call is going to be closed."); } if (lc->vtable.display_warning!=NULL) lc->vtable.display_warning(lc,temp); linphone_core_terminate_call(lc,call); }
static void call_forking_with_urgent_reply(void){ LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc_tcp"); LinphoneCoreManager* marie = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie2 = linphone_core_manager_new( "marie_rc"); LinphoneCoreManager* marie3 = linphone_core_manager_new( "marie_rc"); MSList* lcs=ms_list_append(NULL,pauline->lc); lcs=ms_list_append(lcs,marie->lc); lcs=ms_list_append(lcs,marie2->lc); lcs=ms_list_append(lcs,marie3->lc); linphone_core_set_user_agent(marie->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie2->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(marie3->lc,"Natted Linphone",NULL); linphone_core_set_user_agent(pauline->lc,"Natted Linphone",NULL); CU_ASSERT_TRUE(linphone_core_media_encryption_supported(pauline->lc,LinphoneMediaEncryptionSRTP)); linphone_core_set_media_encryption(pauline->lc,LinphoneMediaEncryptionSRTP); linphone_core_set_network_reachable(marie2->lc,FALSE); linphone_core_set_network_reachable(marie3->lc,FALSE); linphone_core_invite_address(pauline->lc,marie->identity); /*pauline should hear ringback, after 5 seconds, when it will retry without SRTP*/ CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallOutgoingRinging,1,6000)); /*Marie should be ringing*/ CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallIncomingReceived,1,1000)); /*marie accepts the call on its first device*/ linphone_core_accept_call(marie->lc,linphone_core_get_current_call(marie->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallStreamsRunning,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallConnected,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallStreamsRunning,1,1000)); linphone_core_terminate_call(pauline->lc,linphone_core_get_current_call(pauline->lc)); CU_ASSERT_TRUE(wait_for_list(lcs,&pauline->stat.number_of_LinphoneCallEnd,1,1000)); CU_ASSERT_TRUE(wait_for_list(lcs,&marie->stat.number_of_LinphoneCallEnd,1,1000)); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(marie2); linphone_core_manager_destroy(marie3); ms_list_free(lcs); }
static void call_invite_200ok_without_contact_header(void) { LinphoneCoreManager *mgr; char *identity_char; char *scen; FILE * sipp_out; LinphoneCall *call = NULL; /*currently we use direct connection because sipp do not properly set ACK request uri*/ mgr= linphone_core_manager_new2("empty_rc", FALSE); mgr->identity = linphone_core_get_primary_contact_parsed(mgr->lc); linphone_address_set_username(mgr->identity,"marie"); identity_char = linphone_address_as_string(mgr->identity); linphone_core_set_primary_contact(mgr->lc,identity_char); linphone_core_iterate(mgr->lc); scen = bc_tester_res("sipp/call_invite_200ok_without_contact_header.xml"); sipp_out = sip_start_recv(scen); if (sipp_out) { call = linphone_core_invite(mgr->lc, "[email protected]"); BC_ASSERT_PTR_NOT_NULL(call); BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallOutgoingInit, 1)); BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallOutgoingProgress, 1)); BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallOutgoingRinging, 1)); /*assert that the call never gets connected nor terminated*/ BC_ASSERT_FALSE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallConnected, 1)); BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneCallEnd, 0, int, "%d"); BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneCallError, 0, int, "%d"); linphone_core_terminate_call(mgr->lc, call); BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallEnd, 1)); BC_ASSERT_TRUE(wait_for(mgr->lc, mgr->lc, &mgr->stat.number_of_LinphoneCallReleased, 1)); pclose(sipp_out); } linphone_core_manager_destroy(mgr); }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneVideoPolicy policy; int i; LinphoneAddress *addr=NULL; LCSipTransports tp; char * tmp = NULL; LpConfig * lp_config = lp_config_new(NULL); int max_call_duration=3600; static const char *media_file = NULL; policy.automatically_accept=TRUE; signal(SIGINT,stop); #ifndef _WIN32 signal(SIGUSR1,stats); signal(SIGUSR2,dump_call_logs); #endif for(i = 1; i < argc; ++i) { if (strcmp(argv[i], "--verbose") == 0) { linphone_core_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); } else if (strcmp(argv[i], "--max-call-duration") == 0){ max_call_duration = atoi(argv[++i]); } else if (strcmp(argv[i], "--listening-uri") == 0){ addr = linphone_address_new(argv[++i]); if (!addr) { printf("Error, bad sip uri"); helper(argv[0]); } /* switch(linphone_address_get_transport(addr)) { case LinphoneTransportUdp: case LinphoneTransportTcp: break; default: ms_error("Error, bad sip uri [%s] transport, should be udp | tcp",argv[i]); helper(); break; }*/ } else if (strcmp(argv[i], "--media-file") == 0){ i++; if (i<argc){ media_file = argv[i]; }else helper(argv[0]); } else { helper(argv[0]); } } if (!addr) { addr = linphone_address_new("sip:[email protected]:5060"); } lp_config_set_string(lp_config,"sip","bind_address",linphone_address_get_domain(addr)); lp_config_set_string(lp_config,"rtp","bind_address",linphone_address_get_domain(addr)); lp_config_set_int(lp_config,"misc","history_max_size",100000); vtable.call_state_changed=call_state_changed; lc=linphone_core_new_with_config(&vtable,lp_config,NULL); linphone_core_enable_video_capture(lc,TRUE); linphone_core_enable_video_display(lc,FALSE); linphone_core_set_video_policy(lc,&policy); linphone_core_enable_keep_alive(lc,FALSE); /*instead of using sound capture card, a file is played to the calling party*/ linphone_core_set_use_files(lc,TRUE); linphone_core_enable_echo_cancellation(lc, FALSE); /*no need for local echo cancellation when playing files*/ if (!media_file){ linphone_core_set_play_file(lc,PACKAGE_DATA_DIR "/sounds/linphone/hello16000.wav"); linphone_core_set_preferred_framerate(lc,5); }else{ PayloadType *pt = linphone_core_find_payload_type(lc, "opus", 48000, -1); /*if opus is present, give it a bitrate for good quality with music, and stereo enabled*/ if (pt){ linphone_core_set_payload_type_bitrate(lc, pt, 150); payload_type_set_send_fmtp(pt, "stereo=1"); payload_type_set_recv_fmtp(pt, "stereo=1"); } linphone_core_set_play_file(lc, media_file); linphone_core_set_preferred_video_size_by_name(lc, "720p"); } { MSWebCamDesc *desc = ms_mire_webcam_desc_get(); if (desc){ ms_web_cam_manager_add_cam(ms_factory_get_web_cam_manager(linphone_core_get_ms_factory(lc)),ms_web_cam_new(desc)); linphone_core_set_video_device(lc,"Mire: Mire (synthetic moving picture)"); } } memset(&tp,0,sizeof(LCSipTransports)); tp.udp_port = linphone_address_get_port(addr); tp.tcp_port = linphone_address_get_port(addr); linphone_core_set_sip_transports(lc,&tp); linphone_core_set_audio_port_range(lc,1024,65000); linphone_core_set_video_port_range(lc,1024,65000); linphone_core_set_primary_contact(lc,tmp=linphone_address_as_string(addr)); ms_free(tmp); /* main loop for receiving notifications and doing background linphonecore work: */ while(running){ const bctbx_list_t * iterator; linphone_core_iterate(lc); ms_usleep(50000); if (print_stats) { ms_message("*********************************"); ms_message("*Current number of calls [%10u] *", (unsigned int)bctbx_list_size(linphone_core_get_calls(lc))); ms_message("*Number of calls until now [%10u] *", (unsigned int)bctbx_list_size(linphone_core_get_call_logs(lc))); ms_message("*********************************"); print_stats=FALSE; } if (dump_stats) { ms_message("*********************************"); for (iterator=linphone_core_get_call_logs(lc);iterator!=NULL;iterator=iterator->next) { LinphoneCallLog *call_log=(LinphoneCallLog *)iterator->data; char * tmp_str = linphone_call_log_to_str(call_log); ms_message("\n%s",tmp_str); ms_free(tmp_str); } dump_stats=FALSE; ms_message("*********************************"); } for (iterator=linphone_core_get_calls(lc);iterator!=NULL;iterator=iterator->next) { LinphoneCall *call=(LinphoneCall *)iterator->data; if (linphone_call_get_duration(call) > max_call_duration) { ms_message("Terminating call [%p] after [%i] s",call,linphone_call_get_duration(call)); linphone_core_terminate_call(lc,call); break; } } } ms_message("Shutting down...\n"); linphone_core_destroy(lc); ms_message("Exited\n"); return 0; }
int main(int argc, char *argv[]){ LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneCall *call=NULL; LinphoneChatRoom *chat_room; LinphoneChatMessage *chat_message=NULL; const char *dest=NULL; LCSipTransports tp; tp.udp_port=LC_SIP_TRANSPORT_RANDOM; tp.tcp_port=LC_SIP_TRANSPORT_RANDOM; tp.tls_port=LC_SIP_TRANSPORT_RANDOM; /* take the destination sip uri from the command line arguments */ if (argc>1){ dest=argv[1]; } signal(SIGINT,stop); #ifdef DEBUG linphone_core_enable_logs(NULL); /*enable liblinphone logs.*/ #endif /* Instanciate a LinphoneCore object given the LinphoneCoreVTable */ lc=linphone_core_new(&vtable,NULL,NULL,NULL); linphone_core_set_sip_transports(lc,&tp); /*to avoid port colliding with receiver*/ if (dest){ /* Place an outgoing call with rtt enabled */ LinphoneCallParams *cp = linphone_core_create_call_params(lc, NULL); linphone_call_params_enable_realtime_text(cp,TRUE); /*enable real time text*/ call=linphone_core_invite_with_params(lc,dest,cp); linphone_call_params_destroy(cp); if (call==NULL){ printf("Could not place call to %s\n",dest); goto end; }else printf("Call to %s is in progress...",dest); linphone_call_ref(call); } /*wait for call to be established*/ while (running && (linphone_call_get_state(call) == LinphoneCallOutgoingProgress || linphone_call_get_state(call) == LinphoneCallOutgoingInit)) { linphone_core_iterate(lc); ms_usleep(50000); } /*check if call is established*/ switch (linphone_call_get_state(call)) { case LinphoneCallError: case LinphoneCallReleased: case LinphoneCallEnd: printf("Could not place call to %s\n",dest); goto end; break; default: break; /*continue*/ } chat_room=linphone_call_get_chat_room(call); /*create a chat room associated to this call*/ /* main loop for sending message and doing background linphonecore work: */ while(running){ char character; /*to disable terminal buffering*/ if (system ("/bin/stty raw") == -1){ ms_error("/bin/stty error"); } character = getchar(); if (system("/bin/stty cooked") == -1){ ms_error("/bin/stty error"); } if (character==0x03) {/*CTRL C*/ running=0; break; } if (character != EOF) { /* user has typed something*/ if (chat_message == NULL) { /*create a new message*/ chat_message = linphone_chat_room_create_message(chat_room,""); /*create an empty message*/ } if (character == '\r') { /*new line, committing message*/ linphone_chat_room_send_chat_message(chat_room,chat_message); chat_message = NULL; /*reset message*/ } else { linphone_chat_message_put_char(chat_message,character); /*send char in realtime*/ } } linphone_core_iterate(lc); ms_usleep(50000); } if (call && linphone_call_get_state(call)!=LinphoneCallEnd){ /* terminate the call */ printf("Terminating the call...\n"); linphone_core_terminate_call(lc,call); /*at this stage we don't need the call object */ linphone_call_unref(call); } end: printf("Shutting down...\n"); linphone_core_destroy(lc); printf("Exited\n"); return 0; }