项目要求使用RTSP协议进行点播直播,
找了很多开源流媒体服务器,最后决定使用Drawin做服务器。
但是在部署中发现,Drawin不支持Client在NAT后面的情况。 尽管RTSP Client已经发出了RTSP的打洞包。
还好, Darwin 是开源的 ,直接上手修改代码。
其实修改的部分很少,也很简单。
就是RTPStream.cpp
RTPStream::Write 方法
现实修改RTCP部分
if ( fTransportType == qtssRTPTransportTypeTCP )// write out in interleave format on the RTSP TCP channel { err = this->InterleavedWrite( thePacket->packetData, inLen, outLenWritten, fRTCPChannel ); } else if ( inLen > 0 ) { (void)fSockets->GetSocketB()->SendTo(fRemoteAddr, fRemoteRTCPPort, thePacket->packetData, inLen); }
修改为
if ( fTransportType == qtssRTPTransportTypeTCP )// write out in interleave format on the RTSP TCP channel { err = this->InterleavedWrite( thePacket->packetData, inLen, outLenWritten, fRTCPChannel ); } else if ( inLen > 0 ) { UInt32 iRemoteAddr=0; UInt16 iRemotePort=0; char szBuff[64]; UInt32 iBufLen=sizeof(szBuff); UInt32 iRecvLen=0; (void)fSockets->GetSocketB()->RecvFrom(&iRemoteAddr,&iRemotePort,szBuff,iBufLen,&iRecvLen); if (iRemoteAddr==fRemoteAddr &&iRemotePort!=0 &&iRecvLen>0) { fRemoteRTCPPort=iRemotePort; } (void)fSockets->GetSocketB()->SendTo(fRemoteAddr, fRemoteRTCPPort, thePacket->packetData, inLen); }
以类似的方法修改RTP的发送部分
if ( fTransportType == qtssRTPTransportTypeTCP ) // write out in interleave format on the RTSP TCP channel err = this->InterleavedWrite( thePacket->packetData, inLen, outLenWritten, fRTPChannel ); else if ( fTransportType == qtssRTPTransportTypeReliableUDP ) err = this->ReliableRTPWrite( thePacket->packetData, inLen, theCurrentPacketDelay ); else if ( inLen > 0 ) (void)fSockets->GetSocketA()->SendTo(fRemoteAddr, fRemoteRTPPort, thePacket->packetData, inLen);