支持H264、H265视频编码的多线程RTSP-Server组件EasyRTSPServer支持回放控制参数设置参考

RTSP协议以客户服务器方式工作,它是一个多媒体播放控制协议,用来使用户在播放从因特网下载的实时数据时能够进行控制,如:暂停/继续、后退、前进等。因此 RTSP 又称为“因特网录像机遥控协议”。

EasyRTSPServer是一套稳定、高效、可靠、多平台支持的RTSP-Server组件, 接口调用非常简单成熟,无需关注RTSPServer中关于客户端监听接入、音视频多路复用、RTSP具体流程、RTP打包与发送等相关问题,支持多种音视频格式,再也不用去处理整个RTSP OPTIONS/DESCRIBE/SETUP/PLAY/RTP/RTCP的复杂流程和担心内存释放的问题了,非常适合于安防领域、教育领域、互联网直播领域等。

EasyRTSPServer支持回放控制

提出问题

EasyRTSPServer 用于集成在NVR时,实时流可通过回调URL让上层应用去拉流再转发就可以了,是否可以让其也支持回放流呢? 答案是肯定的。

分析问题

EasyRTSPServer基于live555改造而来,在live555官方代码中就已支持回放控制,只是控制部分需要改成我们自己实现的部分,将控制消息通过回调函数回调出来。

解决问题

参考代码如下:

#include "LiveServerMediaSubsession.h"

LiveServerMediaSubsession::LiveServerMediaSubsession(UsageEnvironment& env, LiveSource *LiveSource, char *streamName, char *mediaTypeName, unsigned estimatedBitrate, RTSP_MEDIA_INFO_T *mediainfo, Boolean reuseFirstSource, unsigned int mediaType, portNumBits defaultPort)
  : OnDemandServerMediaSubsession(env, reuseFirstSource /*reuse the first source*/, streamName, mediaTypeName, defaultPort, false),
    fLiveSource(LiveSource), mMediaInfo(mediainfo), mMediaType(mediaType)
{
  //fEstimatedKbps = (estimatedBitrate + 500)/1000;

	fEstimatedKbps = estimatedBitrate;
}

LiveServerMediaSubsession::~LiveServerMediaSubsession() {
}

void LiveServerMediaSubsession::getAbsoluteTimeRange(char*& absStartTime, char*& absEndTime)// const
{
	absStartTime = absEndTime = NULL;
	//20100929T095038.00Z-20100929T102038.00Z

	RTSPSvrCallBack	pCallback = (RTSPSvrCallBack )fLiveSource->mCallbackPtr;
	if (NULL == pCallback)		return;
	
	RTSP_PLAY_CONTROL_INFO_T	durationCtlInfo;
	memset(&durationCtlInfo, 0x00, sizeof(RTSP_PLAY_CONTROL_INFO_T));
	durationCtlInfo.ctrlCommand = RTSP_PLAY_CTRL_CMD_GET_DURATION;
	durationCtlInfo.mediaType = mMediaType;

	if (fLiveSource->GetFlag() != LIVE_FLAG)	return;

	pCallback(RTSP_CHANNEL_PLAY_CONTROL, fLiveSource->channelName, &fLiveSource->mChannelHandle, fLiveSource->mMediaInfoPtr, &durationCtlInfo, fLiveSource->mUserPtr, (void *)fLiveSource->mChannelUserPtr);

	if ( (int)strlen((char *)durationCtlInfo.startTime) > 0 )
	{
		absStartTime = (char *)durationCtlInfo.startTime;
	}

	if ( (int)strlen((char *)durationCtlInfo.endTime) > 0 )
	{
		absEndTime = (char *)durationCtlInfo.endTime;
	}
}


//pause play
void	LiveServerMediaSubsession::pauseStreamSource()
{
	RTSPSvrCallBack	pCallback = (RTSPSvrCallBack )fLiveSource->mCallbackPtr;
	if (NULL == pCallback)			return;

	RTSP_PLAY_CONTROL_INFO_T	playCtrlInfo;
	memset(&playCtrlInfo, 0x00, sizeof(RTSP_PLAY_CONTROL_INFO_T));
	playCtrlInfo.ctrlCommand = RTSP_PLAY_CTRL_CMD_PAUSE;
	playCtrlInfo.mediaType = mMediaType;

	pCallback(RTSP_CHANNEL_PLAY_CONTROL, fLiveSource->channelName, &fLiveSource->mChannelHandle, fLiveSource->mMediaInfoPtr, &playCtrlInfo, fLiveSource->mUserPtr, (void *)fLiveSource->mChannelUserPtr);
}

