AudioStream *audio_stream_new(int loc_rtp_port, int loc_rtcp_port, bool_t ipv6){ AudioStream *stream=(AudioStream *)ms_new0(AudioStream,1); MSFilterDesc *ec_desc=ms_filter_lookup_by_name("MSOslec"); ms_filter_enable_statistics(TRUE); ms_filter_reset_statistics(); stream->ms.type = AudioStreamType; stream->ms.session=create_duplex_rtpsession(loc_rtp_port,loc_rtcp_port,ipv6); /*some filters are created right now to allow configuration by the application before start() */ stream->ms.rtpsend=ms_filter_new(MS_RTP_SEND_ID); stream->ms.ice_check_list=NULL; stream->ms.qi=ms_quality_indicator_new(stream->ms.session); if (ec_desc!=NULL) stream->ec=ms_filter_new_from_desc(ec_desc); else #if defined(BUILD_WEBRTC_AECM) stream->ec=ms_filter_new(MS_WEBRTC_AEC_ID); #else stream->ec=ms_filter_new(MS_SPEEX_EC_ID); #endif stream->ms.evq=ortp_ev_queue_new(); rtp_session_register_event_queue(stream->ms.session,stream->ms.evq); stream->play_dtmfs=TRUE; stream->use_gc=FALSE; stream->use_agc=FALSE; stream->use_ng=FALSE; stream->features=AUDIO_STREAM_FEATURE_ALL; return stream; }
static void dtmfgen_tonedet(void) { MSConnectionHelper h; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); ms_filter_set_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL); 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_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_tonedet, 0, 0); ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1); ms_filter_log_statistics(); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
TextStream *text_stream_new_with_sessions(const MSMediaStreamSessions *sessions) { TextStream *stream = (TextStream *)ms_new0(TextStream, 1); stream->pt_red = 0; stream->pt_t140 = 0; stream->ms.type = MSText; stream->ms.sessions = *sessions; media_stream_init(&stream->ms, ms_factory_get_fallback()); ms_filter_enable_statistics(TRUE); ms_filter_reset_statistics(); if (sessions->zrtp_context != NULL) { ms_zrtp_set_stream_sessions(sessions->zrtp_context, &(stream->ms.sessions)); } if (sessions->dtls_context != NULL) { ms_dtls_srtp_set_stream_sessions(sessions->dtls_context, &(stream->ms.sessions)); } rtp_session_resync(stream->ms.sessions.rtp_session); /*some filters are created right now to allow configuration by the application before start() */ stream->ms.rtpsend = ms_filter_new(MS_RTP_SEND_ID); stream->ms.ice_check_list = NULL; stream->ms.qi = ms_quality_indicator_new(stream->ms.sessions.rtp_session); ms_quality_indicator_set_label(stream->ms.qi, "text"); stream->ms.process_rtcp = text_stream_process_rtcp; return stream; }
static void dtmfgen_tonedet(void) { MSConnectionHelper h; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK; bool_t send_silence = TRUE; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); ms_filter_add_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL,TRUE); 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_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(); /*try unrecognized DTMF*/ BC_ASSERT_NOT_EQUAL(ms_filter_call_method(ms_tester_dtmfgen, MS_DTMF_GEN_PLAY, "F"),0,int,"%d"); 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_tonedet, 0, 0); ms_connection_helper_unlink(&h, ms_tester_voidsink, 0, -1); ms_filter_log_statistics(); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
static void fileplay_soundwrite(const char *filename) { MSConnectionHelper h; bool_t need_resampler = FALSE; unsigned int filter_mask = FILTER_MASK_FILEPLAY | FILTER_MASK_SOUNDWRITE; int sample_rate = 8000; int nchannels = 1; int done = FALSE; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); ms_filter_set_notify_callback(ms_tester_fileplay, fileplay_eof, &done); ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE); ms_filter_call_method(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, (void *)filename); ms_filter_call_method(ms_tester_fileplay, MS_FILTER_GET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_fileplay, MS_FILTER_GET_NCHANNELS, &nchannels); if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_BITRATE, &sample_rate) != 0) { int soundwrite_sample_rate = 48000; ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_BITRATE, &soundwrite_sample_rate); if (sample_rate != soundwrite_sample_rate) need_resampler = TRUE; } if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) { int soundwrite_nchannels = 1; ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_NCHANNELS, &soundwrite_nchannels); if (nchannels != soundwrite_nchannels) need_resampler = TRUE; } if (need_resampler == TRUE) { ms_tester_create_filters(FILTER_MASK_RESAMPLER); configure_resampler(ms_tester_resampler, ms_tester_fileplay, ms_tester_soundwrite); } 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); if (need_resampler == TRUE) { ms_connection_helper_link(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_fileplay); while (done != TRUE) { ms_usleep(10000); } ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE); ms_ticker_detach(ms_tester_ticker, ms_tester_fileplay); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_fileplay, -1, 0); if (need_resampler == TRUE) { ms_connection_helper_unlink(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1); if (need_resampler == TRUE) { ms_tester_destroy_filters(FILTER_MASK_RESAMPLER); } ms_filter_log_statistics(); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
static void dtmfgen_soundwrite(void) { MSConnectionHelper h; bool_t need_resampler = FALSE; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_SOUNDWRITE; int sample_rate = 8000; int nchannels = 1; bool_t send_silence = TRUE; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); 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); if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_SAMPLE_RATE, &sample_rate) != 0) { need_resampler = TRUE; } if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) { need_resampler = TRUE; } if (need_resampler == TRUE) { ms_tester_create_filters(FILTER_MASK_RESAMPLER); configure_resampler(ms_tester_resampler, ms_tester_dtmfgen, ms_tester_soundwrite); } 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); if (need_resampler == TRUE) { ms_connection_helper_link(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource); ms_tester_tone_generation_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); if (need_resampler == TRUE) { ms_connection_helper_unlink(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1); if (need_resampler == TRUE) { ms_tester_destroy_filters(FILTER_MASK_RESAMPLER); } ms_filter_log_statistics(); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
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; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_codec_mime = mime; ms_tester_create_filters(filter_mask); /* 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_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
static void dtmfgen_filerec_fileplay_tonedet(void) { MSConnectionHelper h; unsigned int filter_mask = FILTER_MASK_VOIDSOURCE | FILTER_MASK_DTMFGEN | FILTER_MASK_FILEREC | FILTER_MASK_FILEPLAY | FILTER_MASK_TONEDET | FILTER_MASK_VOIDSINK; bool_t send_silence = TRUE; char* recorded_file = bc_tester_file(DTMFGEN_FILE_NAME); ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); ms_filter_add_notify_callback(ms_tester_tonedet, (MSFilterNotifyFunc)tone_detected_cb, NULL,TRUE); // Generate tones and save them to a file ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE); ms_filter_call_method(ms_tester_filerec, MS_FILE_REC_OPEN, recorded_file); ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_START); 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_filerec, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_voidsource); ms_tester_tone_generation_loop(); ms_filter_call_method_noarg(ms_tester_filerec, MS_FILE_REC_CLOSE); 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_filerec, 0, -1); // Read the previous file and detect the tones ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE); ms_filter_call_method(ms_tester_fileplay, MS_FILE_PLAYER_OPEN, recorded_file); 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_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_fileplay); ms_tester_tone_detection_loop(); ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE); ms_ticker_detach(ms_tester_ticker, ms_tester_fileplay); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_fileplay, -1, 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_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); unlink(recorded_file); free(recorded_file); }
static void soundread_soundwrite(void) { MSConnectionHelper h; bool_t need_resampler = FALSE; unsigned int filter_mask = FILTER_MASK_SOUNDREAD | FILTER_MASK_SOUNDWRITE; int sample_rate = 8000; int nchannels = 1; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_SAMPLE_RATE, &sample_rate); ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_NCHANNELS, &nchannels); if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_BITRATE, &sample_rate) != 0) { int soundwrite_sample_rate = 48000; ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_BITRATE, &soundwrite_sample_rate); if (sample_rate != soundwrite_sample_rate) need_resampler = TRUE; } if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) { int soundwrite_nchannels = 1; ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_NCHANNELS, &soundwrite_nchannels); if (nchannels != soundwrite_nchannels) need_resampler = TRUE; } if (need_resampler == TRUE) { ms_tester_create_filters(FILTER_MASK_RESAMPLER); configure_resampler(ms_tester_resampler, ms_tester_soundread, ms_tester_soundwrite); } ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_soundread, -1, 0); if (need_resampler == TRUE) { ms_connection_helper_link(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_soundread); ms_sleep(3); ms_ticker_detach(ms_tester_ticker, ms_tester_soundread); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_soundread, -1, 0); if (need_resampler == TRUE) { ms_connection_helper_unlink(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1); if (need_resampler == TRUE) { ms_tester_destroy_filters(FILTER_MASK_RESAMPLER); } ms_filter_log_statistics(); 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; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_codec_mime = "pcmu"; ms_tester_create_filters(filter_mask); 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); 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_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); rtp_session_destroy(rtps); }
static void soundread_speexenc_speexdec_soundwrite(void) { MSConnectionHelper h; MSFilter *read_resampler = NULL, *write_resampler = NULL; bool_t need_read_resampler = FALSE, need_write_resampler = FALSE; unsigned int filter_mask = FILTER_MASK_SOUNDREAD | FILTER_MASK_ENCODER | FILTER_MASK_DECODER | FILTER_MASK_SOUNDWRITE; int sample_rate = 8000; int nchannels = 1; ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_codec_mime = "speex"; ms_tester_create_filters(filter_mask); ms_filter_call_method(ms_tester_encoder, MS_FILTER_GET_BITRATE, &sample_rate); ms_filter_call_method(ms_tester_decoder, MS_FILTER_SET_BITRATE, &sample_rate); if (ms_filter_call_method(ms_tester_soundread, MS_FILTER_SET_BITRATE, &sample_rate) != 0) { int soundread_sample_rate = 48000; ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_BITRATE, &soundread_sample_rate); if (sample_rate != soundread_sample_rate) need_read_resampler = TRUE; } if (ms_filter_call_method(ms_tester_soundread, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) { int soundread_nchannels = 1; ms_filter_call_method(ms_tester_soundread, MS_FILTER_GET_NCHANNELS, &soundread_nchannels); if (nchannels != soundread_nchannels) need_read_resampler = TRUE; } if (need_read_resampler == TRUE) { ms_tester_create_filter(&read_resampler, MS_RESAMPLE_ID); configure_resampler(read_resampler, ms_tester_soundread, ms_tester_encoder); } if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_BITRATE, &sample_rate) != 0) { int soundwrite_sample_rate = 48000; ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_BITRATE, &soundwrite_sample_rate); if (sample_rate != soundwrite_sample_rate) need_write_resampler = TRUE; } if (ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_SET_NCHANNELS, &nchannels) != 0) { int soundwrite_nchannels = 1; ms_filter_call_method(ms_tester_soundwrite, MS_FILTER_GET_NCHANNELS, &soundwrite_nchannels); if (nchannels != soundwrite_nchannels) need_write_resampler = TRUE; } if (need_write_resampler == TRUE) { ms_tester_create_filter(&write_resampler, MS_RESAMPLE_ID); configure_resampler(write_resampler, ms_tester_decoder, ms_tester_soundwrite); } ms_connection_helper_start(&h); ms_connection_helper_link(&h, ms_tester_soundread, -1, 0); if (need_read_resampler == TRUE) { ms_connection_helper_link(&h, read_resampler, 0, 0); } ms_connection_helper_link(&h, ms_tester_encoder, 0, 0); ms_connection_helper_link(&h, ms_tester_decoder, 0, 0); if (need_write_resampler == TRUE) { ms_connection_helper_link(&h, write_resampler, 0, 0); } ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_soundread); ms_sleep(5); ms_ticker_detach(ms_tester_ticker, ms_tester_soundread); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_soundread, -1, 0); if (need_read_resampler == TRUE) { ms_connection_helper_unlink(&h, read_resampler, 0, 0); } ms_connection_helper_unlink(&h, ms_tester_encoder, 0, 0); ms_connection_helper_unlink(&h, ms_tester_decoder, 0, 0); if (need_write_resampler == TRUE) { ms_connection_helper_unlink(&h, write_resampler, 0, 0); } ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1); if (need_read_resampler == TRUE) { ms_tester_destroy_filter(&read_resampler); } if (need_write_resampler == TRUE) { ms_tester_destroy_filter(&write_resampler); } ms_filter_log_statistics(); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); }
static void soundread_filerec_fileplay_soundwrite(void) { MSConnectionHelper h; unsigned int filter_mask = FILTER_MASK_SOUNDREAD | FILTER_MASK_FILEREC | FILTER_MASK_FILEPLAY | FILTER_MASK_SOUNDWRITE; 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); ms_filter_reset_statistics(); ms_tester_create_ticker(); ms_tester_create_filters(filter_mask); // 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); ms_sleep(4); 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); } 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); if (ms_tester_resampler != NULL) { ms_connection_helper_link(&h, ms_tester_resampler, 0, 0); ms_filter_call_method(ms_tester_resampler, MS_FILTER_SET_SAMPLE_RATE, &capture_sample_rate); ms_filter_call_method(ms_tester_resampler, MS_FILTER_SET_OUTPUT_SAMPLE_RATE, &playback_sample_rate); ms_filter_call_method(ms_tester_resampler, MS_FILTER_SET_NCHANNELS, &capture_nchannels); ms_filter_call_method(ms_tester_resampler, MS_FILTER_SET_OUTPUT_NCHANNELS, &capture_nchannels); } ms_connection_helper_link(&h, ms_tester_soundwrite, 0, -1); ms_ticker_attach(ms_tester_ticker, ms_tester_fileplay); ms_sleep(4); ms_filter_call_method_noarg(ms_tester_fileplay, MS_FILE_PLAYER_CLOSE); ms_ticker_detach(ms_tester_ticker, ms_tester_fileplay); ms_connection_helper_start(&h); ms_connection_helper_unlink(&h, ms_tester_fileplay, -1, 0); if (ms_tester_resampler != NULL) { ms_connection_helper_unlink(&h, ms_tester_resampler, 0, 0); } ms_connection_helper_unlink(&h, ms_tester_soundwrite, 0, -1); ms_filter_log_statistics(); ms_tester_destroy_filters(filter_mask); ms_tester_destroy_ticker(); unlink(writable_filename); free(writable_filename); }
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); } }