让EasyDarwin只支持RTP over TCP传输
我们经常需要EasyDarwin服务器支持公网流媒体传输,但很多时候,播放器默认都是通过RTP over UDP的形式在RTSP SETUP中请求,往往都以在内网接收不到UDP数据失败结束,那么我们如何使EasyDarwin将客户端的RTP over UDP自动切换成RTP over TCP形式呢,如下方法亲测可用:
在EasyDarwin的RTSPSession::SetupRequest()方法中插入以下代码:
// // If we don't have an RTP session yet, create one... if (fRTPSession == NULL) { theErr = this->CreateNewRTPSession(theMap); if (theErr != QTSS_NoErr) return;
} if (fRequest->GetMethod() == qtssSetupMethod) { if(fRequest->GetTransportType() != qtssRTPTransportTypeTCP) { (void)QTSSModuleUtils::SendErrorResponse(fRequest, qtssClientUnsupportedTransport, 0); return; }
} OSMutexLocker locker(fRTPSession->GetMutex()); UInt32 headerBits = fRequest->GetBandwidthHeaderBits(); if (headerBits != 0) (void)fRTPSession->SetValue(qtssCliSessLastRTSPBandwidth, 0,&headerBits,sizeof(headerBits), QTSSDictionary::kDontObeyReadOnly ); |
这样,在客户端发送SETUP的时候,服务器检查是否为RTP over TCP模式,如果不是,返回461 qtssClientUnsupportedTransport,标准客户端,如VLC、ffplay都支持此返回码!
同时,还有一个地方需要修改,保证EasyDarwin返回461后,不会把当前连接断开,代码在QTSSModuleUtils::SendErrorResponse中加入如下:
QTSS_Error QTSSModuleUtils::SendErrorResponse( QTSS_RTSPRequestObject inRequest, QTSS_RTSPStatusCode inStatusCode, QTSS_AttributeID inTextMessage, StrPtrLen* inStringArg) { static Bool16 sFalse = false; //set RTSP headers necessary for this error response message (void)QTSS_SetValue(inRequest, qtssRTSPReqStatusCode, 0, &inStatusCode, sizeof(inStatusCode)); if(inStatusCode != qtssClientUnsupportedTransport) (void)QTSS_SetValue(inRequest, qtssRTSPReqRespKeepAlive, 0, &sFalse, sizeof(sFalse)); StringFormatter theErrorMsgFormatter(NULL, 0); char *messageBuffPtr = NULL; |
本文转自www.easydarwin.org,更多开源流媒体解决方案,请关注我们的微信:EasyDarwin