static void ecc_init_filters(EcCalibrator *ecc){ unsigned int rate; ecc->ticker=ms_ticker_new(); ecc->sndread=ms_snd_card_create_reader(ecc->play_card); ms_filter_call_method(ecc->sndread,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->det=ms_filter_new(MS_TONE_DETECTOR_ID); ms_filter_call_method(ecc->det,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->rec=ms_filter_new(MS_FILE_REC_ID); ms_filter_link(ecc->sndread,0,ecc->det,0); ms_filter_link(ecc->det,0,ecc->rec,0); ecc->play=ms_filter_new(MS_FILE_PLAYER_ID); ecc->gen=ms_filter_new(MS_DTMF_GEN_ID); ms_filter_call_method(ecc->gen,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->resampler=ms_filter_new(MS_RESAMPLE_ID); ecc->sndwrite=ms_snd_card_create_writer(ecc->capt_card); ms_filter_link(ecc->play,0,ecc->gen,0); ms_filter_link(ecc->gen,0,ecc->resampler,0); ms_filter_link(ecc->resampler,0,ecc->sndwrite,0); ms_filter_call_method(ecc->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->resampler,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&rate); ms_ticker_attach(ecc->ticker,ecc->play); ms_ticker_attach(ecc->ticker,ecc->sndread); }
int local_sound_card_start(ConfSoundCard *sndcard, MSSndCard *playcard, MSSndCard *captcard,int sample_rate) { if(!playcard || !captcard) return -1; sndcard->capture_card=ms_snd_card_create_reader(captcard); if(sndcard->capture_card!=NULL) ms_filter_call_method(sndcard->capture_card,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); sndcard->playback_card=ms_snd_card_create_writer(playcard); if(sndcard->playback_card!=NULL) ms_filter_call_method(sndcard->playback_card,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); sndcard->itc_source = ms_filter_new(MS_CONF_ITC_SOURCE_ID); sndcard->itc_sink = ms_filter_new(MS_CONF_ITC_SINK_ID); ms_filter_link(sndcard->capture_card,0,sndcard->itc_sink,0); ms_filter_link(sndcard->itc_source,0,sndcard->playback_card,0); sndcard->ticker = ms_ticker_new(); ms_ticker_set_name(sndcard->ticker,"Local Sound Card MSTicker"); ms_ticker_attach(sndcard->ticker,sndcard->capture_card); ms_ticker_attach(sndcard->ticker,sndcard->itc_source); return 0; }
int main(int argc, char *argv[]){ MSFilter *f1,*f2; MSSndCard *card; MSTicker *ticker; char *card_id=NULL; ms_init(); signal(SIGINT,stop); if (argc>1) card_id=argv[1]; if (card_id!=NULL) card=ms_snd_card_manager_get_card(ms_snd_card_manager_get(),card_id); else card=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get()); if (card==NULL){ ms_error("No card."); return -1; } f1=ms_snd_card_create_reader(card); f2=ms_snd_card_create_writer(card); ticker=ms_ticker_new(); ms_filter_link(f1,0,f2,0); ms_ticker_attach(ticker,f1); while(run) sleep(1); ms_ticker_detach(ticker,f1); ms_ticker_destroy(ticker); ms_filter_unlink(f1,0,f2,0); ms_filter_destroy(f1); ms_filter_destroy(f2); return 0; }
static void ecc_init_filters(EcCalibrator *ecc) { unsigned int rate; int channels = 1; int ecc_channels = 1; MSTickerParams params= {0}; params.name="Echo calibrator"; params.prio=MS_TICKER_PRIO_HIGH; ecc->ticker=ms_ticker_new_with_params(¶ms); ecc->sndread=ms_snd_card_create_reader(ecc->capt_card); ms_filter_call_method(ecc->sndread,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->sndread,MS_FILTER_GET_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->sndread,MS_FILTER_SET_NCHANNELS,&ecc_channels); ms_filter_call_method(ecc->sndread,MS_FILTER_GET_NCHANNELS,&channels); ecc->read_resampler=ms_filter_new(MS_RESAMPLE_ID); ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_NCHANNELS,&ecc_channels); ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&channels); ecc->det=ms_filter_new(MS_TONE_DETECTOR_ID); ms_filter_call_method(ecc->det,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->rec=ms_filter_new(MS_VOID_SINK_ID); ms_filter_link(ecc->sndread,0,ecc->read_resampler,0); ms_filter_link(ecc->read_resampler,0,ecc->det,0); ms_filter_link(ecc->det,0,ecc->rec,0); ecc->play=ms_filter_new(MS_VOID_SOURCE_ID); ecc->gen=ms_filter_new(MS_DTMF_GEN_ID); ms_filter_call_method(ecc->gen,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->write_resampler=ms_filter_new(MS_RESAMPLE_ID); ecc->sndwrite=ms_snd_card_create_writer(ecc->play_card); ms_filter_call_method(ecc->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->sndwrite,MS_FILTER_SET_NCHANNELS,&ecc_channels); ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_NCHANNELS,&channels); ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_NCHANNELS,&ecc_channels); ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&channels); ms_filter_link(ecc->play,0,ecc->gen,0); ms_filter_link(ecc->gen,0,ecc->write_resampler,0); ms_filter_link(ecc->write_resampler,0,ecc->sndwrite,0); ms_ticker_attach(ecc->ticker,ecc->sndread); ms_ticker_attach(ecc->ticker,ecc->play); if (ecc->audio_init_cb != NULL) { (*ecc->audio_init_cb)(ecc->cb_data); } }
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); } }
static void ecc_init_filters(EcCalibrator *ecc){ unsigned int rate; MSTickerParams params={0}; params.name="Echo calibrator"; params.prio=MS_TICKER_PRIO_HIGH; ecc->ticker=ms_ticker_new_with_params(¶ms); ecc->sndread=ms_snd_card_create_reader(ecc->play_card); ms_filter_call_method(ecc->sndread,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->sndread,MS_FILTER_GET_SAMPLE_RATE,&rate); ecc->read_resampler=ms_filter_new(MS_RESAMPLE_ID); ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&ecc->rate); ecc->det=ms_filter_new(MS_TONE_DETECTOR_ID); ms_filter_call_method(ecc->det,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->rec=ms_filter_new(MS_FILE_REC_ID); ms_filter_link(ecc->sndread,0,ecc->read_resampler,0); ms_filter_link(ecc->read_resampler,0,ecc->det,0); ms_filter_link(ecc->det,0,ecc->rec,0); ecc->play=ms_filter_new(MS_FILE_PLAYER_ID); ecc->gen=ms_filter_new(MS_DTMF_GEN_ID); ms_filter_call_method(ecc->gen,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ecc->write_resampler=ms_filter_new(MS_RESAMPLE_ID); ecc->sndwrite=ms_snd_card_create_writer(ecc->capt_card); ms_filter_call_method(ecc->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&rate); ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate); ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&rate); ms_filter_link(ecc->play,0,ecc->gen,0); ms_filter_link(ecc->gen,0,ecc->write_resampler,0); ms_filter_link(ecc->write_resampler,0,ecc->sndwrite,0); ms_ticker_attach(ecc->ticker,ecc->sndread); ms_ticker_attach(ecc->ticker,ecc->play); }
void ms_tester_create_filters(unsigned int filter_mask) { MSSndCardManager *manager; MSSndCard *playcard; MSSndCard *captcard; CREATE_FILTER(FILTER_MASK_FILEPLAY, ms_tester_fileplay, MS_FILE_PLAYER_ID); CREATE_FILTER(FILTER_MASK_FILEREC, ms_tester_filerec, MS_FILE_REC_ID); CREATE_FILTER(FILTER_MASK_DTMFGEN, ms_tester_dtmfgen, MS_DTMF_GEN_ID); CREATE_FILTER(FILTER_MASK_TONEDET, ms_tester_tonedet, MS_TONE_DETECTOR_ID); CREATE_FILTER(FILTER_MASK_VOIDSOURCE, ms_tester_voidsource, MS_VOID_SOURCE_ID); CREATE_FILTER(FILTER_MASK_VOIDSINK, ms_tester_voidsink, MS_VOID_SINK_ID); if (filter_mask & FILTER_MASK_ENCODER) { CU_ASSERT_PTR_NULL(ms_tester_encoder); ms_tester_encoder = ms_filter_create_encoder(ms_tester_codec_mime); CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_encoder); } if (filter_mask & FILTER_MASK_DECODER) { CU_ASSERT_PTR_NULL(ms_tester_decoder); ms_tester_decoder = ms_filter_create_decoder(ms_tester_codec_mime); CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_decoder); } CREATE_FILTER(FILTER_MASK_RTPRECV, ms_tester_rtprecv, MS_RTP_RECV_ID); CREATE_FILTER(FILTER_MASK_RTPSEND, ms_tester_rtpsend, MS_RTP_SEND_ID); CREATE_FILTER(FILTER_MASK_RESAMPLER, ms_tester_resampler, MS_RESAMPLE_ID); if (filter_mask & FILTER_MASK_SOUNDWRITE) { CU_ASSERT_PTR_NULL(ms_tester_soundwrite); manager = ms_snd_card_manager_get(); playcard = ms_snd_card_manager_get_default_playback_card(manager); CU_ASSERT_PTR_NOT_NULL_FATAL(playcard); ms_tester_soundwrite = ms_snd_card_create_writer(playcard); CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_soundwrite); } if (filter_mask & FILTER_MASK_SOUNDREAD) { CU_ASSERT_PTR_NULL(ms_tester_soundread); manager = ms_snd_card_manager_get(); captcard = ms_snd_card_manager_get_default_capture_card(manager); CU_ASSERT_PTR_NOT_NULL_FATAL(captcard); ms_tester_soundread = ms_snd_card_create_reader(captcard); CU_ASSERT_PTR_NOT_NULL_FATAL(ms_tester_soundread); } }
/* This function is used either on IOS to workaround the long time to initialize the Audio Unit or for ICE candidates gathering. */ void audio_stream_prepare_sound(AudioStream *stream, MSSndCard *playcard, MSSndCard *captcard){ audio_stream_unprepare_sound(stream); stream->dummy=ms_filter_new(MS_RTP_RECV_ID); rtp_session_set_payload_type(stream->ms.session,0); ms_filter_call_method(stream->dummy,MS_RTP_RECV_SET_SESSION,stream->ms.session); if (captcard && playcard){ #ifdef __ios stream->soundread=ms_snd_card_create_reader(captcard); stream->soundwrite=ms_snd_card_create_writer(playcard); ms_filter_link(stream->dummy,0,stream->soundwrite,0); #else stream->ms.voidsink=ms_filter_new(MS_VOID_SINK_ID); ms_filter_link(stream->dummy,0,stream->ms.voidsink,0); #endif } else { stream->ms.voidsink=ms_filter_new(MS_VOID_SINK_ID); ms_filter_link(stream->dummy,0,stream->ms.voidsink,0); } if (stream->ms.ticker == NULL) start_ticker(&stream->ms); ms_ticker_attach(stream->ms.ticker,stream->dummy); }
int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *rem_rtp_ip,int rem_rtp_port, const char *rem_rtcp_ip, int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile, MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec) { RtpSession *rtps=stream->ms.session; PayloadType *pt,*tel_ev; int tmp; MSConnectionHelper h; int sample_rate; MSRtpPayloadPickerContext picker_context; bool_t has_builtin_ec=FALSE; rtp_session_set_profile(rtps,profile); if (rem_rtp_port>0) rtp_session_set_remote_addr_full(rtps,rem_rtp_ip,rem_rtp_port,rem_rtcp_ip,rem_rtcp_port); if (rem_rtcp_port<=0){ rtp_session_enable_rtcp(rtps,FALSE); } rtp_session_set_payload_type(rtps,payload); rtp_session_set_jitter_compensation(rtps,jitt_comp); if (rem_rtp_port>0) ms_filter_call_method(stream->ms.rtpsend,MS_RTP_SEND_SET_SESSION,rtps); stream->ms.rtprecv=ms_filter_new(MS_RTP_RECV_ID); ms_filter_call_method(stream->ms.rtprecv,MS_RTP_RECV_SET_SESSION,rtps); stream->ms.session=rtps; if((stream->features & AUDIO_STREAM_FEATURE_DTMF) != 0) stream->dtmfgen=ms_filter_new(MS_DTMF_GEN_ID); else stream->dtmfgen=NULL; rtp_session_signal_connect(rtps,"telephone-event",(RtpCallback)on_dtmf_received,(unsigned long)stream); rtp_session_signal_connect(rtps,"payload_type_changed",(RtpCallback)mediastream_payload_type_changed,(unsigned long)&stream->ms); /* creates the local part */ if (captcard!=NULL){ if (stream->soundread==NULL) stream->soundread=ms_snd_card_create_reader(captcard); has_builtin_ec=!!(ms_snd_card_get_capabilities(captcard) & MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER); }else { stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID); stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID); if (infile!=NULL) audio_stream_play(stream,infile); } if (playcard!=NULL) { if (stream->soundwrite==NULL) stream->soundwrite=ms_snd_card_create_writer(playcard); }else { stream->soundwrite=ms_filter_new(MS_FILE_REC_ID); if (outfile!=NULL) audio_stream_record(stream,outfile); } /* creates the couple of encoder/decoder */ pt=rtp_profile_get_payload(profile,payload); if (pt==NULL){ ms_error("audiostream.c: undefined payload type."); return -1; } tel_ev=rtp_profile_get_payload_from_mime (profile,"telephone-event"); if ((stream->features & AUDIO_STREAM_FEATURE_DTMF_ECHO) != 0 && (tel_ev==NULL || ( (tel_ev->flags & PAYLOAD_TYPE_FLAG_CAN_RECV) && !(tel_ev->flags & PAYLOAD_TYPE_FLAG_CAN_SEND))) && ( strcasecmp(pt->mime_type,"pcmu")==0 || strcasecmp(pt->mime_type,"pcma")==0)){ /*if no telephone-event payload is usable and pcma or pcmu is used, we will generate inband dtmf*/ stream->dtmfgen_rtp=ms_filter_new (MS_DTMF_GEN_ID); } else { stream->dtmfgen_rtp=NULL; } if (ms_filter_call_method(stream->ms.rtpsend,MS_FILTER_GET_SAMPLE_RATE,&sample_rate)!=0){ ms_error("Sample rate is unknown for RTP side !"); return -1; } stream->ms.encoder=ms_filter_create_encoder(pt->mime_type); stream->ms.decoder=ms_filter_create_decoder(pt->mime_type); if ((stream->ms.encoder==NULL) || (stream->ms.decoder==NULL)){ /* big problem: we have not a registered codec for this payload...*/ ms_error("audio_stream_start_full: No decoder or encoder available for payload %s.",pt->mime_type); return -1; } if (ms_filter_has_method(stream->ms.decoder, MS_FILTER_SET_RTP_PAYLOAD_PICKER)) { ms_message(" decoder has FEC capabilities"); picker_context.filter_graph_manager=stream; picker_context.picker=&audio_stream_payload_picker; ms_filter_call_method(stream->ms.decoder,MS_FILTER_SET_RTP_PAYLOAD_PICKER, &picker_context); } if((stream->features & AUDIO_STREAM_FEATURE_VOL_SND) != 0) stream->volsend=ms_filter_new(MS_VOLUME_ID); else stream->volsend=NULL; if((stream->features & AUDIO_STREAM_FEATURE_VOL_RCV) != 0) stream->volrecv=ms_filter_new(MS_VOLUME_ID); else stream->volrecv=NULL; audio_stream_enable_echo_limiter(stream,stream->el_type); audio_stream_enable_noise_gate(stream,stream->use_ng); if (stream->use_agc){ int tmp=1; if (stream->volsend==NULL) stream->volsend=ms_filter_new(MS_VOLUME_ID); ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_AGC,&tmp); } if (stream->dtmfgen) { ms_filter_call_method(stream->dtmfgen,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); ms_filter_call_method(stream->dtmfgen,MS_FILTER_SET_NCHANNELS,&pt->channels); } if (stream->dtmfgen_rtp) { ms_filter_call_method(stream->dtmfgen_rtp,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); ms_filter_call_method(stream->dtmfgen_rtp,MS_FILTER_SET_NCHANNELS,&pt->channels); } /* give the sound filters some properties */ if (ms_filter_call_method(stream->soundread,MS_FILTER_SET_SAMPLE_RATE,&sample_rate) != 0) { /* need to add resampler*/ if (stream->read_resampler == NULL) stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID); } ms_filter_call_method(stream->soundread,MS_FILTER_SET_NCHANNELS,&pt->channels); if (ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_SAMPLE_RATE,&sample_rate) != 0) { /* need to add resampler*/ if (stream->write_resampler == NULL) stream->write_resampler=ms_filter_new(MS_RESAMPLE_ID); } ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_NCHANNELS,&pt->channels); // Override feature if ( ((stream->features & AUDIO_STREAM_FEATURE_EC) && !use_ec) || has_builtin_ec ) stream->features &=~AUDIO_STREAM_FEATURE_EC; /*configure the echo canceller if required */ if ((stream->features & AUDIO_STREAM_FEATURE_EC) == 0 && stream->ec != NULL) { ms_filter_destroy(stream->ec); stream->ec=NULL; } if (stream->ec){ if (!stream->is_ec_delay_set){ int delay_ms=ms_snd_card_get_minimal_latency(captcard); if (delay_ms!=0){ ms_message("Setting echo canceller delay with value provided by soundcard: %i ms",delay_ms); ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&delay_ms); } } ms_filter_call_method(stream->ec,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); } if (stream->features & AUDIO_STREAM_FEATURE_MIXED_RECORDING){ int val=0; int pin=1; stream->recorder=ms_filter_new(MS_FILE_REC_ID); stream->recorder_mixer=ms_filter_new(MS_AUDIO_MIXER_ID); stream->recv_tee=ms_filter_new(MS_TEE_ID); stream->send_tee=ms_filter_new(MS_TEE_ID); ms_filter_call_method(stream->recorder_mixer,MS_AUDIO_MIXER_ENABLE_CONFERENCE_MODE,&val); ms_filter_call_method(stream->recorder_mixer,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); ms_filter_call_method(stream->recorder_mixer,MS_FILTER_SET_NCHANNELS,&pt->channels); ms_filter_call_method(stream->recv_tee,MS_TEE_MUTE,&pin); ms_filter_call_method(stream->send_tee,MS_TEE_MUTE,&pin); ms_filter_call_method(stream->recorder,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); ms_filter_call_method(stream->recorder,MS_FILTER_SET_NCHANNELS,&pt->channels); } /* give the encoder/decoder some parameters*/ ms_filter_call_method(stream->ms.encoder,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); ms_message("Payload's bitrate is %i",pt->normal_bitrate); if (pt->normal_bitrate>0){ ms_message("Setting audio encoder network bitrate to %i",pt->normal_bitrate); ms_filter_call_method(stream->ms.encoder,MS_FILTER_SET_BITRATE,&pt->normal_bitrate); } ms_filter_call_method(stream->ms.encoder,MS_FILTER_SET_NCHANNELS,&pt->channels); ms_filter_call_method(stream->ms.decoder,MS_FILTER_SET_SAMPLE_RATE,&sample_rate); ms_filter_call_method(stream->ms.decoder,MS_FILTER_SET_NCHANNELS,&pt->channels); if (pt->send_fmtp!=NULL) { char value[16]={0}; int ptime; if (ms_filter_has_method(stream->ms.encoder,MS_AUDIO_ENCODER_SET_PTIME)){ if (fmtp_get_value(pt->send_fmtp,"ptime",value,sizeof(value)-1)){ ptime=atoi(value); ms_filter_call_method(stream->ms.encoder,MS_AUDIO_ENCODER_SET_PTIME,&ptime); } } ms_filter_call_method(stream->ms.encoder,MS_FILTER_ADD_FMTP, (void*)pt->send_fmtp); } if (pt->recv_fmtp!=NULL) ms_filter_call_method(stream->ms.decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp); /*create the equalizer*/ if ((stream->features & AUDIO_STREAM_FEATURE_EQUALIZER) != 0){ stream->equalizer=ms_filter_new(MS_EQUALIZER_ID); if(stream->equalizer) { tmp=stream->eq_active; ms_filter_call_method(stream->equalizer,MS_EQUALIZER_SET_ACTIVE,&tmp); } }else stream->equalizer=NULL; /*configure resampler if needed*/ ms_filter_call_method(stream->ms.rtpsend, MS_FILTER_SET_NCHANNELS, &pt->channels); ms_filter_call_method(stream->ms.rtprecv, MS_FILTER_SET_NCHANNELS, &pt->channels); if (stream->read_resampler){ audio_stream_configure_resampler(stream->read_resampler,stream->soundread,stream->ms.rtpsend); } if (stream->write_resampler){ audio_stream_configure_resampler(stream->write_resampler,stream->ms.rtprecv,stream->soundwrite); } if (stream->ms.use_rc){ stream->ms.rc=ms_audio_bitrate_controller_new(stream->ms.session,stream->ms.encoder,0); } /* Create PLC */ if ((stream->features & AUDIO_STREAM_FEATURE_PLC) != 0) { int decoder_have_plc = 0; if (ms_filter_has_method(stream->ms.decoder, MS_AUDIO_DECODER_HAVE_PLC)) { if (ms_filter_call_method(stream->ms.decoder, MS_AUDIO_DECODER_HAVE_PLC, &decoder_have_plc) != 0) { ms_warning("MS_AUDIO_DECODER_HAVE_PLC function error: enable default plc"); } } else { ms_warning("MS_DECODER_HAVE_PLC function not implemented by the decoder: enable default plc"); } if (decoder_have_plc == 0) { stream->plc = ms_filter_new(MS_GENERIC_PLC_ID); } if (stream->plc) { ms_filter_call_method(stream->plc, MS_FILTER_SET_NCHANNELS, &pt->channels); ms_filter_call_method(stream->plc, MS_FILTER_SET_SAMPLE_RATE, &sample_rate); } } else { stream->plc = NULL; } /* create ticker */ if (stream->ms.ticker==NULL) start_ticker(&stream->ms); else{ /*we were using the dummy preload graph, destroy it*/ if (stream->dummy) stop_preload_graph(stream); } /* and then connect all */ /* tip: draw yourself the picture if you don't understand */ /*sending graph*/ ms_connection_helper_start(&h); ms_connection_helper_link(&h,stream->soundread,-1,0); if (stream->read_resampler) ms_connection_helper_link(&h,stream->read_resampler,0,0); if (stream->ec) ms_connection_helper_link(&h,stream->ec,1,1); if (stream->volsend) ms_connection_helper_link(&h,stream->volsend,0,0); if (stream->dtmfgen_rtp) ms_connection_helper_link(&h,stream->dtmfgen_rtp,0,0); if (stream->send_tee) ms_connection_helper_link(&h,stream->send_tee,0,0); ms_connection_helper_link(&h,stream->ms.encoder,0,0); ms_connection_helper_link(&h,stream->ms.rtpsend,0,-1); /*receiving graph*/ ms_connection_helper_start(&h); ms_connection_helper_link(&h,stream->ms.rtprecv,-1,0); ms_connection_helper_link(&h,stream->ms.decoder,0,0); if (stream->plc) ms_connection_helper_link(&h,stream->plc,0,0); if (stream->dtmfgen) ms_connection_helper_link(&h,stream->dtmfgen,0,0); if (stream->volrecv) ms_connection_helper_link(&h,stream->volrecv,0,0); if (stream->recv_tee) ms_connection_helper_link(&h,stream->recv_tee,0,0); if (stream->equalizer) ms_connection_helper_link(&h,stream->equalizer,0,0); if (stream->ec) ms_connection_helper_link(&h,stream->ec,0,0); if (stream->write_resampler) ms_connection_helper_link(&h,stream->write_resampler,0,0); ms_connection_helper_link(&h,stream->soundwrite,0,-1); /*call recording part, attached to both outgoing and incoming graphs*/ if (stream->recorder){ ms_filter_link(stream->send_tee,1,stream->recorder_mixer,0); ms_filter_link(stream->recv_tee,1,stream->recorder_mixer,1); ms_filter_link(stream->recorder_mixer,0,stream->recorder,0); } /*to make sure all preprocess are done before befre processing audio*/ ms_ticker_attach_multiple(stream->ms.ticker ,stream->soundread ,stream->ms.rtprecv ,NULL); stream->ms.start_time=ms_time(NULL); stream->ms.is_beginning=TRUE; return 0; }
int video_mail_record_start(VideoMailRecord *vp, MSSndCard *sndcard,MSWebCam *webcam,unsigned long video_window_id,const char *filename){ MSConnectionHelper h; MSPixFmt format=MS_YUV420P; { strcpy(vp->filename, filename); vp->os = video_recoder_new(); video_recoder_init(vp->os); video_recoder_set_vsize(vp->os,vp->vsize); video_recoder_set_rate(vp->os,vp->rate); video_recoder_set_audio_bit_rate(vp->os, get_bit_rate_by_samples_rate(vp->rate)); video_recoder_set_video_bit_rate(vp->os, vp->bit_rate - get_bit_rate_by_samples_rate(vp->rate)); video_recoder_set_nbchannels(vp->os,vp->nchannels); if(video_recoder_open_file(vp->os,vp->filename)<0){ video_recoder_destory(vp->os); vp->os=NULL; return -1; } video_mail_record_set_audio_sink(vp,video_recoder_create_audio_filter(vp->os)); video_mail_record_set_video_sink(vp,video_recoder_create_video_filter(vp->os)); video_recoder_start(vp->os); } { if (sndcard!=NULL) vp->snd_read=ms_snd_card_create_reader(sndcard); if(vp->snd_read){ ms_filter_call_method(vp->snd_read,MS_FILTER_SET_NCHANNELS,&vp->nchannels); ms_filter_call_method(vp->snd_read,MS_FILTER_SET_SAMPLE_RATE,&vp->rate); } } { if (webcam==NULL){ webcam=ms_web_cam_manager_get_default_cam ( ms_web_cam_manager_get()); } vp->video_source = ms_web_cam_create_reader(webcam); vp->video_tee = ms_filter_new(MS_TEE_ID); ms_message("Setting sent vsize=%ix%i, fps=%f",vp->vsize.width,vp->vsize.height,vp->fps); /* configure the filters */ if (ms_filter_get_id(vp->video_source)!=MS_STATIC_IMAGE_ID) { ms_filter_call_method(vp->video_source,MS_FILTER_SET_FPS,&vp->fps); } ms_filter_call_method(vp->video_source,MS_FILTER_SET_VIDEO_SIZE,&vp->vsize); ms_filter_call_method(vp->video_source,MS_FILTER_GET_PIX_FMT,&format); if (format==MS_MJPEG){ vp->pixconv=ms_filter_new(MS_MJPEG_DEC_ID); }else{ vp->pixconv = ms_filter_new(MS_PIX_CONV_ID); /*set it to the pixconv */ ms_filter_call_method(vp->pixconv,MS_FILTER_SET_PIX_FMT,&format); ms_filter_call_method(vp->video_source,MS_FILTER_GET_VIDEO_SIZE,&vp->vsize); ms_filter_call_method(vp->pixconv,MS_FILTER_SET_VIDEO_SIZE,&vp->vsize); } vp->sizeconv=ms_filter_new(MS_SIZE_CONV_ID); ms_filter_call_method(vp->sizeconv,MS_FILTER_SET_VIDEO_SIZE,&vp->vsize); choose_display_name(vp); vp->video_output=ms_filter_new_from_name (vp->display_name); if (video_window_id!=0) ms_filter_call_method(vp->video_output, MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID,&video_window_id); } if(vp->snd_read!=NULL && vp->snd_sink!=NULL){ ms_filter_link(vp->snd_read,0,vp->snd_sink,0); } if(vp->video_source!=NULL && vp->video_output!=NULL) { ms_connection_helper_start(&h); ms_connection_helper_link(&h,vp->video_source,-1,0); ms_connection_helper_link(&h,vp->pixconv,0,0); ms_connection_helper_link(&h,vp->sizeconv,0,0); ms_connection_helper_link(&h,vp->video_tee,0,0); ms_filter_link(vp->video_tee,1,vp->video_output,0); ms_connection_helper_link(&h,vp->video_sink,0,-1); } vp->ticker = ms_ticker_new(); ms_ticker_set_name(vp->ticker,"VideoMailRecord"); if(vp->snd_read!=NULL && vp->snd_sink!=NULL) ms_ticker_attach(vp->ticker,vp->snd_read); if(vp->video_source!=NULL && vp->video_output!=NULL) ms_ticker_attach(vp->ticker,vp->video_source); return 0; }
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; }
int main(int argc, char* argv[]){ ms_init(); ortp_init(); RtpSession* temp_session; temp_session=rtp_session_new(1); MSSndCard *sndcard; sndcard=ms_snd_card_manager_get_default_card(ms_snd_card_manager_get()); /*define sample audio capture filter */ MSFilter *soundread=ms_snd_card_create_reader(sndcard); MSFilter *soundwrite=ms_snd_card_create_writer(sndcard); MSFilter *encoder=ms_filter_create_encoder("PCMU"); MSFilter *decoder=ms_filter_create_decoder("PCMU"); MSFilter *rtpsend=ms_filter_new(MS_RTP_SEND_ID); MSFilter *rtprecv=ms_filter_new(MS_RTP_RECV_ID); RtpSession *rtp_session = temp_session ; ms_filter_call_method(rtpsend,MS_RTP_SEND_SET_SESSION,rtp_session); ms_filter_call_method(rtprecv,MS_RTP_RECV_SET_SESSION,rtp_session); /*define capture rate and initialize filters*/ MSFilter *dtmfgen=ms_filter_new(MS_DTMF_GEN_ID); int sr = 8000; int chan=1; ms_filter_call_method(soundread,MS_FILTER_SET_SAMPLE_RATE,&sr); ms_filter_call_method(soundwrite,MS_FILTER_SET_SAMPLE_RATE,&sr); ms_filter_call_method(encoder,MS_FILTER_SET_SAMPLE_RATE,&sr); ms_filter_call_method(decoder,MS_FILTER_SET_SAMPLE_RATE,&sr); ms_filter_call_method(soundwrite,MS_FILTER_SET_NCHANNELS, &chan); /*link the filters and run the graph*/ ms_filter_link(soundread,0, encoder,0); ms_filter_link( encoder,0, rtpsend,0); ms_filter_link( rtprecv,0, decoder,0); ms_filter_link( decoder,0, dtmfgen,0); ms_filter_link( dtmfgen,0, soundwrite,0); /*create tiker*/ MSTicker *ticker=ms_ticker_new(); ms_ticker_attach(ticker,soundread); ms_ticker_attach(ticker,rtprecv); ms_ticker_detach(ticker,soundread); ms_ticker_detach(ticker,rtprecv); /*unlink filters and destroy the MS objects*/ ms_filter_unlink( soundread,0, encoder,0); ms_filter_unlink( encoder,0, rtpsend,0); ms_filter_unlink( rtprecv,0, decoder,0); ms_filter_unlink( decoder,0, dtmfgen,0); ms_filter_unlink( dtmfgen,0, soundwrite,0); if (rtp_session!=NULL) rtp_session_destroy(rtp_session); if (rtpsend!=NULL) ms_filter_destroy(rtpsend); if (rtprecv!=NULL) ms_filter_destroy(rtprecv); if (soundread!=NULL) ms_filter_destroy(soundread); if (soundwrite!=NULL) ms_filter_destroy(soundwrite); if (encoder!=NULL) ms_filter_destroy(encoder); if (decoder!=NULL) ms_filter_destroy(decoder); if (dtmfgen!=NULL) ms_filter_destroy(dtmfgen); if (ticker!=NULL) ms_ticker_destroy(ticker); }
int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *remip,int remport, int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile, MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec) { RtpSession *rtps=stream->session; PayloadType *pt; int tmp; MSConnectionHelper h; rtp_session_set_profile(rtps,profile); if (remport>0) rtp_session_set_remote_addr_full(rtps,remip,remport,rem_rtcp_port); rtp_session_set_payload_type(rtps,payload); rtp_session_set_jitter_compensation(rtps,jitt_comp); if (remport>0) ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_SET_SESSION,rtps); stream->rtprecv=ms_filter_new(MS_RTP_RECV_ID); ms_filter_call_method(stream->rtprecv,MS_RTP_RECV_SET_SESSION,rtps); stream->session=rtps; stream->dtmfgen=ms_filter_new(MS_DTMF_GEN_ID); rtp_session_signal_connect(rtps,"telephone-event",(RtpCallback)on_dtmf_received,(unsigned long)stream); rtp_session_signal_connect(rtps,"payload_type_changed",(RtpCallback)payload_type_changed,(unsigned long)stream); /* creates the local part */ if (captcard!=NULL) stream->soundread=ms_snd_card_create_reader(captcard); else { stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID); stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID); if (infile!=NULL) audio_stream_play(stream,infile); } if (playcard!=NULL) stream->soundwrite=ms_snd_card_create_writer(playcard); else { stream->soundwrite=ms_filter_new(MS_FILE_REC_ID); if (outfile!=NULL) audio_stream_record(stream,outfile); } /* creates the couple of encoder/decoder */ pt=rtp_profile_get_payload(profile,payload); if (pt==NULL){ ms_error("audiostream.c: undefined payload type."); return -1; } stream->encoder=ms_filter_create_encoder(pt->mime_type); stream->decoder=ms_filter_create_decoder(pt->mime_type); if ((stream->encoder==NULL) || (stream->decoder==NULL)){ /* big problem: we have not a registered codec for this payload...*/ ms_error("mediastream.c: No decoder available for payload %i.",payload); return -1; } if (stream->el_type!=ELInactive || stream->use_gc || stream->use_ng){ stream->volsend=ms_filter_new(MS_VOLUME_ID); stream->volrecv=ms_filter_new(MS_VOLUME_ID); if (stream->el_type!=ELInactive){ if (stream->el_type==ELControlFull) { /* also reduce speaker gain when no signal - same parameters as std. noise gate */ int tmp=1; ms_filter_call_method(stream->volrecv,MS_VOLUME_ENABLE_NOISE_GATE,&tmp); } ms_filter_call_method(stream->volsend,MS_VOLUME_SET_PEER,stream->volrecv); } if (stream->use_ng){ int tmp=1; ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_NOISE_GATE,&tmp); } } if (stream->use_agc || stream->use_nr){ int tmp=1; if (stream->volsend==NULL) stream->volsend=ms_filter_new(MS_VOLUME_ID); if(stream->use_agc) ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_AGC,&tmp); /*Noise Reduction*/ if(stream->use_nr) ms_filter_call_method(stream->volsend,MS_VOLUME_ENABLE_NR,&tmp); } /* give the sound filters some properties */ if (ms_filter_call_method(stream->soundread,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate) != 0) { /* need to add resampler*/ if (stream->read_resampler == NULL) stream->read_resampler=ms_filter_new(MS_RESAMPLE_ID); } if (ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate) != 0) { /* need to add resampler*/ if (stream->write_resampler == NULL) stream->write_resampler=ms_filter_new(MS_RESAMPLE_ID); } tmp=1; ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_NCHANNELS, &tmp); if(stream->record_enabled) { stream->filewriter = ms_filter_new(MS_FILE_REC_ID); stream->recordmixer= ms_filter_new(MS_AUDIO_MIXER_ID); stream->mic_tee = ms_filter_new(MS_TEE_ID); stream->spk_tee = ms_filter_new(MS_TEE_ID); ms_filter_call_method(stream->filewriter,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); ms_filter_call_method(stream->recordmixer,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); tmp=1; ms_filter_call_method(stream->recordmixer,MS_FILTER_SET_NCHANNELS,&tmp); } /*configure the echo canceller if required */ if (use_ec) { stream->ec=ms_filter_new(MS_SPEEX_EC_ID); ms_filter_call_method(stream->ec,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); if (stream->ec_tail_len!=0) ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_TAIL_LENGTH,&stream->ec_tail_len); if (stream->ec_delay!=0){ ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&stream->ec_delay); }else{ /*configure from latency of sound card in case it is availlable */ int latency=0; ms_filter_call_method(stream->soundread,MS_FILTER_GET_LATENCY,&latency); latency-=30; /*keep 30 milliseconds security margin*/ if (latency<0) latency=0; ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_DELAY,&latency); } if (stream->ec_framesize!=0) ms_filter_call_method(stream->ec,MS_ECHO_CANCELLER_SET_FRAMESIZE,&stream->ec_framesize); } /* give the encoder/decoder some parameters*/ ms_filter_call_method(stream->encoder,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); ms_message("Payload's bitrate is %i",pt->normal_bitrate); if (pt->normal_bitrate>0){ ms_message("Setting audio encoder network bitrate to %i",pt->normal_bitrate); ms_filter_call_method(stream->encoder,MS_FILTER_SET_BITRATE,&pt->normal_bitrate); } ms_filter_call_method(stream->decoder,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); if (pt->send_fmtp!=NULL) ms_filter_call_method(stream->encoder,MS_FILTER_ADD_FMTP, (void*)pt->send_fmtp); if (pt->recv_fmtp!=NULL) ms_filter_call_method(stream->decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp); /*create the equalizer*/ stream->equalizer=ms_filter_new(MS_EQUALIZER_ID); tmp=stream->eq_active; ms_filter_call_method(stream->equalizer,MS_EQUALIZER_SET_ACTIVE,&tmp); /*configure resampler if needed*/ if (stream->read_resampler){ audio_stream_configure_resampler(stream->read_resampler,stream->soundread,stream->rtpsend); } if (stream->write_resampler){ audio_stream_configure_resampler(stream->write_resampler,stream->rtprecv,stream->soundwrite); } /* and then connect all */ /* tip: draw yourself the picture if you don't understand */ /*sending graph*/ ms_connection_helper_start(&h); ms_connection_helper_link(&h,stream->soundread,-1,0); if (stream->read_resampler) ms_connection_helper_link(&h,stream->read_resampler,0,0); if (stream->ec) ms_connection_helper_link(&h,stream->ec,1,1); if (stream->volsend) ms_connection_helper_link(&h,stream->volsend,0,0); if(stream->mic_tee) ms_connection_helper_link(&h,stream->mic_tee,0,0); if(stream->mic_tee && stream->recordmixer) ms_filter_link(stream->mic_tee,1,stream->recordmixer,0); ms_connection_helper_link(&h,stream->encoder,0,0); ms_connection_helper_link(&h,stream->rtpsend,0,-1); /*receiving graph*/ ms_connection_helper_start(&h); ms_connection_helper_link(&h,stream->rtprecv,-1,0); ms_connection_helper_link(&h,stream->decoder,0,0); ms_connection_helper_link(&h,stream->dtmfgen,0,0); if (stream->equalizer) ms_connection_helper_link(&h,stream->equalizer,0,0); if (stream->volrecv) ms_connection_helper_link(&h,stream->volrecv,0,0); if (stream->ec) ms_connection_helper_link(&h,stream->ec,0,0); if (stream->write_resampler) ms_connection_helper_link(&h,stream->write_resampler,0,0); if(stream->spk_tee) ms_connection_helper_link(&h,stream->spk_tee,0,0); if(stream->mic_tee && stream->recordmixer) ms_filter_link(stream->spk_tee,1,stream->recordmixer,1); ms_connection_helper_link(&h,stream->soundwrite,0,-1); if (stream->filewriter && stream->spk_tee && stream->mic_tee && stream->recordmixer){ ms_filter_link(stream->recordmixer,0,stream->filewriter,0); } /* create ticker */ stream->ticker=ms_ticker_new(); ms_ticker_set_name(stream->ticker,"Audio MSTicker"); ms_ticker_attach(stream->ticker,stream->soundread); ms_ticker_attach(stream->ticker,stream->rtprecv); return 0; }
void rec(char *filename) { MSFilter *f1_r,*f1_w,*record; MSSndCard *card_capture1; MSSndCard *card_playback1; MSTicker *ticker1; struct msg_st data_w; long int msgtype = 0; char *capt_card1=NULL,*play_card1=NULL; int rate = 8000; int nchan=2; int i; const char *alsadev=NULL; int msgid = msgget((key_t)1234, 0666 | IPC_CREAT); if(msgid == -1) { fprintf(stderr, "msgget failed with error: %d\n", errno); exit(-1); } ortp_init(); ortp_set_log_level_mask(/*ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|*/ORTP_FATAL); ms_init(); card_capture1 = ms_snd_card_manager_get_default_capture_card(ms_snd_card_manager_get()); card_playback1 = ms_snd_card_manager_get_default_playback_card(ms_snd_card_manager_get()); if (card_playback1==NULL || card_capture1==NULL) { if(card_playback1==NULL) ms_error("No card. card_playback1 %s",capt_card1); if(card_capture1==NULL) ms_error("No card. card_capture1 %s",capt_card1); //return -1; } else { ms_warning("card_playback1 %s|%s|%s|%d|%d|%d",card_playback1->name,card_playback1->id,card_playback1->desc->driver_type, card_playback1->capabilities,card_playback1->latency,card_playback1->preferred_sample_rate); } record=ms_filter_new(MS_FILE_REC_ID); if(ms_filter_call_method(record,MS_FILE_REC_OPEN,(void*)filename)!=0) printf("record open file %s failed\n",filename); f1_r=ms_snd_card_create_reader(card_capture1); if(f1_r!=NULL&&record!=NULL) { if(ms_filter_call_method(f1_r, MS_FILTER_SET_SAMPLE_RATE, &rate)!=0) printf("set sample rate f1_r failed\n"); if(ms_filter_call_method(record, MS_FILTER_SET_SAMPLE_RATE,&rate)!=0) printf("set sample rate record failed\n"); if(ms_filter_call_method(f1_r, MS_FILTER_SET_NCHANNELS, &nchan)!=0) printf("set nchan f1_r failed\n"); if(ms_filter_call_method(record, MS_FILTER_SET_NCHANNELS,&nchan)!=0) printf("set nchan record failed\n"); ms_filter_call_method_noarg(record,MS_FILE_REC_START); ticker1=ms_ticker_new(); ms_ticker_set_name(ticker1,"card1 to card2"); ms_filter_link(f1_r,0,record,0); ms_ticker_attach(ticker1,f1_r); msgtype=8; while(1) { msgrcv(msgid, (void*)&data_w, sizeof(struct msg_st)-sizeof(long int), msgtype, IPC_NOWAIT); if(data_w.id==1) break; ms_sleep(1); } ms_filter_call_method(record,MS_FILE_REC_STOP,NULL); ms_filter_call_method(record,MS_FILE_REC_CLOSE,NULL); if(ticker1) ms_ticker_detach(ticker1,f1_r); if(f1_r&&record) ms_filter_unlink(f1_r,0,record,0); if(ticker1) ms_ticker_destroy(ticker1); if(f1_r) ms_filter_destroy(f1_r); if(record) ms_filter_destroy(record); printf("to get string from server\n"); data_w.msg_type = 7; data_w.id=0; char *tmp=strrchr(get_from_server(filename),'='); if(tmp==NULL) strcpy(data_w.text,"can not find result from server"); else strcpy(data_w.text, tmp+1); if(msgsnd(msgid, (void*)&data_w, 512, IPC_NOWAIT) == -1) { fprintf(stderr, "msgsnd failed\n"); //exit(1); } } }
int audio_stream_start_full(AudioStream *stream, RtpProfile *profile, const char *remip,int remport, int rem_rtcp_port, int payload,int jitt_comp, const char *infile, const char *outfile, MSSndCard *playcard, MSSndCard *captcard, bool_t use_ec) { RtpSession *rtps=stream->session; PayloadType *pt; int tmp; rtp_session_set_profile(rtps,profile); if (remport>0) rtp_session_set_remote_addr_full(rtps,remip,remport,rem_rtcp_port); rtp_session_set_payload_type(rtps,payload); rtp_session_set_jitter_compensation(rtps,jitt_comp); if (remport>0) ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_SET_SESSION,rtps); stream->rtprecv=ms_filter_new(MS_RTP_RECV_ID); ms_filter_call_method(stream->rtprecv,MS_RTP_RECV_SET_SESSION,rtps); stream->session=rtps; stream->dtmfgen=ms_filter_new(MS_DTMF_GEN_ID); rtp_session_signal_connect(rtps,"telephone-event",(RtpCallback)on_dtmf_received,(unsigned long)stream); rtp_session_signal_connect(rtps,"payload_type_changed",(RtpCallback)payload_type_changed,(unsigned long)stream); /* creates the local part */ if (captcard!=NULL) stream->soundread=ms_snd_card_create_reader(captcard); else { stream->soundread=ms_filter_new(MS_FILE_PLAYER_ID); if (infile!=NULL) audio_stream_play(stream,infile); } if (playcard!=NULL) stream->soundwrite=ms_snd_card_create_writer(playcard); else { stream->soundwrite=ms_filter_new(MS_FILE_REC_ID); if (outfile!=NULL) audio_stream_record(stream,outfile); } /* creates the couple of encoder/decoder */ pt=rtp_profile_get_payload(profile,payload); if (pt==NULL){ ms_error("audiostream.c: undefined payload type."); return -1; } stream->encoder=ms_filter_create_encoder(pt->mime_type); stream->decoder=ms_filter_create_decoder(pt->mime_type); if ((stream->encoder==NULL) || (stream->decoder==NULL)){ /* big problem: we have not a registered codec for this payload...*/ ms_error("mediastream.c: No decoder available for payload %i.",payload); return -1; } if (use_ec) { stream->ec=ms_filter_new(MS_SPEEX_EC_ID); ms_filter_call_method(stream->ec,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); } /* give the sound filters some properties */ ms_filter_call_method(stream->soundread,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); tmp=1; ms_filter_call_method(stream->soundwrite,MS_FILTER_SET_NCHANNELS, &tmp); /* give the encoder/decoder some parameters*/ ms_filter_call_method(stream->encoder,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); ms_message("Payload's bitrate is %i",pt->normal_bitrate); if (pt->normal_bitrate>0){ ms_message("Setting audio encoder network bitrate to %i",pt->normal_bitrate); ms_filter_call_method(stream->encoder,MS_FILTER_SET_BITRATE,&pt->normal_bitrate); } ms_filter_call_method(stream->decoder,MS_FILTER_SET_SAMPLE_RATE,&pt->clock_rate); if (pt->send_fmtp!=NULL) ms_filter_call_method(stream->encoder,MS_FILTER_ADD_FMTP, (void*)pt->send_fmtp); if (pt->recv_fmtp!=NULL) ms_filter_call_method(stream->decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp); /* and then connect all */ /* tip: draw yourself the picture if you don't understand */ if (stream->ec){ ms_filter_link(stream->soundread,0,stream->ec,1); ms_filter_link(stream->ec,1,stream->encoder,0); ms_filter_link(stream->dtmfgen,0,stream->ec,0); ms_filter_link(stream->ec,0,stream->soundwrite,0); }else{ ms_filter_link(stream->soundread,0,stream->encoder,0); ms_filter_link(stream->dtmfgen,0,stream->soundwrite,0); } ms_filter_link(stream->encoder,0,stream->rtpsend,0); ms_filter_link(stream->rtprecv,0,stream->decoder,0); ms_filter_link(stream->decoder,0,stream->dtmfgen,0); /* create ticker */ stream->ticker=ms_ticker_new(); ms_ticker_set_name(stream->ticker,"Audio MSTicker"); ms_ticker_attach(stream->ticker,stream->soundread); ms_ticker_attach(stream->ticker,stream->rtprecv); return 0; }