struct ntree_data* ntree_sub_alignment(struct ntree_data* ntree_data,int* tree,int num) { struct dp_matrix *dp = 0; struct alignment* aln = 0; int i,j,g,a,b,c; int len_a; int len_b; float** local_profile = 0; float* profa = 0; float* profb = 0; int** local_map = 0; int* local_sl = 0; int* local_nsip = 0; int** local_sip = 0; int* which_to_alloc = 0; unsigned int numseq; unsigned int numprofiles; struct kalign_context *ctx = get_kalign_context(); numseq = ctx->numseq; numprofiles = ctx->numprofiles; aln = ntree_data->aln; which_to_alloc = malloc(sizeof(int*)*numprofiles); for ( i = 0;i< numprofiles;i++){ which_to_alloc[i] = 0; } local_profile = malloc(sizeof(float*)*numprofiles); local_sl = malloc(sizeof(int)*numprofiles); local_nsip = malloc(sizeof(int)*numprofiles); local_sip = malloc(sizeof(int*)*numprofiles); for (i = 0; i < num-1;i++){ a = tree[i*3+1]; if(!which_to_alloc[a]){ which_to_alloc[a] = 1; } b = tree[i*3+2]; if(!which_to_alloc[b]){ which_to_alloc[b] = 1; } c = tree[i*3+3]; if(!which_to_alloc[c]){ which_to_alloc[c] = 2; } } //for ( i = 0;i< numprofiles;i++){ // k_printf("alloc?:%d %d\n",i,which_to_alloc[i]); //} // exit(0); for ( i = 0;i< numprofiles;i++){ if(which_to_alloc[i] == 1){ local_profile[i] = ntree_data->profile[i]; local_sl[i] = aln->sl[i]; local_nsip[i] = aln->nsip[i]; local_sip[i] = malloc(sizeof(int*)*aln->nsip[i]); for(j = 0;j < aln->nsip[i];j++){ local_sip[i][j] = aln->sip[i][j]; } }else{ local_profile[i] = 0; local_sl[i] = 0; local_nsip[i] = 0; local_sip[i] = 0; } } /* for ( i = 0;i< numprofiles;i++){ local_profile[i] = ntree_data->profile[i]; local_sl[i] = aln->sl[i]; local_nsip[i] = aln->nsip[i]; if(aln->sip[i]){ k_printf("Allocing..:%d\n",aln->nsip[i]); local_sip[i] = malloc(sizeof(int*)*aln->nsip[i]); for(j = 0;j < aln->nsip[i];j++){ local_sip[i][j] = aln->sip[i][j]; } }else{ local_sip[i] = 0; } }*/ local_map = malloc(sizeof(int*)*numprofiles); for ( i = 0;i < numprofiles;i++){ local_map[i] = 0; } dp = dp_matrix_alloc(dp,511,511); c = numseq; for (i = 0; i < num-1;i++){ a = tree[i*3+1]; b = tree[i*3+2]; c = tree[i*3+3]; // k_printf("Aligning:%d %d->%d\n",a,b,c); len_a = local_sl[a]; len_b = local_sl[b]; dp = dp_matrix_realloc(dp,len_a,len_b); local_map[c] = malloc(sizeof(int) * (len_a+len_b+2)); for (j = len_a+len_b+2;j--;){ local_map[c][j] = 0; } if (a < numseq){ local_profile[a] = make_profile(local_profile[a],aln->s[a],len_a,ntree_data->submatrix); } if (b < numseq){ local_profile[b] = make_profile(local_profile[b],aln->s[b],len_b,ntree_data->submatrix); } profa = local_profile[a]; profb = local_profile[b]; set_gap_penalties(profa,len_a,local_nsip[b],0,local_nsip[a]); set_gap_penalties(profb,len_b,local_nsip[a],0,local_nsip[b]); if(local_nsip[a] == 1){ if(local_nsip[b] == 1){ local_map[c] = ss_dyn(ntree_data->submatrix,local_map[c],dp,aln->s[a],aln->s[b],len_a,len_b); }else{ local_map[c] = ps_dyn(local_map[c],dp,profb,aln->s[a],len_b,len_a,local_nsip[b]); local_map[c] = mirror_path(local_map[c]); } }else{ if(local_nsip[b] == 1){ local_map[c] = ps_dyn(local_map[c],dp,profa,aln->s[b],len_a,len_b,local_nsip[a]); }else{ if (len_a > len_b){ local_map[c] = pp_dyn(local_map[c],dp,profa,profb,len_a,len_b); }else{ local_map[c] = pp_dyn(local_map[c],dp,profb,profa,len_b,len_a); local_map[c] = mirror_path(local_map[c]); } } } local_profile[c] = malloc(sizeof(float)*64*(len_a+len_b+2)); local_profile[c] = update(profa,profb,local_profile[c],local_map[c],local_nsip[a],local_nsip[b]); local_sl[c] = local_map[c][0]; local_nsip[c] = local_nsip[a] + local_nsip[b]; local_sip[c] = malloc(sizeof(int)*(local_nsip[a] + local_nsip[b])); g =0; for (j = local_nsip[a];j--;){ local_sip[c][g] = local_sip[a][j]; g++; } for (j = local_nsip[b];j--;){ local_sip[c][g] = local_sip[b][j]; g++; } // free(profa); // free(profb); } if(ntree_data->profile[c]){ if(ntree_data->map[c][ntree_data->map[c][0]+2] < local_map[c][local_map[c][0]+2]){ k_printf("%d\n",local_map[c][local_map[c][0]+2]); //remove old map,profile,etc.. for (i = 0; i < num-1;i++){ c = tree[i*3+3]; free(ntree_data->map[c]); free(ntree_data->profile[c]); free(aln->sip[c]); ntree_data->map[c] = malloc(sizeof(int)*(local_map[c][0]+3)); for (j = 0; j < local_map[c][0]+3;j++){ ntree_data->map[c][j] = local_map[c][j]; } aln->sip[c] = malloc(sizeof(int)*local_nsip[c]); aln->nsip[c] = local_nsip[c]; for (j = 0; j < local_nsip[c];j++){ aln->sip[c][j] = local_sip[c][j]; } aln->sl[c] = local_sl[c]; } ntree_data->profile[c] = malloc(sizeof(int)*64*(aln->sl[c]+1)); for (i = 0; i < (64*(aln->sl[c]+1));i++){ ntree_data->profile[c][i] = local_profile[c][i]; } ntree_data->tree[0] -= (tree[0]-1); for (j = 1; j < tree[0];j++){ ntree_data->tree[ntree_data->tree[0]+j-1] = tree[j]; } ntree_data->tree[0] += (tree[0]-1); }else{ k_printf("no improvement\n"); } }else{ k_printf("%d\n",local_map[c][local_map[c][0]+2]); for (i = 0; i < num-1;i++){ c = tree[i*3+3]; ntree_data->map[c] = malloc(sizeof(int)*(local_map[c][0]+3)); for (j = 0; j < local_map[c][0]+3;j++){ ntree_data->map[c][j] = local_map[c][j]; } aln->sip[c] = malloc(sizeof(int)*local_nsip[c]); aln->nsip[c] = local_nsip[c]; for (j = 0; j < local_nsip[c];j++){ aln->sip[c][j] = local_sip[c][j]; } aln->sl[c] = local_sl[c]; } ntree_data->profile[c] = malloc(sizeof(int)*64*(aln->sl[c]+1)); for (i = 0; i < (64*(aln->sl[c]+1));i++){ ntree_data->profile[c][i] = local_profile[c][i]; } for (j = 1; j < tree[0];j++){ ntree_data->tree[ntree_data->tree[0]+j-1] = tree[j]; } ntree_data->tree[0] += tree[0]-1; } for ( i = 0;i< numprofiles;i++){ if(which_to_alloc[i] == 1){ free(local_sip[i]); if(i < numseq){ free(local_profile[i]); } } if(which_to_alloc[i] == 2){ free(local_profile[i]); free(local_map[i]); free(local_sip[i]); } } free(which_to_alloc); free(local_map); free(local_sip); free(local_nsip); free(local_profile); free(local_sl); dp_matrix_free(dp); return ntree_data; }
void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_muted, bool_t send_ringbacktone){ LinphoneCore *lc=call->core; LinphoneAddress *me=linphone_core_get_primary_contact_parsed(lc); const char *tool="linphone-" LINPHONE_VERSION; char *cname; int used_pt=-1; #ifdef VIDEO_ENABLED const SalStreamDescription *vstream=sal_media_description_find_stream(call->resultdesc, SalProtoRtpAvp,SalVideo); #endif bool_t use_arc=linphone_core_adaptive_rate_control_enabled(lc); if(call->audiostream == NULL) { ms_fatal("start_media_stream() called without prior init !"); return; } call->current_params = call->params; /* adjust rtp jitter compensation. It must be at least the latency of the sound card */ int jitt_comp=MAX(lc->sound_conf.latency,lc->rtp_conf.audio_jitt_comp); if (call->media_start_time==0) call->media_start_time=time(NULL); cname=linphone_address_as_string_uri_only(me); { const SalStreamDescription *stream=sal_media_description_find_stream(call->resultdesc, SalProtoRtpAvp,SalAudio); if (stream && stream->dir!=SalStreamInactive && stream->port!=0){ MSSndCard *playcard=lc->sound_conf.lsd_card ? lc->sound_conf.lsd_card : lc->sound_conf.play_sndcard; MSSndCard *captcard=lc->sound_conf.capt_sndcard; const char *playfile=lc->play_file; const char *recfile=lc->rec_file; call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt); bool_t use_ec,use_arc_audio=use_arc; if (used_pt!=-1){ if (playcard==NULL) { ms_warning("No card defined for playback !"); } if (captcard==NULL) { ms_warning("No card defined for capture !"); } /*Replace soundcard filters by inactive file players or recorders when placed in recvonly or sendonly mode*/ if (stream->port==0 || stream->dir==SalStreamRecvOnly){ captcard=NULL; playfile=NULL; }else if (stream->dir==SalStreamSendOnly){ playcard=NULL; captcard=NULL; recfile=NULL; /*And we will eventually play "playfile" if set by the user*/ /*playfile=NULL;*/ } if (send_ringbacktone){ captcard=NULL; playfile=NULL;/* it is setup later*/ } /*if playfile are supplied don't use soundcards*/ if (lc->use_files) { captcard=NULL; playcard=NULL; } use_ec=captcard==NULL ? FALSE : linphone_core_echo_cancellation_enabled(lc); #if defined(VIDEO_ENABLED) if (vstream && vstream->dir!=SalStreamInactive && vstream->payloads!=NULL){ /*when video is used, do not make adaptive rate control on audio, it is stupid.*/ use_arc_audio=FALSE; #if defined(ANDROID) /*On android we have to disable the echo canceller to preserve CPU for video codecs */ use_ec=FALSE; #endif } #endif audio_stream_enable_adaptive_bitrate_control(call->audiostream,use_arc_audio); audio_stream_start_full( call->audiostream, call->audio_profile, stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr, stream->port, stream->port+1, used_pt, jitt_comp, playfile, recfile, playcard, captcard, use_ec ); post_configure_audio_streams(call); if (all_inputs_muted && !send_ringbacktone){ audio_stream_set_mic_gain(call->audiostream,0); } if (stream->dir==SalStreamSendOnly && playfile!=NULL){ int pause_time=500; ms_filter_call_method(call->audiostream->soundread,MS_FILE_PLAYER_LOOP,&pause_time); } if (send_ringbacktone){ setup_ring_player(lc,call); } audio_stream_set_rtcp_information(call->audiostream, cname, tool); }else ms_warning("No audio stream accepted ?"); } } #ifdef VIDEO_ENABLED { used_pt=-1; /* shutdown preview */ if (lc->previewstream!=NULL) { video_preview_stop(lc->previewstream); lc->previewstream=NULL; } call->current_params.has_video=FALSE; if (vstream && vstream->dir!=SalStreamInactive && vstream->port!=0) { const char *addr=vstream->addr[0]!='\0' ? vstream->addr : call->resultdesc->addr; call->video_profile=make_profile(call,call->resultdesc,vstream,&used_pt); if (used_pt!=-1){ VideoStreamDir dir=VideoStreamSendRecv; MSWebCam *cam=lc->video_conf.device; bool_t is_inactive=FALSE; call->current_params.has_video=TRUE; video_stream_set_sent_video_size(call->videostream,linphone_core_get_preferred_video_size(lc)); video_stream_enable_self_view(call->videostream,lc->video_conf.selfview); if (lc->video_window_id!=0) video_stream_set_native_window_id(call->videostream,lc->video_window_id); if (lc->preview_window_id!=0) video_stream_set_native_preview_window_id (call->videostream,lc->preview_window_id); video_stream_use_preview_video_window (call->videostream,lc->use_preview_window); if (vstream->dir==SalStreamSendOnly && lc->video_conf.capture ){ cam=get_nowebcam_device(); dir=VideoStreamSendOnly; }else if (vstream->dir==SalStreamRecvOnly && lc->video_conf.display ){ dir=VideoStreamRecvOnly; }else if (vstream->dir==SalStreamSendRecv){ if (lc->video_conf.display && lc->video_conf.capture) dir=VideoStreamSendRecv; else if (lc->video_conf.display) dir=VideoStreamRecvOnly; else dir=VideoStreamSendOnly; }else{ ms_warning("video stream is inactive."); /*either inactive or incompatible with local capabilities*/ is_inactive=TRUE; } if (call->camera_active==FALSE || all_inputs_muted){ cam=get_nowebcam_device(); } if (!is_inactive){ video_stream_set_direction (call->videostream, dir); video_stream_start(call->videostream, call->video_profile, addr, vstream->port, vstream->port+1, used_pt, jitt_comp, cam); video_stream_set_rtcp_information(call->videostream, cname,tool); } }else ms_warning("No video stream accepted."); }else{ ms_warning("No valid video stream defined."); } } #endif call->all_muted=all_inputs_muted; call->playing_ringbacktone=send_ringbacktone; call->up_bw=linphone_core_get_upload_bandwidth(lc); if (ortp_zrtp_available()) { OrtpZrtpParams params; params.zid=get_hexa_zrtp_identifier(lc); params.zid_file=lc->zrtp_secrets_cache; audio_stream_enable_zrtp(call->audiostream,¶ms); } goto end; end: ms_free(cname); linphone_address_destroy(me); }