void linphone_core_setup_local_rtp_profile(LinphoneCore *lc) { int i; MSList *audiopt,*videopt; PayloadType *payload; bool_t prepend; lc->local_profile=rtp_profile_clone_full(&av_profile); /* first look at the list given by configuration file to see if it is correct */ audiopt=fix_codec_list(lc->local_profile,lc->codecs_conf.audio_codecs); videopt=fix_codec_list(lc->local_profile,lc->codecs_conf.video_codecs); /* now find and add payloads that are not listed in the configuration codec list */ for (i=0;i<127;i++) { payload=rtp_profile_get_payload(lc->local_profile,i); if (payload!=NULL){ if (payload_type_get_user_data(payload)!=NULL) continue; /* find a mediastreamer codec for this payload type */ if (ms_filter_codec_supported(payload->mime_type)){ MSFilterDesc *desc=ms_filter_get_encoder(payload->mime_type); ms_message("Adding new codec %s/%i",payload->mime_type,payload->clock_rate); payload_type_set_enable(payload,1); payload_type_set_user_data(payload,(void *)desc->text); prepend=FALSE; /* by default, put speex and theora on top of list*/ if (strcmp(payload->mime_type,"speex")==0) prepend=TRUE; if (strcmp(payload->mime_type,"theora")==0) prepend=TRUE; switch (payload->type){ case PAYLOAD_AUDIO_CONTINUOUS: case PAYLOAD_AUDIO_PACKETIZED: if (prepend) audiopt=ms_list_prepend(audiopt,(void *)payload); else audiopt=ms_list_append(audiopt,(void *)payload); break; case PAYLOAD_VIDEO: if (prepend) videopt=ms_list_prepend(videopt,(void *)payload); else videopt=ms_list_append(videopt,(void *)payload); break; default: ms_error("Unsupported rtp media type."); } } } } ms_list_for_each(lc->codecs_conf.audio_codecs,(void (*)(void*))payload_type_destroy); ms_list_for_each(lc->codecs_conf.video_codecs,(void (*)(void *))payload_type_destroy); ms_list_free(lc->codecs_conf.audio_codecs); ms_list_free(lc->codecs_conf.video_codecs); /* set the fixed lists instead:*/ lc->codecs_conf.audio_codecs=audiopt; lc->codecs_conf.video_codecs=videopt; }
static void setup_media_streams(MediastreamDatas *args) { MSConnectionHelper h; MSTickerParams params = {0}; /*create the rtp session */ ortp_init(); if (args->is_verbose) { ortp_set_log_level_mask(ORTP_DEBUG | ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL); } else { ortp_set_log_level_mask(ORTP_MESSAGE | ORTP_WARNING | ORTP_ERROR | ORTP_FATAL); } rtp_profile_set_payload(&av_profile, 110, &payload_type_speex_nb); rtp_profile_set_payload(&av_profile, 111, &payload_type_speex_wb); rtp_profile_set_payload(&av_profile, 112, &payload_type_ilbc); rtp_profile_set_payload(&av_profile, 113, &payload_type_amr); rtp_profile_set_payload(&av_profile, 115, &payload_type_lpc1015); #ifdef VIDEO_ENABLED rtp_profile_set_payload(&av_profile, 26, &payload_type_jpeg); rtp_profile_set_payload(&av_profile, 98, &payload_type_h263_1998); rtp_profile_set_payload(&av_profile, 97, &payload_type_theora); rtp_profile_set_payload(&av_profile, 99, &payload_type_mp4v); rtp_profile_set_payload(&av_profile, 100, &payload_type_x_snow); rtp_profile_set_payload(&av_profile, 102, &payload_type_h264); rtp_profile_set_payload(&av_profile, 103, &payload_type_vp8); #endif args->profile = rtp_profile_clone_full(&av_profile); ms_init(); ms_filter_enable_statistics(TRUE); ms_filter_reset_statistics(); signal(SIGINT, stop_handler); if (args->pt==NULL) args->pt = rtp_profile_get_payload(args->profile, args->payload); if (args->pt == NULL) { printf("Error: no payload defined with number %i.", args->payload); exit(-1); } if (args->pt->type == PAYLOAD_VIDEO) { #ifdef VIDEO_ENABLED const char *display_name; MSPixFmt format; MSVideoSize disp_size; int tmp = 1; #if defined(HAVE_GL) display_name = "MSGLXVideo"; #elif defined(HAVE_XV) display_name = "MSX11Video"; #elif __APPLE__ && !defined(__ios) display_name ="MSOSXGLDisplay"; #else display_name = "MSVideoOut"; #endif args->read = ms_filter_new(MS_FILE_PLAYER_ID); args->write = ms_filter_new_from_name(display_name); args->decoder = ms_filter_create_decoder(args->pt->mime_type); ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_CLOSE); ms_filter_call_method(args->read, MS_FILE_PLAYER_OPEN, args->infile); ms_filter_call_method(args->read, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate); ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_START); ms_filter_add_notify_callback(args->read, reader_notify_cb, NULL,FALSE); /*force the decoder to output YUV420P */ format = MS_YUV420P; ms_filter_call_method(args->decoder, MS_FILTER_SET_PIX_FMT, &format); /*configure the display window */ disp_size.width = MS_VIDEO_SIZE_CIF_W; disp_size.height = MS_VIDEO_SIZE_CIF_H; ms_filter_call_method(args->write, MS_FILTER_SET_VIDEO_SIZE, &disp_size); ms_filter_call_method(args->write, MS_VIDEO_DISPLAY_ENABLE_AUTOFIT, &tmp); ms_filter_call_method(args->write, MS_FILTER_SET_PIX_FMT, &format); params.name = "Video MSTicker"; params.prio = MS_TICKER_PRIO_REALTIME; args->ticker = ms_ticker_new_with_params(¶ms); ms_connection_helper_start(&h); ms_connection_helper_link(&h, args->read, -1, 0); ms_connection_helper_link(&h, args->decoder, 0, 0); ms_connection_helper_link(&h, args->write, 0, -1); ms_ticker_attach(args->ticker, args->read); #else printf("Error: video support not compiled.\n"); #endif } else { MSSndCardManager *manager = ms_snd_card_manager_get(); MSSndCard *play = args->playback_card == NULL ? ms_snd_card_manager_get_default_playback_card(manager) : ms_snd_card_manager_get_card(manager, args->playback_card); args->read = ms_filter_new(MS_FILE_PLAYER_ID); args->write = ms_snd_card_create_writer(play); args->decoder = ms_filter_create_decoder(args->pt->mime_type); ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_CLOSE); ms_filter_call_method(args->read, MS_FILE_PLAYER_OPEN, args->infile); ms_filter_call_method_noarg(args->read, MS_FILE_PLAYER_START); ms_filter_call_method(args->read, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate); ms_filter_call_method(args->decoder, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate); ms_filter_call_method(args->decoder, MS_FILTER_SET_NCHANNELS, &args->pt->channels); ms_filter_call_method(args->write, MS_FILTER_SET_SAMPLE_RATE, &args->pt->clock_rate); ms_filter_call_method(args->write, MS_FILTER_SET_NCHANNELS, &args->pt->channels); params.name = "Audio MSTicker"; params.prio = MS_TICKER_PRIO_REALTIME; args->ticker = ms_ticker_new_with_params(¶ms); ms_connection_helper_start(&h); ms_connection_helper_link(&h, args->read, -1, 0); ms_connection_helper_link(&h, args->decoder, 0, 0); ms_connection_helper_link(&h, args->write, 0, -1); ms_ticker_attach(args->ticker, args->read); } }
static void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp, int jitter, int bitrate, MSVideoSize vs, bool_t ec, bool_t agc, bool_t eq) { AudioStream *audio=NULL; #ifdef VIDEO_ENABLED VideoStream *video=NULL; #endif RtpSession *session=NULL; PayloadType *pt; RtpProfile *profile=rtp_profile_clone_full(&av_profile); OrtpEvQueue *q=ortp_ev_queue_new(); ms_init(); signal(SIGINT,stop_handler); pt=rtp_profile_get_payload(profile,payload); if (pt==NULL){ printf("Error: no payload defined with number %i.",payload); exit(-1); } if (fmtp!=NULL) payload_type_set_send_fmtp(pt,fmtp); if (bitrate>0) pt->normal_bitrate=bitrate; if (pt->type!=PAYLOAD_VIDEO){ MSSndCardManager *manager=ms_snd_card_manager_get(); MSSndCard *capt= capture_card==NULL ? ms_snd_card_manager_get_default_capture_card(manager) : ms_snd_card_manager_get_card(manager,capture_card); MSSndCard *play= playback_card==NULL ? ms_snd_card_manager_get_default_playback_card(manager) : ms_snd_card_manager_get_card(manager,playback_card); audio=audio_stream_new(localport,ms_is_ipv6(remote_ip)); audio_stream_enable_automatic_gain_control(audio,agc); audio_stream_enable_noise_gate(audio,use_ng); audio_stream_set_echo_canceller_params(audio,ec_len_ms,ec_delay_ms,ec_framesize); printf("Starting audio stream.\n"); audio_stream_start_full(audio,profile,remote_ip,remoteport,remoteport+1, payload, jitter,infile,outfile, outfile==NULL ? play : NULL ,infile==NULL ? capt : NULL,infile!=NULL ? FALSE: ec); if (audio) { if (use_ng && ng_threshold!=-1) ms_filter_call_method(audio->volsend,MS_VOLUME_SET_NOISE_GATE_THRESHOLD,&ng_threshold); session=audio->session; } }else{ #ifdef VIDEO_ENABLED if (eq){ ms_fatal("Cannot put an audio equalizer in a video stream !"); exit(-1); } printf("Starting video stream.\n"); video=video_stream_new(localport, ms_is_ipv6(remote_ip)); video_stream_set_sent_video_size(video,vs); video_stream_use_preview_video_window(video,two_windows); video_stream_start(video,profile, remote_ip, remoteport,remoteport+1, payload, jitter, ms_web_cam_manager_get_default_cam(ms_web_cam_manager_get())); session=video->session; #else printf("Error: video support not compiled.\n"); #endif } if (eq || ec){ /*read from stdin interactive commands */ char commands[128]; commands[127]='\0'; ms_sleep(1); /* ensure following text be printed after ortp messages */ if (eq) printf("\nPlease enter equalizer requests, such as 'eq active 1', 'eq active 0', 'eq 1200 0.1 200'\n"); if (ec) printf("\nPlease enter echo canceller requests: ec reset; ec <delay ms> <tail_length ms'\n"); while(fgets(commands,sizeof(commands)-1,stdin)!=NULL){ int active,freq,freq_width; int delay_ms, tail_ms; float gain; if (sscanf(commands,"eq active %i",&active)==1){ audio_stream_enable_equalizer(audio,active); printf("OK\n"); }else if (sscanf(commands,"eq %i %f %i",&freq,&gain,&freq_width)==3){ audio_stream_equalizer_set_gain(audio,freq,gain,freq_width); printf("OK\n"); }else if (sscanf(commands,"eq %i %f",&freq,&gain)==2){ audio_stream_equalizer_set_gain(audio,freq,gain,0); printf("OK\n"); }else if (strstr(commands,"dump")){ int n=0,i; float *t; ms_filter_call_method(audio->equalizer,MS_EQUALIZER_GET_NUM_FREQUENCIES,&n); t=(float*)alloca(sizeof(float)*n); ms_filter_call_method(audio->equalizer,MS_EQUALIZER_DUMP_STATE,t); for(i=0;i<n;++i){ if (fabs(t[i]-1)>0.01){ printf("%i:%f:0 ",(i*pt->clock_rate)/(2*n),t[i]); } } printf("\nOK\n"); }else if (sscanf(commands,"ec reset %i",&active)==1){ //audio_stream_enable_equalizer(audio,active); //printf("OK\n"); }else if (sscanf(commands,"ec active %i",&active)==1){ //audio_stream_enable_equalizer(audio,active); //printf("OK\n"); }else if (sscanf(commands,"ec %i %i",&delay_ms,&tail_ms)==2){ audio_stream_set_echo_canceller_params(audio,tail_ms,delay_ms,128); // revisit: workaround with old method call to force echo reset delay_ms*=8; ms_filter_call_method(audio->ec,MS_FILTER_SET_PLAYBACKDELAY,&delay_ms); printf("OK\n"); }else if (strstr(commands,"quit")){ break; }else printf("Cannot understand this.\n"); } }else{ /* no interactive stuff - continuous debug output */ rtp_session_register_event_queue(session,q); while(cond) { int n; for(n=0;n<100;++n){ #ifdef WIN32 MSG msg; Sleep(10); while (PeekMessage(&msg, NULL, 0, 0,1)){ TranslateMessage(&msg); DispatchMessage(&msg); } #else struct timespec ts; ts.tv_sec=0; ts.tv_nsec=10000000; nanosleep(&ts,NULL); #endif #if defined(VIDEO_ENABLED) if (video) video_stream_iterate(video); #endif } ortp_global_stats_display(); if (session){ printf("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n", rtp_session_compute_recv_bandwidth(session)*1e-3, rtp_session_compute_send_bandwidth(session)*1e-3); parse_events(q); } } } printf("stopping all...\n"); if (audio) audio_stream_stop(audio); #ifdef VIDEO_ENABLED if (video) video_stream_stop(video); #endif ortp_ev_queue_destroy(q); rtp_profile_destroy(profile); }
void run_media_streams(int localport, const char *remote_ip, int remoteport, int payload, const char *fmtp, int jitter, bool_t ec, int bitrate) { AudioStream *audio=NULL; #ifdef VIDEO_ENABLED VideoStream *video=NULL; #endif RtpSession *session=NULL; PayloadType *pt; RtpProfile *profile=rtp_profile_clone_full(&av_profile); OrtpEvQueue *q=ortp_ev_queue_new(); ms_init(); signal(SIGINT,stop_handler); pt=rtp_profile_get_payload(profile,payload); if (pt==NULL) { printf("Error: no payload defined with number %i.",payload); exit(-1); } if (fmtp!=NULL) payload_type_set_send_fmtp(pt,fmtp); if (bitrate>0) pt->normal_bitrate=bitrate; if (pt->type!=PAYLOAD_VIDEO) { printf("Starting audio stream.\n"); audio=audio_stream_start(profile,localport,remote_ip,remoteport,payload,jitter, ec); if (audio) session=audio->session; } else { #ifdef VIDEO_ENABLED printf("Starting video stream.\n"); video=video_stream_new(localport, ms_is_ipv6(remote_ip)); video_stream_start(video,profile, remote_ip, remoteport, payload, jitter, "/dev/video0"); session=video->session; #else printf("Error: video support not compiled.\n"); #endif } rtp_session_register_event_queue(session,q); while(cond) { /* sleep until we receive SIGINT */ #ifdef WIN32 int n; MSG msg; for(n=0; n<100; ++n) { Sleep(10); while (PeekMessage(&msg, NULL, 0, 0,1)) { TranslateMessage(&msg); DispatchMessage(&msg); } } #else sleep(1); #endif ortp_global_stats_display(); if (session) { printf("Bandwidth usage: download=%f kbits/sec, upload=%f kbits/sec\n", rtp_session_compute_recv_bandwidth(session)*1e-3, rtp_session_compute_send_bandwidth(session)*1e-3); parse_events(q); } } printf("stoping all...\n"); if (audio) audio_stream_stop(audio); #ifdef VIDEO_ENABLED if (video) video_stream_stop(video); #endif ortp_ev_queue_destroy(q); rtp_profile_destroy(profile); }