static RtpProfile *make_dummy_profile(int samplerate){ RtpProfile *prof=rtp_profile_new("dummy"); PayloadType *pt=payload_type_clone(&payload_type_l16_mono); pt->clock_rate=samplerate; rtp_profile_set_payload(prof,0,pt); return prof; }
static void basic_audio_stream() { AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); stats_t marielle_stats; AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE); stats_t margaux_stats; RtpProfile* profile = rtp_profile_new("default profile"); 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_8K_1S_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_8K_1S_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)); 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_8K_1S_FILE); }
static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){ int bw; const MSList *elem; RtpProfile *prof=rtp_profile_new("Call profile"); bool_t first=TRUE; int remote_bw=0; LinphoneCore *lc=call->core; int up_ptime=0; *used_pt=-1; for(elem=desc->payloads;elem!=NULL;elem=elem->next){ PayloadType *pt=(PayloadType*)elem->data; int number; if ((pt->flags & PAYLOAD_TYPE_FLAG_CAN_SEND) && first) { if (desc->type==SalAudio){ linphone_core_update_allocated_audio_bandwidth_in_call(call,pt); up_ptime=linphone_core_get_upload_ptime(lc); } *used_pt=payload_type_get_number(pt); first=FALSE; } if (desc->bandwidth>0) remote_bw=desc->bandwidth; else if (md->bandwidth>0) { /*case where b=AS is given globally, not per stream*/ remote_bw=md->bandwidth; if (desc->type==SalVideo){ remote_bw=get_video_bandwidth(remote_bw,call->audio_bw); } } if (desc->type==SalAudio){ bw=get_min_bandwidth(call->audio_bw,remote_bw); }else bw=get_min_bandwidth(get_video_bandwidth(linphone_core_get_upload_bandwidth (lc),call->audio_bw),remote_bw); if (bw>0) pt->normal_bitrate=bw*1000; else if (desc->type==SalAudio){ pt->normal_bitrate=-1; } if (desc->ptime>0){ up_ptime=desc->ptime; } if (up_ptime>0){ char tmp[40]; snprintf(tmp,sizeof(tmp),"ptime=%i",up_ptime); payload_type_append_send_fmtp(pt,tmp); } number=payload_type_get_number(pt); if (rtp_profile_get_payload(prof,number)!=NULL){ ms_warning("A payload type with number %i already exists in profile !",number); }else rtp_profile_set_payload(prof,number,pt); } return prof; }
/*clone a profile and its payloads */ RtpProfile * rtp_profile_clone_full(RtpProfile *prof) { int i; PayloadType *pt; RtpProfile *newprof=rtp_profile_new(prof->name); for (i=0; i<RTP_PROFILE_MAX_PAYLOADS; i++) { pt=rtp_profile_get_payload(prof,i); if (pt!=NULL) { rtp_profile_set_payload(newprof,i,payload_type_clone(pt)); } } return newprof; }
bool myAudioStream::init_stream() { /** Init stream **/ stream = (AudioStream *)ms_new0(AudioStream,1); if (stream == 0) { ms_error("Failed to create new stream"); return false; } /** Configure stream **/ stream->play_dtmfs = false; stream->use_gc = false; stream->use_agc = false; stream->use_ng = false; /** Init RTP session **/ stream->session = rtp_session_new(RTP_SESSION_RECVONLY); if (stream->session == 0) { ms_error("Failed to create new RTP session"); return false; } /** Configure RTP session **/ /* Create profile to use in session */ RtpProfile *rtp_profile = rtp_profile_new("My profile"); if (rtp_profile == 0) { ms_error("Failed to create new RTP profile"); return false; } rtp_session_set_profile(stream->session, rtp_profile); /* Define some payloads */ rtp_profile_set_payload(rtp_profile,110,&payload_type_speex_nb); rtp_profile_set_payload(rtp_profile,111,&payload_type_speex_wb); rtp_profile_set_payload(rtp_profile,112,&payload_type_speex_uwb); /* Set local address and port */ rtp_session_set_local_addr(stream->session, "0.0.0.0", 1337); return true; }
Call * call_new(Sipomatic *root, eXosip_event_t *ev) { Call *obj; char *sdpans; int status; sdp_message_t *sdp; sdp_context_t *sdpc; sdp=eXosip_get_sdp_info(ev->request); sdpc=sdp_handler_create_context(&sipomatic_sdp_handler,NULL,"sipomatic"); obj=ms_new0(Call,1); obj->profile=rtp_profile_new("remote"); eXosip_call_send_answer(ev->tid,100,NULL); sdp_context_set_user_pointer(sdpc,obj); sdpans=sdp_context_get_answer(sdpc,sdp); if (sdpans!=NULL){ eXosip_call_send_answer(ev->tid,180,NULL); }else{ status=sdp_context_get_status(sdpc); eXosip_call_send_answer(ev->tid,status,NULL); sdp_context_free(sdpc); rtp_profile_destroy(obj->profile); ms_free(obj); return NULL; } obj->sdpc=sdpc; obj->did=ev->did; obj->tid=ev->tid; obj->time=time(NULL); obj->audio_stream=NULL; obj->state=CALL_STATE_INIT; obj->eof=0; obj->root=root; root->calls=ms_list_append(root->calls,obj); return obj; }
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 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 basic_audio_stream_base_2( const char* marielle_local_ip , const char* marielle_remote_ip , int marielle_local_rtp_port , int marielle_remote_rtp_port , int marielle_local_rtcp_port , int marielle_remote_rtcp_port , const char* margaux_local_ip , const char* margaux_remote_ip , int margaux_local_rtp_port , int margaux_remote_rtp_port , int margaux_local_rtcp_port , int margaux_remote_rtcp_port , int lost_percentage) { AudioStream * marielle = audio_stream_new2 (_factory, marielle_local_ip, marielle_local_rtp_port, marielle_local_rtcp_port); stats_t marielle_stats; AudioStream * margaux = audio_stream_new2 (_factory, 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 = bc_tester_res(HELLO_8K_1S_FILE); char* recorded_file = bc_tester_file(RECORDED_8K_1S_FILE); uint64_t marielle_rtp_sent=0; rtp_session_set_multicast_loopback(marielle->ms.sessions.rtp_session,TRUE); rtp_session_set_multicast_loopback(margaux->ms.sessions.rtp_session,TRUE); rtp_session_set_rtcp_report_interval(marielle->ms.sessions.rtp_session, 1000); rtp_session_set_rtcp_report_interval(margaux->ms.sessions.rtp_session, 1000); reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); BC_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , ms_is_multicast(margaux_local_ip)?margaux_local_ip:margaux_remote_ip , ms_is_multicast(margaux_local_ip)?margaux_local_rtp_port:margaux_remote_rtp_port , margaux_remote_ip , margaux_remote_rtcp_port , 0 , 50 , NULL , recorded_file , NULL , NULL , 0) ,0, int, "%d"); BC_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , marielle_remote_ip , marielle_remote_rtp_port , marielle_remote_ip , marielle_remote_rtcp_port , 0 , 50 , hello_file , NULL , NULL , NULL , 0) ,0, int, "%d"); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); marielle_rtp_sent = marielle_stats.rtp.sent; if (rtp_session_rtcp_enabled(marielle->ms.sessions.rtp_session) && rtp_session_rtcp_enabled(margaux->ms.sessions.rtp_session)) { BC_ASSERT_GREATER_STRICT(rtp_session_get_round_trip_propagation(marielle->ms.sessions.rtp_session),0,float,"%f"); BC_ASSERT_GREATER_STRICT(rtp_session_get_stats(marielle->ms.sessions.rtp_session)->recv_rtcp_packets,0,unsigned long long,"%llu"); }
/* * This small program starts a video stream to either * - read an H264 video track from mkv file and stream it out with RTP to specified destination * - receive H264 RTP packets on a local port and record them into an mkv file */ int main(int argc, char *argv[]){ const char *command; const char *file; const char *ip; int port; VideoStream *stream; RtpProfile *profile; PayloadType *pt; Mode mode = INVALID_MODE; int local_port = 7778; MSFactory *factory ; MSMediaStreamIO io = MS_MEDIA_STREAM_IO_INITIALIZER; int err; /*parse command line arguments*/ if (argc<4) usage(argv[0]); command = argv[1]; if (strcasecmp(command,"play")==0) mode = PLAY_MODE; else if (strcasecmp(command, "record")==0) mode = RECORD_MODE; else usage(argv[0]); file = argv[2]; if (mode == PLAY_MODE){ ip = argv[3]; if (argc<5) usage(argv[0]); port = atoi(argv[4]); }else{ local_port = atoi(argv[3]); ip = "127.0.0.1"; port = 9990; /*dummy destination address, we won't send anything here anyway*/ } /*set a signal handler to interrupt the program cleanly*/ signal(SIGINT,stop_handler); /*initialize mediastreamer2*/ factory = ms_factory_new_with_voip(); /*create the video stream */ stream = video_stream_new(factory, local_port, local_port+1, FALSE); /*define its local input and outputs with the MSMediaStreamIO structure*/ if (mode == PLAY_MODE){ io.input.type = MSResourceFile; io.input.file = file; /*the file we want to stream out via rtp*/ io.output.type = MSResourceFile; io.output.file = NULL; /*we don't set a record file in PLAY_MODE, we just want the received video stream to be ignored, if something is received*/ }else{ io.input.type = MSResourceFile; io.input.file = NULL; /*We don't want to send anything via RTP in RECORD_MODE*/ io.output.type = MSResourceFile; io.output.file = file; /*The file to which we want to record the received video stream*/ } /*define the RTP profile to use: in this case we just want to use H264 codec*/ profile = rtp_profile_new("My RTP profile"); pt = payload_type_clone(&payload_type_h264); rtp_profile_set_payload(profile, payload_type_number, pt); /*we assign H264 to payload type number payload_type_number*/ media_stream_set_target_network_bitrate(&stream->ms, 500000); /*set a target IP bitrate in bits/second */ /*By default, the VideoStream will show up a display window where the received video is played, with a local preview as well. * If you don't need this, assign (void*)-1 as window id, which explicitely disable the display feature.*/ /*video_stream_set_native_window_id(stream, (void*)-1);*/ /*start the video stream, given the RtpProfile and "io" definition */ err = video_stream_start_from_io(stream, profile, ip, port, ip, port+1, payload_type_number, &io); if (err !=0 ){ fprintf(stderr,"Could not start video stream."); goto end; } /*Register an event handler on the player to be notified of end of file*/ ms_filter_add_notify_callback(stream->source, on_end_of_play, NULL, FALSE); /*program's main loop*/ while (active){ /*handle video stream background activity. This is non blocking*/ video_stream_iterate(stream); /*process event callbacks*/ ms_event_queue_pump(ms_factory_get_event_queue(factory)); ms_usleep(50000); /*pause 50ms to avoid busy loop*/ } end: /*stop and destroy the video stream object*/ if (stream) video_stream_stop(stream); /*free the RTP profile and payload type inside*/ if (profile) rtp_profile_destroy(profile); ms_factory_destroy(factory); return err; }