void ms_tester_create_filters(unsigned int filter_mask, MSFactory * f) { MSSndCardManager *snd_manager; MSWebCamManager *cam_manager; MSSndCard *playcard; MSSndCard *captcard; MSWebCam *camera; CREATE_FILTER(FILTER_MASK_FILEPLAY, ms_tester_fileplay,f, MS_FILE_PLAYER_ID); CREATE_FILTER(FILTER_MASK_FILEREC, ms_tester_filerec,f, MS_FILE_REC_ID); CREATE_FILTER(FILTER_MASK_DTMFGEN, ms_tester_dtmfgen, f, MS_DTMF_GEN_ID); CREATE_FILTER(FILTER_MASK_TONEDET, ms_tester_tonedet, f, MS_TONE_DETECTOR_ID); CREATE_FILTER(FILTER_MASK_VOIDSOURCE, ms_tester_voidsource, f, MS_VOID_SOURCE_ID); CREATE_FILTER(FILTER_MASK_VOIDSINK, ms_tester_voidsink, f, MS_VOID_SINK_ID); if (filter_mask & FILTER_MASK_ENCODER) { BC_ASSERT_PTR_NULL(ms_tester_encoder); ms_tester_encoder = ms_factory_create_encoder(f, ms_tester_codec_mime); BC_ASSERT_PTR_NOT_NULL(ms_tester_encoder); } if (filter_mask & FILTER_MASK_DECODER) { BC_ASSERT_PTR_NULL(ms_tester_decoder); ms_tester_decoder = ms_factory_create_decoder(f, ms_tester_codec_mime); BC_ASSERT_PTR_NOT_NULL(ms_tester_decoder); } CREATE_FILTER(FILTER_MASK_RTPRECV, ms_tester_rtprecv, f, MS_RTP_RECV_ID); CREATE_FILTER(FILTER_MASK_RTPSEND, ms_tester_rtpsend, f ,MS_RTP_SEND_ID); CREATE_FILTER(FILTER_MASK_RESAMPLER, ms_tester_resampler, f, MS_RESAMPLE_ID); if (filter_mask & FILTER_MASK_SOUNDWRITE) { BC_ASSERT_PTR_NULL(ms_tester_soundwrite); snd_manager = ms_factory_get_snd_card_manager(f); playcard = ms_snd_card_manager_get_default_playback_card(snd_manager); BC_ASSERT_PTR_NOT_NULL(playcard); ms_tester_soundwrite = ms_snd_card_create_writer(playcard); BC_ASSERT_PTR_NOT_NULL(ms_tester_soundwrite); } if (filter_mask & FILTER_MASK_SOUNDREAD) { BC_ASSERT_PTR_NULL(ms_tester_soundread); snd_manager = ms_factory_get_snd_card_manager(f); captcard = ms_snd_card_manager_get_default_capture_card(snd_manager); BC_ASSERT_PTR_NOT_NULL(captcard); ms_tester_soundread = ms_snd_card_create_reader(captcard); BC_ASSERT_PTR_NOT_NULL(ms_tester_soundread); } if (filter_mask & FILTER_MASK_VIDEOCAPTURE) { BC_ASSERT_PTR_NULL(ms_tester_videocapture); cam_manager = ms_factory_get_web_cam_manager(f); camera = ms_web_cam_manager_get_default_cam(cam_manager); BC_ASSERT_PTR_NOT_NULL(camera); ms_tester_videocapture = ms_web_cam_create_reader(camera); BC_ASSERT_PTR_NOT_NULL(ms_tester_videocapture); } }
int main(int argc, char *argv[]) { RingStream *r; const char *file; MSSndCard *sc; const char * card_id=NULL; MSFactory *factory; ortp_init(); ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); factory = ms_factory_new_with_voip(); if (argc>1) { file=argv[1]; } else file="/usr/share/sounds/linphone/rings/oldphone.wav"; if (argc>2) { card_id=argv[2]; } sc=ms_snd_card_manager_get_card(ms_factory_get_snd_card_manager(factory),card_id); #ifdef __linux if (sc==NULL) sc = ms_alsa_card_new_custom(card_id, card_id); #endif r=ring_start(factory, file,2000,sc); ms_sleep(10); ring_stop(r); ms_factory_destroy(factory); return 0; }
static void play_file(const char *filepath, bool_t unsupported_format, bool_t seeking_test, bool_t play_twice) { bool_t succeed; Eof eof; MSMediaPlayer *file_player = NULL; MSSndCard *snd_card = ms_snd_card_manager_get_default_playback_card(ms_factory_get_snd_card_manager(_factory)); const char *display_name = video_stream_get_default_video_renderer(); int duration, timeout; const int seek_time = 6100; const double timeout_prec = 0.05; eof_init(&eof); BC_ASSERT_PTR_NOT_NULL(snd_card); file_player = ms_media_player_new(_factory, snd_card, display_name, 0); BC_ASSERT_PTR_NOT_NULL(file_player); if(file_player == NULL) return; BC_ASSERT_EQUAL(ms_media_player_get_state(file_player), MSPlayerClosed, int, "%d"); ms_media_player_set_eof_callback(file_player, eof_callback, &eof); succeed = ms_media_player_open(file_player, filepath); if(unsupported_format) { BC_ASSERT_FALSE(succeed); BC_ASSERT_EQUAL(ms_media_player_get_state(file_player), MSPlayerClosed, int, "%d"); } else {
static void dtmfgen_enc_dec_tonedet(char *mime, int sample_rate, int nchannels) { MSConnectionHelper h; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_ENCODER | FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK; bool_t send_silence = TRUE; MSSndCardManager *scm = ms_factory_get_snd_card_manager(factory); ms_factory_reset_statistics(scm->factory); //ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_codec_mime = mime; ms_tester_create_filters(filter_mask, scm->factory); /* set sample rate and channel number to all filters (might need to check the return value to insert a resampler if needed?) */ ms_filter_call_method(ms_tester_voidsource, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_voidsource, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_voidsource, MS_VOID_SOURCE_SEND_SILENCE, &send_silence); ms_filter_call_method(ms_tester_dtmfgen, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_dtmfgen, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_encoder, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_encoder, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_decoder, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_decoder, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_tonedet, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_tonedet, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_voidsink, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_voidsink, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_add_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL,TRUE); ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0); ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0); ms_connection_helper_link(&h, ms_tester_encoder, 0, 0); ms_connection_helper_link(&h, ms_tester_decoder, 0, 0); ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0); ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource); ms_tester_tone_generation_and_detection_loop(); ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0); ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0); ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0); ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1); // ms_filter_log_statistics(); ms_factory_log_statistics(scm->factory); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
static void dtmfgen_enc_rtp_dec_tonedet(void) { MSConnectionHelper h; RtpSession *rtps; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_ENCODER | FILTER_MASK_RTPSEND | FILTER_MASK_RTPRECV | FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK; bool_t send_silence = TRUE; MSSndCardManager *scm = ms_factory_get_snd_card_manager(factory); ms_factory_reset_statistics(factory); //ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_codec_mime = "pcmu"; ms_tester_create_filters(filter_mask, factory); ms_filter_add_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL,TRUE); rtps = ms_create_duplex_rtp_session("0.0.0.0", 50060, 0, ms_factory_get_mtu(factory)); rtp_session_set_remote_addr_full(rtps, "127.0.0.1", 50060, "127.0.0.1", 50061); rtp_session_set_payload_type(rtps, 8); rtp_session_enable_rtcp(rtps,FALSE); ms_filter_call_method(ms_tester_rtprecv, MS_RTP_RECV_SET_SESSION, rtps); ms_filter_call_method(ms_tester_rtpsend, MS_RTP_SEND_SET_SESSION, rtps); ms_filter_call_method(ms_tester_voidsource, MS_VOID_SOURCE_SEND_SILENCE, &send_silence); ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0); ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0); ms_connection_helper_link(&h, ms_tester_encoder, 0, 0); ms_connection_helper_link(&h, ms_tester_rtpsend, 0, -1); ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_rtprecv, -1, 0); ms_connection_helper_link(&h, ms_tester_decoder, 0, 0); ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0); ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1); ms_ticker_attach_multiple(ms_tester_ticker, ms_tester_voidsource, ms_tester_rtprecv, NULL); ms_tester_tone_generation_and_detection_loop(); ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource); ms_ticker_detach(ms_tester_ticker, ms_tester_rtprecv); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0); ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0); ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_rtpsend, 0, -1); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_rtprecv, -1, 0); ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0); ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1); // ms_filter_log_statistics(); ms_factory_log_statistics(scm->factory); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); rtp_session_destroy(rtps); }
int main(int argc, char *argv[]){ MSFilter *f1,*f2; MSSndCard *card_capture; MSSndCard *card_playback; MSTicker *ticker; MSFactory *factory; char *capt_card=NULL,*play_card=NULL; int rate = 8000; int i; #ifdef __linux const char *alsadev=NULL; #endif ortp_init(); ortp_set_log_level_mask(ORTP_LOG_DOMAIN, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); factory = ms_factory_new_with_voip(); #ifndef _WIN32_WCE signal(SIGINT,stop); #endif #ifdef __linux alsadev=getenv("MS2_ALSADEV"); if (alsadev!=NULL){ ms_snd_card_manager_add_card( ms_factory_get_snd_card_manager(factory), ms_alsa_card_new_custom (alsadev,alsadev)); } #endif for(i=1;i<argc;++i){ if (strcmp(argv[i],"--help")==0){ print_usage(); }else if (strcmp(argv[i],"--card")==0){ i++; capt_card=play_card=argv[i]; }else if (strcmp(argv[i],"--capt-card")==0){ i++; capt_card=argv[i]; }else if (strcmp(argv[i],"--play-card")==0){ i++; play_card=argv[i]; } } if (capt_card) card_capture = ms_snd_card_manager_get_card(ms_factory_get_snd_card_manager(factory),capt_card); else card_capture = ms_snd_card_manager_get_default_capture_card(ms_factory_get_snd_card_manager(factory)); if (play_card) card_playback = ms_snd_card_manager_get_card(ms_factory_get_snd_card_manager(factory),play_card); else card_playback = ms_snd_card_manager_get_default_playback_card(ms_factory_get_snd_card_manager(factory)); if (card_playback==NULL || card_capture==NULL){ ms_error("No card."); return -1; } f1=ms_snd_card_create_reader(card_capture); f2=ms_snd_card_create_writer(card_playback); ms_filter_call_method (f1, MS_FILTER_SET_SAMPLE_RATE, &rate); ms_filter_call_method (f2, MS_FILTER_SET_SAMPLE_RATE, &rate); ticker=ms_ticker_new(); ms_filter_link(f1,0,f2,0); ms_ticker_attach(ticker,f1); #ifndef _WIN32_WCE while(run) ms_sleep(1); #else ms_sleep(5); #endif ms_ticker_detach(ticker,f1); ms_ticker_destroy(ticker); ms_filter_unlink(f1,0,f2,0); ms_filter_destroy(f1); ms_filter_destroy(f2); ms_factory_destroy(factory); return 0; }
static void dtmfgen_enc_dec_tonedet_filerec_fileplay(char *mime, int sample_rate, int nchannels) { MSConnectionHelper h; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_ENCODER | FILTER_MASK_DECODER | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK | FILTER_MASK_SOUNDREAD | FILTER_MASK_FILEREC | FILTER_MASK_FILEPLAY | FILTER_MASK_SOUNDWRITE; bool_t send_silence = TRUE; int capture_sample_rate = 8000; int playback_sample_rate = 8000; int capture_nchannels = 1; int playback_nchannels = 1; char *writable_filename = bc_tester_file(SOUNDREAD_FILE_NAME); MSSndCardManager *scm = ms_factory_get_snd_card_manager(factory); ms_factory_reset_statistics(scm->factory); //ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_codec_mime = mime; ms_tester_create_filters(filter_mask, scm->factory); // Write audio capture to a file ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_SAMPLE_RATE, &capture_sample_rate); ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_NCHANNELS, &capture_nchannels); ms_filter_call_method(ms_tester_filerec, MS_FILTER_SET_SAMPLE_RATE, &capture_sample_rate); ms_filter_call_method(ms_tester_filerec, MS_FILTER_SET_NCHANNELS, &capture_nchannels); ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE); ms_filter_call_method(ms_tester_filerec, MS_FILE_REC_OPEN, writable_filename); ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_START); ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_soundread, -1, 0); ms_connection_helper_link(&h, ms_tester_filerec, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_soundread); /* set sample rate and channel number to all filters (might need to check the return value to insert a resampler if needed?) */ ms_filter_call_method(ms_tester_voidsource, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_voidsource, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_voidsource, MS_VOID_SOURCE_SEND_SILENCE, &send_silence); ms_filter_call_method(ms_tester_dtmfgen, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_dtmfgen, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_encoder, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_encoder, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_decoder, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_decoder, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_tonedet, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_tonedet, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_call_method(ms_tester_voidsink, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_voidsink, MS_FILTER_SET_NCHANNELS, &nchannels); ms_filter_add_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL,TRUE); ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_voidsource, -1, 0); ms_connection_helper_link(&h, ms_tester_dtmfgen, 0, 0); ms_connection_helper_link(&h, ms_tester_encoder, 0, 0); ms_connection_helper_link(&h, ms_tester_decoder, 0, 0); ms_connection_helper_link(&h, ms_tester_tonedet, 0, 0); ms_connection_helper_link(&h, ms_tester_voidsink, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource); ms_tester_tone_generation_and_detection_loop(); ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE); ms_ticker_detach(ms_tester_ticker, ms_tester_soundread); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_soundread, -1, 0); ms_connection_helper_unlink(&h, ms_tester_filerec, 0, -1); // Read the previous file and play it ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_SAMPLE_RATE, &playback_sample_rate); ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_NCHANNELS, &playback_nchannels); if ((capture_sample_rate != playback_sample_rate) || (capture_nchannels != playback_nchannels)) { ms_tester_create_filter(&ms_tester_resampler, MS_RESAMPLE_ID, scm->factory); } ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE); ms_filter_call_method(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, writable_filename); ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_START); ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_fileplay, -1, 0); ms_ticker_detach(ms_tester_ticker, ms_tester_voidsource); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_voidsource, -1, 0); ms_connection_helper_unlink(&h, ms_tester_dtmfgen, 0, 0); ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_tonedet, 0, 0); ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1); // ms_filter_log_statistics(); ms_factory_log_statistics(scm->factory); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }