コード例 #1
0
/* this code is not part of the library itself, it is part of the mediastream program */
void video_stream_free (VideoStream * stream)
{
	if (stream->session!=NULL){
		rtp_session_unregister_event_queue(stream->session,stream->evq);
		rtp_session_destroy(stream->session);
	}
	if (stream->rtprecv != NULL)
		ms_filter_destroy (stream->rtprecv);
	if (stream->rtpsend!=NULL) 
		ms_filter_destroy (stream->rtpsend);
	if (stream->source != NULL)
		ms_filter_destroy (stream->source);
	if (stream->output != NULL)
		ms_filter_destroy (stream->output);
	if (stream->decoder != NULL)
		ms_filter_destroy (stream->decoder);
	if (stream->sizeconv != NULL)
		ms_filter_destroy (stream->sizeconv);
	if (stream->pixconv!=NULL)
		ms_filter_destroy(stream->pixconv);
	if (stream->tee!=NULL)
		ms_filter_destroy(stream->tee);
	if (stream->ticker != NULL)
		ms_ticker_destroy (stream->ticker);
	if (stream->evq!=NULL)
		ortp_ev_queue_destroy(stream->evq);
	ms_free (stream);
}
コード例 #2
0
ファイル: SinkBase.cpp プロジェクト: FihlaTV/conference
SinkBase::~SinkBase(void)
{
	ms_ticker_destroy(ticker_);
	ms_filter_destroy(f_void_);
	ms_filter_destroy(f_recv_);
	rtp_session_destroy(rtp_);
}
コード例 #3
0
void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions){
	if (sessions->srtp_session) {
		RtpTransport *rtptr=NULL,*rtcptr=NULL;
		ortp_srtp_dealloc(sessions->srtp_session);
		if (sessions->rtp_session){
			rtp_session_get_transports(sessions->rtp_session,&rtptr,&rtcptr);
			rtp_session_set_transports(sessions->rtp_session,NULL,NULL);
			if (rtptr) srtp_transport_destroy(rtptr);
			if (rtcptr) srtp_transport_destroy(rtcptr);
		}
		sessions->srtp_session=NULL;
	}
	if (sessions->rtp_session) {
		rtp_session_destroy(sessions->rtp_session);
		sessions->rtp_session=NULL;
	}
	if (sessions->zrtp_context != NULL) {
		ortp_zrtp_context_destroy(sessions->zrtp_context);
		sessions->zrtp_context = NULL;
	}
	if (sessions->ticker){
		ms_ticker_destroy(sessions->ticker);
		sessions->ticker=NULL;
	}
}
コード例 #4
0
ファイル: VodWnd.cpp プロジェクト: FihlaTV/conference
void VodWnd::stop_vod()
{
    if (ticker_) {
        char opt[128];
        snprintf(opt, sizeof(opt), "sinkid=%d", sinkid_);
        zk_xmpp_uac_send_cmd(uac_, mcu_jid_.c_str(), "test.fc.del_sink", opt, 0, 0);

        ms_ticker_detach(ticker_, filter_rtp_);

        ms_filter_destroy(filter_rtp_);
        filter_rtp_ = 0;
        ms_filter_destroy(filter_decoder_);
        filter_decoder_ = 0;
        ms_filter_destroy(filter_sink_);
        filter_sink_ = 0;

        rtp_session_destroy(rtp_);
        rtp_ = 0;
        ortp_ev_queue_destroy(evq_);
        evq_ = 0;

        ms_ticker_destroy(ticker_);
        ticker_ = 0;

        if (render_) {
            rv_close(render_);
            render_ = 0;
        }
    }
}
コード例 #5
0
ファイル: rtp_send.c プロジェクト: freeloops/openDMD
void rtp_send(const char *sendfile,
        const char *clientIP, const int clientPort,
        const char *remoteIP, const int remotePort) {
    unsigned char buffer[SEND_LEN];
    unsigned int user_ts = 0;
    int readlen = 0;
    int sendlen = 0;

    rtp_send_init();
    RtpSession *rtpsession = rtp_send_createSession(
            clientIP, clientPort, remoteIP, remotePort);
    assert(rtpsession != NULL);

    assert(sendfile != NULL);
    FILE *fp = fopen(sendfile, "r");
    assert(fp != NULL);

    while ((readlen = fread(buffer,
                    sizeof(unsigned char), SEND_LEN, fp)) > 0) {
        sendlen = rtp_session_send_with_ts(rtpsession,
                buffer, readlen, user_ts);
        printf("read %d bytes, send %d bytes\n", readlen, sendlen);

        user_ts += VIDEO_TIME_STAMP_INC;
    }

    fclose(fp);

    rtp_session_destroy(rtpsession);
    rtp_send_release();
    ortp_global_stats_display();
}
コード例 #6
0
ファイル: tevrtpsend.c プロジェクト: tibastral/symphonie
int main(int argc, char *argv[])
{
	RtpSession *session;
	unsigned char buffer[160];
	int i;
	FILE *infile;
	char *ssrc;
	uint32_t user_ts=0;
	int tel=0;
	
	if (argc<4){
		printf(help);
		return -1;
	}
	
	ortp_init();
	ortp_scheduler_init();
	
	/* set the telephony event payload type to 96 in the av profile.*/
	rtp_profile_set_payload(&av_profile,96,&payload_type_telephone_event);
	
	session=rtp_session_new(RTP_SESSION_SENDONLY);
	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
	rtp_session_set_send_payload_type(session,0);
	
	ssrc=getenv("SSRC");
	if (ssrc!=NULL) {
		printf("using SSRC=%i.\n",atoi(ssrc));
		rtp_session_set_ssrc(session,atoi(ssrc));
	}
		
	infile=fopen(argv[1],"rb");
	if (infile==NULL) {
		perror("Cannot open file");
		return -1;
	}
	signal(SIGINT,stophandler);
	while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
	{
		//ortp_message("Sending packet.");
		rtp_session_send_with_ts(session,buffer,i,user_ts);
		user_ts+=160;
		tel++;
		if (tel==50){
			tel=0;
			ortp_message("Sending telephony event packet.");
			rtp_session_send_dtmf(session,'*',user_ts);
			user_ts+=160+160+160; /* the duration of the dtmf */
		}
	}
	fclose(infile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();
	return 0;
}
コード例 #7
0
ファイル: rtp.c プロジェクト: Excalibur201010/ghpsdr3-alex
void rtp_disconnect(RtpSession * session) {

    sem_wait(&rtp_semaphore);
    ortp_global_stats_display();
    rtp_session_destroy(session);
    sem_post(&rtp_semaphore);

}
コード例 #8
0
void ph_media_stop(phcall_t *ca)
{
  phmstream_t *stream = (phmstream_t *) ca->phstream;


  ca->hasaudio = 0;
  ca->phstream = 0;

  stream->running = 0;

  osip_thread_join(stream->audio_in_thread);
  osip_thread_join(stream->audio_out_thread);
  osip_free(stream->audio_in_thread);
  osip_free(stream->audio_out_thread);

  
  rtp_session_signal_disconnect_by_callback(stream->rtp_session, "telephone-event",
					    (RtpCallback)ph_telephone_event);
  ortp_set_debug_file("oRTP", stdout);
  ortp_global_stats_display();
  ortp_set_debug_file("oRTP", NULL);
  rtp_session_destroy(stream->rtp_session);

#if USE_CODECS
  if (stream->codec->encoder_cleanup)
	  stream->codec->encoder_cleanup(stream->encoder_ctx);
  if (stream->codec->decoder_cleanup)
	  stream->codec->decoder_cleanup(stream->decoder_ctx);
#endif /* !USE_CODECS */

  waveInReset(stream->hWaveIn);
  waveInClose(stream->hWaveIn);
  waveOutReset(stream->hWaveOut);
  waveOutClose(stream->hWaveOut);

#if DO_ECHO_CAN
   printf("\nbytes echoed %d %d\n", stream->sent_cnt, stream->recv_cnt);

  free(stream->pcm_sent);

# if !AEC_BIS
  if(stream->ec)
    echo_can_free(stream->ec);
# else /* AEC_BIS */
  kill_AEC();
# endif /* AEC_BIS */

  g_mutex_free(stream->synclock);
  g_cond_free(stream->sync_cond);
  g_mutex_free(stream->aec_mutex);


#endif /* !DO_ECHO_CAN */

  g_mutex_free(stream->dtmfg_lock);

  osip_free(stream);
}
コード例 #9
0
int yy_exit(int handle) {

	RtpSession *session = (RtpSession *) handle;
	rtp_session_destroy(session);
	ortp_exit();

	ortp_global_stats_display();
	return 0;
}
コード例 #10
0
int main(int argc, char *argv[])
{
	RtpSession *session;
	unsigned char buffer[160];
	int err;
	FILE *outfile;
	uint32_t ts=0;
	int have_more;

	if (argc<3){
		printf("%s",help);
		return -1;
	}

	ortp_init();
	ortp_scheduler_init();
	
	/* set the telephony event payload type to 96 in the av profile.*/
	rtp_profile_set_payload(&av_profile,96,&payload_type_telephone_event);
	
	session=rtp_session_new(RTP_SESSION_RECVONLY);	
	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_local_addr(session,"0.0.0.0",atoi(argv[2]));
	rtp_session_set_payload_type(session,0);
	
	/* register for telephony events */
	rtp_session_signal_connect(session,"telephone-event",(RtpCallback)recv_tev_cb,0);
		
	outfile=fopen(argv[1],"wb");
	if (outfile==NULL) {
		perror("Cannot open file");
		return -1;
	}
	signal(SIGINT,stophandler);
	while(runcond)
	{
		have_more=1;
		while (have_more){
			err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
			if (err>0) {
				size_t ret = fwrite(buffer,1,err,outfile);
				assert( ret == err );
			}
		}
		ts+=160;
		//ortp_message("Receiving packet.");
	}
	fclose(outfile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();
	printf("Total dtmf events received: %i\n",dtmf_count);
	return 0;
}
コード例 #11
0
myAudioStream::~myAudioStream()
{
    stop_ticker();
    unlink_filters();
    /* Destroy RTP session */
    ms_message("Destroying RTP session");
    rtp_session_destroy(stream->session);

    ortp_exit();
    ms_exit();
}
コード例 #12
0
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);
}
コード例 #13
0
/* this code is not part of the library itself, it is part of the mediastream program */
void audio_stream_free(AudioStream *stream)
{
	if (stream->session!=NULL) rtp_session_destroy(stream->session);
	if (stream->rtpsend!=NULL) ms_filter_destroy(stream->rtpsend);
	if (stream->rtprecv!=NULL) ms_filter_destroy(stream->rtprecv);
	if (stream->soundread!=NULL) ms_filter_destroy(stream->soundread);
	if (stream->soundwrite!=NULL) ms_filter_destroy(stream->soundwrite);
	if (stream->encoder!=NULL) ms_filter_destroy(stream->encoder);
	if (stream->decoder!=NULL) ms_filter_destroy(stream->decoder);
	if (stream->dtmfgen!=NULL) ms_filter_destroy(stream->dtmfgen);
	if (stream->ec!=NULL)	ms_filter_destroy(stream->ec);
	if (stream->ticker!=NULL) ms_ticker_destroy(stream->ticker);
	ms_free(stream);
}
コード例 #14
0
/* this code is not part of the library itself, it is part of the mediastream program */
void video_stream_free (VideoStream * stream)
{
	if (stream->ortpZrtpContext)
		ortp_zrtp_context_destroy(stream->ortpZrtpContext);
	if (stream->session!=NULL){
		rtp_session_unregister_event_queue(stream->session,stream->evq);
		rtp_session_destroy(stream->session);
	}
	if (stream->rtprecv != NULL)
		ms_filter_destroy (stream->rtprecv);
	if (stream->rtpsend!=NULL)
		ms_filter_destroy (stream->rtpsend);
	if (stream->source != NULL)
		ms_filter_destroy (stream->source);
	if (stream->output != NULL)
		ms_filter_destroy (stream->output);
	if (stream->encoder != NULL)
		ms_filter_destroy (stream->encoder);
	if (stream->decoder != NULL)
		ms_filter_destroy (stream->decoder);
	if (stream->sizeconv != NULL)
		ms_filter_destroy (stream->sizeconv);
	if (stream->pixconv!=NULL)
		ms_filter_destroy(stream->pixconv);
	if (stream->tee!=NULL)
		ms_filter_destroy(stream->tee);
	if (stream->tee2!=NULL)
		ms_filter_destroy(stream->tee2);
	if (stream->jpegwriter!=NULL)
		ms_filter_destroy(stream->jpegwriter);
	if (stream->output2!=NULL)
		ms_filter_destroy(stream->output2);
	if (stream->voidsink!=NULL)
		ms_filter_destroy(stream->voidsink);
	if (stream->ticker != NULL)
		ms_ticker_destroy (stream->ticker);
	if (stream->evq!=NULL)
		ortp_ev_queue_destroy(stream->evq);
	if (stream->display_name!=NULL)
		ms_free(stream->display_name);
	if (stream->rc!=NULL){
		ms_bitrate_controller_destroy(stream->rc);
	}

	ms_free (stream);
}
コード例 #15
0
/* this code is not part of the library itself, it is part of the mediastream program */
void video_stream_free (VideoStream * stream)
{
	if (stream->session!=NULL){
		rtp_session_unregister_event_queue(stream->session,stream->evq);
		rtp_session_destroy(stream->session);
	}
	if (stream->rtprecv != NULL)
		ms_filter_destroy (stream->rtprecv);
	if (stream->rtpsend!=NULL) 
		ms_filter_destroy (stream->rtpsend);
	if (stream->source != NULL)
		ms_filter_destroy (stream->source);
	if (stream->output != NULL)
		ms_filter_destroy (stream->output);
	if (stream->encoder != NULL)
		ms_filter_destroy (stream->encoder);
	if (stream->decoder != NULL)
		ms_filter_destroy (stream->decoder);
	if (stream->sizeconv != NULL)
		ms_filter_destroy (stream->sizeconv);
	if (stream->pixconv!=NULL)
		ms_filter_destroy(stream->pixconv);
	if (stream->tee!=NULL)
		ms_filter_destroy(stream->tee);
	if (stream->tee2!=NULL)
		ms_filter_destroy(stream->tee2);
	if (stream->jpegwriter!=NULL)
		ms_filter_destroy(stream->jpegwriter);
	if(stream->video_record!=NULL)
		ms_filter_destroy(stream->video_record);
	if (stream->output2!=NULL)
		ms_filter_destroy(stream->output2);
#ifdef ENABLE_UDT
	if (stream->udt!=NULL)
		ms_filter_destroy(stream->udt);
#endif // ENABLE_UDT
	if (stream->ticker != NULL)
		ms_ticker_destroy (stream->ticker);
	if (stream->evq!=NULL)
		ortp_ev_queue_destroy(stream->evq);
	if (stream->display_name!=NULL)
		ms_free(stream->display_name);
	
	ms_free (stream);
}
コード例 #16
0
void os_sound_close(jcall_t *ca)
{
  osip_thread_join(ca->audio_thread);
  osip_free(ca->audio_thread);
  osip_thread_join(ca->out_audio_thread);
  osip_free(ca->out_audio_thread);
  rtp_session_signal_disconnect_by_callback(ca->rtp_session, "telephone-event",
					    (RtpCallback)rcv_telephone_event);
  rtp_session_destroy(ca->rtp_session);

#ifdef SPEEX_SUPPORT
  speex_bits_destroy(&ca->speex_bits);
  speex_bits_destroy(&ca->dec_speex_bits);
  speex_encoder_destroy(&ca->speex_enc);
  speex_decoder_destroy(&ca->speex_dec);
#endif
  
  close(fd); /* close the sound card */
}
コード例 #17
0
ファイル: rtp.c プロジェクト: Geal/vlc
/**
 * Releases resources
 */
