⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videostream.c

📁 基于osip、eXosip、speex、ffmpeg的VoIP源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	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;}void video_stream_send_vfu(VideoStream *stream){	if (stream->encoder)		ms_filter_call_method_noarg(stream->encoder,MS_FILTER_REQ_VFU);}voidvideo_stream_stop (VideoStream * stream){	if (stream->ticker){		ms_ticker_detach(stream->ticker,stream->source);			rtp_stats_display(rtp_session_get_stats(stream->session),"Video session's RTP statistics");				ms_filter_unlink(stream->source,0,stream->pixconv,0);		ms_filter_unlink (stream->pixconv, 0, stream->sizeconv, 0);		ms_filter_unlink (stream->sizeconv, 0, stream->tee, 0);		ms_filter_unlink(stream->tee,0,stream->encoder,0);		ms_filter_unlink(stream->encoder, 0, stream->rtpsend,0);		ms_filter_unlink(stream->rtprecv, 0, stream->decoder, 0);		ms_filter_unlink(stream->decoder,0,stream->output,0);		ms_filter_unlink(stream->tee,1,stream->output,1);	}	video_stream_free (stream);}void video_stream_set_rtcp_information(VideoStream *st, const char *cname, const char *tool){	if (st->session!=NULL){		rtp_session_set_source_description(st->session,cname,NULL,NULL,NULL,NULL,tool,											"This is free software (GPL) !");	}}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;}void video_preview_stop(VideoStream *stream){	ms_ticker_detach(stream->ticker, stream->source);	ms_filter_unlink(stream->source,0,stream->pixconv,0);	ms_filter_unlink(stream->pixconv,0,stream->output,0);		video_stream_free(stream);}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;}void video_stream_send_only_stop(VideoStream *stream){	if (stream->ticker){		ms_ticker_detach (stream->ticker, stream->source);		ms_filter_unlink(stream->source,0,stream->pixconv,0);		ms_filter_unlink (stream->pixconv, 0, stream->sizeconv, 0);		ms_filter_unlink (stream->sizeconv, 0, stream->encoder, 0);		ms_filter_unlink(stream->encoder,0,stream->rtpsend,0);	}	video_stream_free(stream);}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;}void video_stream_recv_only_stop (VideoStream * stream){	if (stream->ticker!=NULL){		ms_ticker_detach(stream->ticker, stream->rtprecv);		rtp_stats_display(rtp_session_get_stats(stream->session),"Video session's RTP statistics");		ms_filter_unlink(stream->rtprecv, 0, stream->decoder, 0);		ms_filter_unlink(stream->decoder,0,stream->output,0);	}	video_stream_free (stream);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -