Exemplo n.º 1
0
DirectorConference::DirectorConference(int id, int livingcast)
	: Conference(id)
{
	filter_tee_ = ms_filter_new(MS_TEE_ID);
	filter_sink_ = ms_filter_new_from_name("ZonekeyVoidSink");

	log("%s: ... id=%d \n", __FUNCTION__, id);

#if 1
	audio_mixer_ = ms_filter_new_from_name("ZonekeyAudioMixer");
	int rate = 16000;
	ms_filter_call_method(audio_mixer_, MS_FILTER_SET_SAMPLE_RATE, &rate);
#else
	audio_mixer_ = ms_filter_new(MS_AUDIO_MIXER_ID);
	int tmp = 1, rate = 16000;
	ms_filter_call_method(audio_mixer_, MS_AUDIO_MIXER_ENABLE_CONFERENCE_MODE, &tmp);
	ms_filter_call_method(audio_mixer_, MS_FILTER_SET_SAMPLE_RATE, &rate);
#endif
	video_mixer_ = ms_filter_new_from_name("ZonekeyVideoMixer");
	audio_publisher_ = ms_filter_new_from_name("ZonekeyPublisher");
	video_publisher_ = ms_filter_new_from_name("ZonekeyPublisher");
	audio_resample_ = ms_filter_new(MS_RESAMPLE_ID);
	audio_encoder_ = ms_filter_new_from_name("MSIlbcEnc");
	video_tee_ = ms_filter_new(MS_TEE_ID);

	// 是否启用 video mixer
	ms_filter_call_method(video_mixer_, ZONEKEY_METHOD_VIDEO_MIXER_ENABLE, (void*)livingcast);

	audio_ticker_ = ms_ticker_new();
	video_ticker_ = ms_ticker_new();

	/// 总是将 audio mixer 的 preview 使用 iLBC 输出
	int in_sample = 16000, in_ch = 1;
	int out_sample = 8000, out_ch = 1;
	ms_filter_call_method(audio_resample_, MS_FILTER_SET_SAMPLE_RATE, &in_sample);
	ms_filter_call_method(audio_resample_, MS_FILTER_SET_NCHANNELS, &in_ch);
	ms_filter_call_method(audio_resample_, MS_FILTER_SET_OUTPUT_SAMPLE_RATE, &out_sample);
	ms_filter_call_method(audio_resample_, MS_FILTER_SET_OUTPUT_NCHANNELS, &out_ch);

	// simple link
	ms_filter_link(audio_mixer_, ZONEKEY_AUDIO_MIXER_PREVIEW_PIN, audio_resample_, 0);
	ms_filter_link(audio_resample_, 0, audio_encoder_, 0);
	ms_filter_link(audio_encoder_, 0, audio_publisher_, 0);

	ms_filter_link(video_mixer_, 1, video_tee_, 0);
	ms_filter_link(video_tee_, MAX_STREAMS, video_publisher_, 0);

	audio_stream_cnt_ = 0;
	video_stream_cnt_ = 0;

	resume_audio();
	resume_video();

	log("ok\n");
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
SinkBase::SinkBase(int payload, const char *mcu_ip, int mcu_rtp_port, int mcu_rtcp_port, void (*data)(void *opaque, double stamp, void *data, int len, bool key), void *opaque)
	: cb_data_(data)
	, opaque_(opaque)
	, mcu_ip_(mcu_ip)
	, mcu_rtp_port_(mcu_rtp_port)
	, mcu_rtcp_port_(mcu_rtcp_port)
	, payload_(payload)
{
	rtp_ = rtp_session_new(RTP_SESSION_RECVONLY);
	if (payload == 100) {
		rtp_session_set_rtp_socket_recv_buffer_size(rtp_, 1024*1024);
	}
	rtp_session_set_remote_addr_and_port(rtp_, mcu_ip, mcu_rtp_port, mcu_rtcp_port);
	rtp_session_set_payload_type(rtp_, payload);
	rtp_session_enable_jitter_buffer(rtp_, false);

	f_recv_ = ms_filter_new(MS_RTP_RECV_ID);
	ms_filter_call_method(f_recv_, MS_RTP_RECV_SET_SESSION, rtp_);

	f_void_ = ms_filter_new_from_name("ZonekeyVoidSink");
	ZonekeyVoidSinkCallback cbs = { this, cb_data };
	ms_filter_call_method(f_void_, ZONEKEY_METHOD_VOID_SINK_SET_CALLBACK, &cbs);

	ticker_ = ms_ticker_new();

	ms_queue_init(&queue_);
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard, MSFilterNotifyFunc func,void * user_data)
{
	RingStream *stream;
	int tmp;
	stream=(RingStream *)ms_new0(RingStream,1);
	stream->source=ms_filter_new(MS_FILE_PLAYER_ID);
	if (ms_filter_call_method(stream->source,MS_FILE_PLAYER_OPEN,(void*)file)<0){
		ms_filter_destroy(stream->source);
		ms_free(stream);
		return NULL;
	}
	ms_filter_call_method(stream->source,MS_FILE_PLAYER_LOOP,&interval);
	ms_filter_call_method_noarg(stream->source,MS_FILE_PLAYER_START);
	if (func!=NULL)
		ms_filter_set_notify_callback(stream->source,func,user_data);
	stream->sndwrite=ms_snd_card_create_writer(sndcard);
	ms_filter_call_method(stream->source,MS_FILTER_GET_SAMPLE_RATE,&tmp);
	ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&tmp);
	ms_filter_call_method(stream->source,MS_FILTER_GET_NCHANNELS,&tmp);
	ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_NCHANNELS,&tmp);
	stream->ticker=ms_ticker_new();
	ms_ticker_set_name(stream->ticker,"Audio (ring) MSTicker");
	ms_filter_link(stream->source,0,stream->sndwrite,0);
	ms_ticker_attach(stream->ticker,stream->source);
	return stream;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
