static void friends_if_no_db_set(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); LinphoneFriend *lf = linphone_core_create_friend(manager->lc); LinphoneAddress *addr = linphone_address_new("sip:[email protected]"); const MSList *friends = NULL; LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); linphone_friend_list_add_friend(lfl, lf); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 1, int, "%d"); linphone_friend_list_remove_friend(lfl, lf); linphone_friend_unref(lf); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); linphone_friend_list_unref(lfl); linphone_address_unref(addr); linphone_core_manager_destroy(manager); }
static void text_message_with_send_error(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_rc"); char* to = linphone_address_as_string(pauline->identity); LinphoneChatRoom* chat_room = linphone_core_create_chat_room(marie->lc,to); LinphoneChatMessage* message = linphone_chat_room_create_message(chat_room,"Bli bli bli \n blu"); LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(message); reset_counters(&marie->stat); reset_counters(&pauline->stat); /*simultate a network error*/ sal_set_send_error(marie->lc->sal, -1); { int dummy=0; wait_for_until(marie->lc,pauline->lc,&dummy,1,100); /*just to have time to purge message stored in the server*/ reset_counters(&marie->stat); reset_counters(&pauline->stat); } linphone_chat_message_cbs_set_msg_state_changed(cbs,liblinphone_tester_chat_message_msg_state_changed); linphone_chat_room_send_chat_message(chat_room,message); /* check transient message list: the message should be in it, and should be the only one */ CU_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 1); CU_ASSERT_EQUAL(ms_list_nth_data(chat_room->transient_messages,0), message); CU_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneMessageNotDelivered,1)); /*CU_ASSERT_EQUAL(marie->stat.number_of_LinphoneMessageInProgress,1);*/ CU_ASSERT_EQUAL(pauline->stat.number_of_LinphoneMessageReceived,0); /* the message should have been discarded from transient list after an error */ CU_ASSERT_EQUAL(ms_list_size(chat_room->transient_messages), 0); sal_set_send_error(marie->lc->sal, 0); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
void linphone_gtk_create_in_call_view(LinphoneCall *call){ GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame"); GtkWidget *main_window=linphone_gtk_get_main_window (); GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch"); static int call_index=1; int idx; GtkWidget *transfer; GtkWidget *conf; GtkWidget *button; GtkWidget *image; if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){ /*this is the only call at this time */ call_index=1; } g_object_set_data(G_OBJECT(call_view),"call",call); g_object_set_data(G_OBJECT(call_view),"call_index",GINT_TO_POINTER(call_index)); linphone_call_set_user_pointer (call,call_view); linphone_call_ref(call); gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index)); gtk_widget_show(call_view); idx = gtk_notebook_page_num(notebook, call_view); gtk_notebook_set_current_page(notebook, idx); call_index++; linphone_gtk_enable_hold_button (call,FALSE,TRUE); linphone_gtk_enable_video_button (call,FALSE,TRUE); linphone_gtk_enable_mute_button( GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE); transfer = linphone_gtk_get_widget(call_view,"transfer_button"); gtk_button_set_image(GTK_BUTTON(transfer),gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,GTK_ICON_SIZE_BUTTON)); g_signal_connect(G_OBJECT(transfer),"clicked",(GCallback)transfer_button_clicked,call); gtk_widget_hide(transfer); conf = linphone_gtk_get_widget(call_view,"conference_button"); gtk_button_set_image(GTK_BUTTON(conf),gtk_image_new_from_stock (GTK_STOCK_ADD,GTK_ICON_SIZE_BUTTON)); g_signal_connect(G_OBJECT(conf),"clicked",(GCallback)conference_button_clicked,call); gtk_widget_hide(conf); button=linphone_gtk_get_widget(call_view,"terminate_call"); image=create_pixmap (linphone_gtk_get_ui_config("stop_call_icon","stopcall-small.png")); gtk_button_set_label(GTK_BUTTON(button),_("Hang up")); gtk_button_set_image(GTK_BUTTON(button),image); gtk_widget_show(image); g_signal_connect_swapped(G_OBJECT(linphone_gtk_get_widget(call_view,"quality_indicator")),"button-press-event",(GCallback)linphone_gtk_show_call_stats,call); }
static void friends_migration(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("friends_rc", FALSE); LpConfig *lpc = linphone_core_get_config(manager->lc); LinphoneFriendList *lfl = linphone_core_get_default_friend_list(manager->lc); const MSList *friends = linphone_friend_list_get_friends(lfl); MSList *friends_from_db = NULL; char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 0, int, "%i"); unlink(friends_db); linphone_core_set_friends_database_path(manager->lc, friends_db); lfl = linphone_core_get_default_friend_list(manager->lc); friends = linphone_friend_list_get_friends(lfl); BC_ASSERT_EQUAL(ms_list_size(friends), 3, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(manager->lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 3, int, "%d"); BC_ASSERT_EQUAL(lp_config_get_int(lpc, "misc", "friends_migration_done", 0), 1, int, "%i"); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); unlink(friends_db); ms_free(friends_db); linphone_core_manager_destroy(manager); }
static gboolean linphone_gtk_process_buddy_lookup(GtkWidget *w){ BuddyLookupStatus bls; SipSetupContext *ctx; int last_state; gchar *tmp; MSList *results=NULL; GtkProgressBar *pb=GTK_PROGRESS_BAR(linphone_gtk_get_widget(w,"progressbar")); ctx=(SipSetupContext*)g_object_get_data(G_OBJECT(w),"SipSetupContext"); last_state=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(w),"last_state")); bls=sip_setup_context_get_buddy_lookup_status(ctx); if (last_state==bls) return TRUE; switch(bls){ case BuddyLookupNone: gtk_progress_bar_set_fraction(pb,0); gtk_progress_bar_set_text(pb,NULL); break; case BuddyLookupFailure: gtk_progress_bar_set_fraction(pb,0); gtk_progress_bar_set_text(pb,_("Error communicating with server.")); break; case BuddyLookupConnecting: gtk_progress_bar_set_fraction(pb,0.2); gtk_progress_bar_set_text(pb,_("Connecting...")); break; case BuddyLookupConnected: gtk_progress_bar_set_fraction(pb,0.4); gtk_progress_bar_set_text(pb,_("Connected")); break; case BuddyLookupReceivingResponse: gtk_progress_bar_set_fraction(pb,0.8); gtk_progress_bar_set_text(pb,_("Receiving data...")); break; case BuddyLookupDone: sip_setup_context_get_buddy_lookup_results(ctx,&results); linphone_gtk_display_lookup_results( linphone_gtk_get_widget(w,"search_results"), results); gtk_progress_bar_set_fraction(pb,1); tmp=g_strdup_printf(_("Found %i contact(s)"),ms_list_size(results)); gtk_progress_bar_set_text(pb,tmp); g_free(tmp); if (results) sip_setup_context_free_results(results); break; } enable_add_buddy_button(w,bls==BuddyLookupDone); g_object_set_data(G_OBJECT(w),"last_state",GINT_TO_POINTER(bls)); return TRUE; }
LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_for_proxies) { LinphoneCoreManager* mgr= ms_new0(LinphoneCoreManager,1); LinphoneProxyConfig* proxy; char *rc_path = NULL; int proxy_count; mgr->v_table.registration_state_changed=registration_state_changed; mgr->v_table.auth_info_requested=auth_info_requested; mgr->v_table.call_state_changed=call_state_changed; mgr->v_table.text_received=text_message_received; mgr->v_table.message_received=message_received; mgr->v_table.file_transfer_received=file_transfer_received; mgr->v_table.file_transfer_send=file_transfer_send; mgr->v_table.file_transfer_progress_indication=file_transfer_progress_indication; mgr->v_table.is_composing_received=is_composing_received; mgr->v_table.new_subscription_requested=new_subscription_requested; mgr->v_table.notify_presence_received=notify_presence_received; mgr->v_table.transfer_state_changed=linphone_transfer_state_changed; mgr->v_table.info_received=info_message_received; mgr->v_table.subscription_state_changed=linphone_subscription_state_change; mgr->v_table.notify_received=linphone_notify_received; mgr->v_table.publish_state_changed=linphone_publish_state_changed; mgr->v_table.configuring_status=linphone_configuration_status; mgr->v_table.call_encryption_changed=linphone_call_encryption_changed; reset_counters(&mgr->stat); if (rc_file) rc_path = ms_strdup_printf("rcfiles/%s", rc_file); mgr->lc=configure_lc_from(&mgr->v_table, liblinphone_tester_file_prefix, rc_path, mgr); /*CU_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count);*/ if (check_for_proxies && rc_file) /**/ proxy_count=ms_list_size(linphone_core_get_proxy_config_list(mgr->lc)); else proxy_count=0; if (proxy_count) wait_for_until(mgr->lc,NULL,&mgr->stat.number_of_LinphoneRegistrationOk,proxy_count,5000*proxy_count); CU_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count); enable_codec(mgr->lc,"PCMU",8000); linphone_core_get_default_proxy(mgr->lc,&proxy); if (proxy) { mgr->identity = linphone_address_new(linphone_proxy_config_get_identity(proxy)); linphone_address_clean(mgr->identity); } if (rc_path) ms_free(rc_path); return mgr; }
LinphoneCall *linphone_gtk_get_currently_displayed_call(){ LinphoneCore *lc=linphone_gtk_get_core(); GtkWidget *main_window=linphone_gtk_get_main_window (); GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch"); const MSList *calls=linphone_core_get_calls(lc); if (!linphone_gtk_use_in_call_view() || ms_list_size(calls)==1){ if (calls) return (LinphoneCall*)calls->data; }else{ int idx=gtk_notebook_get_current_page (notebook); GtkWidget *page=gtk_notebook_get_nth_page(notebook,idx); if (page!=NULL){ LinphoneCall *call=(LinphoneCall*)g_object_get_data(G_OBJECT(page),"call"); return call; } } return NULL; }
jlongArray Java_com_acsoftware_android_domophone_LibLP_nlistVideoPayloadTypes(JNIEnv* env ,jobject thiz ) { const MSList* codecs = linphone_core_get_video_codecs(lc); int codecsCount = ms_list_size(codecs); jlongArray jCodecs = env->NewLongArray(codecsCount); jlong *jInternalArray = env->GetLongArrayElements(jCodecs, NULL); for (int i = 0; i < codecsCount; i++ ) { jInternalArray[i] = (unsigned long) (codecs->data); codecs = codecs->next; } env->ReleaseLongArrayElements(jCodecs, jInternalArray, 0); return jCodecs; }
static void quality_reporting_not_sent_if_call_not_started() { LinphoneCoreManager* marie = linphone_core_manager_new( "marie_quality_reporting_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); LinphoneCallLog* out_call_log; LinphoneCall* out_call; linphone_core_set_max_calls(pauline->lc,0); out_call = linphone_core_invite(marie->lc,"pauline"); linphone_call_ref(out_call); BC_ASSERT_TRUE(wait_for_until(marie->lc,pauline->lc,&marie->stat.number_of_LinphoneCallError,1, 10000)); BC_ASSERT_EQUAL(marie->stat.number_of_LinphoneCallError,1, int, "%d"); if (ms_list_size(linphone_core_get_call_logs(marie->lc))>0) { out_call_log=(LinphoneCallLog*)(linphone_core_get_call_logs(marie->lc)->data); BC_ASSERT_PTR_NOT_NULL(out_call_log); BC_ASSERT_EQUAL(linphone_call_log_get_status(out_call_log),LinphoneCallAborted, int, "%d"); }
void linphone_core_manager_start(LinphoneCoreManager *mgr, int check_for_proxies) { LinphoneProxyConfig* proxy; int proxy_count; /*BC_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count, int, "%d");*/ if (check_for_proxies){ /**/ proxy_count=ms_list_size(linphone_core_get_proxy_config_list(mgr->lc)); }else{ proxy_count=0; /*this is to prevent registration to go on*/ linphone_core_set_network_reachable(mgr->lc, FALSE); } if (proxy_count){ #define REGISTER_TIMEOUT 20 /* seconds */ int success = wait_for_until(mgr->lc,NULL,&mgr->stat.number_of_LinphoneRegistrationOk, proxy_count,(REGISTER_TIMEOUT * 1000 * proxy_count)); if( !success ){ ms_error("Did not register after %d seconds for %d proxies", REGISTER_TIMEOUT, proxy_count); } } BC_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count, int, "%d"); enable_codec(mgr->lc,"PCMU",8000); proxy = linphone_core_get_default_proxy_config(mgr->lc); if (proxy) { if (mgr->identity){ linphone_address_destroy(mgr->identity); } mgr->identity = linphone_address_clone(linphone_proxy_config_get_identity_address(proxy)); linphone_address_clean(mgr->identity); } if (linphone_core_get_stun_server(mgr->lc) != NULL){ /*before we go, ensure that the stun server is resolved, otherwise all ice related test will fail*/ BC_ASSERT_TRUE(wait_for_stun_resolution(mgr)); } if (!check_for_proxies){ /*now that stun server resolution is done, we can start registering*/ linphone_core_set_network_reachable(mgr->lc, TRUE); } }
static void call_terminated(SalOp *op, const char *from){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL) return; switch(linphone_call_get_state(call)){ case LinphoneCallEnd: case LinphoneCallError: ms_warning("call_terminated: ignoring."); return; break; case LinphoneCallIncomingReceived: case LinphoneCallIncomingEarlyMedia: call->reason=LinphoneReasonNotAnswered; break; default: break; } ms_message("Current call terminated..."); if (call->refer_pending){ linphone_core_start_refered_call(lc,call,NULL); } //we stop the call only if we have this current call or if we are in call if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) { linphone_core_stop_ringing(lc); } linphone_call_stop_media_streams(call); if (lc->vtable.show!=NULL) lc->vtable.show(lc); if (lc->vtable.display_status!=NULL) lc->vtable.display_status(lc,_("Call terminated.")); #ifdef BUILD_UPNP linphone_call_delete_upnp_session(call); #endif //BUILD_UPNP linphone_call_set_state(call, LinphoneCallEnd,"Call ended"); }
static bool_t h264_dec_update_format_description(VTH264DecCtx *ctx, const MSList *parameter_sets) { const MSList *it; const size_t max_ps_count = 20; size_t ps_count; const uint8_t *ps_ptrs[max_ps_count]; size_t ps_sizes[max_ps_count]; int sps_count = 0, pps_count = 0; int i; OSStatus status; if(ctx->format_desc) CFRelease(ctx->format_desc); ctx->format_desc = NULL; ps_count = ms_list_size(parameter_sets); if(ps_count > max_ps_count) { ms_error("VideoToolboxDec: too much SPS/PPS"); return FALSE; } for(it=parameter_sets,i=0; it; it=it->next,i++) { mblk_t *m = (mblk_t *)it->data; ps_ptrs[i] = m->b_rptr; ps_sizes[i] = m->b_wptr - m->b_rptr; if(ms_h264_nalu_get_type(m) == MSH264NaluTypeSPS) sps_count++; else if(ms_h264_nalu_get_type(m) == MSH264NaluTypePPS) pps_count++; } if(sps_count==0) { ms_error("VideoToolboxDec: no SPS"); return FALSE; } if(pps_count==0) { ms_error("VideoToolboxDec: no PPS"); return FALSE; } status = CMVideoFormatDescriptionCreateFromH264ParameterSets(NULL, ps_count, ps_ptrs, ps_sizes, H264_NALU_HEAD_SIZE, &ctx->format_desc); if(status != noErr) { ms_error("VideoToolboxDec: could not find out the input format: %d", status); return FALSE; } return TRUE; }
static void linphone_call_set_terminated(LinphoneCall *call){ LinphoneCore *lc=call->core; linphone_core_update_allocated_audio_bandwidth(lc); call->owns_call_log=FALSE; linphone_call_log_completed(call); if (call == lc->current_call){ ms_message("Resetting the current call"); lc->current_call=NULL; } if (linphone_core_del_call(lc,call) != 0){ ms_error("Could not remove the call from the list !!!"); } if (ms_list_size(lc->calls)==0) linphone_core_notify_all_friends(lc,lc->presence_mode); }
void linphone_gtk_create_in_call_view(LinphoneCall *call){ GtkWidget *call_view=linphone_gtk_create_widget("main","in_call_frame"); GtkWidget *main_window=linphone_gtk_get_main_window (); GtkNotebook *notebook=(GtkNotebook *)linphone_gtk_get_widget(main_window,"viewswitch"); static int call_index=1; int idx; if (ms_list_size(linphone_core_get_calls(linphone_gtk_get_core()))==1){ /*this is the only call at this time */ call_index=1; } g_object_set_data(G_OBJECT(call_view),"call",call); linphone_call_set_user_pointer (call,call_view); linphone_call_ref(call); gtk_notebook_append_page (notebook,call_view,make_tab_header(call_index)); gtk_widget_show(call_view); idx = gtk_notebook_page_num(notebook, call_view); gtk_notebook_set_current_page(notebook, idx); call_index++; linphone_gtk_enable_hold_button (call,FALSE,TRUE); linphone_gtk_enable_mute_button( GTK_BUTTON(linphone_gtk_get_widget(call_view,"incall_mute")),FALSE); }
static void call_terminated(SalOp *op, const char *from){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(op)); LinphoneCall *call=(LinphoneCall*)sal_op_get_user_pointer(op); if (call==NULL) return; if (linphone_call_get_state(call)==LinphoneCallEnd || linphone_call_get_state(call)==LinphoneCallError){ ms_warning("call_terminated: ignoring."); return; } ms_message("Current call terminated..."); //we stop the call only if we have this current call or if we are in call if (lc->ringstream!=NULL && ( (ms_list_size(lc->calls) == 1) || linphone_core_in_call(lc) )) { ring_stop(lc->ringstream); lc->ringstream=NULL; } linphone_call_stop_media_streams(call); if (lc->vtable.show!=NULL) lc->vtable.show(lc); if (lc->vtable.display_status!=NULL) lc->vtable.display_status(lc,_("Call terminated.")); linphone_call_set_state(call, LinphoneCallEnd,"Call ended"); }
static double compute_available_bw(MSStatefulQosAnalyzer *obj){ MSList *it; double constant_network_loss = 0.; double mean_bw = 0.; MSList *current = obj->rtcpstatspoint; MSList *last = current; int size = ms_list_size(obj->rtcpstatspoint); if (current == NULL){ ms_message("MSStatefulQosAnalyzer[%p]: no points available for estimation", obj); return -1; } while (last->next){ last = last->next; } if (size > 3){ smooth_values(obj); } /*suppose that first point is a reliable estimation of the constant network loss rate*/ constant_network_loss = ((rtcpstatspoint_t *)obj->rtcpstatspoint->data)->loss_percent; ms_message("MSStatefulQosAnalyzer[%p]:\tconstant_network_loss=%f", obj, constant_network_loss); #ifdef DEBUG for (it = obj->rtcpstatspoint; it != NULL; it=it->next){ rtcpstatspoint_t * point = (rtcpstatspoint_t *)it->data; (void)point; ms_message("MSStatefulQosAnalyzer[%p]:\t\tsorted values %d: %f %f", obj, ms_list_position(obj->rtcpstatspoint, it), point->bandwidth, point->loss_percent); } #endif if (size == 1){ rtcpstatspoint_t *p = (rtcpstatspoint_t *)current->data; ms_message("MSStatefulQosAnalyzer[%p]: one single point", obj); mean_bw = p->bandwidth * ((p->loss_percent>1e-5) ? (100-p->loss_percent)/100.f:2); }else{ while (current!=NULL && ((rtcpstatspoint_t*)current->data)->loss_percent<3+constant_network_loss){ ms_message("MSStatefulQosAnalyzer[%p]:\t%d is stable", obj, ms_list_position(obj->rtcpstatspoint, current)); /*find the last stable measure point, starting from highest bandwidth*/ for (it=last;it!=current;it=it->prev){ if (((rtcpstatspoint_t *)it->data)->loss_percent <= 3 + ((rtcpstatspoint_t*)current->data)->loss_percent){ ms_message("MSStatefulQosAnalyzer[%p]:\t%d is less than %d", obj, ms_list_position(obj->rtcpstatspoint, it), ms_list_position(obj->rtcpstatspoint, current)); current = it; break; } } /*current is the first unstable point, so taking the next one*/ current = current->next; } /*all points are below the constant loss rate threshold: there might be bad network conditions but no congestion*/ if (current == NULL){ mean_bw = 2 * ((rtcpstatspoint_t*)last->data)->bandwidth; /*only first packet is stable*/ }else if (current->prev == obj->rtcpstatspoint){ rtcpstatspoint_t *p = (rtcpstatspoint_t *)current->prev->data; mean_bw = p->bandwidth * (100 - p->loss_percent) / 100.; /*otherwise, there is a congestion detected starting at "current"*/ }else{ rtcpstatspoint_t *laststable = (rtcpstatspoint_t*)current->prev->data; rtcpstatspoint_t *firstunstable = (rtcpstatspoint_t*)current->data; mean_bw = .5*(laststable->bandwidth+firstunstable->bandwidth); } ms_message("MSStatefulQosAnalyzer[%p]: [0->%d] last stable is %d(%f;%f)" , obj , ms_list_position(obj->rtcpstatspoint, last) , ms_list_position(obj->rtcpstatspoint, (current ? current->prev : last)) , ((rtcpstatspoint_t*) (current ? current->prev->data : last->data))->bandwidth , ((rtcpstatspoint_t*) (current ? current->prev->data : last->data))->loss_percent); if (current!=NULL){ ms_message("MSStatefulQosAnalyzer[%p]: , first unstable is %d(%f;%f)" , obj , ms_list_position(obj->rtcpstatspoint, current) , ((rtcpstatspoint_t*) current->data)->bandwidth , ((rtcpstatspoint_t*) current->data)->loss_percent); } } ms_message("MSStatefulQosAnalyzer[%p]: --> estimated_available_bw=%f", obj, mean_bw); obj->network_loss_rate = constant_network_loss; obj->congestion_bandwidth = mean_bw; return mean_bw; }
int linphone_conference_get_members_nb(LinphoneConference * conf) { return ms_list_size(conf->members); }
static float compute_available_bw(MSStatefulQosAnalyzer *obj){ MSList *it; float constant_network_loss = 0.; float mean_bw = 0.; MSList *current = obj->rtcpstatspoint; MSList *last = current; int size = ms_list_size(obj->rtcpstatspoint); if (current == NULL){ ms_message("MSStatefulQosAnalyzer[%p]: no points available for estimation", obj); return -1; } while (last->next){ last = last->next; } if (size > 3){ smooth_values(obj); } /*suppose that first point is a reliable estimation of the constant network loss rate*/ constant_network_loss = ((rtcpstatspoint_t *)obj->rtcpstatspoint->data)->loss_percent; ms_message("MSStatefulQosAnalyzer[%p]:\tconstant_network_loss=%f", obj, constant_network_loss); #ifdef DEBUG for (it = obj->rtcpstatspoint; it != NULL; it=it->next){ rtcpstatspoint_t * point = (rtcpstatspoint_t *)it->data; (void)point; ms_message("MSStatefulQosAnalyzer[%p]:\t\tsorted values %d: %f %f", obj, ms_list_position(obj->rtcpstatspoint, it), point->bandwidth, point->loss_percent); } #endif if (size == 1){ rtcpstatspoint_t *p = (rtcpstatspoint_t *)current->data; ms_message("MSStatefulQosAnalyzer[%p]: one single point", obj); mean_bw = p->bandwidth * ((p->loss_percent>1e-5) ? (100-p->loss_percent)/100.f:2); }else{ while (current!=NULL && ((rtcpstatspoint_t*)current->data)->loss_percent<3+constant_network_loss){ ms_message("MSStatefulQosAnalyzer[%p]:\t%d is stable", obj, ms_list_position(obj->rtcpstatspoint, current)); for (it=last;it!=current;it=it->prev){ if (((rtcpstatspoint_t *)it->data)->loss_percent <= 3 + ((rtcpstatspoint_t*)current->data)->loss_percent){ ms_message("MSStatefulQosAnalyzer[%p]:\t%d is less than %d", obj, ms_list_position(obj->rtcpstatspoint, it), ms_list_position(obj->rtcpstatspoint, current)); current = it; break; } } current = current->next; } if (current == NULL){ /*constant loss rate - bad network conditions but no congestion*/ mean_bw = 2 * ((rtcpstatspoint_t*)last->data)->bandwidth; }else if (current->prev == obj->rtcpstatspoint){ /*only first packet is stable - might still be above real bandwidth*/ rtcpstatspoint_t *p = (rtcpstatspoint_t *)current->prev->data; mean_bw = p->bandwidth * (100 - p->loss_percent) / 100.f; }else{ /*there is some congestion*/ mean_bw = .5*(((rtcpstatspoint_t*)current->prev->data)->bandwidth+((rtcpstatspoint_t*)current->data)->bandwidth); } ms_message("MSStatefulQosAnalyzer[%p]: [0->%d] last stable is %d(%f;%f)" , obj , ms_list_position(obj->rtcpstatspoint, last) , ms_list_position(obj->rtcpstatspoint, (current ? current->prev : last)) , ((rtcpstatspoint_t*) (current ? current->prev->data : last->data))->bandwidth , ((rtcpstatspoint_t*) (current ? current->prev->data : last->data))->loss_percent); if (current!=NULL){ ms_message("MSStatefulQosAnalyzer[%p]: , first unstable is %d(%f;%f)" , obj , ms_list_position(obj->rtcpstatspoint, current) , ((rtcpstatspoint_t*) current->data)->bandwidth , ((rtcpstatspoint_t*) current->data)->loss_percent); } } ms_message("MSStatefulQosAnalyzer[%p]: --> estimated_available_bw=%f", obj, mean_bw); obj->network_loss_rate = constant_network_loss; obj->congestion_bandwidth = mean_bw; return mean_bw; }
static void stateful_analyzer_suggest_action(MSQosAnalyzer *objbase, MSRateControlAction *action){ MSStatefulQosAnalyzer *obj=(MSStatefulQosAnalyzer*)objbase; float curbw = 0; float bw = 0; rtcpstatspoint_t* greatest_pt = NULL; /*if this is the first measure, there is not enough reliable data to use; we assume loss rate is due to non congestionned network. This is mainly useful in the case loss rate is high (>30%), to reduce quality even before the second RTCP report which can be really used. */ if (obj->curindex==1){ if (obj->network_loss_rate!=0.f){ action->type=MSRateControlActionDecreaseBitrate; action->value=obj->network_loss_rate; } }else { curbw = obj->latest ? obj->latest->bandwidth : 0.f; bw = compute_available_bw(obj); greatest_pt = ms_list_size(obj->rtcpstatspoint) ? (rtcpstatspoint_t*)ms_list_nth_data(obj->rtcpstatspoint, ms_list_size(obj->rtcpstatspoint)-1) : NULL; /*try a burst every 50 seconds (10 RTCP packets)*/ if (obj->curindex % 10 == 6){ ms_message("MSStatefulQosAnalyzer[%p]: try burst!", obj); obj->burst_state = MSStatefulQosAnalyzerBurstEnable; } /*test a min burst to avoid overestimation of available bandwidth but only if there is some loss*/ else if (greatest_pt!=NULL && greatest_pt->loss_percent>1 && (obj->curindex % 10 == 2 || obj->curindex % 10 == 3)){ ms_message("MSStatefulQosAnalyzer[%p]: try minimal burst!", obj); bw *= .33; } /*no bandwidth estimation computed*/ if (bw <= 0 || curbw <= 0){ action->type=MSRateControlActionDoNothing; action->value=0; }else if (bw > curbw){ action->type=MSRateControlActionIncreaseQuality; action->value=MAX(0, 100. * (bw / curbw - 1)); }else{ action->type=MSRateControlActionDecreaseBitrate; action->value=MAX(10, -100. * (bw / curbw - 1)); } } ms_message("MSStatefulQosAnalyzer[%p]: %s of value %d", obj, ms_rate_control_action_type_name(action->type), action->value); if (objbase->on_action_suggested!=NULL){ int i; char *data[4]; int datac = sizeof(data) / sizeof(data[0]); data[0]=ms_strdup("%loss rtt_ms cur_bw"); data[1]=ms_strdup_printf("%d %d %d" , obj->latest?(int)obj->latest->loss_percent:0 , obj->latest?(int)obj->latest->rtt:0 , obj->latest?(int)obj->latest->bandwidth:0 ); data[2]=ms_strdup("action_type action_value est_bw"); data[3]=ms_strdup_printf("%s %d %d" , ms_rate_control_action_type_name(action->type) , action->value , (int)bw ); objbase->on_action_suggested(objbase->on_action_suggested_user_pointer, datac, (const char**)data); for (i=0;i<datac;++i){ ms_free(data[i]); } } }
static char * create_resource_list_xml(const LinphoneFriendList *list) { char *xml_content = NULL; MSList *elem; xmlBufferPtr buf; xmlTextWriterPtr writer; int err; if (ms_list_size(list->friends) <= 0) return NULL; buf = xmlBufferCreate(); if (buf == NULL) { ms_error("%s: Error creating the XML buffer", __FUNCTION__); return NULL; } writer = xmlNewTextWriterMemory(buf, 0); if (writer == NULL) { ms_error("%s: Error creating the XML writer", __FUNCTION__); return NULL; } xmlTextWriterSetIndent(writer,1); err = xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL); if (err >= 0) { err = xmlTextWriterStartElementNS(writer, NULL, (const xmlChar *)"resource-lists", (const xmlChar *)"urn:ietf:params:xml:ns:resource-lists"); } if (err >= 0) { err = xmlTextWriterWriteAttributeNS(writer, (const xmlChar *)"xmlns", (const xmlChar *)"xsi", NULL, (const xmlChar *)"http://www.w3.org/2001/XMLSchema-instance"); } if (err>= 0) { err = xmlTextWriterStartElement(writer, (const xmlChar *)"list"); } for (elem = list->friends; elem != NULL; elem = elem->next) { LinphoneFriend *friend = (LinphoneFriend *)elem->data; char *uri = linphone_address_as_string_uri_only(friend->uri); if (err >= 0) { err = xmlTextWriterStartElement(writer, (const xmlChar *)"entry"); } if (err >= 0) { err = xmlTextWriterWriteAttribute(writer, (const xmlChar *)"uri", (const xmlChar *)uri); } if (err >= 0) { /* Close the "entry" element. */ err = xmlTextWriterEndElement(writer); } if (uri) ms_free(uri); } if (err >= 0) { /* Close the "list" element. */ err = xmlTextWriterEndElement(writer); } if (err >= 0) { /* Close the "resource-lists" element. */ err = xmlTextWriterEndElement(writer); } if (err >= 0) { err = xmlTextWriterEndDocument(writer); } if (err > 0) { /* xmlTextWriterEndDocument returns the size of the content. */ xml_content = ms_strdup((char *)buf->content); } xmlFreeTextWriter(writer); xmlBufferFree(buf); return xml_content; }
static bool_t stateful_analyzer_process_rtcp(MSQosAnalyzer *objbase, mblk_t *rtcp){ MSStatefulQosAnalyzer *obj=(MSStatefulQosAnalyzer*)objbase; const report_block_t *rb=NULL; if (rtcp_is_SR(rtcp)){ rb=rtcp_SR_get_report_block(rtcp,0); }else if (rtcp_is_RR(rtcp)){ rb=rtcp_RR_get_report_block(rtcp,0); } if (rb && report_block_get_ssrc(rb)==rtp_session_get_send_ssrc(obj->session)){ if (ortp_loss_rate_estimator_process_report_block(objbase->lre,&obj->session->rtp,rb)){ int i; float loss_rate = ortp_loss_rate_estimator_get_value(objbase->lre); float up_bw = stateful_qos_analyzer_upload_bandwidth(obj,report_block_get_high_ext_seq(rb)); obj->curindex++; /*flush bandwidth estimation measures for seq number lower than remote report block received*/ for (i=0;i<BW_HISTORY;i++){ if (obj->upload_bandwidth[i].seq_number<report_block_get_high_ext_seq(rb)){ obj->upload_bandwidth[i].seq_number=0; obj->upload_bandwidth[i].up_bandwidth=0.f; } } /* Always skip the first report, since values might be erroneous due to initialization of multiples objects (encoder/decoder/stats computing..) Instead assume loss rate is a good estimation of network capacity */ if (obj->curindex==1) { obj->network_loss_rate=loss_rate; return TRUE; } obj->latest=ms_new0(rtcpstatspoint_t, 1); obj->latest->timestamp=ms_time(0); obj->latest->bandwidth=up_bw; obj->latest->loss_percent=loss_rate; obj->latest->rtt=rtp_session_get_round_trip_propagation(obj->session); obj->rtcpstatspoint=ms_list_insert_sorted(obj->rtcpstatspoint, obj->latest, (MSCompareFunc)sort_by_bandwidth); /*if the measure was 0% loss, reset to 0% every measures below it*/ if (obj->latest->loss_percent < 1e-5){ MSList *it=obj->rtcpstatspoint; MSList *latest_pos=ms_list_find(obj->rtcpstatspoint,obj->latest); while (it!=latest_pos->next){ ((rtcpstatspoint_t *)it->data)->loss_percent=0.f; it = it->next; } } ms_message("MSStatefulQosAnalyzer[%p]: one more %d: %f %f", obj, obj->curindex-1, obj->latest->bandwidth, obj->latest->loss_percent); if (ms_list_size(obj->rtcpstatspoint) > ESTIM_HISTORY){ int prev_size = ms_list_size(obj->rtcpstatspoint); /*clean everything which occurred 60 sec or more ago*/ time_t clear_time = ms_time(0) - 60; obj->rtcpstatspoint = ms_list_remove_custom(obj->rtcpstatspoint, (MSCompareFunc)earlier_than, &clear_time); ms_message("MSStatefulQosAnalyzer[%p]: reached list maximum capacity " "(count=%d) --> Cleaned list (count=%d)", obj, prev_size, ms_list_size(obj->rtcpstatspoint)); } return TRUE; } } return FALSE; }
void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md){ SalMediaDescription *oldmd=call->resultdesc; bool_t all_muted=FALSE; bool_t send_ringbacktone=FALSE; linphone_core_stop_ringing(lc); if (!new_md) { ms_error("linphone_core_update_streams() called with null media description"); return; } if (call->biggestdesc==NULL || new_md->n_total_streams>call->biggestdesc->n_total_streams){ /*we have been offered and now are ready to proceed, or we added a new stream*/ /*store the media description to remember the mapping of calls*/ if (call->biggestdesc){ sal_media_description_unref(call->biggestdesc); call->biggestdesc=NULL; } if (sal_call_is_offerer(call->op)) call->biggestdesc=sal_media_description_ref(call->localdesc); else call->biggestdesc=sal_media_description_ref(sal_call_get_remote_media_description(call->op)); } sal_media_description_ref(new_md); call->expect_media_in_ack=FALSE; call->resultdesc=new_md; if ((call->audiostream && call->audiostream->ms.ticker) || (call->videostream && call->videostream->ms.ticker)){ /* we already started media: check if we really need to restart it*/ if (oldmd){ int md_changed = media_parameters_changed(call, oldmd, new_md); if ((md_changed & SAL_MEDIA_DESCRIPTION_CODEC_CHANGED) || call->playing_ringbacktone) { ms_message("Media descriptions are different, need to restart the streams."); } else { if (md_changed == SAL_MEDIA_DESCRIPTION_UNCHANGED) { if (call->all_muted){ ms_message("Early media finished, unmuting inputs..."); /*we were in early media, now we want to enable real media */ linphone_call_enable_camera (call,linphone_call_camera_enabled (call)); if (call->audiostream) linphone_core_enable_mic(lc, linphone_core_mic_enabled(lc)); #ifdef VIDEO_ENABLED if (call->videostream && call->camera_enabled) video_stream_change_camera(call->videostream,lc->video_conf.device ); #endif } ms_message("No need to restart streams, SDP is unchanged."); goto end; }else { if (md_changed & SAL_MEDIA_DESCRIPTION_NETWORK_CHANGED) { ms_message("Network parameters have changed, update them."); linphone_core_update_streams_destinations(lc, call, oldmd, new_md); } if (md_changed & SAL_MEDIA_DESCRIPTION_CRYPTO_CHANGED) { ms_message("Crypto parameters have changed, update them."); linphone_call_update_crypto_parameters(call, oldmd, new_md); } goto end; } } } linphone_call_stop_media_streams (call); linphone_call_init_media_streams (call); } if (call->audiostream==NULL){ /*this happens after pausing the call locally. The streams are destroyed and then we wait the 200Ok to recreate them*/ linphone_call_init_media_streams (call); } if (call->state==LinphoneCallIncomingEarlyMedia && linphone_core_get_remote_ringback_tone (lc)!=NULL){ send_ringbacktone=TRUE; } if (call->state==LinphoneCallIncomingEarlyMedia || (call->state==LinphoneCallOutgoingEarlyMedia && !call->params.real_early_media)){ all_muted=TRUE; } linphone_call_start_media_streams(call,all_muted,send_ringbacktone); if (call->state==LinphoneCallPausing && call->paused_by_app && ms_list_size(lc->calls)==1){ linphone_core_play_named_tone(lc,LinphoneToneCallOnHold); } end: if (oldmd) sal_media_description_unref(oldmd); }
static void friends_sqlite_storage(void) { LinphoneCoreVTable *v_table = linphone_core_v_table_new(); LinphoneCore* lc = NULL; LinphoneFriendList *lfl = NULL; LinphoneFriend *lf = NULL; LinphoneFriend *lf2 = NULL; LinphoneVcard *lvc = linphone_vcard_new(); LinphoneAddress *addr = linphone_address_new("sip:[email protected]"); const MSList *friends = NULL; MSList *friends_from_db = NULL; MSList *friends_lists_from_db = NULL; char *friends_db = create_filepath(bc_tester_get_writable_dir_prefix(), "friends", "db"); LinphoneFriendListStats *stats = (LinphoneFriendListStats *)ms_new0(LinphoneFriendListStats, 1); v_table->friend_list_created = friend_list_created_cb; v_table->friend_list_removed = friend_list_removed_cb; lc = linphone_core_new(v_table, NULL, NULL, NULL); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); lfl = linphone_core_create_friend_list(lc); linphone_friend_list_set_user_data(lfl, stats); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); unlink(friends_db); linphone_core_set_friends_database_path(lc, friends_db); friends_from_db = linphone_core_fetch_friends_from_db(lc, linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d"); linphone_vcard_set_etag(lvc, "\"123-456789\""); linphone_vcard_set_url(lvc, "http://dav.somewhere.fr/addressbook/me/someone.vcf"); lf = linphone_friend_new_from_vcard(lvc); linphone_friend_set_address(lf, addr); linphone_friend_set_name(lf, "Sylvain"); linphone_core_add_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->new_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->new_list_count, 1, int, "%i"); linphone_friend_list_unref(lfl); linphone_friend_list_set_display_name(lfl, "Test"); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%i"); linphone_friend_unref(lf); BC_ASSERT_EQUAL(lfl->storage_id, 1, int, "%d"); BC_ASSERT_EQUAL(lf->storage_id, 1, int, "%d"); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); friends_lists_from_db = linphone_core_fetch_friends_lists_from_db(lc); BC_ASSERT_EQUAL(ms_list_size(friends_lists_from_db), 1, int, "%d"); friends_from_db = ((LinphoneFriendList *)friends_lists_from_db->data)->friends; BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_PTR_NOT_NULL(lf2->lc); BC_ASSERT_PTR_NOT_NULL(lf2->friend_list); friends_lists_from_db = ms_list_free_with_data(friends_lists_from_db, (void (*)(void *))linphone_friend_list_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); if (ms_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), linphone_friend_get_name(lf)); BC_ASSERT_EQUAL(lf2->storage_id, lf->storage_id, int, "%i"); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_etag(linphone_friend_get_vcard(lf2)), linphone_vcard_get_etag(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_vcard_get_url(linphone_friend_get_vcard(lf2)), linphone_vcard_get_url(linphone_friend_get_vcard(lf))); BC_ASSERT_STRING_EQUAL(linphone_address_as_string(linphone_friend_get_address(lf2)), linphone_address_as_string(linphone_friend_get_address(lf))); linphone_friend_edit(lf); linphone_friend_set_name(lf, "Margaux"); linphone_friend_done(lf); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 1, int, "%d"); if (ms_list_size(friends_from_db) < 1) { goto end; } lf2 = (LinphoneFriend *)friends_from_db->data; BC_ASSERT_STRING_EQUAL(linphone_friend_get_name(lf2), "Margaux"); friends_from_db = ms_list_free_with_data(friends_from_db, (void (*)(void *))linphone_friend_unref); linphone_friend_list_remove_friend(lfl, lf); friends = linphone_friend_list_get_friends(linphone_core_get_default_friend_list(lc)); BC_ASSERT_EQUAL(ms_list_size(friends), 0, int, "%d"); friends_from_db = linphone_core_fetch_friends_from_db(lc, lfl); BC_ASSERT_EQUAL(ms_list_size(friends_from_db), 0, int, "%d"); linphone_core_remove_friend_list(lc, lfl); wait_for_until(lc, NULL, &stats->removed_list_count, 1, 1000); BC_ASSERT_EQUAL(stats->removed_list_count, 1, int, "%i"); end: ms_free(stats); unlink(friends_db); ms_free(friends_db); linphone_address_unref(addr); linphone_core_destroy(lc); }
static void carddav_integration(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:[email protected]\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); LinphoneVcard *lvc2 = NULL; LinphoneFriend *lf2 = NULL; LinphoneFriendListCbs *cbs = NULL; LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); const char *refkey = "toto"; linphone_friend_list_set_uri(lfl, CARDDAV_SERVER); cbs = linphone_friend_list_get_callbacks(lfl); linphone_friend_list_cbs_set_user_data(cbs, stats); linphone_friend_list_cbs_set_contact_created(cbs, carddav_contact_created); linphone_friend_list_cbs_set_contact_deleted(cbs, carddav_contact_deleted); linphone_friend_list_cbs_set_contact_updated(cbs, carddav_contact_updated); linphone_friend_list_cbs_set_sync_status_changed(cbs, carddav_sync_status_changed); linphone_core_add_friend_list(manager->lc, lfl); BC_ASSERT_PTR_NULL(linphone_vcard_get_uid(lvc)); BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 0, int, "%d"); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 1, int, "%d"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 1, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 1, int, "%i"); BC_ASSERT_EQUAL(ms_list_size(lfl->dirty_friends_to_update), 0, int, "%d"); BC_ASSERT_PTR_NOT_NULL(linphone_vcard_get_uid(lvc)); linphone_friend_list_remove_friend(lfl, lf); BC_ASSERT_EQUAL(ms_list_size(lfl->friends), 0, int, "%d"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 2, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 2, int, "%i"); linphone_friend_unref(lf); lf = NULL; lvc = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:[email protected]\r\nEND:VCARD\r\n"); lf = linphone_friend_new_from_vcard(lvc); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); linphone_friend_unref(lf); lvc2 = linphone_vcard_new_from_vcard4_buffer("BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:[email protected]\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n"); linphone_vcard_set_url(lvc2, "/card.php/addressbooks/tester/default/me.vcf"); lf2 = linphone_friend_new_from_vcard(lvc2); linphone_friend_set_ref_key(lf2, refkey); BC_ASSERT_EQUAL_FATAL(linphone_friend_list_add_local_friend(lfl, lf2), LinphoneFriendListOK, int, "%d"); BC_ASSERT_EQUAL(lfl->revision, 0, int, "%i"); linphone_friend_list_synchronize_friends_from_server(lfl); wait_for_until(manager->lc, NULL, &stats->new_contact_count, 0, 5000); BC_ASSERT_EQUAL(stats->new_contact_count, 0, int, "%i"); wait_for_until(manager->lc, NULL, &stats->removed_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->removed_contact_count, 1, int, "%i"); wait_for_until(manager->lc, NULL, &stats->updated_contact_count, 1, 5000); BC_ASSERT_EQUAL(stats->updated_contact_count, 1, int, "%i"); BC_ASSERT_NOT_EQUAL(lfl->revision, 0, int, "%i"); wait_for_until(manager->lc, NULL, &stats->sync_done_count, 3, 5000); BC_ASSERT_EQUAL(stats->sync_done_count, 3, int, "%i"); BC_ASSERT_EQUAL_FATAL(ms_list_size(lfl->friends), 1, int, "%i"); lf = (LinphoneFriend *)lfl->friends->data; BC_ASSERT_STRING_EQUAL(lf->refkey, refkey); BC_ASSERT_EQUAL(lf->storage_id, lf2->storage_id, int, "%i"); linphone_friend_unref(lf2); BC_ASSERT_STRING_EQUAL(linphone_address_as_string_uri_only(lf->uri), "sip:[email protected]"); linphone_friend_edit(lf); linphone_friend_done(lf); BC_ASSERT_EQUAL(ms_list_size(lf->friend_list->dirty_friends_to_update), 0, int, "%i"); linphone_core_set_network_reachable(manager->lc, FALSE); //To prevent the CardDAV update linphone_friend_edit(lf); linphone_friend_set_name(lf, "François Grisez"); linphone_friend_done(lf); BC_ASSERT_EQUAL(ms_list_size(lf->friend_list->dirty_friends_to_update), 1, int, "%i"); ms_free(stats); linphone_friend_list_unref(lfl); linphone_core_manager_destroy(manager); }
static LinphoneCoreManager* configure_lcm(void) { LinphoneCoreManager *mgr=linphone_core_manager_new( "multi_account_lrc"); stats *counters=&mgr->stat; CU_ASSERT_TRUE(wait_for(mgr->lc,mgr->lc,&counters->number_of_LinphoneRegistrationOk,ms_list_size(linphone_core_get_proxy_config_list(mgr->lc)))); return mgr; }
void linphone_core_update_local_media_description_from_ice(SalMediaDescription *desc, IceSession *session) { const char *rtp_addr, *rtcp_addr; IceSessionState session_state = ice_session_state(session); int nb_candidates; int i, j; bool_t result; if (session_state == IS_Completed) { desc->ice_completed = TRUE; result = ice_check_list_selected_valid_local_candidate(ice_session_check_list(session, 0), &rtp_addr, NULL, NULL, NULL); if (result == TRUE) { strncpy(desc->addr, rtp_addr, sizeof(desc->addr)); } else { ms_warning("If ICE has completed successfully, rtp_addr should be set!"); } } else { desc->ice_completed = FALSE; } strncpy(desc->ice_pwd, ice_session_local_pwd(session), sizeof(desc->ice_pwd)); strncpy(desc->ice_ufrag, ice_session_local_ufrag(session), sizeof(desc->ice_ufrag)); for (i = 0; i < desc->n_active_streams; i++) { SalStreamDescription *stream = &desc->streams[i]; IceCheckList *cl = ice_session_check_list(session, i); nb_candidates = 0; if (cl == NULL) continue; if (ice_check_list_state(cl) == ICL_Completed) { stream->ice_completed = TRUE; result = ice_check_list_selected_valid_local_candidate(ice_session_check_list(session, i), &rtp_addr, &stream->rtp_port, &rtcp_addr, &stream->rtcp_port); } else { stream->ice_completed = FALSE; result = ice_check_list_default_local_candidate(ice_session_check_list(session, i), &rtp_addr, &stream->rtp_port, &rtcp_addr, &stream->rtcp_port); } if (result == TRUE) { strncpy(stream->rtp_addr, rtp_addr, sizeof(stream->rtp_addr)); strncpy(stream->rtcp_addr, rtcp_addr, sizeof(stream->rtcp_addr)); } else { memset(stream->rtp_addr, 0, sizeof(stream->rtp_addr)); memset(stream->rtcp_addr, 0, sizeof(stream->rtcp_addr)); } if ((strlen(ice_check_list_local_pwd(cl)) != strlen(desc->ice_pwd)) || (strcmp(ice_check_list_local_pwd(cl), desc->ice_pwd))) strncpy(stream->ice_pwd, ice_check_list_local_pwd(cl), sizeof(stream->ice_pwd)); else memset(stream->ice_pwd, 0, sizeof(stream->ice_pwd)); if ((strlen(ice_check_list_local_ufrag(cl)) != strlen(desc->ice_ufrag)) || (strcmp(ice_check_list_local_ufrag(cl), desc->ice_ufrag))) strncpy(stream->ice_ufrag, ice_check_list_local_ufrag(cl), sizeof(stream->ice_ufrag)); else memset(stream->ice_pwd, 0, sizeof(stream->ice_pwd)); stream->ice_mismatch = ice_check_list_is_mismatch(cl); if ((ice_check_list_state(cl) == ICL_Running) || (ice_check_list_state(cl) == ICL_Completed)) { memset(stream->ice_candidates, 0, sizeof(stream->ice_candidates)); for (j = 0; j < MIN(ms_list_size(cl->local_candidates), SAL_MEDIA_DESCRIPTION_MAX_ICE_CANDIDATES); j++) { SalIceCandidate *sal_candidate = &stream->ice_candidates[nb_candidates]; IceCandidate *ice_candidate = ms_list_nth_data(cl->local_candidates, j); const char *default_addr = NULL; int default_port = 0; if (ice_candidate->componentID == 1) { default_addr = stream->rtp_addr; default_port = stream->rtp_port; } else if (ice_candidate->componentID == 2) { default_addr = stream->rtcp_addr; default_port = stream->rtcp_port; } else continue; if (default_addr[0] == '\0') default_addr = desc->addr; /* Only include the candidates matching the default destination for each component of the stream if the state is Completed as specified in RFC5245 section 9.1.2.2. */ if ((ice_check_list_state(cl) == ICL_Completed) && !((ice_candidate->taddr.port == default_port) && (strlen(ice_candidate->taddr.ip) == strlen(default_addr)) && (strcmp(ice_candidate->taddr.ip, default_addr) == 0))) continue; strncpy(sal_candidate->foundation, ice_candidate->foundation, sizeof(sal_candidate->foundation)); sal_candidate->componentID = ice_candidate->componentID; sal_candidate->priority = ice_candidate->priority; strncpy(sal_candidate->type, ice_candidate_type(ice_candidate), sizeof(sal_candidate->type)); strncpy(sal_candidate->addr, ice_candidate->taddr.ip, sizeof(sal_candidate->addr)); sal_candidate->port = ice_candidate->taddr.port; if ((ice_candidate->base != NULL) && (ice_candidate->base != ice_candidate)) { strncpy(sal_candidate->raddr, ice_candidate->base->taddr.ip, sizeof(sal_candidate->raddr)); sal_candidate->rport = ice_candidate->base->taddr.port; } nb_candidates++; } } if ((ice_check_list_state(cl) == ICL_Completed) && (ice_session_role(session) == IR_Controlling)) { int rtp_port, rtcp_port; memset(stream->ice_remote_candidates, 0, sizeof(stream->ice_remote_candidates)); if (ice_check_list_selected_valid_remote_candidate(cl, &rtp_addr, &rtp_port, &rtcp_addr, &rtcp_port) == TRUE) { strncpy(stream->ice_remote_candidates[0].addr, rtp_addr, sizeof(stream->ice_remote_candidates[0].addr)); stream->ice_remote_candidates[0].port = rtp_port; strncpy(stream->ice_remote_candidates[1].addr, rtcp_addr, sizeof(stream->ice_remote_candidates[1].addr)); stream->ice_remote_candidates[1].port = rtcp_port; } else { ms_error("ice: Selected valid remote candidates should be present if the check list is in the Completed state"); } } else { for (j = 0; j < SAL_MEDIA_DESCRIPTION_MAX_ICE_REMOTE_CANDIDATES; j++) { stream->ice_remote_candidates[j].addr[0] = '\0'; stream->ice_remote_candidates[j].port = 0; } } } }
static void call_received(SalOp *h){ LinphoneCore *lc=(LinphoneCore *)sal_get_user_pointer(sal_op_get_sal(h)); char *barmesg; LinphoneCall *call; const char *from,*to; char *tmp; LinphoneAddress *from_parsed; LinphoneAddress *from_addr, *to_addr; SalMediaDescription *md; bool_t propose_early_media=lp_config_get_int(lc->config,"sip","incoming_calls_early_media",FALSE); const char *ringback_tone=linphone_core_get_remote_ringback_tone (lc); /* first check if we can answer successfully to this invite */ if (lc->presence_mode==LinphoneStatusBusy || lc->presence_mode==LinphoneStatusOffline || lc->presence_mode==LinphoneStatusDoNotDisturb || lc->presence_mode==LinphoneStatusMoved){ if (lc->presence_mode==LinphoneStatusBusy ) sal_call_decline(h,SalReasonBusy,NULL); else if (lc->presence_mode==LinphoneStatusOffline) sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); else if (lc->presence_mode==LinphoneStatusDoNotDisturb) sal_call_decline(h,SalReasonTemporarilyUnavailable,NULL); else if (lc->alt_contact!=NULL && lc->presence_mode==LinphoneStatusMoved) sal_call_decline(h,SalReasonRedirect,lc->alt_contact); sal_op_release(h); return; } if (!linphone_core_can_we_add_call(lc)){/*busy*/ sal_call_decline(h,SalReasonBusy,NULL); sal_op_release(h); return; } from=sal_op_get_from(h); to=sal_op_get_to(h); from_addr=linphone_address_new(from); to_addr=linphone_address_new(to); if (is_duplicate_call(lc,from_addr,to_addr)){ ms_warning("Receiving duplicated call, refusing this one."); sal_call_decline(h,SalReasonBusy,NULL); linphone_address_destroy(from_addr); linphone_address_destroy(to_addr); return; } call=linphone_call_new_incoming(lc,from_addr,to_addr,h); sal_call_set_local_media_description(h,call->localdesc); md=sal_call_get_final_media_description(h); if (md && sal_media_description_empty(md)){ sal_call_decline(h,SalReasonMedia,NULL); linphone_call_unref(call); return; } /* the call is acceptable so we can now add it to our list */ linphone_core_add_call(lc,call); from_parsed=linphone_address_new(sal_op_get_from(h)); linphone_address_clean(from_parsed); tmp=linphone_address_as_string(from_parsed); linphone_address_destroy(from_parsed); barmesg=ortp_strdup_printf("%s %s%s",tmp,_("is contacting you"), (sal_call_autoanswer_asked(h)) ?_(" and asked autoanswer."):_(".")); if (lc->vtable.show) lc->vtable.show(lc); if (lc->vtable.display_status) lc->vtable.display_status(lc,barmesg); /* play the ring if this is the only call*/ if (lc->sound_conf.ring_sndcard!=NULL && ms_list_size(lc->calls)==1){ lc->current_call=call; if (lc->ringstream && lc->dmfs_playing_start_time!=0){ ring_stop(lc->ringstream); lc->ringstream=NULL; lc->dmfs_playing_start_time=0; } if(lc->ringstream==NULL && lc->sound_conf.local_ring){ MSSndCard *ringcard=lc->sound_conf.lsd_card ?lc->sound_conf.lsd_card : lc->sound_conf.ring_sndcard; ms_message("Starting local ring..."); lc->ringstream=ring_start(lc->sound_conf.local_ring,2000,ringcard); } else { ms_message("the local ring is already started"); } }else{ /*TODO : play a tone within the context of the current call */ } linphone_call_ref(call); /*prevent the call from being destroyed while we are notifying, if the user declines within the state callback */ linphone_call_set_state(call,LinphoneCallIncomingReceived,"Incoming call"); if (call->state==LinphoneCallIncomingReceived){ sal_call_notify_ringing(h,propose_early_media || ringback_tone!=NULL); if (propose_early_media || ringback_tone!=NULL){ linphone_call_set_state(call,LinphoneCallIncomingEarlyMedia,"Incoming call early media"); linphone_core_update_streams(lc,call,md); } if (sal_call_get_replaces(call->op)!=NULL && lp_config_get_int(lc->config,"sip","auto_answer_replacing_calls",1)){ linphone_core_accept_call(lc,call); } } linphone_call_unref(call); ms_free(barmesg); ms_free(tmp); }
static void conference_free(LinphoneConference *conf) { if(conf->name!=NULL) ms_free(conf->name); if(ms_list_size(conf->members)!=0) ms_message("free members"); ms_free(conf); }
LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_for_proxies) { LinphoneCoreManager* mgr= ms_new0(LinphoneCoreManager,1); LinphoneProxyConfig* proxy; char *rc_path = NULL; int proxy_count; mgr->v_table.registration_state_changed=registration_state_changed; mgr->v_table.auth_info_requested=auth_info_requested; mgr->v_table.call_state_changed=call_state_changed; mgr->v_table.text_received=text_message_received; mgr->v_table.message_received=message_received; mgr->v_table.is_composing_received=is_composing_received; mgr->v_table.new_subscription_requested=new_subscription_requested; mgr->v_table.notify_presence_received=notify_presence_received; mgr->v_table.transfer_state_changed=linphone_transfer_state_changed; mgr->v_table.info_received=info_message_received; mgr->v_table.subscription_state_changed=linphone_subscription_state_change; mgr->v_table.notify_received=linphone_notify_received; mgr->v_table.publish_state_changed=linphone_publish_state_changed; mgr->v_table.configuring_status=linphone_configuration_status; mgr->v_table.call_encryption_changed=linphone_call_encryption_changed; mgr->v_table.network_reachable=network_reachable; mgr->v_table.dtmf_received=dtmf_received; mgr->v_table.call_stats_updated=call_stats_updated; reset_counters(&mgr->stat); if (rc_file) rc_path = ms_strdup_printf("rcfiles/%s", rc_file); mgr->lc=configure_lc_from(&mgr->v_table, liblinphone_tester_file_prefix, rc_path, mgr); linphone_core_manager_check_accounts(mgr); /*CU_ASSERT_EQUAL(ms_list_size(linphone_core_get_proxy_config_list(lc)),proxy_count);*/ if (check_for_proxies && rc_file) /**/ proxy_count=ms_list_size(linphone_core_get_proxy_config_list(mgr->lc)); else proxy_count=0; manager_count++; #if TARGET_OS_IPHONE linphone_core_set_ringer_device( mgr->lc, "AQ: Audio Queue Device"); linphone_core_set_ringback(mgr->lc, NULL); #endif if( manager_count >= 2){ char hellopath[512]; ms_message("Manager for '%s' using files", rc_file ? rc_file : "--"); linphone_core_use_files(mgr->lc, TRUE); snprintf(hellopath,sizeof(hellopath), "%s/sounds/hello8000.wav", liblinphone_tester_file_prefix); linphone_core_set_play_file(mgr->lc,hellopath); } if (proxy_count){ #define REGISTER_TIMEOUT 20 /* seconds */ int success = wait_for_until(mgr->lc,NULL,&mgr->stat.number_of_LinphoneRegistrationOk, proxy_count,(REGISTER_TIMEOUT * 1000 * proxy_count)); if( !success ){ ms_error("Did not register after %d seconds for %d proxies", REGISTER_TIMEOUT, proxy_count); } } CU_ASSERT_EQUAL(mgr->stat.number_of_LinphoneRegistrationOk,proxy_count); enable_codec(mgr->lc,"PCMU",8000); linphone_core_get_default_proxy(mgr->lc,&proxy); if (proxy) { mgr->identity = linphone_address_new(linphone_proxy_config_get_identity(proxy)); linphone_address_clean(mgr->identity); } if (rc_path) ms_free(rc_path); return mgr; }
static void add_line(sdp_message_t *msg, int lineno, const SalStreamDescription *desc){ const char *mt=NULL; const MSList *elem; const char *addr; const char *dir="sendrecv"; int port; bool_t strip_well_known_rtpmaps; switch (desc->type) { case SalAudio: mt="audio"; break; case SalVideo: mt="video"; break; case SalOther: mt=desc->typeother; break; } if (desc->candidates[0].addr[0]!='\0'){ addr=desc->candidates[0].addr; port=desc->candidates[0].port; }else{ addr=desc->addr; port=desc->port; } /*only add a c= line within the stream description if address are differents*/ if (strcmp(addr,sdp_message_c_addr_get(msg, -1, 0))!=0){ bool_t inet6; if (strchr(addr,':')!=NULL){ inet6=TRUE; }else inet6=FALSE; sdp_message_c_connection_add (msg, lineno, osip_strdup ("IN"), inet6 ? osip_strdup ("IP6") : osip_strdup ("IP4"), osip_strdup (addr), NULL, NULL); } sdp_message_m_media_add (msg, osip_strdup (mt), int_2char (port), NULL, osip_strdup ("RTP/AVP")); if (desc->bandwidth>0) sdp_message_b_bandwidth_add (msg, lineno, osip_strdup ("AS"), int_2char(desc->bandwidth)); if (desc->ptime>0) sdp_message_a_attribute_add(msg,lineno,osip_strdup("ptime"), int_2char(desc->ptime)); strip_well_known_rtpmaps=ms_list_size(desc->payloads)>5; if (desc->payloads){ for(elem=desc->payloads;elem!=NULL;elem=elem->next){ add_payload(msg, lineno, (PayloadType*)elem->data,strip_well_known_rtpmaps); } }else{ /* to comply with SDP we cannot have an empty payload type number list */ /* as it happens only when mline is declined with a zero port, it does not matter to put whatever codec*/ sdp_message_m_payload_add (msg,lineno, int_2char (0)); } switch(desc->dir){ case SalStreamSendRecv: /*dir="sendrecv";*/ dir=NULL; break; case SalStreamRecvOnly: dir="recvonly"; break; case SalStreamSendOnly: dir="sendonly"; break; case SalStreamInactive: dir="inactive"; break; } if (dir) sdp_message_a_attribute_add (msg, lineno, osip_strdup (dir),NULL); }