//Resume play
void  LiveServerMediaSubsession::resumeStreamSource()
{
	RTSPSvrCallBack	pCallback = (RTSPSvrCallBack )fLiveSource->mCallbackPtr;
	if (NULL == pCallback)			return;

	RTSP_PLAY_CONTROL_INFO_T	playCtrlInfo;
	memset(&playCtrlInfo, 0x00, sizeof(RTSP_PLAY_CONTROL_INFO_T));
	playCtrlInfo.ctrlCommand = RTSP_PLAY_CTRL_CMD_RESUME;
	playCtrlInfo.mediaType = mMediaType;

	pCallback(RTSP_CHANNEL_PLAY_CONTROL, fLiveSource->channelName, &fLiveSource->mChannelHandle, fLiveSource->mMediaInfoPtr, &playCtrlInfo, fLiveSource->mUserPtr, (void *)fLiveSource->mChannelUserPtr);
}


void LiveServerMediaSubsession::testScaleFactor(float& scale)
{
	if ( (scale >= 1.0000000f && scale <= 32.00000000f) ||
		 (scale >= 0.0312500f && scale<=0.500000000f)  ||
		 (scale >= -32.00000000f && scale <= 0.00000000f) )
	{
		return;
	}
	else
	{
		scale = 1.0f;
	}
}

void LiveServerMediaSubsession::setStreamSourceScale(FramedSource* inputSource, float scale)
{
	RTSPSvrCallBack	pCallback = (RTSPSvrCallBack )fLiveSource->mCallbackPtr;
	if (NULL == pCallback)			return;

	RTSP_PLAY_CONTROL_INFO_T	playCtrlInfo;
	memset(&playCtrlInfo, 0x00, sizeof(RTSP_PLAY_CONTROL_INFO_T));
	playCtrlInfo.ctrlCommand = RTSP_PLAY_CTRL_CMD_SCALE;
	playCtrlInfo.mediaType = mMediaType;
	playCtrlInfo.scale = scale;

	pCallback(RTSP_CHANNEL_PLAY_CONTROL, fLiveSource->channelName, &fLiveSource->mChannelHandle, fLiveSource->mMediaInfoPtr, &playCtrlInfo, fLiveSource->mUserPtr, (void *)fLiveSource->mChannelUserPtr);
}

void LiveServerMediaSubsession::seekStreamSource(FramedSource* inputSource, char*& absStart, char*& absEnd)
{
	RTSPSvrCallBack	pCallback = (RTSPSvrCallBack )fLiveSource->mCallbackPtr;
	if (NULL == pCallback)			return;

	RTSP_PLAY_CONTROL_INFO_T	playCtrlInfo;
	memset(&playCtrlInfo, 0x00, sizeof(RTSP_PLAY_CONTROL_INFO_T));
	playCtrlInfo.ctrlCommand = RTSP_PLAY_CTRL_CMD_SEEK_STREAM;
	playCtrlInfo.mediaType = mMediaType;
	if (NULL!=absStart && ((int)strlen(absStart)>0))		strcpy((char*)playCtrlInfo.startTime, absStart);
	if (NULL!=absEnd && ((int)strlen(absEnd)>0))		strcpy((char*)playCtrlInfo.endTime, absStart);

	pCallback(RTSP_CHANNEL_PLAY_CONTROL, fLiveSource->channelName, &fLiveSource->mChannelHandle, fLiveSource->mMediaInfoPtr, &playCtrlInfo, fLiveSource->mUserPtr, (void *)fLiveSource->mChannelUserPtr);
}


#if 0
void LiveServerMediaSubsession::seekStreamSource(FramedSource* inputSource, double& seekNPT, double streamDuration, u_int64_t& numBytes)
{
	printf("LiveServerMediaSubsession::seekStreamSource  seekNPT[%s]  absEnd[%.2f]\n", seekNPT, streamDuration);
}
void LiveServerMediaSubsession::seekStreamSource(FramedSource* inputSource, char*& absStart, char*& absEnd)
{
	printf("LiveServerMediaSubsession::seekStreamSource  absStart[%s]  absEnd[%s]\n", absStart, absEnd);
}

void LiveServerMediaSubsession::setStreamSourceDuration(FramedSource* inputSource, double streamDuration, u_int64_t& numBytes)
{
	printf("LiveServerMediaSubsession::setStreamSourceDuration  streamDuration: %.2f\n", streamDuration);
}

void LiveServerMediaSubsession::closeStreamSource(FramedSource* inputSource)
{

	printf("LiveServerMediaSubsession::closeStreamSource\n");
}
#endif

 

posted on 2019-10-15 14:59  TSINGSEE  阅读(760)  评论(0)    收藏  举报