Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Receive rtp over tcp payload data code

Shulou Source: shulou.com Published: 2022-06-02 23:32:17 10月06日 Update

Scene

After the RTSP connection is established, the video data is received through rtp over tcp. The data stream obtained in the following example still has the problem of 2 RTP payloads apart, but from a byte point of view, the RTP load is very small and should not have any impact on the data.

Description

Masks RecvBuffer-> RecvBuffer (pszOneBytes, nRealReadLen, 1); the second parameter is the actual number of bytes read, and the third parameter specifies how many bytes are currently read

Code

Struct RTPHeader

{

Unsigned char szHeader [4]

}

Unsigned short sRTPPayLoadLen = 0 RTP / the length of the entire RTP message is determined by the two bytes after $0x00 | 0x01

Unsigned char cOneBytes = 0 Byte / save the first byte to determine whether it is $to determine whether it is a RTP payload packet or a RTSP instruction package

Char* pszOneBytes = (char*) & cOneBytes;// can only receive data through symbolic characters, so forced conversion is used.

Int nRealReadLen = 0 position / saved the number of bytes read each time

Int nRet = mSecretsock-> RecvBuffer (pszOneBytes, nRealReadLen, 1); / / after establishing the rtsp link, start reading the first byte

If (nRet RecvBuffer (pszOneBytes, nRealReadLen, 1)

If ((nRet RecvBuffer (pszOneBytes, nRealReadLen, 1); / / try to read the high load length

If ((nRet RecvBuffer (pszOneBytes, nRealReadLen, 1); / / attempt to read the low load length

If ((nRet 1500) continue;// data cannot exceed 1500, LAN transmission bandwidth requirements

Char szRTPPayLoadContent [1500] = {0}

NRealReadLen = 0

NRet = masked socks-> RecvBuffer (szRTPPayLoadContent, nRealReadLen, sRTPPayLoadLen)

RTPHeader* pHeader = (RTPHeader*) szRTPPayLoadContent

Unsigned short sRTPSeq = (pHeader- > szHeader [2] szHeader [3])

/ / std::cout

Tags: Data byte length message two low parameter or high try loop code valid three number example information just scene multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia Shulou Technology OPPO Reno Redmi