标签:CONTROL PLAY fLiveSource H264 RTSP LiveServerMediaSubsession playCtrlInfo 多线程 参数
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
标签:CONTROL,PLAY,fLiveSource,H264,RTSP,LiveServerMediaSubsession,playCtrlInfo,多线程,参数 来源: https://www.cnblogs.com/TSINGSEE/p/11677708.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。