LinphoneCoreManager* linphone_core_manager_init(const char* rc_file) { LinphoneCoreManager* mgr= ms_new0(LinphoneCoreManager,1); char *rc_path = NULL; mgr->number_of_cunit_error_at_creation = CU_get_number_of_failures(); 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, bc_tester_read_dir_prefix, rc_path, mgr); linphone_core_manager_check_accounts(mgr); 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 #ifdef VIDEO_ENABLED { MSWebCam *cam; cam = ms_web_cam_manager_get_cam(ms_web_cam_manager_get(), "Mire: Mire (synthetic moving picture)"); if (cam == NULL) { MSWebCamDesc *desc = ms_mire_webcam_desc_get(); if (desc){ cam=ms_web_cam_new(desc); ms_web_cam_manager_add_cam(ms_web_cam_manager_get(), cam); } } } #endif if( manager_count >= 2){ char hellopath[512]; char *recordpath = ms_strdup_printf("%s/record_for_lc_%p.wav",bc_tester_writable_dir_prefix,mgr->lc); 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", bc_tester_read_dir_prefix); linphone_core_set_play_file(mgr->lc,hellopath); linphone_core_set_record_file(mgr->lc,recordpath); ms_free(recordpath); } linphone_core_set_user_certificates_path(mgr->lc,bc_tester_writable_dir_prefix); if (rc_path) ms_free(rc_path); return mgr; }
static void linphonec_dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf){ char *from=linphone_call_get_remote_address_as_string(call); fprintf(stdout,"Receiving tone %c from %s\n",dtmf,from); fflush(stdout); ms_free(from); }
static void dtmfgen_uninit(MSFilter *f){ ms_free(f->data); }
static void jpg_process(MSFilter *f){ JpegWriter *s=(JpegWriter*)f->data; ms_filter_lock(f); if (s->file!=NULL && s->codec!=NULL){ MSPicture yuvbuf, yuvjpeg; mblk_t *m=ms_queue_peek_last(f->inputs[0]); if (ms_yuv_buf_init_from_mblk(&yuvbuf,m)==0){ int error,got_pict; int comp_buf_sz=msgdsize(m); uint8_t *comp_buf=(uint8_t*)ms_malloc0(comp_buf_sz); mblk_t *jpegm; struct SwsContext *sws_ctx; struct AVPacket packet; AVCodecContext *avctx=avcodec_alloc_context3(s->codec); memset(&packet, 0, sizeof(packet)); avctx->width=yuvbuf.w; avctx->height=yuvbuf.h; avctx->time_base.num = 1; avctx->time_base.den =1; avctx->pix_fmt=AV_PIX_FMT_YUVJ420P; error=avcodec_open2(avctx,s->codec,NULL); if (error!=0) { ms_error("avcodec_open() failed: %i",error); cleanup(s,NULL, FALSE); av_free(avctx); goto end; } sws_ctx=sws_getContext(avctx->width,avctx->height,AV_PIX_FMT_YUV420P, avctx->width,avctx->height,avctx->pix_fmt,SWS_FAST_BILINEAR,NULL, NULL, NULL); if (sws_ctx==NULL) { ms_error(" sws_getContext() failed."); cleanup(s,avctx, FALSE); goto end; } jpegm=ms_yuv_buf_alloc (&yuvjpeg,avctx->width, avctx->height); #if LIBSWSCALE_VERSION_INT >= AV_VERSION_INT(0,9,0) if (sws_scale(sws_ctx,(const uint8_t *const*)yuvbuf.planes,yuvbuf.strides,0,avctx->height,yuvjpeg.planes,yuvjpeg.strides)<0){ #else if (sws_scale(sws_ctx,(uint8_t **)yuvbuf.planes,yuvbuf.strides,0,avctx->height,yuvjpeg.planes,yuvjpeg.strides)<0){ #endif ms_error("sws_scale() failed."); sws_freeContext(sws_ctx); cleanup(s,avctx, FALSE); freemsg(jpegm); goto end; } sws_freeContext(sws_ctx); av_frame_unref(s->pict); avpicture_fill((AVPicture*)s->pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height); packet.data=comp_buf; packet.size=comp_buf_sz; error=avcodec_encode_video2(avctx, &packet, s->pict, &got_pict); if (error<0){ ms_error("Could not encode jpeg picture."); }else{ if (fwrite(comp_buf,packet.size,1,s->file)>0){ ms_message("Snapshot done"); }else{ ms_error("Error writing snapshot."); } } ms_free(comp_buf); cleanup(s,avctx, TRUE); freemsg(jpegm); } goto end; } end: ms_filter_unlock(f); ms_queue_flush(f->inputs[0]); } static MSFilterMethod jpg_methods[]={ { MS_JPEG_WRITER_TAKE_SNAPSHOT, take_snapshot }, { 0,NULL} }; #ifndef _MSC_VER MSFilterDesc ms_jpeg_writer_desc={ .id=MS_JPEG_WRITER_ID, .name="MSJpegWriter", .text="Take a video snapshot as jpg file", .category=MS_FILTER_OTHER, .ninputs=1, .noutputs=0, .init=jpg_init, .process=jpg_process, .uninit=jpg_uninit, .methods=jpg_methods }; #else MSFilterDesc ms_jpeg_writer_desc={ MS_JPEG_WRITER_ID, "MSJpegWriter", "Take a video snapshot as jpg file", MS_FILTER_OTHER, NULL, 1, 0, jpg_init, NULL, jpg_process, NULL, jpg_uninit, jpg_methods }; #endif MS_FILTER_DESC_EXPORT(ms_jpeg_writer_desc)
void lp_config_parse(LpConfig *lpconfig, FILE *file){ char tmp[MAX_LEN]= {'\0'}; LpSection *cur=NULL; if (file==NULL) return; while(fgets(tmp,MAX_LEN,file)!=NULL){ tmp[sizeof(tmp) -1] = '\0'; char *pos1,*pos2; pos1=strchr(tmp,'['); if (pos1!=NULL && is_first_char(tmp,pos1) ){ pos2=strchr(pos1,']'); if (pos2!=NULL){ int nbs; char secname[MAX_LEN]; secname[0]='\0'; /* found section */ *pos2='\0'; nbs = sscanf(pos1+1,"%s",secname); if (nbs == 1 ){ if (strlen(secname)>0){ cur=lp_config_find_section (lpconfig,secname); if (cur==NULL){ cur=lp_section_new(secname); lp_config_add_section(lpconfig,cur); } } }else{ ms_warning("parse error!"); } } }else { pos1=strchr(tmp,'='); if (pos1!=NULL){ char key[MAX_LEN]; key[0]='\0'; *pos1='\0'; if (sscanf(tmp,"%s",key)>0){ pos1++; pos2=strchr(pos1,'\r'); if (pos2==NULL) pos2=strchr(pos1,'\n'); if (pos2==NULL) pos2=pos1+strlen(pos1); else { *pos2='\0'; /*replace the '\n' */ } /* remove ending white spaces */ for (; pos2>pos1 && pos2[-1]==' ';pos2--) pos2[-1]='\0'; if (pos2-pos1>=0){ /* found a pair key,value */ if (cur!=NULL){ LpItem *item=lp_section_find_item(cur,key); if (item==NULL){ lp_section_add_item(cur,lp_item_new(key,pos1)); }else{ ms_free(item->value); item->value=strdup(pos1); } /*printf("Found %s %s={%s}\n",cur->name,key,pos1);*/ }else{ ms_warning("found key,item but no sections"); } } } } } } }
static void presence_information(void) { const char *bike_description = "Riding my bike"; const char *vacation_note = "I'm on vacation until July 4th"; const char *vacation_lang = "en"; const char *contact = "sip:[email protected]"; LinphoneCoreManager *marie = presence_linphone_core_manager_new("marie"); LinphoneCoreManager *pauline = presence_linphone_core_manager_new("pauline"); LinphonePresenceModel *presence; LinphonePresenceActivity *activity = NULL; LinphonePresenceNote *note = NULL; const char *description = NULL; const char *note_content = NULL; char *contact2; time_t current_timestamp, presence_timestamp; CU_ASSERT_TRUE(subscribe_to_callee_presence(marie, pauline)); /* Presence activity without description. */ presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityDinner, NULL); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityDinner,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityDinner, 1); activity = linphone_presence_model_get_activity(marie->stat.last_received_presence); CU_ASSERT_PTR_NOT_NULL(activity); CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityDinner); description = linphone_presence_activity_get_description(activity); CU_ASSERT_PTR_NULL(description); /* Presence activity with description. */ presence = linphone_presence_model_new_with_activity(LinphonePresenceActivitySteering, bike_description); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivitySteering,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivitySteering, 1); activity = linphone_presence_model_get_activity(marie->stat.last_received_presence); CU_ASSERT_PTR_NOT_NULL(activity); CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivitySteering); description = linphone_presence_activity_get_description(activity); CU_ASSERT_PTR_NOT_NULL(description); if (description != NULL) CU_ASSERT_EQUAL(strcmp(description, bike_description), 0); /* Presence activity with description and note. */ presence = linphone_presence_model_new_with_activity_and_note(LinphonePresenceActivityVacation, NULL, vacation_note, vacation_lang); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityVacation,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityVacation, 1); activity = linphone_presence_model_get_activity(marie->stat.last_received_presence); CU_ASSERT_PTR_NOT_NULL(activity); CU_ASSERT_EQUAL(linphone_presence_activity_get_type(activity), LinphonePresenceActivityVacation); description = linphone_presence_activity_get_description(activity); CU_ASSERT_PTR_NULL(description); note = linphone_presence_model_get_note(marie->stat.last_received_presence, NULL); CU_ASSERT_PTR_NOT_NULL(note); if (note != NULL) { note_content = linphone_presence_note_get_content(note); CU_ASSERT_PTR_NOT_NULL(note_content); if (note_content != NULL) { CU_ASSERT_EQUAL(strcmp(note_content, vacation_note), 0); } } /* Presence contact. */ presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityOnThePhone, NULL); linphone_presence_model_set_contact(presence, contact); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityOnThePhone,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityOnThePhone, 1); contact2 = linphone_presence_model_get_contact(presence); CU_ASSERT_PTR_NOT_NULL(contact2); if (contact2 != NULL) { CU_ASSERT_EQUAL(strcmp(contact, contact2), 0); ms_free(contact2); } /* Presence timestamp. */ current_timestamp = time(NULL); presence = linphone_presence_model_new_with_activity(LinphonePresenceActivityShopping, NULL); linphone_core_set_presence_model(pauline->lc, presence); wait_for(marie->lc,pauline->lc,&marie->stat.number_of_LinphonePresenceActivityShopping,1); CU_ASSERT_EQUAL(marie->stat.number_of_LinphonePresenceActivityShopping, 1); presence_timestamp = linphone_presence_model_get_timestamp(presence); CU_ASSERT_TRUE(presence_timestamp >= current_timestamp); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); }
void ms_web_cam_destroy(MSWebCam *obj){ if (obj->desc->uninit!=NULL) obj->desc->uninit(obj); if (obj->name!=NULL) ms_free(obj->name); if (obj->id!=NULL) ms_free(obj->id); ms_free(obj); }
void linphone_chat_message_destroy(LinphoneChatMessage* msg) { if (msg->message) ms_free(msg->message); if (msg->external_body_url) ms_free(msg->external_body_url); if (msg->from) linphone_address_destroy(msg->from); ms_free(msg); }
void linphone_chat_message_set_external_body_url(LinphoneChatMessage* message,const char* url) { if (message->external_body_url) { ms_free(message->external_body_url); } message->external_body_url=url?ms_strdup(url):NULL; }
void __sal_op_set_network_origin_address(SalOp *op, SalAddress *origin){ char* address_string=sal_address_as_string(origin); /*can probably be optimized*/ __sal_op_set_network_origin(op,address_string); ms_free(address_string); }
void __sal_op_free(SalOp *op){ SalOpBase *b=(SalOpBase *)op; if (b->from_address){ sal_address_destroy(b->from_address); b->from_address=NULL; } if (b->to_address){ sal_address_destroy(b->to_address); b->to_address=NULL; } if (b->service_route){ sal_address_destroy(b->service_route); b->service_route=NULL; } if (b->origin_address){ sal_address_destroy(b->origin_address); b->origin_address=NULL; } if (b->from) { ms_free(b->from); b->from=NULL; } if (b->to) { ms_free(b->to); b->to=NULL; } if (b->route) { ms_free(b->route); b->route=NULL; } #ifndef USE_BELLESIP if (b->contact) { ms_free(b->contact); b->contact=NULL; } #else if (b->contact_address) { sal_address_destroy(b->contact_address); } #endif if (b->origin){ ms_free(b->origin); b->origin=NULL; } if (b->remote_ua){ ms_free(b->remote_ua); b->remote_ua=NULL; } if (b->remote_contact){ ms_free(b->remote_contact); b->remote_contact=NULL; } if (b->local_media) sal_media_description_unref(b->local_media); if (b->remote_media) sal_media_description_unref(b->remote_media); if (b->call_id) ms_free((void*)b->call_id); if (b->service_route) { sal_address_destroy(b->service_route); } if (b->route_addresses){ ms_list_for_each(b->route_addresses,(void (*)(void*)) sal_address_destroy); b->route_addresses=ms_list_free(b->route_addresses); } if (b->recv_custom_headers) sal_custom_header_free(b->recv_custom_headers); if (b->sent_custom_headers) sal_custom_header_free(b->sent_custom_headers); ms_free(op); }
void sal_op_set_to_address(SalOp *op, const SalAddress *to){ char* address_string=sal_address_as_string(to); /*can probably be optimized*/ sal_op_set_to(op,address_string); ms_free(address_string); }
void sal_op_set_from_address(SalOp *op, const SalAddress *from){ char* address_string=sal_address_as_string(from); /*can probably be optimized*/ sal_op_set_from(op,address_string); ms_free(address_string); }
void sal_op_set_route_address(SalOp *op, const SalAddress *address){ char* address_string=sal_address_as_string(address); /*can probably be optimized*/ sal_op_set_route(op,address_string); ms_free(address_string); }
static void enc_uninit(MSFilter *f) { EncState *s = (EncState *)f->data; ms_free(s); }
void linphone_chat_room_destroy(LinphoneChatRoom *cr) { LinphoneCore *lc=cr->lc; lc->chatrooms=ms_list_remove(lc->chatrooms,(void *) cr); linphone_address_destroy(cr->peer_url); ms_free(cr->peer); }
static void enc_uninit(MSFilter *f){ EncState *s=(EncState*)f->data; theora_info_clear(&s->tinfo); ms_free(s); }
static void v4w_uninit(MSFilter *f){ V4wState *s=(V4wState*)f->data; int idx; flushq(&s->rq,0); ms_mutex_destroy(&s->mutex); for (idx=0;idx<10;idx++) { if (s->mire[idx]==NULL) break; freemsg(s->mire[idx]); } if (s->rotregvalue>0){ HRESULT hr = s->m_pControl->Stop(); if(FAILED(hr)) { ms_message("v4w: could not stop graph"); } if (s->m_pGraph!=NULL) { if (s->m_pNullRenderer!=NULL) s->m_pGraph->RemoveFilter(s->m_pNullRenderer); if (s->m_pIDXFilter!=NULL) s->m_pGraph->RemoveFilter(s->m_pIDXFilter); if (s->m_pDeviceFilter!=NULL) s->m_pGraph->RemoveFilter(s->m_pDeviceFilter); } if (s->m_pNullRenderer) s->m_pNullRenderer->Release(); if (s->m_pIDXFilter) s->m_pIDXFilter->Release(); if (s->m_pDeviceFilter) s->m_pDeviceFilter->Release(); if (s->m_pBuilder) s->m_pBuilder->Release(); if (s->m_pControl) s->m_pControl->Release(); if (s->m_pGraph) s->m_pGraph->Release(); if (s->m_pDXFilter!=NULL) s->m_pDXFilter->Release(); s->m_pNullRenderer=NULL; s->m_pIDXFilter=NULL; s->m_pDeviceFilter=NULL; s->m_pBuilder=NULL; s->m_pControl=NULL; s->m_pGraph=NULL; s->m_pDXFilter=NULL; CoUninitialize(); s_callback = NULL; flushq(&s->rq,0); ms_message("v4w: graph destroyed"); s->rotregvalue=0; } ms_free(s); }
void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf) { stats* counters; LinphonePresenceActivity *activity = NULL; char* from=linphone_address_as_string(linphone_friend_get_address(lf)); ms_message("New Notify request from [%s] ",from); ms_free(from); counters = get_stats(lc); counters->number_of_NotifyReceived++; counters->last_received_presence = linphone_friend_get_presence_model(lf); activity = linphone_presence_model_get_activity(counters->last_received_presence); switch (linphone_presence_activity_get_type(activity)) { case LinphonePresenceActivityOffline: counters->number_of_LinphonePresenceActivityOffline++; break; case LinphonePresenceActivityOnline: counters->number_of_LinphonePresenceActivityOnline++; break; case LinphonePresenceActivityAppointment: counters->number_of_LinphonePresenceActivityAppointment++; break; case LinphonePresenceActivityAway: counters->number_of_LinphonePresenceActivityAway++; break; case LinphonePresenceActivityBreakfast: counters->number_of_LinphonePresenceActivityBreakfast++; break; case LinphonePresenceActivityBusy: counters->number_of_LinphonePresenceActivityBusy++; break; case LinphonePresenceActivityDinner: counters->number_of_LinphonePresenceActivityDinner++; break; case LinphonePresenceActivityHoliday: counters->number_of_LinphonePresenceActivityHoliday++; break; case LinphonePresenceActivityInTransit: counters->number_of_LinphonePresenceActivityInTransit++; break; case LinphonePresenceActivityLookingForWork: counters->number_of_LinphonePresenceActivityLookingForWork++; break; case LinphonePresenceActivityLunch: counters->number_of_LinphonePresenceActivityLunch++; break; case LinphonePresenceActivityMeal: counters->number_of_LinphonePresenceActivityMeal++; break; case LinphonePresenceActivityMeeting: counters->number_of_LinphonePresenceActivityMeeting++; break; case LinphonePresenceActivityOnThePhone: counters->number_of_LinphonePresenceActivityOnThePhone++; break; case LinphonePresenceActivityOther: counters->number_of_LinphonePresenceActivityOther++; break; case LinphonePresenceActivityPerformance: counters->number_of_LinphonePresenceActivityPerformance++; break; case LinphonePresenceActivityPermanentAbsence: counters->number_of_LinphonePresenceActivityPermanentAbsence++; break; case LinphonePresenceActivityPlaying: counters->number_of_LinphonePresenceActivityPlaying++; break; case LinphonePresenceActivityPresentation: counters->number_of_LinphonePresenceActivityPresentation++; break; case LinphonePresenceActivityShopping: counters->number_of_LinphonePresenceActivityShopping++; break; case LinphonePresenceActivitySleeping: counters->number_of_LinphonePresenceActivitySleeping++; break; case LinphonePresenceActivitySpectator: counters->number_of_LinphonePresenceActivitySpectator++; break; case LinphonePresenceActivitySteering: counters->number_of_LinphonePresenceActivitySteering++; break; case LinphonePresenceActivityTravel: counters->number_of_LinphonePresenceActivityTravel++; break; case LinphonePresenceActivityTV: counters->number_of_LinphonePresenceActivityTV++; break; case LinphonePresenceActivityUnknown: counters->number_of_LinphonePresenceActivityUnknown++; break; case LinphonePresenceActivityVacation: counters->number_of_LinphonePresenceActivityVacation++; break; case LinphonePresenceActivityWorking: counters->number_of_LinphonePresenceActivityWorking++; break; case LinphonePresenceActivityWorship: counters->number_of_LinphonePresenceActivityWorship++; break; } }
static void size_conv_uninit(MSFilter *f){ SizeConvState *s=(SizeConvState*)f->data; ms_free(s); }
static LpSection* lp_config_parse_line(LpConfig* lpconfig, const char* line, LpSection* cur) { LpSectionParam *params = NULL; char *pos1,*pos2; int nbs; int size=strlen(line)+1; char *secname=ms_malloc(size); char *key=ms_malloc(size); char *value=ms_malloc(size); LpItem *item; pos1=strchr(line,'['); if (pos1!=NULL && is_first_char(line,pos1) ){ pos2=strchr(pos1,']'); if (pos2!=NULL){ secname[0]='\0'; /* found section */ *pos2='\0'; nbs = sscanf(pos1+1, "%s", secname); if (nbs >= 1) { if (strlen(secname) > 0) { cur = lp_config_find_section (lpconfig,secname); if (cur == NULL) { cur = lp_section_new(secname); lp_config_add_section(lpconfig, cur); } if (pos2 > pos1 + 1 + strlen(secname)) { /* found at least one section param */ pos2 = pos1 + 1 + strlen(secname) + 1; // Remove the white space after the secname pos1 = strchr(pos2, '='); while (pos1 != NULL) { /* for each section param */ key[0] = '\0'; value[0] = '\0'; *pos1 = ' '; if (sscanf(pos2, "%s %s", key, value) == 2) { params = lp_section_param_new(key, value); lp_config_add_section_param(cur, params); pos2 += strlen(key) + strlen(value) + 2; // Remove the = sign + the white space after each param pos1 = strchr(pos2, '='); } else { ms_warning("parse section params error !"); pos1 = NULL; } } } } } else { ms_warning("parse error!"); } } }else { if (is_a_comment(line)){ if (cur){ LpItem *comment=lp_comment_new(line); lp_section_add_item(cur,comment); } }else{ pos1=strchr(line,'='); if (pos1!=NULL){ key[0]='\0'; *pos1='\0'; if (sscanf(line,"%s",key)>0){ pos1++; pos2=strchr(pos1,'\r'); if (pos2==NULL) pos2=strchr(pos1,'\n'); if (pos2==NULL) pos2=pos1+strlen(pos1); else { *pos2='\0'; /*replace the '\n' */ } /* remove ending white spaces */ for (; pos2>pos1 && pos2[-1]==' ';pos2--) pos2[-1]='\0'; if (pos2-pos1>0){ /* found a pair key,value */ if (cur!=NULL){ item=lp_section_find_item(cur,key); if (item==NULL){ lp_section_add_item(cur,lp_item_new(key,pos1)); }else{ ortp_free(item->value); item->value=ortp_strdup(pos1); } /*ms_message("Found %s=%s",key,pos1);*/ }else{ ms_warning("found key,item but no sections"); } } } } } } ms_free(key); ms_free(value); ms_free(secname); return cur; }
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 void two_incoming_early_media_video_calls_test(void) { char *ringback_path; LinphoneCoreManager *marie; LinphoneCoreManager *pauline; LinphoneCoreManager *laure; LinphoneCallParams *marie_params; LinphoneCallParams *pauline_params; LinphoneCallParams *laure_params; LinphoneCall *call; const MSList *calls_list; marie = linphone_core_manager_new("marie_rc"); pauline = linphone_core_manager_new("pauline_rc"); laure = linphone_core_manager_new("laure_rc"); marie_params = configure_for_early_media_video_receiving(marie); pauline_params = configure_for_early_media_video_sending(pauline); laure_params = configure_for_early_media_video_sending(laure); /* Configure early media audio to play ring during early-media and send remote ring back tone. */ linphone_core_set_ring_during_incoming_early_media(marie->lc, TRUE); ringback_path = ms_strdup_printf("%s/sounds/ringback.wav", liblinphone_tester_file_prefix); linphone_core_set_remote_ringback_tone(marie->lc, ringback_path); ms_free(ringback_path); /* Early media video call from pauline to marie. */ CU_ASSERT_TRUE(video_call_with_params(pauline, marie, pauline_params, NULL, FALSE)); /* Wait for 2s. */ wait_for_three_cores(marie->lc, pauline->lc, NULL, 2000); /* Early media video call from laure to marie. */ CU_ASSERT_TRUE(video_call_with_params(laure, marie, laure_params, NULL, FALSE)); /* Wait for 2s. */ wait_for_three_cores(marie->lc, pauline->lc, laure->lc, 2000); CU_ASSERT_EQUAL(linphone_core_get_calls_nb(marie->lc), 2); if (linphone_core_get_calls_nb(marie->lc) == 2) { calls_list = linphone_core_get_calls(marie->lc); call = (LinphoneCall *)ms_list_nth_data(calls_list, 0); CU_ASSERT_PTR_NOT_NULL(call); if (call != NULL) { LinphoneCallParams *params = linphone_call_params_copy(linphone_call_get_current_params(call)); linphone_call_params_set_audio_direction(params, LinphoneMediaDirectionSendRecv); linphone_call_params_set_video_direction(params, LinphoneMediaDirectionSendRecv); linphone_core_accept_call_with_params(marie->lc, call, params); /* Wait for 5s. */ wait_for_three_cores(marie->lc, pauline->lc, laure->lc, 5000); } } linphone_core_terminate_all_calls(marie->lc); CU_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallEnd, 1)); CU_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallEnd, 1)); CU_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &marie->stat.number_of_LinphoneCallReleased, 1)); CU_ASSERT_TRUE(wait_for(marie->lc, pauline->lc, &pauline->stat.number_of_LinphoneCallReleased, 1)); CU_ASSERT_TRUE(wait_for(marie->lc, laure->lc, &marie->stat.number_of_LinphoneCallEnd, 1)); CU_ASSERT_TRUE(wait_for(marie->lc, laure->lc, &laure->stat.number_of_LinphoneCallEnd, 1)); CU_ASSERT_EQUAL(marie->stat.number_of_video_windows_created, 2); CU_ASSERT_EQUAL(pauline->stat.number_of_video_windows_created, 1); CU_ASSERT_EQUAL(laure->stat.number_of_video_windows_created, 1); linphone_call_params_unref(marie_params); linphone_call_params_unref(pauline_params); linphone_call_params_unref(laure_params); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); linphone_core_manager_destroy(laure); }
static void encrypted_audio_stream_base( bool_t change_ssrc, bool_t change_send_key_in_the_middle ,bool_t set_both_send_recv_key ,bool_t send_key_first) { AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE); RtpProfile* profile = rtp_profile_new("default profile"); char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE); char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE); stats_t marielle_stats; stats_t margaux_stats; int dummy=0; if (ms_srtp_supported()) { reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); CU_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , MARIELLE_IP , MARIELLE_RTP_PORT , MARIELLE_IP , MARIELLE_RTCP_PORT , 0 , 50 , NULL , recorded_file , NULL , NULL , 0),0); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); if (send_key_first) { CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") ==0); } else { CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") ==0); CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); } ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); if (change_send_key_in_the_middle) { int dummy=0; wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,2000); CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "eCYF4nYyCvmCpFWjUeDaxI2GWp2BzCRlIPfg52Te") == 0); CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "eCYF4nYyCvmCpFWjUeDaxI2GWp2BzCRlIPfg52Te") ==0); } CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ if (change_send_key_in_the_middle) { /*we can accept one or 2 error in such case*/ CU_ASSERT_TRUE((marielle_stats.rtp.packet_sent-margaux_stats.rtp.packet_recv)<3); } else CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv); if (change_ssrc) { audio_stream_stop(marielle); marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); CU_ASSERT_FATAL(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,2,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ CU_ASSERT_EQUAL(marielle_stats.rtp.sent*2,margaux_stats.rtp.recv); } unlink(recorded_file); ms_free(recorded_file); ms_free(hello_file); } else { ms_warning("srtp not available, skiping..."); } audio_stream_stop(marielle); audio_stream_stop(margaux); rtp_profile_destroy(profile); }
static void linphonec_call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState st, const char *msg){ char *from=linphone_call_get_remote_address_as_string(call); long id=(long)linphone_call_get_user_pointer (call); switch(st){ case LinphoneCallEnd: linphonec_out("Call %i with %s ended (%s).\n", id, from, linphone_reason_to_string(linphone_call_get_reason(call))); break; case LinphoneCallResuming: linphonec_out("Resuming call %i with %s.\n", id, from); break; case LinphoneCallStreamsRunning: linphonec_out("Media streams established with %s for call %i (%s).\n", from,id,( linphone_call_params_video_enabled( linphone_call_get_current_params(call)) ? "video":"audio")); break; case LinphoneCallPausing: linphonec_out("Pausing call %i with %s.\n", id, from); break; case LinphoneCallPaused: linphonec_out("Call %i with %s is now paused.\n", id, from); break; case LinphoneCallPausedByRemote: linphonec_out("Call %i has been paused by %s.\n",id,from); break; case LinphoneCallIncomingReceived: linphonec_call_identify(call); linphone_call_enable_camera (call,linphonec_camera_enabled); id=(long)linphone_call_get_user_pointer (call); linphonec_set_caller(from); linphonec_out("Receiving new incoming call from %s, assigned id %i\n", from,id); if ( auto_answer) { answer_call=TRUE; } else if (real_early_media_sending) { LinphoneCallParams* callparams = linphone_core_create_call_params(lc, call); linphonec_out("Sending early media using real hardware\n"); linphone_call_params_enable_early_media_sending(callparams, TRUE); if (vcap_enabled) linphone_call_params_enable_video(callparams, TRUE); linphone_core_accept_early_media_with_params(lc, call, callparams); linphone_call_params_destroy(callparams); } break; case LinphoneCallOutgoingInit: linphonec_call_identify(call); id=(long)linphone_call_get_user_pointer (call); linphonec_out("Establishing call id to %s, assigned id %i\n", from,id); break; case LinphoneCallUpdatedByRemote: linphonec_call_updated(call); break; case LinphoneCallOutgoingProgress: linphonec_out("Call %i to %s in progress.\n", id, from); break; case LinphoneCallOutgoingRinging: linphonec_out("Call %i to %s ringing.\n", id, from); break; case LinphoneCallConnected: linphonec_out("Call %i with %s connected.\n", id, from); break; case LinphoneCallOutgoingEarlyMedia: linphonec_out("Call %i with %s early media.\n", id, from); break; case LinphoneCallError: linphonec_out("Call %i with %s error.\n", id, from); break; default: break; } ms_free(from); }
static void basic_audio_stream_base( const char* marielle_local_ip , int marielle_local_rtp_port , int marielle_local_rtcp_port , const char* margaux_local_ip , int margaux_local_rtp_port , int margaux_local_rtcp_port) { AudioStream * marielle = audio_stream_new2 (marielle_local_ip, marielle_local_rtp_port, marielle_local_rtcp_port); stats_t marielle_stats; AudioStream * margaux = audio_stream_new2 (margaux_local_ip, margaux_local_rtp_port,margaux_local_rtcp_port); stats_t margaux_stats; RtpProfile* profile = rtp_profile_new("default profile"); char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE); char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE); int dummy=0; rtp_session_set_multicast_loopback(marielle->ms.sessions.rtp_session,TRUE); rtp_session_set_multicast_loopback(margaux->ms.sessions.rtp_session,TRUE); reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); CU_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , ms_is_multicast(margaux_local_ip)?margaux_local_ip:marielle_local_ip , ms_is_multicast(margaux_local_ip)?margaux_local_rtp_port:marielle_local_rtp_port , marielle_local_ip , marielle_local_rtcp_port , 0 , 50 , NULL , recorded_file , NULL , NULL , 0),0); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , margaux_local_ip , margaux_local_rtp_port , margaux_local_ip , margaux_local_rtcp_port , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv); audio_stream_stop(marielle); audio_stream_stop(margaux); unlink(recorded_file); ms_free(recorded_file); ms_free(hello_file); }
static void vfw_uninit(MSFilter *f){ VfwState *s=(VfwState*)f->data; flushq(&s->rq,0); ms_mutex_destroy(&s->mutex); ms_free(s); }
static void winsndcard_uninit(MSSndCard *card){ ms_free(card->data); }
static void free_preset_config(MSVideoPresetConfiguration *vpc) { ms_list_for_each(vpc->tags, ms_free); ms_list_free(vpc->tags); ms_free(vpc); }
static void dec_uninit(MSFilter *f){ DecState *s=(DecState*)f->data; bv16_decode_release(s->dec); bv16_decode_free(s->dec); ms_free(s); }