static void Close (vlc_object_t *obj)
{
    demux_t *demux = (demux_t *)obj;
    demux_sys_t *p_sys = demux->p_sys;

    if (p_sys->thread_ready)
    {
        vlc_cancel (p_sys->thread);
        vlc_join (p_sys->thread, NULL);
    }

#ifdef HAVE_SRTP
    if (p_sys->srtp)
        srtp_destroy (p_sys->srtp);
#endif
    if (p_sys->session)
        rtp_session_destroy (demux, p_sys->session);
    if (p_sys->rtcp_fd != -1)
        net_Close (p_sys->rtcp_fd);
    net_Close (p_sys->fd);
    free (p_sys);
}
コード例 #18
0
ファイル: mediastream.c プロジェクト: duh931/mediastreamer2
void ms_media_stream_sessions_uninit(MSMediaStreamSessions *sessions){
	if (sessions->srtp_context) {
		ms_srtp_context_delete(sessions->srtp_context);
		sessions->srtp_context=NULL;
	}
	if (sessions->rtp_session) {
		rtp_session_destroy(sessions->rtp_session);
		sessions->rtp_session=NULL;
	}
	if (sessions->zrtp_context != NULL) {
		ms_zrtp_context_destroy(sessions->zrtp_context);
		sessions->zrtp_context = NULL;
	}
	if (sessions->dtls_context != NULL) {
		ms_dtls_srtp_context_destroy(sessions->dtls_context);
		sessions->dtls_context = NULL;
	}
	if (sessions->ticker){
		ms_ticker_destroy(sessions->ticker);
		sessions->ticker=NULL;
	}
}
コード例 #19
0
ファイル: CameraStream.cpp プロジェクト: FihlaTV/conference
int CameraStream::close()
{
	if (rtp_) {
		ms_ticker_detach(ticker_sender_, filter_h264_sender_);
		ms_ticker_detach(ticker_recver_, filter_rtp_recver_);

		ms_ticker_destroy(ticker_sender_);
		ms_ticker_destroy(ticker_recver_);
		
		ms_filter_destroy(filter_h264_sender_);
		ms_filter_destroy(filter_rtp_sender_);
		ms_filter_destroy(filter_rtp_recver_);
		ms_filter_destroy(filter_decoder_);
		ms_filter_destroy(filter_yuv_sink_);

		rtp_session_destroy(rtp_);
		rtp_ = 0;
	}

	if (cap_) {
		cvReleaseCapture(&cap_);
		cap_ = 0;
	}

	if (sws_) {
		avpicture_free(&pic_);
		sws_freeContext(sws_);
		sws_ = 0;
	}

	if (encoder_) {
		x264_encoder_close(encoder_);
		encoder_ = 0;
	}

	return 0;
}
コード例 #20
0
ファイル: audiostream.c プロジェクト: github188/Sip-MCU
/* this code is not part of the library itself, it is part of the mediastream program */
void audio_stream_free(AudioStream *stream)
{
	if (stream->session!=NULL) {
		rtp_session_unregister_event_queue(stream->session,stream->evq);
		rtp_session_destroy(stream->session);
	}
	if (stream->evq) ortp_ev_queue_destroy(stream->evq);
	if (stream->rtpsend!=NULL) ms_filter_destroy(stream->rtpsend);
	if (stream->rtprecv!=NULL) ms_filter_destroy(stream->rtprecv);
	if (stream->soundread!=NULL) ms_filter_destroy(stream->soundread);
	if (stream->soundwrite!=NULL) ms_filter_destroy(stream->soundwrite);
	if (stream->encoder!=NULL) ms_filter_destroy(stream->encoder);
	if (stream->decoder!=NULL) ms_filter_destroy(stream->decoder);
	if (stream->dtmfgen!=NULL) ms_filter_destroy(stream->dtmfgen);
#ifndef ENABLED_MCU_MEDIA_SERVER
	if (stream->ec!=NULL)	ms_filter_destroy(stream->ec);
	if (stream->volrecv!=NULL) ms_filter_destroy(stream->volrecv);
	if (stream->volsend!=NULL) ms_filter_destroy(stream->volsend);
	if (stream->equalizer!=NULL) ms_filter_destroy(stream->equalizer);
#endif // ENABLED_MCU_MEDIA_SERVER
	if (stream->ticker!=NULL) ms_ticker_destroy(stream->ticker);
#ifdef ENABLE_UDT
	if (stream->udt!=NULL) ms_filter_destroy(stream->udt);
#endif // ENABLE_UDT
	if (stream->read_resampler!=NULL) ms_filter_destroy(stream->read_resampler);
	if (stream->write_resampler!=NULL) ms_filter_destroy(stream->write_resampler);

	if (stream->mic_tee!=NULL) ms_filter_destroy(stream->mic_tee);
	if (stream->spk_tee!=NULL) ms_filter_destroy(stream->spk_tee);
	if (stream->filewriter!=NULL) ms_filter_destroy(stream->filewriter);
	if (stream->recordmixer!=NULL) ms_filter_destroy(stream->recordmixer);

	if (stream->tee2!=NULL) ms_filter_destroy(stream->tee2);
	if (stream->audio_record!=NULL) ms_filter_destroy(stream->audio_record);
	if (stream->dtmfgen_rtp!=NULL) ms_filter_destroy(stream->dtmfgen_rtp);
	ms_free(stream);
}
コード例 #21
0
/* this code is not part of the library itself, it is part of the mediastream program */
void audio_stream_free(AudioStream *stream)
{
	if (stream->session!=NULL)
	{
		rtp_session_unregister_event_queue(stream->session,stream->evq);
		rtp_session_destroy(stream->session);
	}
	if (stream->rtpsend!=NULL) ms_filter_destroy(stream->rtpsend);
	if (stream->rtprecv!=NULL) ms_filter_destroy(stream->rtprecv);
	if (stream->soundread!=NULL) ms_filter_destroy(stream->soundread);
	if (stream->soundwrite!=NULL) ms_filter_destroy(stream->soundwrite);
	if (stream->encoder!=NULL) ms_filter_destroy(stream->encoder);
	if (stream->decoder!=NULL) ms_filter_destroy(stream->decoder);
	if (stream->dtmfgen!=NULL) ms_filter_destroy(stream->dtmfgen);
	if (stream->ec!=NULL)	ms_filter_destroy(stream->ec);
	if (stream->volrecv!=NULL) ms_filter_destroy(stream->volrecv);
	if (stream->volsend!=NULL) ms_filter_destroy(stream->volsend);
	if (stream->equalizer!=NULL) ms_filter_destroy(stream->equalizer);
	if (stream->ticker!=NULL) ms_ticker_destroy(stream->ticker);
	if (stream->read_resampler!=NULL) ms_filter_destroy(stream->read_resampler);
	if (stream->write_resampler!=NULL) ms_filter_destroy(stream->write_resampler);
	if (stream->evq!=NULL) ortp_ev_queue_destroy(stream->evq);
	ms_free(stream);
}
コード例 #22
0
ファイル: rtprecv.c プロジェクト: chris-magic/amr-audio
int main(int argc, char*argv[])
{
	RtpSession *session;
	unsigned char buffer[32];
	int err;
	uint32_t ts=0;
	int stream_received=0;
	FILE *outfile;
	int local_port;
	int have_more;
	int i;
	int format=0;
	int soundcard=0;
	int sound_fd=0;
	int jittcomp=40;
	bool_t adapt=TRUE;
	
	/* init the lib */
	if (argc<3){
		printf("%s",help);
		return -1;
	}
	local_port=atoi(argv[2]);
	if (local_port<=0) {
		printf("%s",help);
		return -1;
	}
	for (i=3;i<argc;i++)
	{
		if (strcmp(argv[i],"--noadapt")==0) adapt=FALSE;
		if (strcmp(argv[i],"--format")==0){
			i++;
			if (i<argc){
				if (strcmp(argv[i],"mulaw")==0){
					format=MULAW;
				}else
				if (strcmp(argv[i],"alaw")==0){
					format=ALAW;
				}else{
					printf("Unsupported format %s\n",argv[i]);
					return -1;
				}
			}
		}
		else if (strcmp(argv[i],"--soundcard")==0){
			soundcard=1;
		}
		else if (strcmp(argv[i],"--with-jitter")==0){
			i++;
			if (i<argc){
				jittcomp=atoi(argv[i]);
				printf("Using a jitter buffer of %i milliseconds.\n",jittcomp);
			}
		}
	}
	
	outfile=fopen(argv[1],"wb");
	if (outfile==NULL) {
		perror("Cannot open file for writing");
		return -1;
	}
	
	
	if (soundcard){
		sound_fd=sound_init(format);
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
	signal(SIGINT,stop_handler);
	session=rtp_session_new(RTP_SESSION_RECVONLY);	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_local_addr(session,"0.0.0.0",atoi(argv[2]));
	rtp_session_set_connected_mode(session,TRUE);
	rtp_session_set_symmetric_rtp(session,TRUE);
	rtp_session_enable_adaptive_jitter_compensation(session,adapt);
	rtp_session_set_jitter_compensation(session,jittcomp);
	rtp_session_set_payload_type(session,0);
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);
	

	fwrite("#!AMR\n",1,6,outfile);
//	write(sound_fd,"#!AMR\n",err);
	while(cond)
	{
		have_more=1;
		while (have_more){
			err=rtp_session_recv_with_ts(session,buffer,32,ts,&have_more);
			if (err>0) stream_received=1;
			/* this is to avoid to write to disk some silence before the first RTP packet is returned*/	
			if ((stream_received) && (err>0)) {
				size_t ret = fwrite(buffer,1,err,outfile);
				int ii;
				for(ii =0 ; ii < 32 ; ii ++)
					printf("%x " ,buffer[ii]);
				printf("\n");
//				while(1);
				if (sound_fd>0){
					ret = write(sound_fd,buffer,err);
					if (ret==-1){
						fprintf(stderr,"write to sound card failed (%s)",strerror(errno));
					}
				}
			}
		}
		ts+=160;
		//ortp_message("Receiving packet.");
	}
	
	rtp_session_destroy(session);
	ortp_exit();
	
	ortp_global_stats_display();
	
	return 0;
}
コード例 #23
0
ファイル: rtpsend.c プロジェクト: Distrotech/oRTP
int main(int argc, char *argv[])
{
	RtpSession *session;
	unsigned char buffer[160];
	int i;
	FILE *infile;
	char *ssrc;
	uint32_t user_ts=0;
	int clockslide=0;
	int jitter=0;
	if (argc<4){
		printf("%s", help);
		return -1;
	}
	for(i=4;i<argc;i++){
		if (strcmp(argv[i],"--with-clockslide")==0){
			i++;
			if (i>=argc) {
				printf("%s", help);
				return -1;
			}
			clockslide=atoi(argv[i]);
			ortp_message("Using clockslide of %i milisecond every 50 packets.",clockslide);
		}else if (strcmp(argv[i],"--with-jitter")==0){
			ortp_message("Jitter will be added to outgoing stream.");
			i++;
			if (i>=argc) {
				printf("%s", help);
				return -1;
			}
			jitter=atoi(argv[i]);
		}
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(NULL, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
	session=rtp_session_new(RTP_SESSION_SENDONLY);	
	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_connected_mode(session,TRUE);
	rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
	rtp_session_set_payload_type(session,0);
	
	ssrc=getenv("SSRC");
	if (ssrc!=NULL) {
		printf("using SSRC=%i.\n",atoi(ssrc));
		rtp_session_set_ssrc(session,atoi(ssrc));
	}
		
	#ifndef _WIN32
	infile=fopen(argv[1],"r");
	#else
	infile=fopen(argv[1],"rb");
	#endif

	if (infile==NULL) {
		perror("Cannot open file");
		return -1;
	}

	signal(SIGINT,stophandler);
	while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
	{
		rtp_session_send_with_ts(session,buffer,i,user_ts);
		user_ts+=160;
		if (clockslide!=0 && user_ts%(160*50)==0){
			ortp_message("Clock sliding of %i miliseconds now",clockslide);
			rtp_session_make_time_distorsion(session,clockslide);
		}
		/*this will simulate a burst of late packets */
		if (jitter && (user_ts%(8000)==0)) {
			ortp_message("Simulating late packets now (%i milliseconds)",jitter);
			ortp_sleep_ms(jitter);
		}
	}

	fclose(infile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();

	return 0;
}
コード例 #24
0
int __cdecl main(int argc, char *argv[])
{
	FILE		*	infile				= NULL;
	SessionSet	*	pSessionSet			= NULL;
	int				nCounter			= 0;
	UINT32			m_nUser_Timestamp	= 0;

	ProductVersion();

	if (GetCommandArguments(argc, argv) != 0)
	{
		printf("==> Sorry dude...\n");
		Sleep(1000);
		return -1;
	}

	printf("==> Starting the RTP Sender test\n");


	// =============== INSTALL THE CONTROL HANDLER ===============
	if (SetConsoleCtrlHandler( (PHANDLER_ROUTINE) ctrlHandlerFunction, TRUE) == 0)
	{
		printf("==> Cannot handle the CTRL-C...\n");
	}


	printf("==> Timestamp increment will be %i\n"	, m_nTimestamp_Inc);
	printf("==> Packet size will be %i\n"			, m_nPacket_Size);

	m_pBuffer = (char *) ortp_malloc(m_nPacket_Size);

	ortp_init();
	ortp_scheduler_init();
	printf("==> Scheduler initialized\n");

	m_SSRC	= getenv("SSRC");
	m_nPort	= atoi(argv[3]);

	for (nCounter=0; nCounter < m_nChannels; nCounter++)
	{
		//printf("==> Channel [#%d]\n", nCounter);

		m_Session[nCounter] = rtp_session_new(RTP_SESSION_SENDONLY);	

		rtp_session_set_scheduling_mode(m_Session[nCounter],1);
		rtp_session_set_blocking_mode(m_Session[nCounter],0);
		rtp_session_set_remote_addr(m_Session[nCounter],argv[2], m_nPort);
		rtp_session_set_send_payload_type(m_Session[nCounter],0);
		
		if (m_SSRC != NULL) 
		{
			rtp_session_set_ssrc(m_Session[nCounter],atoi(m_SSRC));
		}

		m_nPort+=2;
	}

	infile=fopen(argv[1],"rb");

	if (infile==NULL) 
	{
		printf("==> Cannot open file !!!!");
		Sleep(1000);
		return -1;
	}

//	printf("==> Open file\n");
	
	/* Create a set */
	pSessionSet = session_set_new();
//	printf("==> Session set\n");

	while( ((nCounter= (int) fread(m_pBuffer,1,m_nPacket_Size,infile))>0) && (m_bExit == FALSE) )
	{
		int k;
		//g_message("Sending packet.");
		for (k=0;k<m_nChannels;k++){	
			/* add the session to the set */
			session_set_set(pSessionSet,m_Session[k]);
			//printf("==> Session set set %d\n", k);
		}
		/* and then suspend the process by selecting() */
		session_set_select(NULL,pSessionSet,NULL);
		//printf("==> Session set select\n");

		for (k=0;k<m_nChannels;k++)
		{
			//printf("---\n");
			/* this is stupid to do this test, because all session work the same way,
			as the same user_ts is used for all sessions, here. */
			if (session_set_is_set(pSessionSet,m_Session[k]))
			{
				//printf("==> Session set is set %d\n", k);
				rtp_session_send_with_ts(m_Session[k],m_pBuffer,nCounter,m_nUser_Timestamp);
				//g_message("packet sended !");
			}
		}
		m_nUser_Timestamp+=m_nTimestamp_Inc;
	}

	fclose(infile);
	printf("==> Close file\n");



	for(nCounter=0;nCounter<m_nChannels;nCounter++)
	{
		rtp_session_destroy(m_Session[nCounter]);
	}

	session_set_destroy(pSessionSet);

	// Give us some time
	Sleep(250);

	ortp_exit();
	ortp_global_stats_display();

	ortp_free(m_pBuffer);

	printf("==> Remove the CTRL-C handler...\n");
	SetConsoleCtrlHandler( (PHANDLER_ROUTINE) ctrlHandlerFunction, FALSE);

	// Wait for an input key
	printf("Waiting for exit : ");

	for (nCounter = 0; nCounter < 4*5; nCounter++)
	{
		printf(".");
		Sleep(250);
	}

	return 0;
}
コード例 #25
0
ファイル: rtpsend_stupid.c プロジェクト: shibainusan/ortp
int main(int argc, char *argv[])
{
	RtpSession *session;
	unsigned char buffer[160];
	int i;
	FILE *infile;
	char *ssrc;
	uint32_t packet_ts=0,send_ts=0;
	uint32_t send_ts_inc=160;
	int clockslide=0;
	int jitter=0;
	if (argc<4){
		printf("%s",help);
		return -1;
	}
	for(i=4;i<argc;i++){
		if (strcmp(argv[i],"--with-clockslide")==0){
			i++;
			if (i>=argc) {
				printf("%s",help);
				return -1;
			}
			clockslide=atoi(argv[i]);
			ortp_message("Using clockslide of %i milisecond every 50 packets.",clockslide);
		}else if (strcmp(argv[i],"--with-ptime")==0){
			ortp_message("Ptime related jitter will be added to outgoing stream.");
			i++;
			if (i>=argc) {
				printf("%s",help);
				return -1;
			}
			jitter=atoi(argv[i]);
			send_ts_inc=jitter*8;
		}
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(NULL, ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
	session=rtp_session_new(RTP_SESSION_SENDONLY);	
	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_connected_mode(session,TRUE);
	rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
	rtp_session_set_payload_type(session,0);
	
	ssrc=getenv("SSRC");
	if (ssrc!=NULL) {
		printf("using SSRC=%i.\n",atoi(ssrc));
		rtp_session_set_ssrc(session,atoi(ssrc));
	}
		
	#ifndef _WIN32
	infile=fopen(argv[1],"r");
	#else
	infile=fopen(argv[1],"rb");
	#endif

	if (infile==NULL) {
		perror("Cannot open file");
		return -1;
	}

	signal(SIGINT,stophandler);
	while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
	{
		mblk_t *m=rtp_session_create_packet(session,RTP_FIXED_HEADER_SIZE,buffer,i);
		__rtp_session_sendm_with_ts(session,m,packet_ts,send_ts);
		packet_ts+=160;
		if ((send_ts+send_ts_inc)<=packet_ts){
			send_ts+=send_ts_inc;
		}
		if (clockslide!=0 && send_ts%(160*50)==0){
			ortp_message("Clock sliding of %i miliseconds now",clockslide);
			rtp_session_make_time_distorsion(session,clockslide);
		}
	}

	fclose(infile);
	rtp_session_destroy(session);
	ortp_exit();
	ortp_global_stats_display();

	return 0;
}
コード例 #26
0
int main(int argc, char *argv[])
{
	RtpSession *session[STREAMS_COUNT];
	gint i;
	gint filefd[STREAMS_COUNT];
	gint port;
	guint32 user_ts=0;
	gint channels;
	SessionSet *set;
	gchar *filename;

	if (argc<4){
		printf(help);
		return -1;
	}
	
	channels=atoi(argv[3]);
	if (channels==0){
		printf(help);
		return -1;
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_debug_file("oRTP",NULL);
	
        /* set the telephony event payload type to 96 in the av profile.*/
        rtp_profile_set_payload(&av_profile,96,&payload_type_telephone_event);

	port=atoi(argv[2]);
	p_channel_id = (int *)g_malloc(channels*sizeof(int));
	for (i=0;i<channels;i++){
		session[i]=rtp_session_new(RTP_SESSION_RECVONLY);	
		rtp_session_set_scheduling_mode(session[i],1);
		rtp_session_set_blocking_mode(session[i],0);

		rtp_session_set_local_addr(session[i],"0.0.0.0",port);
		rtp_session_set_recv_payload_type(session[i],0);
		rtp_session_set_recv_buf_size(session[i],256);

		p_channel_id[i] = i;
		/* register for telephony events */
		rtp_session_signal_connect(session[i],"telephone-event",(RtpCallback)recv_tev_cb,&p_channel_id[i]);

		port+=2;
	}
		
	filename=g_malloc(strlen(argv[1])+8);
	for (i=0;i<channels;i++){
		sprintf(filename,"%s%4.4d.dat",argv[1],i);
		#ifndef _WIN32
		filefd[i]=open(filename,O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
		#else
		filefd[i]=open(filename,_O_BINARY | O_WRONLY | O_CREAT | O_TRUNC);
		#endif
		if (filefd[i]<0) g_error("Could not open %s for writing: %s",filename,strerror(errno));
	}
	signal(SIGINT,stophandler);
	/* create a set */
	set=session_set_new();
	while(runcond)
	{
		int k;
		
		for (k=0;k<channels;k++){
			/* add the session to the set */
			session_set_set(set,session[k]);
			
		}
		/* and then suspend the process by selecting() */
		session_set_select(set,NULL,NULL);
		for (k=0;k<channels;k++){
			if (session_set_is_set(set,session[k])){
				rtp2disk(session[k],user_ts,filefd[k]);
			}
		}
		user_ts+=160;
	}
	for (i=0;i<channels;i++){
		close(filefd[i]);
		rtp_session_destroy(session[i]);
	}
	session_set_destroy(set);
	g_free(p_channel_id);
	g_free(filename);
	ortp_exit();
	ortp_global_stats_display();
	return 0;
}
コード例 #27
0
ファイル: mrtprecv.c プロジェクト: Christof0113/rtsp-tools
int main(int argc, char *argv[])
{
	RtpSession *session[STREAMS_COUNT];
	int i;
	int filefd[STREAMS_COUNT];
	int port;
	uint32_t user_ts=0;
	int channels;
	SessionSet *set;
	char *filename;
	
	if (argc<4){
		printf("%s",help);
		return -1;
	}
	
	channels=atoi(argv[3]);
	if (channels==0){
		printf("%s",help);
		return -1;
	}
	
	ortp_init();
	ortp_scheduler_init();
	
	port=atoi(argv[2]);
	recvbuf=ortp_malloc(160);
	
	for (i=0;i<channels;i++){

		session[i]=rtp_session_new(RTP_SESSION_RECVONLY);	
		rtp_session_set_scheduling_mode(session[i],1);
		rtp_session_set_blocking_mode(session[i],0);
		rtp_session_set_local_addr(session[i],"0.0.0.0",port,port+1);
		rtp_session_set_payload_type(session[i],0);
		rtp_session_enable_adaptive_jitter_compensation(session[i], TRUE);
		rtp_session_set_recv_buf_size(session[i],256);
		port+=2;
	}
		
	filename=ortp_malloc(strlen(argv[1])+15);
	for (i=0;i<channels;i++){
		sprintf(filename,"%s%4.4d.dat",argv[1],i);
		#ifndef _WIN32
		filefd[i]=open(filename,O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
		#else
		filefd[i]=open(filename,_O_BINARY | O_WRONLY | O_CREAT | O_TRUNC);
		#endif
		if (filefd[i]<0) ortp_error("Could not open %s for writing: %s",filename,strerror(errno));
	}
	signal(SIGINT,stophandler);
	/* create a set */
	set=session_set_new();
	while(runcond)
	{
		int k;
		
		for (k=0;k<channels;k++){
			/* add the session to the set */
			session_set_set(set,session[k]);
			//printf("session_set_set %d\n", k);
		}
		/* and then suspend the process by selecting() */
		k=session_set_select(set,NULL,NULL);
		if (k==0) printf("warning: session_set_select() is returning 0...\n");
		for (k=0;k<channels;k++){
			if (session_set_is_set(set,session[k])){
				rtp2disk(session[k],user_ts,filefd[k]);
				//printf("session_set_is_set %d\n", k);
			} else {
				//printf("warning: session %i is not set !\n",k);
			}
		}
		user_ts+=160;
	}
	printf("Exiting\n");
	for (i=0;i<channels;i++){
		close(filefd[i]);
		rtp_session_destroy(session[i]);
	}
	session_set_destroy(set);
	ortp_free(filename);
	ortp_exit();
	ortp_global_stats_display();
	ortp_free(recvbuf);
	return 0;
}
コード例 #28
0
ファイル: rtprecv.c プロジェクト: air-gh/oRTP-SBus
int main(int argc, char*argv[])
{
	RtpSession *session;
#ifndef SBUS
	unsigned char buffer[160];
#else
	unsigned char buffer[SBUS_FRAME_SIZE];
#endif
	int err;
	uint32_t ts=0;
	int stream_received=0;
	FILE *outfile;
	int local_port;
	int have_more;
	int i;
	int format=0;
	int soundcard=0;
	int sound_fd=0;
	int jittcomp=40;
	bool_t adapt=TRUE;
#ifdef SBUS
	RtpProfile prof;
#endif
	
	/* init the lib */
	if (argc<3){
		printf("%s",help);
		return -1;
	}
	local_port=atoi(argv[2]);
	if (local_port<=0) {
		printf("%s",help);
		return -1;
	}
	for (i=3;i<argc;i++)
	{
		if (strcmp(argv[i],"--noadapt")==0) adapt=FALSE;
		if (strcmp(argv[i],"--format")==0){
			i++;
			if (i<argc){
				if (strcmp(argv[i],"mulaw")==0){
					format=MULAW;
				}else
				if (strcmp(argv[i],"alaw")==0){
					format=ALAW;
				}else{
					printf("Unsupported format %s\n",argv[i]);
					return -1;
				}
			}
		}
		else if (strcmp(argv[i],"--soundcard")==0){
			soundcard=1;
		}
		else if (strcmp(argv[i],"--with-jitter")==0){
			i++;
			if (i<argc){
				jittcomp=atoi(argv[i]);
				printf("Using a jitter buffer of %i milliseconds.\n",jittcomp);
			}
		}
	}
	
	outfile=fopen(argv[1],"wb");
	if (outfile==NULL) {
		perror("Cannot open file for writing");
		return -1;
	}
#ifdef SBUS
	setvbuf(outfile, NULL, _IONBF, 0);
#endif
	
	
	if (soundcard){
		sound_fd=sound_init(format);
	}
	
	ortp_init();
	ortp_scheduler_init();
	ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
	signal(SIGINT,stop_handler);
	session=rtp_session_new(RTP_SESSION_RECVONLY);	
	rtp_session_set_scheduling_mode(session,1);
	rtp_session_set_blocking_mode(session,1);
	rtp_session_set_local_addr(session,"0.0.0.0",atoi(argv[2]),-1);
	rtp_session_set_connected_mode(session,TRUE);
	rtp_session_set_symmetric_rtp(session,TRUE);
	rtp_session_enable_adaptive_jitter_compensation(session,adapt);
	rtp_session_set_jitter_compensation(session,jittcomp);
#ifndef SBUS
	rtp_session_set_payload_type(session,0);
#else
	rtp_profile_clear_all(&prof);
	//rtp_profile_set_name(&prof, "SBUS");
	rtp_profile_set_payload(&prof, 71, &payload_type_sbus);
	rtp_session_set_profile(session, &prof);
	rtp_session_set_payload_type(session, 71);
#endif
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
	rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);

	while(cond)
	{
		have_more=1;
		while (have_more){
#ifndef SBUS
			err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
#else
			err=rtp_session_recv_with_ts(session,buffer,SBUS_FRAME_SIZE,ts,&have_more);
#endif
			if (err>0) stream_received=1;
			/* this is to avoid to write to disk some silence before the first RTP packet is returned*/	
			if ((stream_received) && (err>0)) {
#ifdef SBUS
				clock_gettime(CLOCK_REALTIME, &tsnew);
				printf("%09ld\n", tsnew.tv_nsec);
#endif
				size_t ret = fwrite(buffer,1,err,outfile);
				if (sound_fd>0){
					ret = write(sound_fd,buffer,err);
					if (ret==-1){
						fprintf(stderr,"write to sound card failed (%s)",strerror(errno));
					}
				}
			}
		}
#ifndef SBUS
		ts+=160;
#else
		ts+=70;
#endif
		//ortp_message("Receiving packet.");
	}
	
	rtp_session_destroy(session);
	ortp_exit();
	
	ortp_global_stats_display();
	
	return 0;
}
コード例 #29
0
ファイル: work2.c プロジェクト: duh931/mediaExample
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);

}