diff --git a/src/decoder/gb28181/rtp2/RTPReceiver2.cpp b/src/decoder/gb28181/rtp2/RTPReceiver2.cpp index 66e4f93..d53b1c6 100644 --- a/src/decoder/gb28181/rtp2/RTPReceiver2.cpp +++ b/src/decoder/gb28181/rtp2/RTPReceiver2.cpp @@ -56,7 +56,7 @@ void RTPReceiver2::SetVodEndCallback(CallBack_VodFileEnd cb, void* param) bool RTPReceiver2::Open(string channel_id, bool isUdp) { m_SipChannelId = channel_id; - m_rtp_port = allocRtpPort(); + m_rtp_port = allocRtpPort(isUdp); if (m_rtp_port < 0) { return false; } @@ -313,7 +313,7 @@ void RTPReceiver2::parseTcpData(uint8_t* recvBuf, int recvBufSize) { } } -int RTPReceiver2::allocRtpPort() { +int RTPReceiver2::allocRtpPort(bool isUdp) { WebsocketClient* pServer = WebsocketClient::getInstance(); int MIN_RTP_PORT = pServer->GetMinRtpPort() ; @@ -342,7 +342,12 @@ int RTPReceiver2::allocRtpPort() { int i = 0; for (; i < 2; i++) { sockaddr_in sRecvAddr; - int s = socket(AF_INET, SOCK_DGRAM, 0); + int s = -1; + if (isUdp) { + s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + } else { + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + } sRecvAddr.sin_family = AF_INET; sRecvAddr.sin_addr.s_addr = htonl(INADDR_ANY); diff --git a/src/decoder/gb28181/rtp2/RTPReceiver2.h b/src/decoder/gb28181/rtp2/RTPReceiver2.h index 014795b..d319150 100644 --- a/src/decoder/gb28181/rtp2/RTPReceiver2.h +++ b/src/decoder/gb28181/rtp2/RTPReceiver2.h @@ -27,7 +27,7 @@ public: void RequestStreamFailed(); - int allocRtpPort(); + int allocRtpPort(bool isUdp); public: int udp_server();