int video_stream_recv_only_start (VideoStream *stream, RtpProfile *profile, const char *remip, int remport,int payload, int jitt_comp){
	PayloadType *pt;
	MSPixFmt format;
	MSVideoSize vsize;
	RtpSession *rtps=stream->session;
	
	vsize.width=MS_VIDEO_SIZE_CIF_W;
	vsize.height=MS_VIDEO_SIZE_CIF_H;

	rtp_session_set_profile(rtps,profile);
	if (remport>0) rtp_session_set_remote_addr(rtps,remip,remport);
	rtp_session_set_payload_type(rtps,payload);
	rtp_session_set_jitter_compensation(rtps,jitt_comp);
	
	/* creates rtp filters to recv streams */
	rtp_session_set_recv_buf_size(rtps,MAX_RTP_SIZE);
	stream->rtprecv = ms_filter_new (MS_RTP_RECV_ID);
	ms_filter_call_method(stream->rtprecv,MS_RTP_RECV_SET_SESSION,rtps);

	/* creates the filters */
	pt=rtp_profile_get_payload(profile,payload);
	if (pt==NULL){
		ms_error("videostream.c: undefined payload type.");
		return -1;
	}
	stream->decoder=ms_filter_create_decoder(pt->mime_type);
	if (stream->decoder==NULL){
		/* big problem: we have not a registered codec for this payload...*/
		ms_error("videostream.c: No codecs available for payload %i:%s.",payload,pt->mime_type);
		return -1;
	}
	stream->output=ms_filter_new(MS_VIDEO_OUT_ID);

	/*force the decoder to output YUV420P */
	format=MS_YUV420P;
	/*ask the size-converter to always output CIF */
	vsize.width=MS_VIDEO_SIZE_CIF_W;
	vsize.height=MS_VIDEO_SIZE_CIF_H;
	ms_message("Setting output vsize=%ix%i",vsize.width,vsize.height);
	
	ms_filter_call_method(stream->decoder,MS_FILTER_SET_PIX_FMT,&format);
	ms_filter_call_method(stream->output,MS_FILTER_SET_PIX_FMT,&format);
	ms_filter_call_method(stream->output,MS_FILTER_SET_VIDEO_SIZE,&vsize);

	if (pt->recv_fmtp!=NULL) {
		ms_message("pt->recv_fmtp: %s", pt->recv_fmtp);
		ms_filter_call_method(stream->decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp);
	}

	/* and then connect all */
	ms_filter_link (stream->rtprecv, 0, stream->decoder, 0);
	ms_filter_link (stream->decoder,0 , stream->output, 0);

	/* create the ticker */
	stream->ticker = ms_ticker_new(); 
	/* attach it the graph */
	ms_ticker_attach (stream->ticker, stream->rtprecv);
	return 0;
}
Exemplo n.º 8
0
MSMediaPlayer *ms_media_player_new(MSSndCard *snd_card, const char *video_display_name, void *window_id) {
	MSMediaPlayer *obj = (MSMediaPlayer *)ms_new0(MSMediaPlayer, 1);
	obj->ticker = ms_ticker_new();
	ms_mutex_init(&obj->cb_access, NULL);
	obj->snd_card = snd_card;
	if(video_display_name != NULL && strlen(video_display_name) > 0) {
		obj->video_display = ms_strdup(video_display_name);
		obj->window_id = window_id;
	}
	return obj;
}
Exemplo n.º 9
0
MSAudioConference * ms_audio_conference_new(const MSAudioConferenceParams *params){
	MSAudioConference *obj=ms_new0(MSAudioConference,1);
	int tmp=1;
	obj->ticker=ms_ticker_new();
	ms_ticker_set_name(obj->ticker,"Audio conference MSTicker");
	ms_ticker_set_priority(obj->ticker,__ms_get_default_prio(FALSE));
	obj->mixer=ms_filter_new(MS_AUDIO_MIXER_ID);
	obj->params=*params;
	ms_filter_call_method(obj->mixer,MS_AUDIO_MIXER_ENABLE_CONFERENCE_MODE,&tmp);
	ms_filter_call_method(obj->mixer,MS_FILTER_SET_SAMPLE_RATE,&obj->params.samplerate);
	return obj;
}
Exemplo n.º 10
0
int local_webcam_start(ConfWebCam *localcam,MSWebCam *device,MSVideoSize vsize,float fps){

	MSPixFmt format=MS_YUV420P;

	if(!device) return -1;

	if(fps<=0)
		fps=15;

	if (device==NULL){
		device=ms_web_cam_manager_get_default_cam (
			ms_web_cam_manager_get());                                
	}

	localcam->webcam = ms_web_cam_create_reader(device);

	ms_message("Setting sent vsize=%ix%i, fps=%f",vsize.width,vsize.height,fps);
	/* configure the filters */
	if (ms_filter_get_id(localcam->webcam)!=MS_STATIC_IMAGE_ID) {
		ms_filter_call_method(localcam->webcam,MS_FILTER_SET_FPS,&fps);
	}
	ms_filter_call_method(localcam->webcam,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	/* get the output format for webcam reader */
	ms_filter_call_method(localcam->webcam,MS_FILTER_GET_PIX_FMT,&format);
	if (format==MS_MJPEG){
		localcam->pixconv=ms_filter_new(MS_MJPEG_DEC_ID);
	}else{
		localcam->pixconv = ms_filter_new(MS_PIX_CONV_ID);
		/*set it to the pixconv */
		ms_filter_call_method(localcam->pixconv,MS_FILTER_SET_PIX_FMT,&format);
		ms_filter_call_method(localcam->webcam,MS_FILTER_GET_VIDEO_SIZE,&vsize);
		ms_filter_call_method(localcam->pixconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	}
	localcam->sizeconv=ms_filter_new(MS_SIZE_CONV_ID);
	ms_filter_call_method(localcam->sizeconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);

	localcam->itc_sink = ms_filter_new(MS_CONF_ITC_SINK_ID);

	ms_filter_link(localcam->webcam,0,localcam->pixconv,0);
	ms_filter_link(localcam->pixconv,0,localcam->sizeconv,0);
	ms_filter_link(localcam->sizeconv,0,localcam->itc_sink,0);


	localcam->ticker = ms_ticker_new();
	ms_ticker_set_name(localcam->ticker,"Local Camera MSTicker");

	ms_ticker_attach(localcam->ticker,localcam->webcam);

	return 0;
}
Exemplo n.º 11
0
bool myAudioStream::start_ticker()
{
    /* Create ticker */
    ticker = ms_ticker_new();
    if (ticker == 0) {
        ms_error("Failed to create new ticker");
        return false;
    }
    /* Attach chain to ticker */
    if (ms_ticker_attach(ticker, stream->rtprecv) != 0) {
        ms_error("Failed to attach rtprecv to ticker");
        return false;
    }
    return true;
}
Exemplo n.º 12
0
void video_preview_start(VideoPreview *stream, MSWebCam *device){
	MSPixFmt format;
	float fps=(float)29.97;
	int mirroring=1;
	int corner=-1;
	MSVideoSize disp_size=stream->sent_vsize;
	MSVideoSize vsize=disp_size;
	const char *displaytype=stream->display_name;

	stream->source = ms_web_cam_create_reader(device);


	/* configure the filters */
	ms_filter_call_method(stream->source,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	if (ms_filter_get_id(stream->source)!=MS_STATIC_IMAGE_ID)
		ms_filter_call_method(stream->source,MS_FILTER_SET_FPS,&fps);
	ms_filter_call_method(stream->source,MS_FILTER_GET_PIX_FMT,&format);
	ms_filter_call_method(stream->source,MS_FILTER_GET_VIDEO_SIZE,&vsize);
	if (format==MS_MJPEG){
		stream->pixconv=ms_filter_new(MS_MJPEG_DEC_ID);
	}else{
		stream->pixconv=ms_filter_new(MS_PIX_CONV_ID);
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_PIX_FMT,&format);
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	}

	format=MS_YUV420P;

	stream->output2=ms_filter_new_from_name (displaytype);
	ms_filter_call_method(stream->output2,MS_FILTER_SET_PIX_FMT,&format);
	ms_filter_call_method(stream->output2,MS_FILTER_SET_VIDEO_SIZE,&disp_size);
	ms_filter_call_method(stream->output2,MS_VIDEO_DISPLAY_ENABLE_MIRRORING,&mirroring);
	ms_filter_call_method(stream->output2,MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_MODE,&corner);
	/* and then connect all */

	ms_filter_link(stream->source,0, stream->pixconv,0);
	ms_filter_link(stream->pixconv, 0, stream->output2, 0);

	if (stream->preview_window_id!=0){
		video_stream_set_native_preview_window_id(stream, stream->preview_window_id);
	}
	/* create the ticker */
	stream->ms.ticker = ms_ticker_new();
	ms_ticker_set_name(stream->ms.ticker,"Video MSTicker");
	ms_ticker_attach (stream->ms.ticker, stream->source);
}
Exemplo n.º 13
0
LinphoneSoundDaemon * linphone_sound_daemon_new(const char *cardname, int rate, int nchannels){
	int i;
	MSConnectionPoint mp;
	LinphoneSoundDaemon *lsd;
	MSSndCard *card=ms_snd_card_manager_get_card(
	                                             ms_snd_card_manager_get(),
	                                             cardname);
	if (card==NULL){
		card=ms_snd_card_manager_get_default_playback_card (
		                                                    ms_snd_card_manager_get());
		if (card==NULL){
			ms_error("linphone_sound_daemon_new(): No playback soundcard available");
			return NULL;
		}
	}
	
	lsd=ms_new0(LinphoneSoundDaemon,1);
	lsd->soundout=ms_snd_card_create_writer(card);
	lsd->mixer=ms_filter_new(MS_AUDIO_MIXER_ID);
	lsd->out_rate=rate;
	lsd->out_nchans=nchannels;
	ms_filter_call_method(lsd->soundout,MS_FILTER_SET_SAMPLE_RATE,&lsd->out_rate);
	ms_filter_call_method(lsd->soundout,MS_FILTER_SET_NCHANNELS,&lsd->out_nchans);
	ms_filter_call_method(lsd->mixer,MS_FILTER_SET_SAMPLE_RATE,&lsd->out_rate);
	ms_filter_call_method(lsd->mixer,MS_FILTER_SET_NCHANNELS,&lsd->out_nchans);

	mp.filter=lsd->mixer;
	mp.pin=0;

	lsd_player_init(&lsd->branches[0],mp,MS_ITC_SOURCE_ID,lsd);
	ms_filter_set_notify_callback(lsd->branches[0].player,(MSFilterNotifyFunc)lsd_player_configure,&lsd->branches[0]);
	ms_filter_enable_synchronous_notifcations (lsd->branches[0].player,TRUE);
	for(i=1;i<MAX_BRANCHES;++i){
		mp.pin=i;
		lsd_player_init(&lsd->branches[i],mp,MS_FILE_PLAYER_ID,lsd);
	}
	ms_filter_link(lsd->mixer,0,lsd->soundout,0);
	lsd->ticker=ms_ticker_new();
	ms_ticker_attach(lsd->ticker,lsd->soundout);

	lsd->proxycard=ms_snd_card_new(&proxycard);
	lsd->proxycard->data=lsd;
	ms_message("LinphoneSoundDaemon started with rate=%i, nchannels=%i",rate,nchannels);
	return lsd;
}
Exemplo n.º 14
0
RingStream * ring_start_with_cb(const char *file,int interval,MSSndCard *sndcard, MSFilterNotifyFunc func,void * user_data)
{
	RingStream *stream;
	int tmp;
	int srcrate,dstrate;
	MSConnectionHelper h;

	stream=(RingStream *)ms_new0(RingStream,1);
	stream->source=ms_filter_new(MS_FILE_PLAYER_ID);
	if (file)
		ms_filter_call_method(stream->source,MS_FILE_PLAYER_OPEN,(void*)file);
	
	ms_filter_call_method(stream->source,MS_FILE_PLAYER_LOOP,&interval);
	ms_filter_call_method_noarg(stream->source,MS_FILE_PLAYER_START);
	if (func!=NULL)
		ms_filter_set_notify_callback(stream->source,func,user_data);
	stream->gendtmf=ms_filter_new(MS_DTMF_GEN_ID);
	
	
	stream->sndwrite=ms_snd_card_create_writer(sndcard);
	ms_filter_call_method(stream->source,MS_FILTER_GET_SAMPLE_RATE,&srcrate);
	ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_SAMPLE_RATE,&srcrate);
	ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&srcrate);
	ms_filter_call_method(stream->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&dstrate);
	if (srcrate!=dstrate){
		stream->write_resampler=ms_filter_new(MS_RESAMPLE_ID);
		ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_SAMPLE_RATE,&srcrate);
		ms_filter_call_method(stream->write_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&dstrate);
		ms_message("configuring resampler from rate[%i] to rate [%i]", srcrate,dstrate);
	}
	ms_filter_call_method(stream->source,MS_FILTER_GET_NCHANNELS,&tmp);
	ms_filter_call_method(stream->gendtmf,MS_FILTER_SET_NCHANNELS,&tmp);
	ms_filter_call_method(stream->sndwrite,MS_FILTER_SET_NCHANNELS,&tmp);
	stream->ticker=ms_ticker_new();
	ms_ticker_set_name(stream->ticker,"Audio (ring) MSTicker");

	ms_connection_helper_start(&h);
	ms_connection_helper_link(&h,stream->source,-1,0);
	ms_connection_helper_link(&h,stream->gendtmf,0,0);
	if (stream->write_resampler)
		ms_connection_helper_link(&h,stream->write_resampler,0,0);
	ms_connection_helper_link(&h,stream->sndwrite,0,-1);
	ms_ticker_attach(stream->ticker,stream->source);
	return stream;
}
Exemplo n.º 15
0
void VodWnd::vod(const char *ip, int rtp_port, int rtcp_port)
{
    server_ip_ = ip;
    server_rtp_port_ = rtp_port;
    server_rtcp_port_ = rtcp_port;

    rtp_ = rtp_session_new(RTP_SESSION_RECVONLY);
    rtp_session_set_payload_type(rtp_, 100);
    rtp_session_set_local_addr(rtp_, util_get_myip(), 0, 0);
    rtp_session_set_remote_addr_and_port(rtp_, ip, rtp_port, rtcp_port);

    JBParameters jb;
    jb.adaptive = 1;
    jb.max_packets = 3000;
    jb.max_size = -1;
    jb.min_size = jb.nom_size = 300;
    rtp_session_set_jitter_buffer_params(rtp_, &jb);

    rtp_session_enable_jitter_buffer(rtp_, 0);

    evq_ = ortp_ev_queue_new();
    rtp_session_register_event_queue(rtp_, evq_);

    ticker_ = ms_ticker_new();

    filter_rtp_ = ms_filter_new(MS_RTP_RECV_ID);
    ms_filter_call_method(filter_rtp_, MS_RTP_RECV_SET_SESSION, rtp_);

    filter_decoder_ = ms_filter_new(MS_H264_DEC_ID);

    ZonekeyYUVSinkCallbackParam cbp;
    cbp.ctx = this;
    cbp.push = cb_yuv;
    filter_sink_ = ms_filter_new_from_name("ZonekeyYUVSink");
    ms_filter_call_method(filter_sink_, ZONEKEY_METHOD_YUV_SINK_SET_CALLBACK_PARAM, &cbp);

    ms_filter_link(filter_rtp_, 0, filter_decoder_, 0);
    ms_filter_link(filter_decoder_, 0, filter_sink_, 0);

    ms_ticker_attach(ticker_, filter_rtp_);
}
Exemplo n.º 16
0
int main()
{
	ms_init();

	MSFilter *source = get_source();
	MSFilter *render = get_render();

	ms_filter_link(source, 0, render, 0);

	MSTicker *ticker = ms_ticker_new();
	ms_ticker_attach(ticker, source);

	while (true) {
		ms_sleep(1);
	}

	ms_ticker_destroy(ticker);

	ms_filter_destroy(render);
	ms_filter_destroy(source);

	return 0;
}
Exemplo n.º 17
0
VideoStream * video_preview_start(MSWebCam *device){
	VideoStream *stream = (VideoStream *)ms_new0 (VideoStream, 1);
	MSPixFmt format;
	MSVideoSize vsize;
	vsize.width=MS_VIDEO_SIZE_CIF_W;
	vsize.height=MS_VIDEO_SIZE_CIF_H;

	/* creates the filters */
	stream->source = ms_web_cam_create_reader(device);
	stream->output = ms_filter_new(MS_VIDEO_OUT_ID);


	/* configure the filters */
	ms_filter_call_method(stream->source,MS_FILTER_GET_PIX_FMT,&format);
	ms_filter_call_method(stream->source,MS_FILTER_GET_VIDEO_SIZE,&vsize);
	
	if (format==MS_MJPEG){
		stream->pixconv=ms_filter_new(MS_MJPEG_DEC_ID);
	}else{
		stream->pixconv=ms_filter_new(MS_PIX_CONV_ID);
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_PIX_FMT,&format);
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	}

	format=MS_YUV420P;
	ms_filter_call_method(stream->output,MS_FILTER_SET_PIX_FMT,&format);
	ms_filter_call_method(stream->output,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	/* and then connect all */

	ms_filter_link(stream->source,0, stream->pixconv,0);
	ms_filter_link(stream->pixconv, 0, stream->output, 0);

	/* create the ticker */
	stream->ticker = ms_ticker_new(); 
	ms_ticker_attach (stream->ticker, stream->source);
	return stream;
}
Exemplo n.º 18
0
int video_stream_start (VideoStream *stream, RtpProfile *profile, const char *remip, int remport,
	int rem_rtcp_port, int payload, int jitt_comp, MSWebCam *cam)
{
	PayloadType *pt;
	RtpSession *rtps=stream->session;
	MSPixFmt format;
	MSVideoSize vsize;
	float fps=15;

	vsize.height=MS_VIDEO_SIZE_CIF_H;
	vsize.width=MS_VIDEO_SIZE_CIF_W;

	pt=rtp_profile_get_payload(profile,payload);
	if (pt==NULL){
		ms_error("videostream.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("videostream.c: No codecs available for payload %i:%s.",payload,pt->mime_type);
		return -1;
	}
	
	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);

	rtp_session_signal_connect(stream->session,"payload_type_changed",
			(RtpCallback)payload_type_changed,(unsigned long)stream);

	rtp_session_set_recv_buf_size(stream->session,MAX_RTP_SIZE);

	/* creates two rtp filters to recv send streams (remote part) */
	if (remport>0) ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_SET_SESSION,stream->session);
	
	stream->rtprecv = ms_filter_new (MS_RTP_RECV_ID);
	ms_filter_call_method(stream->rtprecv,MS_RTP_RECV_SET_SESSION,stream->session);

	/* creates the filters */
	stream->source = ms_web_cam_create_reader(cam);
	stream->tee = ms_filter_new(MS_TEE_ID);
	stream->output=ms_filter_new(MS_VIDEO_OUT_ID);
	stream->sizeconv=ms_filter_new(MS_SIZE_CONV_ID);
	
	if (pt->normal_bitrate>0){
		ms_message("Limiting bitrate of video encoder to %i bits/s",pt->normal_bitrate);
		ms_filter_call_method(stream->encoder,MS_FILTER_SET_BITRATE,&pt->normal_bitrate);
	}
	/* set parameters to the encoder and decoder*/
	if (pt->send_fmtp){
		ms_filter_call_method(stream->encoder,MS_FILTER_ADD_FMTP,pt->send_fmtp);
		ms_filter_call_method(stream->decoder,MS_FILTER_ADD_FMTP,pt->send_fmtp);
	}
	ms_filter_call_method(stream->encoder,MS_FILTER_GET_VIDEO_SIZE,&vsize);
	ms_filter_call_method(stream->encoder,MS_FILTER_GET_FPS,&fps);
	ms_message("Setting vsize=%ix%i, fps=%f",vsize.width,vsize.height,fps);
	/* configure the filters */
	ms_filter_call_method(stream->source,MS_FILTER_SET_FPS,&fps);
	ms_filter_call_method(stream->source,MS_FILTER_SET_VIDEO_SIZE,&vsize);

	/* get the output format for webcam reader */
	ms_filter_call_method(stream->source,MS_FILTER_GET_PIX_FMT,&format);
	if (format==MS_MJPEG){
		stream->pixconv=ms_filter_new(MS_MJPEG_DEC_ID);
	}else{
		stream->pixconv = ms_filter_new(MS_PIX_CONV_ID);
		/*set it to the pixconv */
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_PIX_FMT,&format);

		ms_filter_call_method(stream->source,MS_FILTER_GET_VIDEO_SIZE,&vsize);
	
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);
		  
	}

	ms_filter_call_method(stream->encoder,MS_FILTER_GET_VIDEO_SIZE,&vsize);
	ms_filter_call_method(stream->sizeconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);

	/*force the decoder to output YUV420P */
	format=MS_YUV420P;
	ms_filter_call_method(stream->decoder,MS_FILTER_SET_PIX_FMT,&format);


	/*ask the video display to always output CIF */
	vsize.height=MS_VIDEO_SIZE_CIF_H;
	vsize.width=MS_VIDEO_SIZE_CIF_W;

	ms_filter_call_method(stream->output,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	ms_filter_call_method(stream->output,MS_FILTER_SET_PIX_FMT,&format);

	if (pt->recv_fmtp!=NULL)
		ms_filter_call_method(stream->decoder,MS_FILTER_ADD_FMTP,(void*)pt->recv_fmtp);

	/* and then connect all */
	ms_filter_link (stream->source, 0, stream->pixconv, 0);
	ms_filter_link (stream->pixconv, 0, stream->sizeconv, 0);
	ms_filter_link (stream->sizeconv, 0, stream->tee, 0);
	ms_filter_link (stream->tee, 0 ,stream->encoder, 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->output, 0);
	/* the source video must be send for preview */
	ms_filter_link(stream->tee,1,stream->output,1);

	/* create the ticker */
	stream->ticker = ms_ticker_new(); 
	/* attach it the graph */
	ms_ticker_attach (stream->ticker, stream->source);
	return 0;
}
Exemplo n.º 19
0
Arquivo: rec.c Projeto: blueskycoco/hp
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);  
		}  
	}	
}
Exemplo n.º 20
0
int main(int argc, char *argv[]){
	MSFilter *src, *gen, *det, *rec;
	MSTicker *ticker;

	ms_base_init();
	ortp_set_log_level_mask (ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);

	src=ms_filter_new(MS_FILE_PLAYER_ID);
	rec=ms_filter_new(MS_FILE_REC_ID);
	gen=ms_filter_new(MS_DTMF_GEN_ID);
	det=ms_filter_new(MS_TONE_DETECTOR_ID);
	
	ms_filter_link(src,0,gen,0);
	ms_filter_link(gen,0,det,0);
	//ms_filter_link(gen,0,rec,0);
	ms_filter_link(det,0,rec,0);

	ticker=ms_ticker_new();

	ms_ticker_attach(ticker,src);

	ms_filter_call_method(rec,MS_FILE_REC_OPEN,"/tmp/output.wav");
	ms_filter_call_method_noarg(rec,MS_FILE_REC_START);
	{
		/*generate and detect the tones*/
		MSDtmfGenCustomTone tone;
		MSToneDetectorDef expected_tone;
		char dtmf='*';
			
		tone.frequency=2000;
		tone.duration=400;
		tone.amplitude=0.6;

		expected_tone.frequency=2000;
		expected_tone.min_duration=200;
		expected_tone.min_amplitude=0.5;
		ms_filter_set_notify_callback(det,(MSFilterNotifyFunc)tone_detected_cb,NULL);
		ms_filter_set_notify_callback(gen,(MSFilterNotifyFunc)tone_sent_cb,NULL);
		
		ms_filter_call_method(det,MS_TONE_DETECTOR_ADD_SCAN,&expected_tone);

		ms_filter_call_method(gen,MS_DTMF_GEN_PLAY,&dtmf);
		ms_sleep(1);
		
		ms_filter_call_method(gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
		ms_sleep(1);
		ms_filter_call_method(gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
		ms_sleep(1);
		ms_filter_call_method(gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
		ms_sleep(1);
		tone.frequency=1500;
		tone.amplitude=1.0;
		ms_filter_call_method(gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
		ms_sleep(1);
	}

	ms_filter_call_method_noarg(rec,MS_FILE_REC_CLOSE);
	ms_ticker_detach(ticker,src);

	ms_filter_unlink(src,0,gen,0);
	ms_filter_unlink(gen,0,det,0);
	//ms_filter_unlink(gen,0,rec,0);
	ms_filter_unlink(det,0,rec,0);

	ms_ticker_destroy(ticker);

	ms_filter_destroy(src);
	ms_filter_destroy(gen);
	ms_filter_destroy(det);
	ms_filter_destroy(rec);

	ms_base_exit();
	return 0;
}
Exemplo n.º 21
0
int main(int argc, char *argv[]){
	MSFilter *f1,*f2,*g729en,*g729de;
	MSSndCard *card_capture;
	MSSndCard *card_playback;
	MSTicker *ticker;
	char *capt_card=NULL,*play_card=NULL;
	int rate = 8000;
	int loop = -2;
	int i;
	const char *name="test.wav";
#ifdef __linux
	const char *alsadev=NULL;
#endif

	ortp_init();
	ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL);
	ms_init();

#ifndef _WIN32_WCE
	signal(SIGINT,stop);
#endif

#ifdef __linux
	alsadev=getenv("MS2_ALSADEV");
	if (alsadev!=NULL){
		ms_snd_card_manager_add_card(ms_snd_card_manager_get(),
			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],"--file-name")==0){
			i++;
			name=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_snd_card_manager_get(),capt_card);
	else card_capture = ms_snd_card_manager_get_default_capture_card(ms_snd_card_manager_get());
	if (play_card)
		card_playback = ms_snd_card_manager_get_card(ms_snd_card_manager_get(),play_card);
	else card_playback = ms_snd_card_manager_get_default_playback_card(ms_snd_card_manager_get());
	
	if (card_playback==NULL || card_capture==NULL){
		ms_error("No card.");
		return -1;
	}

	f1=ms_filter_new(MS_FILE_PLAYER_ID);
	f2=ms_snd_card_create_writer(card_playback);
	g729de=ms_filter_create_decoder("G729");
	ms_filter_call_method (f1, MS_FILTER_SET_SAMPLE_RATE,
		&rate);
	ms_filter_call_method (f2, MS_FILTER_SET_SAMPLE_RATE,
		&rate);
	ms_filter_call_method(g729de, MS_FILTER_SET_SAMPLE_RATE,
		&rate);
	ms_filter_call_method_noarg(f1,MS_FILE_PLAYER_CLOSE);
	ms_filter_call_method(f1,MS_FILE_PLAYER_OPEN,(void*)name);
	ms_filter_call_method_noarg(f1,MS_FILE_PLAYER_START);
	ms_filter_call_method(f1,MS_FILE_PLAYER_LOOP,&loop);
	ticker=ms_ticker_new();
	ms_filter_link(f1,0,g729de,0);
	ms_filter_link(g729de,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(g729de,0,f2,0);
	ms_filter_unlink(f1,0,g729de,0);
	ms_filter_destroy(f1);
	ms_filter_destroy(g729de);
	ms_filter_destroy(f2);
	return 0;
}
Exemplo n.º 22
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;
}
Exemplo n.º 23
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;
}
Exemplo n.º 24
0
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;
}
Exemplo n.º 25
0
int main(int argc, char **argv)
{
	ortp_init();
	ms_init();
	zk_xmpp_uac_init();
	ortp_set_log_level_mask(ORTP_MESSAGE);

	if (argc < 2) {
		fprintf(stderr, "usage: %s <zqpkt src url> [s]\n", argv[0]);
		return -1;
	}

	bool stream_mode = false;
	if (argc == 3 && argv[2][0] == 's')
		stream_mode = true;

	_stream_mode = stream_mode;

	if (stream_mode)
		fprintf(stdout, "=== STREAMING MODE ===\n\n");
	else
		fprintf(stdout, "=== SOURCING MODE ===\n\n");

	_url = argv[1];
	_env = CreateEvent(0, 0, 0, 0);

	fprintf(stdout, "%s: using zqpkt src '%s', just wait mcu .....\n", argv[0], argv[1]);

	// 使用 normaluser 登录
	cb_xmpp_uac cbs = { 0, 0, 0, 0, cb_connect_notify };
	_uac = zk_xmpp_uac_log_in(get_user_jid(), "ddkk1212", &cbs, 0);

	WaitForSingleObject(_env, 10000);

	if (_sid == -1) {
		fprintf(stderr, ":( somthing err, exit!\n");
	}
	else {
		SetConsoleCtrlHandler(signal_ctrl_c, 1);
		
		const char *src_url = argv[1];
		const char *target_ip = _ip.c_str();
		int target_port = _rtp_port;
		int target_port2 = _rtcp_port;

		//fprintf(stdout, "target ip=%s\ntarget port=%d\n\n", target_ip, target_port);

		// only support h264
		rtp_profile_set_payload(&av_profile,100, &payload_type_h264);

		/// 使用 zonekey.h264.source filter
		zonekey_h264_source_register();
		MSFilterDesc *desc = ms_filter_lookup_by_name("ZonekeyH264Source");
		MSFilter *source = ms_filter_new_from_desc(desc);

		if (_stream_mode)
			zonekey_yuv_sink_register();

		// 获取 writer_params
		ZonekeyH264SourceWriterParam writer_param;
		ms_filter_call_method(source, ZONEKEY_METHOD_H264_SOURCE_GET_WRITER_PARAM, &writer_param);

		// RTP Session
		RtpSession *rtpsess = rtp_session_new(RTP_SESSION_SENDRECV);	// 
		rtp_session_set_local_addr(rtpsess, "0.0.0.0", -1, -1);	// 随机端口
		rtp_session_set_remote_addr_and_port(rtpsess, target_ip, target_port, target_port2);
		rtp_session_set_payload_type(rtpsess, 100);	// h264

		JBParameters jb;
		jb.adaptive = 1;
		jb.max_packets = 3000;
		jb.max_size = -1;
		jb.min_size = jb.nom_size = 300;
		rtp_session_set_jitter_buffer_params(rtpsess, &jb);
	
		// disable video jitter control
		rtp_session_enable_jitter_buffer(rtpsess, 0);

		/// rtp sender
		MSFilter *rtp_sender = ms_filter_new(MS_RTP_SEND_ID);
		ms_filter_call_method(rtp_sender, MS_RTP_SEND_SET_SESSION, rtpsess);

		// connect source --> rtp sender
		ms_filter_link(source, 0, rtp_sender, 0);

		// MSTicker
		MSTicker *ticker = ms_ticker_new();

		// attach ticker
		ms_ticker_attach(ticker, source);

		if (_stream_mode) {
			// FIXME: recv, but ....
			MSFilter *rtp_recver = ms_filter_new(MS_RTP_RECV_ID);
			ms_filter_call_method(rtp_recver, MS_RTP_RECV_SET_SESSION, rtpsess);

			MSFilter *decoder = ms_filter_new(MS_H264_DEC_ID);
			MSFilter *sink = ms_filter_new_from_name("ZonekeyYUVSink");

			ms_filter_link(rtp_recver, 0, decoder, 0);
			ms_filter_link(decoder, 0, sink, 0);

			MSTicker *tk = ms_ticker_new();
			//ms_ticker_attach(tk, rtp_recver);
		}

		// 利用 libzqpkt 接收 h264 数据,并且调用 zonekey h264 source 的 writer() 
		void *zqp = 0;
		if (zqpsrc_open(&zqp, src_url) < 0) {
			fprintf(stderr, "to open src err\n");
			return -1;
		}

		while (!_quit) {
			zq_pkt *pkt = zqpsrc_getpkt(zqp);
			if (pkt) {
				if (pkt->type == 1) {
					// h264
					writer_param.write(writer_param.ctx, pkt->ptr, pkt->len, pkt->pts / 45000.0);
				}

				zqpsrc_freepkt(zqp, pkt);
			}
			else
				break;
		}

		// 发送删除 sid 的命令
		char options[128], *cmd="test.fc.del_source";
		if (_stream_mode) {
			snprintf(options, sizeof(options), "streamid=%d", _sid);
			cmd = "test.dc.del_stream";
		}
		else
			snprintf(options, sizeof(options), "sid=%d", _sid);

		zk_xmpp_uac_send_cmd(_uac, get_mcu_jid(), cmd, options, 0, cb_response);
		fprintf(stderr, "\n\nen. to del sid=%d\n\n", _sid);

		zqpsrc_close(zqp);
		fprintf(stderr, "END!\n");

		WaitForSingleObject(_env, 3000);	// 等待 test.fc.de_source 发送成功
	}

	return 0;
}
Exemplo n.º 26
0
int main(int argc, char **argv)
{
	if (argc != 2) {
		fprintf(stderr, "usage: %s <url>\n", argv[0]);
		exit(-1);
	}

	bool webcam = false;
	const char *url = argv[1];
	if (!strcmp("webcam://localhost", url)) {
		if (!zkmcu_hlp_webcam_exist()) {
			fprintf(stderr, "NOT found local webcam!\n");
			return -1;
		}

		webcam = true;
	}

	ms_init();
	ortp_init();
	zonekey_h264_source_register();
	zonekey_yuv_sink_register();

	ZonekeyYUVSinkCallbackParam yuvcb;
	yuvcb.ctx = 0;
	yuvcb.push = cb_yuv;

#if SIMPLE 
	//MSFilter *f_source = build_simple_chain(&yuvcb);
	MSFilter *f_source = build_sender_chain("172.16.1.104", 50000);
	MSTicker *ticker = ms_ticker_new();
	
	ms_ticker_attach(ticker, f_source);
#else
	/**    source --> rtp sender ====> rtp recver --> decoder --> sink
	 */
	MSFilter *f_source = build_sender_chain();
	MSFilter *f_sink = build_recver_chain();

	MSTicker *ticker_send = ms_ticker_new(), *ticker_recv = ms_ticker_new();
	ms_ticker_attach(ticker_send, f_source), ms_ticker_attach(ticker_recv, f_sink);

#endif
	ZonekeyH264SourceWriterParam source_param;
	ms_filter_call_method(f_source, ZONEKEY_METHOD_H264_SOURCE_GET_WRITER_PARAM, &source_param);

	if (webcam) {
		zkmcu_hlp_webcam_t *cam = zkmcu_hlp_webcam_open(1024, 768, 5.0, 100);
		for (;; ) {
			const void *data;
			int len;
			double stamp;

			len = zkmcu_hlp_webcam_get_h264(cam, &data, &stamp);
			if (len > 0) {
				source_param.write(source_param.ctx, data, len, stamp);
			}
		}
	}
	else {
		void *zqp = 0;
		if (zqpsrc_open(&zqp, url) < 0) {
			fprintf(stderr, "can't open url='%s'\n", url);
			exit(-2);
		}

		zq_pkt *pkt = zqpsrc_getpkt(zqp);
		while (pkt) {
			if (pkt->type == 1) {
				// 视频
				source_param.write(source_param.ctx, pkt->ptr, pkt->len, pkt->pts/45000.0);
			}

			zqpsrc_freepkt(zqp, pkt);
			pkt = zqpsrc_getpkt(zqp);
		}
	}
	return 0;
}
Exemplo n.º 27
0
void CameraStream::init()
{
	/** 获取第一帧图像,初始化 sws_,创建 h264 encoder ....
	 */
	IplImage *img = cvQueryFrame(cap_);
	// FIXME: 未必是 rgb24 吧???
	sws_ = sws_getContext(img->width, img->height, PIX_FMT_RGB24, WIDTH, HEIGHT, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, 0, 0, 0);

	x264_param_t param;
	x264_param_default_preset(&param, "veryfast", "zerolatency");
	param.i_threads = 0;
	param.i_width = WIDTH;
	param.i_height = HEIGHT;
	param.i_keyint_max = FPS * 2;
	param.i_fps_den = 1;
	param.i_fps_num = FPS;
	param.i_slice_max_size = 1300;
	param.b_repeat_headers = 1;
	param.b_annexb = 1;
	param.rc.i_rc_method = X264_RC_ABR;
	param.rc.i_bitrate = KBPS;
	param.rc.i_vbv_max_bitrate = KBPS*1.1;
		
	encoder_ = x264_encoder_open(&param);

	avpicture_alloc(&pic_, PIX_FMT_YUV420P, WIDTH, HEIGHT);

	rtp_ = rtp_session_new(RTP_SESSION_SENDRECV);
	rtp_session_set_payload_type(rtp_, 100);
	rtp_session_set_remote_addr_and_port(rtp_, server_ip_.c_str(), server_rtp_port_, server_rtcp_port_);
	rtp_session_set_local_addr(rtp_, util_get_myip(), 0, 0);
	JBParameters jb;
	jb.adaptive = 1;
	jb.max_packets = 500;
	jb.max_size = -1;
	jb.min_size = jb.nom_size = 300;
	rtp_session_set_jitter_buffer_params(rtp_, &jb);

	filter_rtp_sender_ = ms_filter_new(MS_RTP_SEND_ID);
	ms_filter_call_method(filter_rtp_sender_, MS_RTP_SEND_SET_SESSION, rtp_);

	filter_h264_sender_ = ms_filter_new_from_name("ZonekeyH264Source");
	ms_filter_call_method(filter_h264_sender_, ZONEKEY_METHOD_H264_SOURCE_GET_WRITER_PARAM, &sender_params_);

	filter_rtp_recver_ = ms_filter_new(MS_RTP_RECV_ID);
	ms_filter_call_method(filter_rtp_recver_, MS_RTP_RECV_SET_SESSION, rtp_);

	filter_decoder_ = ms_filter_new(MS_H264_DEC_ID);

	filter_yuv_sink_ = ms_filter_new_from_name("ZonekeyYUVSink");
	// TODO: 显示 ...

	ms_filter_link(filter_rtp_recver_, 0, filter_decoder_, 0);
	ms_filter_link(filter_decoder_, 0, filter_yuv_sink_, 0);

	ticker_recver_ = ms_ticker_new();
	ms_ticker_attach(ticker_recver_, filter_rtp_recver_);

	ms_filter_link(filter_h264_sender_, 0, filter_rtp_sender_, 0);

	ticker_sender_ = ms_ticker_new();
	ms_ticker_attach(ticker_sender_, filter_h264_sender_);
}
Exemplo n.º 28
0
void conf_stream_start(LinphoneConferenceStream *stream,bool_t video_monitor)
{
	bool_t ptt = stream->ptt_mode;
	int tmp;

	{
		stream->audio_ticker = ms_ticker_new();
		ms_cond_init(&stream->audio_ticker->cond,NULL);
		ms_ticker_set_name(stream->audio_ticker,"Audio Mixer MSTicker");

		stream->audio_mixer = ms_filter_new(MS_CONF_ID);
		stream->audio_filerecorder = ms_filter_new(MS_FILE_REC_ID);
		stream->audio_fileplayer = ms_filter_new(MS_FILE_PLAYER_ID);


		ms_filter_call_method(stream->audio_mixer,MS_FILTER_SET_SAMPLE_RATE,&stream->sample_rate);
		ms_filter_call_method (stream->audio_fileplayer , MS_FILTER_SET_SAMPLE_RATE,&stream->sample_rate);
		tmp = 1; /*默认采用单声道会议*/
		ms_filter_call_method (stream->audio_fileplayer , MS_FILTER_SET_NCHANNELS,&tmp);
		/*设置会议音频采样率,8k,16k,32k*/
		ms_filter_call_method(stream->audio_filerecorder,MS_FILTER_SET_SAMPLE_RATE,&stream->sample_rate);

		ms_message("Link audio filter list!!!");

		/*创建录制端口*/
		{
			int audio_mixer_pin = NB_AUDIO_MAX_OUPUT_PINS-2;
			stream->audio_record_sink = ms_filter_new(MS_CONF_ITC_SINK_ID);

			ms_filter_link(stream->audio_mixer,audio_mixer_pin,stream->audio_record_sink,0); 
		}

		{/*创建音频对接端口*/
			int max_ports = stream->max_ports;
			for(int i=0; i< max_ports; i++)
			{
				ConfAudioPort *port = audio_slot_new();
				audio_slot_init(port,i);

				stream->audio_ports = ms_list_append(stream->audio_ports, port);

				/*顺序连接音频对接端口*/
				ms_filter_link(port->audio_itc_source,0,stream->audio_mixer,i);// <--- call[i].sink <--- call[i].decode <--- call[i].rtp_recv
				ms_filter_link(stream->audio_mixer,i,port->audio_itc_sink,0);  // ---> call[i].itc_source --->call[i].encode --->call[i].rtp_send

			}

			/*将音频播放,及录制连接至最末端端口*/
			ms_filter_link(stream->audio_fileplayer,0,stream->audio_mixer,stream->max_ports);
			ms_filter_link(stream->audio_mixer,stream->max_ports,stream->audio_filerecorder,0);
		}

		/*启动音频mixer线程*/
		ms_ticker_attach(stream->audio_ticker,stream->audio_mixer);
	}


	if(stream->has_video)
	{
		ms_message("Link video filter list!!!");

		MSPixFmt format=MS_YUV420P;
		MSVideoSize vsize,cam_vsize,disp_size;
		stream->video_mixer=ms_filter_new_from_name("MSVideoMixer");

		if(stream->video_mixer==NULL){
			ms_error("Not have MSVideoStitcher, Can't to Video Conference!!!");
			return;
		}

		stream->video_ticker = ms_ticker_new();
		ms_cond_init(&stream->video_ticker->cond,NULL);
		
		ms_ticker_set_name(stream->video_ticker,"Video Mixer MSTicker");
		/*设置视频会议的输出尺寸*/
		ms_filter_call_method(stream->video_mixer,MS_FILTER_SET_VIDEO_SIZE,&stream->sent_vsize);
		/*添加服务器端视频监视,可添加jpeg画面截取filer,用于web端实时会议的画面截取*/
		if(video_monitor) stream->video_output=ms_filter_new_from_name (stream->display_name);

		/*配置监视器*/
		if(stream->video_output!=NULL){
			disp_size = stream->sent_vsize;
			tmp=1;
			ms_filter_call_method(stream->video_output,MS_FILTER_SET_VIDEO_SIZE,&disp_size);
			ms_filter_call_method(stream->video_output,MS_VIDEO_DISPLAY_ENABLE_AUTOFIT,&tmp);
			ms_filter_call_method(stream->video_output,MS_FILTER_SET_PIX_FMT,&format);

			/*在已有窗口上绘图,或创建新window*/
			if (stream->video_window_id!=0)
				ms_filter_call_method(stream->video_output, MS_VIDEO_DISPLAY_SET_NATIVE_WINDOW_ID,&stream->video_window_id);
		
			/*设置服务器端 视频监视filter,将其连接至视频Mixer输出最后的端口上*/
			ms_filter_link (stream->video_mixer,VIDEO_MIXER_MAX_OUTPUTS-1, stream->video_output, 0);
		}

		/*输出录制端口*/
		{
			int video_mixer_pin = VIDEO_MIXER_MAX_OUTPUTS-2;
			stream->video_record_sink = ms_filter_new(MS_CONF_ITC_SINK_ID);
			ms_filter_link(stream->video_mixer,video_mixer_pin,stream->video_record_sink,0); 
		}

		/*创建无信号输出时,显示的图片*/
		stream->video_static_image = ms_web_cam_create_reader(get_image_webcam_device());
		
		if(stream->static_image_path!=NULL)
			ms_filter_call_method(stream->video_static_image, MS_STATIC_IMAGE_SET_IMAGE,(void *)stream->static_image_path);

		ms_filter_call_method(stream->video_static_image, MS_FILTER_SET_FPS,&stream->fps);
		ms_filter_call_method(stream->video_static_image,MS_FILTER_SET_VIDEO_SIZE,&stream->sent_vsize);

		/*并行输出至所有视频端口*/
		stream->video_static_image_tee = ms_filter_new(MS_TEE_ID);

		ms_filter_link (stream->video_static_image, 0, stream->video_static_image_tee, 0);

		/*最大视频端口,需小于视频Mixer最大布局数,当前最大为 9 画面*/
		int max_ports = (stream->max_ports > NB_MAX_VIDEO_LAYOUT)? NB_MAX_VIDEO_LAYOUT:stream->max_ports;
		int static_pic_index=0;

		/*创建端口连接插座*/
		for(int i=0; i<max_ports; i++)
		{
			ConfVideoPort *port = video_slot_new();
			video_slot_init(port,i);
			stream->video_ports = ms_list_append(stream->video_ports, port);

			/**
			* 视频采集输入源 和 静态图片 同时 join 至mixer的输入端口,
			* 当视频流有效时需MUTE 静态图片的输入,反之则输入静态图片
			*
			* video_input -------> join ------> mixer ----> video_output
			*                       |  
			* static_pic  ----------+
			*
			**/

			ms_filter_link (port->video_itc_source, 0, port->video_input_join,0);
			ms_filter_link (stream->video_static_image_tee, static_pic_index++, port->video_input_join,1);

			/*自动布局模式下除了0号端口外,均不输出静态图片*/
			if(stream->auto_layout && (static_pic_index > 0)){
				ms_filter_call_method(stream->video_static_image_tee,MS_TEE_MUTE,&static_pic_index);
			}

			ms_filter_link (port->video_input_join, 0, stream->video_mixer,i);
			ms_filter_link (stream->video_mixer,i, port->video_itc_sink,0);
		}

		ms_ticker_attach(stream->video_ticker,stream->video_mixer);
	}

}
Exemplo n.º 29
0
int video_stream_send_only_start(VideoStream* stream, RtpProfile *profile, const char *remip, int remport,
	int rem_rtcp_port, int payload, int jitt_comp, MSWebCam *device){
	PayloadType *pt;
	MSPixFmt format;
	MSVideoSize vsize;
	RtpSession *rtps=stream->session;
	float fps=15;
	
	vsize.width=MS_VIDEO_SIZE_CIF_W;
	vsize.height=MS_VIDEO_SIZE_CIF_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);
	
	/* creates rtp filter to send streams (remote part) */
	rtp_session_set_recv_buf_size(rtps,MAX_RTP_SIZE);
	stream->rtpsend =ms_filter_new(MS_RTP_SEND_ID);
	if (remport>0) ms_filter_call_method(stream->rtpsend,MS_RTP_SEND_SET_SESSION,stream->session);

	/* creates the filters */
	pt=rtp_profile_get_payload(profile,payload);
	if (pt==NULL){
		video_stream_free(stream);
		ms_error("videostream.c: undefined payload type.");
		return -1;
	}
	stream->encoder=ms_filter_create_encoder(pt->mime_type);
	if ((stream->encoder==NULL)){
		/* big problem: we have not a registered codec for this payload...*/
		video_stream_free(stream);
		ms_error("videostream.c: No codecs available for payload %i.",payload);
		return -1;
	}

	/* creates the filters */
	stream->source = ms_web_cam_create_reader(device);
	stream->sizeconv=ms_filter_new(MS_SIZE_CONV_ID);

	/* configure the filters */
	if (pt->send_fmtp)
		ms_filter_call_method(stream->encoder,MS_FILTER_ADD_FMTP,pt->send_fmtp);
	ms_filter_call_method(stream->encoder,MS_FILTER_SET_BITRATE,&pt->normal_bitrate);
	ms_filter_call_method(stream->encoder,MS_FILTER_GET_FPS,&fps);
	ms_filter_call_method(stream->encoder,MS_FILTER_GET_VIDEO_SIZE,&vsize);

	ms_filter_call_method(stream->source,MS_FILTER_SET_FPS,&fps);
	ms_filter_call_method(stream->source,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	
	/* get the output format for webcam reader */
	ms_filter_call_method(stream->source,MS_FILTER_GET_PIX_FMT,&format);
	/*set it to the pixconv */

	/* bug fix from AMD: What about MJPEG mode???*/
	if (format==MS_MJPEG){
		stream->pixconv=ms_filter_new(MS_MJPEG_DEC_ID);
	}else{
		stream->pixconv=ms_filter_new(MS_PIX_CONV_ID);
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_PIX_FMT,&format);

		ms_filter_call_method(stream->source,MS_FILTER_GET_VIDEO_SIZE,&vsize);
		ms_filter_call_method(stream->pixconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	}

	ms_filter_call_method(stream->encoder,MS_FILTER_GET_VIDEO_SIZE,&vsize);
	ms_filter_call_method(stream->sizeconv,MS_FILTER_SET_VIDEO_SIZE,&vsize);
	
	ms_message("vsize=%ix%i, fps=%f, send format: %s, capture format: %d, bitrate: %d",
			vsize.width,vsize.height,fps,pt->send_fmtp,format, pt->normal_bitrate);

	/* and then connect all */
	ms_filter_link (stream->source, 0, stream->pixconv, 0);
	ms_filter_link (stream->pixconv, 0, stream->sizeconv, 0);
	ms_filter_link (stream->sizeconv, 0, stream->encoder, 0);
	ms_filter_link (stream->encoder,0, stream->rtpsend,0);

	/* create the ticker */
	stream->ticker = ms_ticker_new(); 
	/* attach it the graph */
	ms_ticker_attach (stream->ticker, stream->source);
	return 0;
}
Exemplo n.º 30
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);

}